Exemple #1
0
        public static complex[] FFT(complex[] x)
        {
            int N = x.Length;

            complex[] X = new complex[N];
            complex[] d, D, e, E;
            if (N == 1)
            {
                X[0] = x[0];
                return(X);
            }
            int k;

            e = new complex[N / 2];
            d = new complex[N / 2];
            for (k = 0; k < N / 2; k++)
            {
                e[k] = x[2 * k];
                d[k] = x[2 * k + 1];
            }
            D = FFT(d);
            E = FFT(e);
            for (k = 0; k < N / 2; k++)
            {
                complex temp = complex.from_polar(1, -2 * Math.PI * k / N);
                D[k] *= temp;
            }
            for (k = 0; k < N / 2; k++)
            {
                X[k]         = E[k] + D[k];
                X[k + N / 2] = E[k] - D[k];
            }
            return(X);
        }
Exemple #2
0
        public static complex[] DFT(complex[] x)
        {
            int N = x.Length;

            complex[] X = new complex[N];
            for (int k = 0; k < N; k++)
            {
                X[k] = new complex(0, 0);
                for (int n = 0; n < N; n++)
                {
                    complex temp = complex.from_polar(1, -2 * Math.PI * n * k / N);
                    temp *= x[n];
                    X[k] += temp;
                }
            }
            return(X);
        }
Exemple #3
0
        /*
         * public class data
         * {
         *  public Double time = 0;
         *  public complex volts = new complex(0, 0);
         * }*/
        #endregion

        // Function that reads the time data froma files and stores in in the variables
        private void PopulateData(String path, ref List <complex> datalist)
        {
            string line;

            StreamReader file = new StreamReader(path);
            bool         time = true;

            while ((line = file.ReadLine()) != null)
            {
                complex data = new complex();
                if (time)
                {
                    try
                    {
                        Time.Add(Double.Parse(line));
                    }
                    catch
                    {
                        time = false;
                        continue;
                    }
                }
                if (!time)
                {
                    data.real = Double.Parse(line);
                    Data.Add(data);
                }
            }

            /*
             * while ((line = file.ReadLine()) != null)
             * {
             *  complex data = new complex();
             *  string[] split = line.Split(Convert.ToChar(9));
             *  Time.Add(Double.Parse(split[0]));
             *  data.real = Double.Parse(split[1]);
             *  datalist.Add(data);
             * }
             */
        }
Exemple #4
0
        //Override subtraction operator
        public static complex operator -(complex a, complex b)
        {
            complex data = new complex(a.real - b.real, a.imag - b.imag);

            return(data);
        }
Exemple #5
0
        //Convert from polar to rectangular
        public static complex from_polar(double r, double radians)
        {
            complex data = new complex(r * Math.Cos(radians), r * Math.Sin(radians));

            return(data);
        }
Exemple #6
0
            public static complex operator -(complex a, complex b)
            {
                complex temp = new complex(a.real - b.real, a.imag - b.imag);

                return(temp);
            }
Exemple #7
0
            public static complex FromPolar(double r, double radians)
            {
                complex temp = new complex(r * Math.Cos(radians), r * Math.Sin(radians));

                return(temp);
            }
Exemple #8
0
            public static complex operator *(complex a, complex b)
            {
                complex temp = new complex((a.real * b.real) - (a.imag * b.imag), (a.real * b.imag + (a.imag * b.real)));

                return(temp);
            }