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; }
public static void ForwardTransform(FFTW.DoubleArray input, FFTW.ComplexArray output) { IntPtr plan = FFTW.dft_r2c_1d(input.Length, input.Handle, output.Handle, Flags.Estimate); //FFTW.print_plan(plan); FFTW.execute(plan); FFTW.destroy_plan(plan); }
public static void BackwardTransform(FFTW.ComplexArray input, FFTW.DoubleArray output) { // TODO: make sure to use input.Length and not the output.Length ?! IntPtr plan = FFTW.dft_c2r_1d(input.Length, input.Handle, output.Handle, Flags.Estimate); //FFTW.print_plan(plan); FFTW.execute(plan); FFTW.destroy_plan(plan); }
private static double GetComponentWeightCenter(List<double[]> a, int size, int component) { double[] windowedValues = a.GetWindowedDimension(component, size, HannWindow); FFTW.DoubleArray fftwInput = new FFTW.DoubleArray(windowedValues); FFTW.ComplexArray fftwOutput = new FFTW.ComplexArray((size >> 1) + 1); FFTW.ForwardTransform(fftwInput, fftwOutput); return fftwOutput.Values.GetWeightCenter(); }
private static double GetComponentWeightCenter(List <double[]> a, int size, int component) { double[] windowedValues = a.GetWindowedDimension(component, size, HannWindow); FFTW.DoubleArray fftwInput = new FFTW.DoubleArray(windowedValues); FFTW.ComplexArray fftwOutput = new FFTW.ComplexArray((size >> 1) + 1); FFTW.ForwardTransform(fftwInput, fftwOutput); return(fftwOutput.Values.GetWeightCenter()); }
public static void FFTWTestUsingDouble(string CSVFilePath=null, double[] audio_data=null, int testLoopCount=1) { if (audio_data == null) { audio_data = GetSignalTestData(); } // prepare the input arrays FFTW.DoubleArray fftwInput = new FFTW.DoubleArray(audio_data); int complexSize = (audio_data.Length >> 1) + 1; FFTW.ComplexArray fftwOutput = new FFTW.ComplexArray(complexSize); // loop if neccesary - e.g. for performance test purposes for (int i = 0; i < testLoopCount; i++) { // perform the FFT FFTW.ForwardTransform(fftwInput, fftwOutput); } // get the result double[] spectrum_fft_real = fftwOutput.Real; double[] spectrum_fft_imag = fftwOutput.Imag; double[] spectrum_fft_abs = fftwOutput.Abs; // prepare the input arrays FFTW.ComplexArray fftwBackwardInput = new FFTW.ComplexArray(spectrum_fft_real, spectrum_fft_imag); FFTW.DoubleArray fftwBackwardOutput = new FFTW.DoubleArray(audio_data.Length); // perform the inverse FFT (IFFT) FFTW.BackwardTransform(fftwBackwardInput, fftwBackwardOutput); // get the result double[] spectrum_inverse_real = fftwBackwardOutput.ValuesDivedByN; // pad for output if (spectrum_fft_real.Length != audio_data.Length) Array.Resize(ref spectrum_fft_real, audio_data.Length); if (spectrum_fft_imag.Length != audio_data.Length) Array.Resize(ref spectrum_fft_imag, audio_data.Length); if (spectrum_fft_abs.Length != audio_data.Length) Array.Resize(ref spectrum_fft_abs, audio_data.Length); if (CSVFilePath!=null) { CommonUtils.Export.exportCSV(CSVFilePath, audio_data, spectrum_fft_real, spectrum_fft_imag, spectrum_fft_abs, spectrum_inverse_real); } }