private void Checkbox_Click_1(object sender, RoutedEventArgs e) { CheckBox checkbox = (CheckBox)sender; int index = (int)checkbox.Tag; if (checkbox.IsChecked == true) { _frequencyDomainLinkedToCheckboxes[index] = new Complex(); } else { _frequencyDomainLinkedToCheckboxes[index] = _frequencyDomain[index]; } FFTW fftw = new FFTW(); _ret = fftw.Backward(_frequencyDomainLinkedToCheckboxes); DataSeries <double, double> points = new DataSeries <double, double>("Data"); for (int c = 0; c < _ret.Length; c++) { points.Add(new DataPoint <double, double> { X = c, Y = _ret[c] }); } dataChart.Series[0].DataSeries = points; }
public static Complex[] padded_FFT(ref double[] @in) { Debug.Assert(@in.Length > 0); int n = @in.Length; int padded = n > 256 ? Util.NextLowPrimes(n) : n; Array.Resize <double>(ref @in, padded); // 4096 real numbers on input processed by FFTW dft_r2c_1d transform gives // 4096/2+1 = 2049 complex numbers at output // prepare the input arrays var fftwInput = new FFTW.DoubleArray(@in); int complexSize = (padded >> 1) + 1; // this is the same as (padded / 2 + 1); var fftwOutput = new FFTW.ComplexArray(complexSize); FFTW.ForwardTransform(fftwInput, fftwOutput); Array.Resize <double>(ref @in, n); // free up memory GC.Collect(); return(FFTUtils.ComplexDoubleToComplex(fftwOutput.ComplexValues)); }
private double[] MagnitudeSpectrum(float[] frame) { // prepare the input arrays FFTW.DoubleArray fftwInput = new FFTW.DoubleArray(MathUtils.FloatToDouble(frame)); int complexSize = (frame.Length >> 1) + 1; FFTW.ComplexArray fftwOutput = new FFTW.ComplexArray(complexSize); FFTW.ForwardTransform(fftwInput, fftwOutput); double[] magSpectrum = fftwOutput.Abs; /* * double[] magSpectrum = new double[frame.Length]; * * // calculate FFT for current frame * fft.ComputeFFT(frame); * * // System.err.println("FFT SUCCEED"); * // calculate magnitude spectrum * for (int k = 0; k < frame.Length; k++) * { * magSpectrum[k] = Math.Sqrt(fft.real[k] * fft.real[k] + fft.imag[k] * fft.imag[k]); * } */ return(magSpectrum); }
private void Button_Click_1(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == true) { TextBox_InputName.Text = ofd.FileName; FFTW fftw = new FFTW(); _input = DataLoader.Load(ofd.FileName); double[] inputCopy = new double[_input.Length]; _input.CopyTo(inputCopy, 0); _frequencyDomain = fftw.Forward(inputCopy); _frequencyDomainLinkedToCheckboxes = new Complex[_frequencyDomain.Length]; _frequencyDomain.CopyTo(_frequencyDomainLinkedToCheckboxes, 0); DataSeries <double, double> points = new DataSeries <double, double>("Magnitudes"); TheList = new ObservableCollection <CheckBoxBinder>(); List <CheckBoxBinder> mags = new List <CheckBoxBinder>(); for (int c = 0; c < _frequencyDomain.Length; c++) { points.Add(new DataPoint <double, double> { X = c, Y = _frequencyDomain[c].Magnitude }); mags.Add(new CheckBoxBinder { TheValue = _frequencyDomain[c].Magnitude, Index = c }); } foreach (CheckBoxBinder d in mags.OrderByDescending(m => m.TheValue)) { TheList.Add(d); } exampleChart.Series[0].DataSeries = points; this.DataContext = this; DataSeries <double, double> data = new DataSeries <double, double>("Data"); for (int c = 0; c < _input.Length; c++) { data.Add(new DataPoint <double, double> { X = c, Y = _input[c] }); } dataChart.Series[0].DataSeries = data; return; } }
public double[] Process(double[] data, int maxToProcess) { double[] output = null; if (data.Length > 0) { double smallest = data.Min(); double largest = data.Max(); FFTW fftw = new FFTW(); output = fftw.Process(data, maxToProcess); } return output; }
public double[] Process(double[] data, int maxToProcess) { double[] output = null; if (data.Length > 0) { double smallest = data.Min(); double largest = data.Max(); FFTW fftw = new FFTW(); output = fftw.Process(data, maxToProcess); } return(output); }
private void Button_Click_1(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == true) { TextBox_InputName.Text = ofd.FileName; FFTW fftw = new FFTW(); _input = DataLoader.Load(ofd.FileName); double[] inputCopy = new double[_input.Length]; _input.CopyTo(inputCopy, 0); _frequencyDomain = fftw.Forward(inputCopy); _frequencyDomainLinkedToCheckboxes = new Complex[_frequencyDomain.Length]; _frequencyDomain.CopyTo(_frequencyDomainLinkedToCheckboxes, 0); DataSeries<double, double> points = new DataSeries<double, double>("Magnitudes"); TheList = new ObservableCollection<CheckBoxBinder>(); List<CheckBoxBinder> mags = new List<CheckBoxBinder>(); for (int c = 0; c < _frequencyDomain.Length; c++) { points.Add(new DataPoint<double, double> { X = c, Y = _frequencyDomain[c].Magnitude }); mags.Add(new CheckBoxBinder { TheValue = _frequencyDomain[c].Magnitude, Index = c }); } foreach (CheckBoxBinder d in mags.OrderByDescending(m => m.TheValue)) { TheList.Add(d); } exampleChart.Series[0].DataSeries = points; this.DataContext = this; DataSeries<double, double> data = new DataSeries<double, double>("Data"); for (int c = 0; c < _input.Length; c++) { data.Add(new DataPoint<double, double> { X = c, Y = _input[c] }); } dataChart.Series[0].DataSeries = data; return; } }
public static double[] padded_IFFT(ref Complex[] @in, bool doProperScaling = false) { Debug.Assert(@in.Length > 1); int originalLength = @in.Length; int n = (@in.Length - 1) * 2; int padded = n > 256 ? Util.NextLowPrimes(n) : n; Array.Resize <Complex>(ref @in, padded / 2 + 1); // prepare the input arrays var complexDouble = FFTUtils.ComplexToComplexDouble(@in); var fftwBackwardInput = new FFTW.ComplexArray(complexDouble); var fftwBackwardOutput = new FFTW.DoubleArray(padded); // this method needs that the backwards transform uses the output.length as it's N // i.e. FFTW.dft_c2r_1d(output.Length, input.Handle, output.Handle, Flags.Estimate); FFTW.BackwardTransform(fftwBackwardInput, fftwBackwardOutput); double[] @out = null; if (doProperScaling) { @out = fftwBackwardOutput.ValuesDivedByN; } else { // in the original method it wasn't scaled correctly (meaning ValuesDivedByN) @out = fftwBackwardOutput.Values; } Array.Resize <Complex>(ref @in, n / 2 + 1); // free up memory GC.Collect(); return(@out); }
private void Checkbox_Click_1(object sender, RoutedEventArgs e) { CheckBox checkbox = (CheckBox)sender; int index = (int)checkbox.Tag; if (checkbox.IsChecked == true) { _frequencyDomainLinkedToCheckboxes[index] = new Complex(); } else { _frequencyDomainLinkedToCheckboxes[index] = _frequencyDomain[index]; } FFTW fftw = new FFTW(); _ret = fftw.Backward(_frequencyDomainLinkedToCheckboxes); DataSeries<double, double> points = new DataSeries<double, double>("Data"); for (int c = 0; c < _ret.Length; c++) { points.Add(new DataPoint<double, double> { X = c, Y = _ret[c] }); } dataChart.Series[0].DataSeries = points; }