예제 #1
0
        //Complex->Real
        public static fftw_plan dft_c2r_1d(int n, fftw_complexarray input, fftw_complexarray output, fftw_direction direction, fftw_flags flags)
        {
            fftw_plan p = new fftw_plan();

            p.handle = fftw.dft_c2r_1d(n, input.Handle, output.Handle, (uint)flags);
            return(p);
        }
예제 #2
0
        //Real<->Real
        public static fftw_plan r2r_1d(int n, fftw_complexarray input, fftw_complexarray output, fftw_kind kind, fftw_flags flags)
        {
            fftw_plan p = new fftw_plan();

            p.handle = fftw.r2r_1d(n, input.Handle, output.Handle, (int)kind, (uint)flags);
            return(p);
        }
예제 #3
0
        public static fftw_plan dft_r2c(int rank, int[] n, fftw_complexarray input, fftw_complexarray output, fftw_flags flags)
        {
            fftw_plan p = new fftw_plan();

            p.handle = fftw.dft_r2c(rank, n, input.Handle, output.Handle, (uint)flags);
            return(p);
        }
예제 #4
0
        public static fftw_plan dft_r2c_2d(int nx, int ny, fftw_complexarray input, fftw_complexarray output, fftw_flags flags)
        {
            var p = new fftw_plan();

            p.handle = fftw.dft_r2c_2d(nx, ny, input.Handle, output.Handle, flags);
            return(p);
        }
예제 #5
0
        //Real->Complex transforms
        public static fftw_plan dft_r2c_1d(int n, fftw_complexarray input, fftw_complexarray output, fftw_flags flags)
        {
            fftw_plan p = new fftw_plan();

            p.handle = fftw.dft_r2c_1d(n, input.Handle, output.Handle, flags);
            return(p);
        }
예제 #6
0
        public static fftw_plan dft_c2r_3d(int nx, int ny, int nz, fftw_complexarray input, fftw_complexarray output, fftw_direction direction, fftw_flags flags)
        {
            var p = new fftw_plan();

            p.handle = fftw.dft_c2r_3d(nx, ny, nz, input.Handle, output.Handle, flags);
            return(p);
        }
예제 #7
0
        public static fftw_plan dft_r2c_3d(int nx, int ny, int nz, fftw_complexarray input, fftw_complexarray output, fftw_flags flags)
        {
            fftw_plan p = new fftw_plan();

            p.handle = fftw.dft_r2c_3d(nx, ny, nz, input.Handle, output.Handle, (uint)flags);
            return(p);
        }
예제 #8
0
        public static fftw_plan dft_c2r(int rank, int[] n, fftw_complexarray input, fftw_complexarray output, fftw_direction direction, fftw_flags flags)
        {
            var p = new fftw_plan();

            p.handle = fftw.dft_c2r(rank, n, input.Handle, output.Handle, flags);
            return(p);
        }
예제 #9
0
        public static fftw_plan r2r_2d(int nx, int ny, fftw_complexarray input, fftw_complexarray output, fftw_kind kindx, fftw_kind kindy, fftw_flags flags)
        {
            var p = new fftw_plan();

            p.handle = fftw.r2r_2d(nx, ny, input.Handle, output.Handle, kindx, kindy, flags);
            return(p);
        }
예제 #10
0
        public static fftw_plan r2r_3d(int nx, int ny, int nz, fftw_complexarray input, fftw_complexarray output,
                                       fftw_kind kindx, fftw_kind kindy, fftw_kind kindz, fftw_flags flags)
        {
            fftw_plan p = new fftw_plan();

            p.handle = fftw.r2r_3d(nx, ny, nz, input.Handle, output.Handle,
                                   (int)kindx, (int)kindy, (int)kindz, (uint)flags);
            return(p);
        }
예제 #11
0
        public static fftw_plan r2r(int rank, int[] n, fftw_complexarray input, fftw_complexarray output,
                                    fftw_kind[] kind, fftw_flags flags)
        {
            var p = new fftw_plan();

            p.handle = fftw.r2r(rank, n, input.Handle, output.Handle,
                                kind, flags);
            return(p);
        }
