Beispiel #1
0
 public double[] BackwardTransform(Complex[] mas)
 {
     mas = GetArrayInRightOrder(FFT(mas, false));
     
     var results = new double[mas.Count()];
     for (int i = 0; i < results.Length; i++ )
     {
         results[i] = mas[i].Real/results.Length;
     }
     
     return results;
 }
Beispiel #2
0
        private Complex[] FFT(Complex[] mas, bool isForward)
        {
            int N = mas.Count();

            Complex Wn = CalculateWn(isForward, N);
            int k = mas.Length;
            var y = new Complex[k];
            var W = new Complex(1, 0);
            for (int j = 0; j < k / 2; j++)
            {
                y[j] = mas[j] + mas[j + k / 2];
                y[j + k / 2] = W * (mas[j] - mas[j + k / 2]);
                W = W * Wn;
            }

            var mas11 = new Complex[N / 2];
            var mas22 = new Complex[N / 2];
            for (int i = 0; i < N / 2; i++ )
            {
                mas11[i] = y[i];
                mas22[i] = y[i + N / 2];
            }

            if (N > 2)
            {
                mas11 = FFT(mas11, isForward);
                mas22 = FFT(mas22, isForward);
            }

            var masRes = new Complex[N];
            for (int i = 0; i < N / 2; i ++ )
            {
                masRes[i] = mas11[i];
                masRes[i + N / 2] = mas22[i];
            }

            return masRes;
        }
Beispiel #3
0
 private Complex[] ButterflyMethod(Complex[] a, bool isForward)
 {
     Complex Wn = CalculateWn(isForward, a.Count());
     int k = a.Length;
     var y = new Complex[k];
     var W = new Complex(1, 0);
     for(int j = 0; j < k / 2; j++)
     {
         y[j] = a[j] + a[j + k / 2];
         y[j + k / 2] = W * (a[j] - a[j + k / 2]);
         W = W * Wn;
     }
     return y;
 }
                    public IIR_Spectrum_Objective(int Filter_Order, Complex[] BasisSpectrum, int samplingFrequency)
                    {
                        //Find all local maxima (within 10 points)
                        List<int> maxima = new List<int>();
                        freq = new double[BasisSpectrum.Length];
                        for (int i = 10; i < BasisSpectrum.Length-10; i++)
                        {
                            bool max = true;
                            for (int s = -10; s < 10; s++)
                            {
                                if (BasisSpectrum[i].Real < BasisSpectrum[i + s].Real)
                                {
                                    max = false;
                                    continue;
                                }
                            }
                            if (max) maxima.Add(i);
                        }

                        fs = samplingFrequency;

                        for (int i = 0; i < freq.Length; i++) freq[i] = (double)(i * samplingFrequency) / freq.Length;

                        pole_phase = new double[maxima.Count];
                        for (int i = 0; i < maxima.Count; i++) pole_phase[i] = 2 * Math.PI * maxima[i] / BasisSpectrum.Count();

                        if (Filter_Order < maxima.Count * 2) Filter_Order = maxima.Count * 2;

                        pzct = Filter_Order;
                        pno_conj = (int)Math.Floor((double)pzct / 2);
                        pno_conj_phase = (int)Math.Floor((double)pzct / 2 - maxima.Count());
                        pno_real = pzct % 2;
                        zno_real = pzct;
                        Spectrum = BasisSpectrum;
                        n = BasisSpectrum.Length;
                        fs = samplingFrequency;
                        sampled = new int[24];
                        sel_Spectrum = new Complex[24];
                        sel_freq = new double[24];
                        abs = new Complex[24];

                        for (int i = 0; i < 24; i++)
                        {
                            double f = 24.803 * Math.Pow(2, (double)i/3);
                            sampled[i] = (int)(f * 2 * BasisSpectrum.Length / samplingFrequency);
                            sel_Spectrum[i] = Spectrum[sampled[i]];
                            abs[i] = AbsorptionModels.Operations.Absorption_Coef(sel_Spectrum[i]);
                            sel_freq[i] = freq[sampled[i]];
                        }
                    }