GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
fft.c
Go to the documentation of this file.
1 
26 #include <grass/config.h>
27 
28 #if defined(HAVE_FFTW_H) || defined(HAVE_DFFTW_H) || defined(HAVE_FFTW3_H)
29 
30 #ifdef HAVE_FFTW_H
31 #include <fftw.h>
32 #endif
33 
34 #ifdef HAVE_DFFTW_H
35 #include <dfftw.h>
36 #endif
37 
38 #ifdef HAVE_FFTW3_H
39 #include <fftw3.h>
40 #define c_re(c) ((c)[0])
41 #define c_im(c) ((c)[1])
42 #endif
43 
44 #include <stdlib.h>
45 #include <stdio.h>
46 #include <math.h>
47 #include <grass/gmath.h>
48 #include <grass/gis.h>
49 
50 
70 int fft2(int i_sign, double (*data)[2], int NN, int dimc, int dimr)
71 {
72 #ifdef HAVE_FFTW3_H
73  fftw_plan plan;
74 #else
75  fftwnd_plan plan;
76 #endif
77  double norm;
78  int i;
79 
80  norm = 1.0 / sqrt(NN);
81 
82 #ifdef HAVE_FFTW3_H
83  plan = fftw_plan_dft_2d(dimr, dimc, data, data,
84  (i_sign < 0) ? FFTW_FORWARD : FFTW_BACKWARD,
85  FFTW_ESTIMATE);
86 
87  fftw_execute(plan);
88 
89  fftw_destroy_plan(plan);
90 #else
91  plan = fftw2d_create_plan(dimc, dimr,
92  (i_sign < 0) ? FFTW_FORWARD : FFTW_BACKWARD,
93  FFTW_ESTIMATE | FFTW_IN_PLACE);
94 
95  fftwnd_one(plan, data, data);
96 
97  fftwnd_destroy_plan(plan);
98 #endif
99 
100  for (i = 0; i < NN; i++) {
101  data[i][0] *= norm;
102  data[i][1] *= norm;
103  }
104 
105  return 0;
106 }
107 
127 int fft(int i_sign, double *DATA[2], int NN, int dimc, int dimr)
128 {
129  fftw_complex *data;
130  int i;
131 
132  data = (fftw_complex *) G_malloc(NN * sizeof(fftw_complex));
133 
134  for (i = 0; i < NN; i++) {
135  c_re(data[i]) = DATA[0][i];
136  c_im(data[i]) = DATA[1][i];
137  }
138 
139  fft2(i_sign, data, NN, dimc, dimr);
140 
141  for (i = 0; i < NN; i++) {
142  DATA[0][i] = c_re(data[i]);
143  DATA[1][i] = c_im(data[i]);
144  }
145 
146  G_free(data);
147 
148  return 0;
149 }
150 
151 #endif /* HAVE_FFT */
Definition: login.c:11
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
tuple data