Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.Clear();
            double[]         real  = new double[512];
            double[]         imag  = new double[512];
            double[]         mag   = new double[512];
            double[]         phase = new double[512];
            Lomont.LomontFFT lom   = new Lomont.LomontFFT();
            double[]         data  = new double[1024];
            lom.A = 1;
            lom.B = -1;

            for (int i = 0; i < 1024; i++)
            {
                data[i] = 30 * Math.Cos(2 * Math.PI * i / 16 + 3 * Math.PI / 2);
            }


            lom.RealFFT(data, true);
            for (int i = 0; i < 512; i++)
            {
                real[i] = data[2 * i];
                imag[i] = data[2 * i + 1];
            }
            for (int i = 0; i < 512; i++)
            {
                mag[i]   = Math.Round(Math.Sqrt(Math.Pow(real[i], 2) + Math.Pow(imag[i], 2)) / 1024);
                phase[i] = Math.Round(Math.Atan2(imag[i], real[i]) * 180 / Math.PI);
            }
            for (int i = 0; i < 512; i++)
            {
                Console.WriteLine(i + ".    " + "mag: " + mag[i] + "   phase: " + phase[i]);
            }
        }
Ejemplo n.º 2
0
Archivo: Fft.cs Proyecto: Faham/emophiz
        public static Complex[] ConvertToFreq(double[] timeData)
        {
            //Get the size of next power of 2
            int length = timeData.Length;
            int root = (int)Math.Log(length, 2);
            root += 1;
            int paddedLength = (int)Math.Pow(2, root);

            //Create an array that is a power of 2 and copy the values over.
            //Pad the end of the array with zeros
            double[] paddedData = new double[paddedLength];
            for(int i=0; i<paddedLength; i++)
            {
                if(i < length)
                    paddedData[i] = timeData[i];
                else
                    paddedData[i] = 0;
            }

            //Do the FFT
            Lomont.LomontFFT lomontFft = new Lomont.LomontFFT();
            lomontFft.RealFFT(paddedData, true);

            //Convert everything to the complex data type
            Complex[] freqData = new Complex[paddedLength / 2];
            for (int i = 0; i < freqData.Length; i++)
            {
                freqData[i] = new Complex(paddedData[i], paddedData[i + 1]);
            }

            return freqData;
        }
        internal FindSimilarSpectrumService(SpectrogramConfig configuration, ILogUtility logUtility)
        {
            this.logUtility = logUtility;

            this.lomontFFT = new Lomont.LomontFFT();
            lomontFFT.A    = 1;
            lomontFFT.B    = 1;
            lomontFFT.Initialize(configuration.WdftSize);
        }
Ejemplo n.º 4
0
        }         //FitBufferSize

        public static double[,] Perform(double[] real, int smallerSize, int shift)
        {
            if (smallerSize > real.Length)
            {
                smallerSize = real.Length;
            }
            double[] shortened = new double[smallerSize];
            Array.Copy(real, shift, shortened, 0, smallerSize);
            var LomontArray = CreateLomontArray(shortened);
            var fft         = new Lomont.LomontFFT();

            fft.FFT(LomontArray, true);
            var split = SplitIntoComplex(LomontArray);
            var max   = NormalizeArray(split);

            convertToAmplitudePhase(split);
            return(split);
        }         //Perform
Ejemplo n.º 5
0
        public BandPassFilter(int bufferSize, double sampleRate)
        {
            if (!IsPositivePowerOfTwo(bufferSize))
            {
                throw new ArgumentException("Must be positive power of 2", nameof(bufferSize));
            }

            _lowBand    = -1;
            _hiBand     = -1;
            _bufferSize = bufferSize;
            _sampleRate = sampleRate;
            _fft        = new Lomont.LomontFFT
            {
                A = 1,
                B = -1
            };

            _spectrumComplexBuffer = new double[2 * _bufferSize];
            _spectrumBuffer        = new double[_bufferSize / 2];
        }
Ejemplo n.º 6
0
        public BandPassFilter(int fftSize, double sampleRate)
        {
            if (!IsPositivePowerOfTwo(fftSize))
            {
                throw new ArgumentException("Must be positive power of 2", nameof(fftSize));
            }

            _lowBand    = -1;
            _hiBand     = -1;
            _fftSize    = fftSize;
            _sampleRate = sampleRate;
            _fft        = new Lomont.LomontFFT
            {
                A = 1,
                B = -1
            };

            // double the size for the imaginary part
            _spectrumComplexBuffer = new double[2 * _fftSize];
            // in an FFT, the bottom half is the valid spectrum
            _spectrumBuffer = new double[_fftSize / 2];
        }
Ejemplo n.º 7
0
        public static void FindPhaseByFFT(IEnumerable<double> inputSignal, double sampelingFrequency, double baseFrequency)
        {
            Lomont.LomontFFT x = new Lomont.LomontFFT();
            double[] pow2array = new double[1024];
            for (double i = 0; i < 1024; i++)
            {
                pow2array[(int) i] = Math.Cos(i * 250e3 / (2 * Math.PI));
            }
            double a1, a2;
            a1 = pow2array[10];
            x.RealFFT(pow2array, true);
            a2 = pow2array[10];
            //x.FFTPhaseFinder()

            a2 = pow2array[10];
        }