IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 16, 2008, 1:10:16 PM (19 years ago)
Author:
eugene
Message:

working on the fft function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.data/fft.c

    r16094 r16099  
    88}
    99
    10 void fft (double *x, double *y, int n, int Nbit) {
     10void fft (float *x, float *y, int n, int Nbit, int forward) {
    1111
    1212  int i,j,k,n1,n2;
    13   double c,s,e,a,t1,t2;       
     13  float c,s,e,a,t1,t2;       
     14  double factor;
    1415         
    1516  // bit-reverse
     
    1920    n1 = n2;
    2021    while ( j >= n1 ) {
    21       j = j - n1;
    22       n1 = n1/2;
     22      j -= n1;
     23      n1 /= 2;
    2324    }
    24     j = j + n1;
     25    j += n1;
    2526               
    2627    if (i < j) {
     
    3334    }
    3435  }
    35  
    3636                                         
    3737  n1 = 0; /* FFT */
    3838  n2 = 1;
    3939                                             
     40  if (forward) {
     41    factor = +2.0*M_PI;
     42  } else {
     43    factor = -2.0*M_PI;
     44  }
     45
    4046  for (i=0; i < Nbit; i++) {
    4147    n1 = n2;
    4248    n2 = n2 + n2;
    43     e = -6.283185307179586/n2;
     49    e = factor/n2;
    4450    a = 0.0;
    4551                                             
     
    6066  }
    6167                                     
     68  // re-normalize
     69  for (i = 0; i < n; i++) {
     70    x[i] /= n;
     71    y[i] /= n;
     72  }
     73
    6274  return;
    6375}                         
    6476
    65 int IsBinary (int N, int *nbin) {
     77// check that a number is binary (2^Nbit).  returns int(log_2(N)) in Nbit
     78int IsBinary (int N, int *Nbit) {
    6679
    67   // check that a number is binary (2^nbit)
     80  int i, Nset;
    6881
    69   Nbit = 0;
     82  *Nbit = 0;
    7083  Nset = 0;
    7184  for (i = 0; i < 8*sizeof(int); i++) {
    7285    if (N & 0x01) {
    7386      Nset ++;
    74       Nbin = i;
     87      *Nbit = i;
    7588    }
    7689    N >>= 1;
    7790  }
    78   *nbin = Nbit;
    7991  if (Nset > 1) return (FALSE);
    8092}
     
    92104/* m: n = 2**m                                            */
    93105/*   input/output                                         */
    94 /* x: double array of length n with real part of data     */
    95 /* y: double array of length n with imag part of data     */
     106/* x: float array of length n with real part of data     */
     107/* y: float array of length n with imag part of data     */
    96108/*                                                        */
    97109/*   Permission to copy and use this program is granted   */
Note: See TracChangeset for help on using the changeset viewer.