예제 #12
0
		/// <summary>
		/// Perform the Fast Fourier Transform utilisizing the FFTW library
		/// </summary>
		/// <param name="in">Input Signal</param>
		/// <param name="out">Output Signal</param>
		/// <param name="N">N</param>
		/// <param name="method">FFT Method (DFT, IDFT, DHT)</param>
		public static void FFT(ref double[] @in, ref double[] @out, int N, FFTMethod method)
		{
			var complexInput = new fftw_complexarray(@in);
			var complexOutput = new fftw_complexarray(@out);
			
			switch(method) {
				case FFTMethod.DFT:
					// fftw_kind.R2HC: input is expected to be real while output is returned in the halfcomplex format
					fftw_plan fft = fftw_plan.r2r_1d(N, complexInput, complexOutput, fftw_kind.R2HC, fftw_flags.Estimate);
					fft.Execute();
					@out = complexOutput.Values;
					
					// free up memory
					fft = null;
					break;
				case FFTMethod.IDFT:
					// fftw_kind.HC2R: input is expected to be halfcomplex format while output is returned as real
					fftw_plan ifft = fftw_plan.r2r_1d(N, complexInput, complexOutput, fftw_kind.HC2R, fftw_flags.Estimate);
					ifft.Execute();
					//@out = complexOutput.ValuesDividedByN; // dividing by N gives the correct scale
					@out = complexOutput.Values;

					// free up memory
					ifft = null;
					break;
				case FFTMethod.DHT:
					fftw_plan dht = fftw_plan.r2r_1d(N, complexInput, complexOutput, fftw_kind.DHT, fftw_flags.Estimate);
					dht.Execute();
					@out = complexOutput.Values;

					// free up memory
					dht = null;
					break;
			}

			// free up memory
			complexInput = null;
			complexOutput = null;
			GC.Collect();
		}
예제 #13
0
        public static fftw_plan r2r_3d(int nx, int ny, int nz, fftw_complexarray input, fftw_complexarray output,
		                               fftw_kind kindx, fftw_kind kindy, fftw_kind kindz, fftw_flags flags)
        {
            fftw_plan p = new fftw_plan();
            p.handle = fftw.r2r_3d(nx, ny, nz, input.Handle, output.Handle,
                                   kindx, kindy, kindz, flags);
            return p;
        }
예제 #14
0
 //Real<->Real
 public static fftw_plan r2r_1d(int n, fftw_complexarray input, fftw_complexarray output, fftw_kind kind, fftw_flags flags)
 {
     fftw_plan p = new fftw_plan();
     p.handle = fftw.r2r_1d(n, input.Handle, output.Handle, kind, flags);
     return p;
 }
예제 #15
0
        public static fftw_plan r2r(int rank, int[] n, fftw_complexarray input, fftw_complexarray output,
		                            fftw_kind[] kind, fftw_flags flags)
        {
            fftw_plan p = new fftw_plan();
            p.handle = fftw.r2r(rank, n, input.Handle, output.Handle,
                                kind, flags);
            return p;
        }
예제 #16
0
 public static fftw_plan dft_r2c_3d(int nx, int ny, int nz, fftw_complexarray input, fftw_complexarray output, fftw_flags flags)
 {
     fftw_plan p = new fftw_plan();
     p.handle = fftw.dft_r2c_3d(nx, ny, nz, input.Handle, output.Handle, flags);
     return p;
 }
예제 #17
0
 public static fftw_plan dft_r2c(int rank, int[] n, fftw_complexarray input, fftw_complexarray output, fftw_flags flags)
 {
     fftw_plan p = new fftw_plan();
     p.handle = fftw.dft_r2c(rank, n, input.Handle, output.Handle, flags);
     return p;
 }
예제 #18
0
 public static fftw_plan dft_c2r_2d(int nx, int ny, fftw_complexarray input, fftw_complexarray output, fftw_direction direction, fftw_flags flags)
 {
     fftw_plan p = new fftw_plan();
     p.handle = fftw.dft_c2r_2d(nx, ny, input.Handle, output.Handle, flags);
     return p;
 }
예제 #19
0
    /// <summary>
    /// Perform the Fast Fourier Transform utilisizing the FFTW library
    /// </summary>
    /// <param name="in">Input Signal</param>
    /// <param name="out">Output Signal</param>
    /// <param name="N">N</param>
    /// <param name="method">FFT Method (DFT, IDFT, DHT)</param>
    public static void FFT(ref double[] @in, ref double[] @out, int N, FFTMethod method)
    {
        fftw_complexarray complexInput = new fftw_complexarray(@in);
        fftw_complexarray complexOutput = new fftw_complexarray(@out);

        switch(method) {
            case FFTMethod.DFT:
                fftw_plan fft = fftw_plan.r2r_1d(N, complexInput, complexOutput, fftw_kind.R2HC, fftw_flags.Estimate);
                fft.Execute();
                @out = complexOutput.Values;

                // free up memory
                fft = null;
                break;
            case FFTMethod.IDFT:
                fftw_plan ifft = fftw_plan.r2r_1d(N, complexInput, complexOutput, fftw_kind.HC2R, fftw_flags.Estimate);
                ifft.Execute();
                @out = complexOutput.ValuesDividedByN;

                // free up memory
                ifft = null;
                break;
            case FFTMethod.DHT:
                fftw_plan dht = fftw_plan.r2r_1d(N, complexInput, complexOutput, fftw_kind.DHT, fftw_flags.Estimate);
                dht.Execute();
                @out = complexOutput.Values;

                // free up memory
                dht = null;
                break;
        }

        // free up memory
        complexInput = null;
        complexOutput = null;
        GC.Collect();
    }
