[SI-LIST] Re: FFT/iFFT tool (for FREE)

  • From: Al Davis <aldavis@xxxxxxxx>
  • To: arap@xxxxxxxxxxxxxx
  • Date: Mon, 4 Mar 2002 01:57:24 -0700

On Monday 04 March 2002 00:40, Tadashi Arai wrote:
> Does anyone know (or use) any tool for FFT / inverse FFT ?
>
> And I prefer to use the tool with no-charge.

If that is all you want, it is too simple for anyone to bother with 
it as a product.

Try this one:

It is in C++.  You need to make a main to read and write files in 
your preferred format.  You also need to #define some constants 
(kPIx2 is  6.2831853071795864769252867665590057683944).
You also need to typedef COMPLEX to be the particular variant of 
complex that you want to use (usually std::complex<double>).

This is the code from Gnucap (the Gnu Circuit Analysis Package).  The 
program is Gnu Public License.  This file is public domain.

/*--------------------------------------------------------------------------*/
void fft(COMPLEX* x, int n, int inv)
{
  int s = (inv) ? 1 : -1;
  int nxp, nxp2;
  for (nxp=n;  (nxp2=nxp/2) > 0;  nxp=nxp2) {
    double wpwr = kPIx2 / nxp;
    for (int m = 0;  m < nxp2;  ++m) {
      double argg = m * wpwr;
      COMPLEX w(cos(argg), s*sin(argg));
      for (int jj1 = m;  jj1+nxp-m <= n;  jj1 += nxp) {
        int jj2 = jj1 + nxp2;
        COMPLEX t = x[jj1] - x[jj2];
        x[jj1] += x[jj2];
        x[jj2] = t * w;
      }
    }
  }
  /* unscramble */
  {
    int i, j;
    for (/*k =*/ i = j = 0;  i < n-1;  ++i) {
      if (i < j) {
        swap(x[i],x[j]);
      }
      int k;
      for (k = n/2;  k <= j;  k /= 2) {
        j -= k;
      }
      j += k;
    }
  }
  /* fix level */
  if (!inv) {
    for (int i = 0;  i < n;  ++i) {
      x[i] /= n;
    }
  }
}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
------------------------------------------------------------------
To unsubscribe from si-list:
si-list-request@xxxxxxxxxxxxx with 'unsubscribe' in the Subject field

or to administer your membership from a web page, go to:
//www.freelists.org/webpage/si-list

For help:
si-list-request@xxxxxxxxxxxxx with 'help' in the Subject field

List archives are viewable at:     
                //www.freelists.org/archives/si-list
or at our remote archives:
                http://groups.yahoo.com/group/si-list/messages 
Old (prior to June 6, 2001) list archives are viewable at:
                http://www.qsl.net/wb6tpu
  

Other related posts: