fftw on FC5?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Has anyone used fftw on FC5? I upgraded two weeks ago, and now I get FFT's all
zeros. I am not sure if I have inadvertently introduced a bug in my program
somewhere, but I am mystified, where. 

So, I thought I would ask if anyone has had problems/no problems with fftw on
FC5. 

Many thanks and best wishes,
Trotter.

Here is a sample function and a calling program:

#include<stdio.h>
#include<math.h>
#include<complex.h>
#include<fftw3.h>

/* calculates the FFT of a complex periodic 1-, 2- and 3-dimensional arrays, 
   using FFTW, described at www.fftw.org. Note that the FFT's are scaled 
   which means that applying the FFT and then its inverse provides the 
   sequence back. This is a variation from the output of FFTW. 
   */


int fft(int n,fftw_complex *f,int sign)
{
  /* calculates the forward and backward Fast Fourier Transform of a complex 
     1-dimensional sequence (using FFTW, the Fastest Fourier Transform of the 
     West). 
     The third argument sign takes one of FFTW_FORWARD and FFTW_BACKWARD.
     Note that the input sequence is replaced by its forward or inverse FFT on
     return.  */
  
  fftw_complex *ff,*out;
  fftw_plan p;
  int i;

  if (!abs(sign)) {
    printf("ERROR: Please specify one of FFTW_FORWARD or FFTW_BACKWARD for
forward/inverse transform\n");
    exit(1);   
  }

  ff = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n);
  out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n);

  for (i=0;i<n;i++) ff[i]=f[i];

  p = fftw_plan_dft_1d(n, ff, out, sign, FFTW_MEASURE);
  
  fftw_execute(p); /* repeat as needed */
  for (i=0;i<n;i++) f[i]=out[i]/sqrt((double)n);
  fftw_destroy_plan(p);
  fftw_free(ff);
  fftw_free(out);
  return 0;
}

int main(void) 
{
  fftw_complex *ff;
  int i,dum,n=216;
  double a;
  FILE *ffile;

  ff = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n);
  ffile=fopen("mu","r");
  for (i=0;i<n;i++) {
    fscanf(ffile,"%lE\n",&a);
    ff[i]=a;
  }
  fclose(ffile);

  dum=fft(n,ff,FFTW_FORWARD);

  ffile=fopen("mu.fftf","w");
  for (i=0;i<n;i++) {
    fprintf(ffile,"%f %f\n",creal(ff[i]),cimag(ff[i]));
  }
  fclose(ffile);
  
  dum=fft(n,ff,FFTW_BACKWARD);
  
  ffile=fopen("mu.fftb","w");
  for (i=0;i<n;i++) {
    fprintf(ffile,"%f %f\n",creal(ff[i]),cimag(ff[i]));
  }
  fclose(ffile);
  fftw_free(ff);
  return 0;
}



Comment: By the way, the malloc is as in the FFTW manual. I prefer the cleaner,
more C-ish 
  ff = fftw_malloc(n * sizeof *ff);
myself.

Best, Trotter

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux