Beispiel #1
0
int Fft::_FFT(double b[], int n)
{
    double fn;
    int i, in, nn, n2pow, n4pow;

    if((n2pow = fastpurelog2(n)) <= 0) return 0;
    fn = (double)n;
    n4pow = n2pow / 2;

    /* radix 2 iteration required; do it now */
    if (n2pow % 2)
    {
        nn = 2;
        in = n / nn;
        FR2TR(in, b, b + in );
    }
    else nn = 1;

    /* perform radix 4 iterations */
    for(i = 1; i <= n4pow; i++)
    {
        nn *= 4;
        in = n / nn;
        FR4TR(in, nn, b, b + in, b + 2 * in, b + 3 * in);
    }

    /* perform inplace reordering */
    FORD1(n2pow, b);
    FORD2(n2pow, b);

    return 1;
}
Beispiel #2
0
Datei: fft.c Projekt: mdqyy/AMPF
/*
** FAST(b,n)
** This routine replaces the real float vector b
** of length n with its finite discrete fourier transform.
** DC term is returned in b[0]; 
** n/2th harmonic real part in b[1].
** jth harmonic is returned as complex number stored as
** b[2*j] + i b[2*j + 1] 
** (i.e., remaining coefficients are as a DPCOMPLEX vector).
** 
*/
int FAST(real *b, int n) {
  real fn;
  int i, in, nn, n2pow, n4pow, nthpo;
  
  n2pow = fastlog2(n);
  if(n2pow <= 0) return 0;
  nthpo = n;
  fn = nthpo;
  n4pow = n2pow / 2;

  /* radix 2 iteration required; do it now */  
  if(n2pow % 2) {
    nn = 2;
    in = n / nn;
    FR2TR(in, b, b + in);
  }
  else nn = 1;

  /* perform radix 4 iterations */
  for(i = 1; i <= n4pow; i++) {
    nn *= 4;
    in = n / nn;
    FR4TR(in, nn, b, b + in, b + 2 * in, b + 3 * in);
  }

  /* perform inplace reordering */
  FORD1(n2pow, b);
  FORD2(n2pow, b);

  /* take conjugates */
  for(i = 3; i < n; i += 2) b[i] = -b[i];

  return 1;
}