Example #1
0
        private void NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            //FFT
            var freq = FFTMethod.ProcessThread(eventArgs.Signal.ToFloat(), eventArgs.Signal.SampleRate, MinFreq, MaxFreq);

            ShowFreq(freq);
            //Accord
            //ComplexSignal complexSignal = ComplexSignal.FromSignal(eventArgs.Signal);
            //complexSignal.ForwardFourierTransform();
            //Complex[] channel = complexSignal.GetChannel(0);//хз почему, но channel 0 дает лучше результат
            //double[] powerSpectrum = Tools.GetPowerSpectrum(channel);
            //double[] frequencyVector = Tools.GetFrequencyVector(complexSignal.Length, complexSignal.SampleRate);
            //powerSpectrum[0] = 0.0;
            //ShowFreq(frequencyVector[powerSpectrum.GetIndexOfMax()]);
        }
        /// <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();
        }
Example #3
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();
		}
Example #4
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();
    }
Example #5
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();
    }
Example #6
0
 protected override void ProcessData(Single[] data)
 {
     //_form.ShowFreq(FrequencyUtil.DetectPitch(data, SampleRate, MinFreq, MaxFreq));
     _form.ShowFreq(FFTMethod.ProcessThread(data, SampleRate, MinFreq, MaxFreq));
 }