示例#1
0
void idft(std::vector<complex<float_type> >& y, int n) {
  int j, l;

  /*  n inverse dft length */
  std::vector<complex<float_type> > x(n + 1);
  complex<float_type> mult;

  /*  calculate the w values recursively */
  //  complex<float_type> w_inc = expj(TWOPI/n);
  //  complex<float_type> w_x = complex<float_type>(1,0);
  for (j = 0; j < n; j++) { x[j] = y[j]; }

  /*  start inverse fft */
  for (l = 0; l < n; l++) {
    y[l] = 0;
    for (j = 0; j < n; j++) {
      mult = x[j] * expj(TWOPI * l * j / (n));
      y[l] += mult;
    }
  }

#define SCALEFFT
#ifdef SCALEFFT
  int i;
  /*  scale all results by 1/n */
  float_type scale = (float_type)(1.0 / n);
  for (i = 0; i < n; i++) y[i] = scale * y[i];
#endif
}
示例#2
0
文件: vco_int_s.cpp 项目: CAOU/spuc
template <> complex<int_s> vco<int_s>::clock() {
  acc += new_fcw;
  phase = acc >> (long)(32-phase_bits); // truncate
  float arg = TWOPI*((float)phase)/phase_bits;
  complex<float> x = ((float)amp)*expj(arg);
  return(complex<int_s>(SPUC_TOLONG(real(x)),SPUC_TOLONG(imag(x))));
}
示例#3
0
void dft(std::vector<complex<float_type> >& y, int n) {
  int j, l;

  /*  n inverse dft length */
  std::vector<complex<float_type> > x(n + 1);

  for (j = 0; j < n; j++) x[j] = y[j];

  /*  start inverse fft */
  for (l = 0; l < n; l++) {
    y[l] = 0;
    for (j = 0; j < n; j++) { y[l] += x[j] * expj(-TWOPI * j * l / n); }
  }
}
示例#4
0
void ifft(complex_t data[], int len)
{
    int i;
    double x;
    complex_t temp[MAX_FFT_LEN];

    /* A very slow and clunky FFT, that's just fine for filter design. */
    for (i = 0;  i < MAX_FFT_LEN/2;  i++)
    {
        x = (2.0*3.1415926535*i)/(double) MAX_FFT_LEN;
        circle[i] = expj(x);
    }
    fftx(data, temp, len);
}
示例#5
0
SPAN_DECLARE(void) ifft(complex_t data[], int len)
{
    int i;
    double x;
    complex_t temp[MAX_FFT_LEN];

    /* A very slow and clunky FFT, that's just fine for tests. */
    if (!icircle_init)
    {
        for (i = 0;  i < MAX_FFT_LEN/2;  i++)
        {
            x = (2.0*3.1415926535*i)/(double) MAX_FFT_LEN;
            icircle[i] = expj(x);
        }
        icircle_init = true;
    }
    ifftx(data, temp, len);
}
示例#6
0
/* *************************************************************************
fft - In-place radix 2 decimation in time inverse FFT

Requires pointer to complex array, x and power of 2 size of FFT, m
(size of FFT = 2**m).  Places inverse FFT output on top of input
frequency domain COMPLEX array.

complex<float_type> fft(complex<float_type> *x, int m)

*************************************************************************/
void fft(std::vector<complex<float_type> >& y, int m) {
  complex<float_type> u, temp, tm;
  int wptr;
  int i, j, k, l, le, windex;

  /*  n = 2**m = inverse fft length */
  int n = 1 << m;
  le = n / 2;
  std::vector<complex<float_type> > w(n + 1);
  std::vector<complex<float_type> > x(n + 1);

  /*  calculate the w values recursively */
  complex<float_type> w_inc = expj(-TWOPI / n);
  complex<float_type> w_x = w_inc;

  for (j = 0; j < le; j++) {
    w[j] = w_x;
    w_x *= w_inc;
    x[j] = y[j];
    x[j + le] = y[j + le];
  }

  /*  start inverse fft */
  le = n;
  windex = 1;
  for (l = 0; l < m; l++) {
    le = le / 2;
    /*  first iteration with no multiplies */
    for (i = 0; i < n; i += 2 * le) {
      temp = (x[i] + x[i + le]);
      x[i + le] = (x[i] - x[i + le]);
      x[i] = temp;
    }

    /*  remaining iterations use stored w */
    wptr = windex - 1;
    for (j = 1; j < le; j++) {
      for (i = j; i < n; i += 2 * le) {
        temp = x[i] + x[i + le];
        tm = x[i] - x[i + le];
        x[i + le] = tm * w[wptr];
        x[i] = temp;
      }
      wptr += windex;
    }
    windex = 2 * windex;
  }

  /*  rearrange data by bit reversing */

  j = 0;
  for (i = 1; i < (n - 1); i++) {
    k = n / 2;
    while (k <= j) {
      j = j - k;
      k = k / 2;
    }
    j = j + k;
    if (i < j) {
      temp = x[j];
      x[j] = x[i];
      x[i] = temp;
    }
  }

  for (i = 0; i < n; i++) y[i] = x[i];
}