private TKomplex kdiff(TKomplex a, TKomplex b)
 {
     res.real = a.real - b.real;
     res.imag = a.imag - b.imag;
     return (res);
 }
Esempio n. 2
0
        private void Initialize(Sample currentSample)
        {
            N  = currentSample.Limit;
            x  = new TKomplex[N + 1];
            y  = new TKomplex[N + 1];
            we = new TKomplex[N / 2];
            for (int i = 0; i < (N / 2); i++)  // Init look up table for sine and cosine values
            {
                we[i].real = Math.Cos(2 * Math.PI * (double)(i) / (double)(N));
                we[i].imag = Math.Sin(2 * Math.PI * (double)(i) / (double)(N));
            }

            var windowedSignal = BuildHanWindow(currentSample);

            for (int i = 0; i < currentSample.Limit; i++)
            {
                y[i].real = windowedSignal[i];
                y[i].imag = 0;
            }
        }
        private void Initialize(Sample currentSample)
        {
            N = currentSample.Limit;
            x = new TKomplex[N + 1];
            y = new TKomplex[N + 1];
            we = new TKomplex[N / 2];
            for (int i = 0; i < (N / 2); i++)  // Init look up table for sine and cosine values
            {
                we[i].real = Math.Cos(2 * Math.PI * (double)(i) / (double)(N));
                we[i].imag = Math.Sin(2 * Math.PI * (double)(i) / (double)(N));
            }

            var windowedSignal = BuildHanWindow(currentSample);

            for (int i = 0; i < currentSample.Limit; i++)
            {
                y[i].real = windowedSignal[i];
                y[i].imag = 0;
            }
        }
Esempio n. 4
0
 private TKomplex kprod(TKomplex a, TKomplex b)
 {
     res.real = a.real * b.real - a.imag * b.imag;
     res.imag = a.real * b.imag + a.imag * b.real;
     return(res);
 }
Esempio n. 5
0
 private TKomplex kdiff(TKomplex a, TKomplex b)
 {
     res.real = a.real - b.real;
     res.imag = a.imag - b.imag;
     return(res);
 }
Esempio n. 6
0
 private TKomplex ksum(TKomplex a, TKomplex b)
 {
     res.real = a.real + b.real;
     res.imag = a.imag + b.imag;
     return(res);
 }
 private TKomplex kprod(TKomplex a, TKomplex b)
 {
     res.real = a.real * b.real - a.imag * b.imag;
     res.imag = a.real * b.imag + a.imag * b.real;
     return (res);
 }
 private TKomplex ksum(TKomplex a, TKomplex b)
 {
     res.real = a.real + b.real;
     res.imag = a.imag + b.imag;
     return (res);
 }
 private void CalcSubFFT(TKomplex[] a, int n)
 {
     int i, k, m;
     TKomplex w;
     TKomplex v;
     TKomplex h;
     k = 1;
     while (k <= n / 2)
     {
         m = 0;
         while (m <= (n - 2 * k))
         {
             for (i = m; i < m + k; i++)
             {
                 // sine and cosine values from look up table
                 w.real = we[((i - m) * N / k / 2)].real;
                 w.imag = we[((i - m) * N / k / 2)].imag;
                 // classic calculation of sine and cosine values
                 //w.real = Math.Cos( Math.PI * (double)(i-m) / (double)(k));
                 //w.imag = Math.Sin( Math.PI * (double)(i-m) / (double)(k));
                 h = kprod(a[i + k], w);
                 v = a[i];
                 a[i] = ksum(a[i], h);
                 a[i + k] = kdiff(v, h);
             }
             m = m + 2 * k;
         }
         k = k * 2;
     }
 }
        private void BitInvert(TKomplex[] a, int n)
        {  // invert bits for each index. n is number of samples and a the array of the samples
            int i, mv = n / 2;
            int k, rev = 0;
            TKomplex b;
            for (i = 1; i < n; i++) // run tru all the indexes from 1 to n
            {
                k = i;
                mv = n / 2;
                rev = 0;
                while (k > 0) // invert the actual index
                {
                    if ((k % 2) > 0)
                        rev = rev + mv;
                    k = k / 2;
                    mv = mv / 2;
                }

                {  // switch the actual sample and the bitinverted one
                    if (i < rev)
                    {
                        b = a[rev];
                        a[rev] = a[i];
                        a[i] = b;
                    }
                }
            }
        }