예제 #20
0
        /// <summary>
        /// Generate a spectrogram array spaced linearily
        /// </summary>
        /// <param name="samples">audio data</param>
        /// <param name="fftWindowsSize">fft window size</param>
        /// <param name="fftOverlap">overlap in number of samples (normaly half of the fft window size) [low number = high overlap]</param>
        /// <returns>spectrogram jagged array</returns>
        public static float[][] CreateSpectrogramFFTWLIB(float[] samples, int fftWindowsSize, int fftOverlap)
        {
            int numberOfSamples = samples.Length;

            // overlap must be an integer smaller than the window size
            // half the windows size is quite normal
            double[] windowArray = FFTWindowFunctions.GetWindowFunction(FFTWindowFunctions.HANNING, fftWindowsSize);

            // width of the segment - e.g. split the file into 78 time slots (numberOfSegments) and do analysis on each slot
            int numberOfSegments = (numberOfSamples - fftWindowsSize)/fftOverlap;
            float[][] frames = new float[numberOfSegments][];

            // even - Re, odd - Img
            double[] complexSignal = new double[2*fftWindowsSize];
            for (int i = 0; i < numberOfSegments; i++)
            {
                // apply Hanning Window
                for (int j = 0; j < fftWindowsSize; j++)
                {
                    // Weight by Hann Window
                    complexSignal[2*j] = (double) (windowArray[j] * samples[i * fftOverlap + j]);

                    // need to clear out as fft modifies buffer (phase)
                    complexSignal[2*j + 1] = 0;
                }

                // prepare the input arrays
                fftw_complexarray complexInput = new fftw_complexarray(complexSignal);
                fftw_complexarray complexOutput = new fftw_complexarray(complexSignal.Length/2);
                fftw_plan fft = fftw_plan.dft_1d(complexSignal.Length/2, complexInput, complexOutput, fftw_direction.Forward, fftw_flags.Estimate);

                // perform the FFT
                fft.Execute();

                // get the result
                float[] band = MathUtils.DoubleToFloat(complexOutput.Abs);
                frames[i] = band;

                // free up memory
                complexInput = null;
                complexOutput = null;
                //GC.Collect();
            }
            return frames;
        }
예제 #21
0
        public static void FFTWTestUsingDoubleFFTWLIB(string CSVFilePath=null, double[] audio_data=null, int testLoopCount=1)
        {
            if (audio_data == null) {
                audio_data = GetSignalTestData();
            }

            // prepare the input arrays
            double[] complexSignal = FFTUtils.DoubleToComplexDouble(audio_data);
            fftw_complexarray complexInput = new fftw_complexarray(complexSignal);
            fftw_complexarray complexOutput = new fftw_complexarray(audio_data.Length);
            fftw_plan fft = fftw_plan.dft_1d(audio_data.Length, complexInput, complexOutput, fftw_direction.Forward, fftw_flags.Estimate);

            // loop if neccesary - e.g. for performance test purposes
            for (int i = 0; i < testLoopCount; i++) {
                // perform the FFT
                fft.Execute();
            }

            // get the result
            double[] spectrum_fft_real = complexOutput.Real;
            double[] spectrum_fft_imag = complexOutput.Imag;
            double[] spectrum_fft_abs = complexOutput.Abs;

            // perform the inverse FFT (IFFT)
            fftw_complexarray complexOutput2 = new fftw_complexarray(audio_data.Length);
            fftw_plan ifft = fftw_plan.dft_1d(audio_data.Length, complexOutput, complexOutput2, fftw_direction.Backward, fftw_flags.Estimate);

            // perform the IFFT
            ifft.Execute();

            // get the result
            double[] spectrum_inverse_real = complexOutput2.RealDividedByN;
            double[] spectrum_inverse_imag = complexOutput2.ImagDividedByN;
            double[] spectrum_inverse_abs = complexOutput2.AbsDividedByN;

            if (CSVFilePath!=null) {
                CommonUtils.Export.exportCSV(CSVFilePath, audio_data, spectrum_fft_real, spectrum_fft_imag, spectrum_fft_abs, spectrum_inverse_real, spectrum_inverse_imag, spectrum_inverse_abs);
            }
        }
예제 #22
0
 public static fftw_plan dft_c2r(int rank, int[] n, fftw_complexarray input, fftw_complexarray output, fftw_direction direction, fftw_flags flags)
 {
     fftw_plan p = new fftw_plan();
     p.handle = fftw.dft_c2r(rank, n, input.Handle, output.Handle, (uint)flags);
     return p;
 }
예제 #23
0
 //Real->Complex transforms
 public static fftw_plan dft_r2c_1d(int n, fftw_complexarray input, fftw_complexarray output, fftw_flags flags)
 {
     fftw_plan p = new fftw_plan();
     p.handle = fftw.dft_r2c_1d(n, input.Handle, output.Handle, (uint)flags);
     return p;
 }