Ejemplo n.º 1
0
        public static complex[] dft(double[] signal, int n)  //(信号,信号长度)
        {
            int     i, j;
            complex w1;

            w1 = omega(n);
            complex[] w = new complex[n];
            for (i = 0; i < n; i++)
            {
                w[i] = complex.powcc(w1, i);
            }
            complex[] f = new complex[n];
            complex   temp;  //w[i]的次方
            complex   temp1; //f中单项的值

            for (i = 0; i < n; i++)
            {
                f[i].a = 0;
                f[i].b = 0;
                for (j = 0; j < n; j++)
                {
                    temp  = complex.powcc(w[i], j);
                    temp1 = complex.commul(signal[j], temp);
                    f[i]  = complex.comsum(f[i], temp1);
                }
            }
            return(f);
        }
Ejemplo n.º 2
0
        public static complex decrease(complex x, complex y)
        {
            complex c = new complex();

            c.a = x.a * y.a - x.b * y.b;
            c.b = x.a * y.b + x.b * y.a;

            return(c);
        }
Ejemplo n.º 3
0
        public static complex comsum1(double x, complex y)
        {
            complex c = new complex();

            c.a = x + y.a;
            c.b = y.b;

            return(c);
        }
Ejemplo n.º 4
0
        public static complex comsum(complex x, complex y)
        {
            complex c = new complex();

            c.a = x.a + y.a;
            c.b = x.b + y.b;

            return(c);
        }
Ejemplo n.º 5
0
        public static complex commul(double x, complex y)
        {
            complex c = new complex();

            c.a = x * y.a;
            c.b = x * y.b;

            return(c);
        }
Ejemplo n.º 6
0
        public static complex powcc(complex x, double n)
        {
            int     k;
            complex xout;

            xout.a = 1;
            xout.b = 0;
            for (k = 1; k <= n; k++)
            {
                xout = complex.commulcc(xout, x);
            }
            return(xout);
        }
Ejemplo n.º 7
0
        private void show_ADCdata_fft()
        {
            ZoomToggle(chart4, true);
            float Fs = 1 / float.Parse(dtADC.Rows[1]["Time(s)"].ToString());

            double[] x = get_data_colomn(dtADC, "ADC(V)").ToArray();
            int      n = x.Length;

            double[] freqs = new Double[n / 2];
            for (int i = 0; i < freqs.Length; i++)
            {
                freqs[i] = Fs * i * 0.5 / freqs.Length;
            }
            complex[] y = new complex[n]; //接收复数结果的数组
            double[]  z = new Double[n];  //接收幅值结果的数组
            y = airthm.dft(x, n);
            z = airthm.amplitude(y, n);
            double[] z_half = new Double[n / 2];
            Array.ConstrainedCopy(z, 0, z_half, 0, n / 2);
            chart4.Series["Series1"].Points.DataBindXY(freqs, z_half);
        }