46
46
#include < stdio.h>
47
47
#include < math.h>
48
48
49
+ #include " RealFFTf.h"
49
50
#include " Experimental.h"
50
51
51
52
static int **gFFTBitTable = NULL ;
@@ -110,10 +111,6 @@ void InitFFT()
110
111
}
111
112
}
112
113
113
- #ifdef EXPERIMENTAL_USE_REALFFTF
114
- #include " RealFFTf.h"
115
- #endif
116
-
117
114
void DeinitFFT ()
118
115
{
119
116
if (gFFTBitTable ) {
@@ -122,10 +119,8 @@ void DeinitFFT()
122
119
}
123
120
delete[] gFFTBitTable ;
124
121
}
125
- #ifdef EXPERIMENTAL_USE_REALFFTF
126
122
// Deallocate any unused RealFFTf tables
127
123
CleanupFFT ();
128
- #endif
129
124
}
130
125
131
126
inline int FastReverseBits (int i, int NumBits)
@@ -238,22 +233,11 @@ void FFT(int NumSamples,
238
233
/*
239
234
* Real Fast Fourier Transform
240
235
*
241
- * This function was based on the code in Numerical Recipes in C.
242
- * In Num. Rec., the inner loop is based on a single 1-based array
243
- * of interleaved real and imaginary numbers. Because we have two
244
- * separate zero-based arrays, our indices are quite different.
245
- * Here is the correspondence between Num. Rec. indices and our indices:
246
- *
247
- * i1 <-> real[i]
248
- * i2 <-> imag[i]
249
- * i3 <-> real[n/2-i]
250
- * i4 <-> imag[n/2-i]
236
+ * This is merely a wrapper of RealFFTf() from RealFFTf.h.
251
237
*/
252
238
253
239
void RealFFT (int NumSamples, float *RealIn, float *RealOut, float *ImagOut)
254
240
{
255
- #ifdef EXPERIMENTAL_USE_REALFFTF
256
- // Remap to RealFFTf() function
257
241
int i;
258
242
HFFT hFFT = GetFFT (NumSamples);
259
243
float *pFFT = new float [NumSamples];
@@ -280,62 +264,8 @@ void RealFFT(int NumSamples, float *RealIn, float *RealOut, float *ImagOut)
280
264
}
281
265
delete [] pFFT;
282
266
ReleaseFFT (hFFT);
283
-
284
- #else
285
-
286
- int Half = NumSamples / 2 ;
287
- int i;
288
-
289
- float theta = M_PI / Half;
290
-
291
- float *tmpReal = new float [Half];
292
- float *tmpImag = new float [Half];
293
-
294
- for (i = 0 ; i < Half; i++) {
295
- tmpReal[i] = RealIn[2 * i];
296
- tmpImag[i] = RealIn[2 * i + 1 ];
297
- }
298
-
299
- FFT (Half, 0 , tmpReal, tmpImag, RealOut, ImagOut);
300
-
301
- float wtemp = float (sin (0.5 * theta));
302
-
303
- float wpr = -2.0 * wtemp * wtemp;
304
- float wpi = -1.0 * float (sin (theta));
305
- float wr = 1.0 + wpr;
306
- float wi = wpi;
307
-
308
- int i3;
309
-
310
- float h1r, h1i, h2r, h2i;
311
-
312
- for (i = 1 ; i < Half / 2 ; i++) {
313
-
314
- i3 = Half - i;
315
-
316
- h1r = 0.5 * (RealOut[i] + RealOut[i3]);
317
- h1i = 0.5 * (ImagOut[i] - ImagOut[i3]);
318
- h2r = 0.5 * (ImagOut[i] + ImagOut[i3]);
319
- h2i = -0.5 * (RealOut[i] - RealOut[i3]);
320
-
321
- RealOut[i] = h1r + wr * h2r - wi * h2i;
322
- ImagOut[i] = h1i + wr * h2i + wi * h2r;
323
- RealOut[i3] = h1r - wr * h2r + wi * h2i;
324
- ImagOut[i3] = -h1i + wr * h2i + wi * h2r;
325
-
326
- wr = (wtemp = wr) * wpr - wi * wpi + wr;
327
- wi = wi * wpr + wtemp * wpi + wi;
328
- }
329
-
330
- RealOut[0 ] = (h1r = RealOut[0 ]) + ImagOut[0 ];
331
- ImagOut[0 ] = h1r - ImagOut[0 ];
332
-
333
- delete[] tmpReal;
334
- delete[] tmpImag;
335
- #endif // EXPERIMENTAL_USE_REALFFTF
336
267
}
337
268
338
- #ifdef EXPERIMENTAL_USE_REALFFTF
339
269
/*
340
270
* InverseRealFFT
341
271
*
@@ -344,10 +274,11 @@ void RealFFT(int NumSamples, float *RealIn, float *RealOut, float *ImagOut)
344
274
* and as a result the output is purely real.
345
275
* Only the first half of RealIn and ImagIn are used due to this
346
276
* symmetry assumption.
277
+ *
278
+ * This is merely a wrapper of InverseRealFFTf() from RealFFTf.h.
347
279
*/
348
280
void InverseRealFFT (int NumSamples, float *RealIn, float *ImagIn, float *RealOut)
349
281
{
350
- // Remap to RealFFTf() function
351
282
int i;
352
283
HFFT hFFT = GetFFT (NumSamples);
353
284
float *pFFT = new float [NumSamples];
@@ -373,24 +304,20 @@ void InverseRealFFT(int NumSamples, float *RealIn, float *ImagIn, float *RealOut
373
304
delete [] pFFT;
374
305
ReleaseFFT (hFFT);
375
306
}
376
- #endif // EXPERIMENTAL_USE_REALFFTF
377
307
378
308
/*
379
309
* PowerSpectrum
380
310
*
381
- * This function computes the same as RealFFT, above, but
382
- * adds the squares of the real and imaginary part of each
383
- * coefficient, extracting the power and throwing away the
384
- * phase.
311
+ * This function uses RealFFTf() from RealFFTf.h to perform the real
312
+ * FFT computation, and then squares the real and imaginary part of
313
+ * each coefficient, extracting the power and throwing away the phase.
385
314
*
386
315
* For speed, it does not call RealFFT, but duplicates some
387
316
* of its code.
388
317
*/
389
318
390
319
void PowerSpectrum (int NumSamples, float *In, float *Out)
391
320
{
392
- #ifdef EXPERIMENTAL_USE_REALFFTF
393
- // Remap to RealFFTf() function
394
321
int i;
395
322
HFFT hFFT = GetFFT (NumSamples);
396
323
float *pFFT = new float [NumSamples];
@@ -411,73 +338,6 @@ void PowerSpectrum(int NumSamples, float *In, float *Out)
411
338
Out[i] = pFFT[1 ]*pFFT[1 ];
412
339
delete [] pFFT;
413
340
ReleaseFFT (hFFT);
414
-
415
- #else // EXPERIMENTAL_USE_REALFFTF
416
-
417
- int Half = NumSamples / 2 ;
418
- int i;
419
-
420
- float theta = M_PI / Half;
421
-
422
- float *tmpReal = new float [Half];
423
- float *tmpImag = new float [Half];
424
- float *RealOut = new float [Half];
425
- float *ImagOut = new float [Half];
426
-
427
- for (i = 0 ; i < Half; i++) {
428
- tmpReal[i] = In[2 * i];
429
- tmpImag[i] = In[2 * i + 1 ];
430
- }
431
-
432
- FFT (Half, 0 , tmpReal, tmpImag, RealOut, ImagOut);
433
-
434
- float wtemp = float (sin (0.5 * theta));
435
-
436
- float wpr = -2.0 * wtemp * wtemp;
437
- float wpi = -1.0 * float (sin (theta));
438
- float wr = 1.0 + wpr;
439
- float wi = wpi;
440
-
441
- int i3;
442
-
443
- float h1r, h1i, h2r, h2i, rt, it;
444
-
445
- for (i = 1 ; i < Half / 2 ; i++) {
446
-
447
- i3 = Half - i;
448
-
449
- h1r = 0.5 * (RealOut[i] + RealOut[i3]);
450
- h1i = 0.5 * (ImagOut[i] - ImagOut[i3]);
451
- h2r = 0.5 * (ImagOut[i] + ImagOut[i3]);
452
- h2i = -0.5 * (RealOut[i] - RealOut[i3]);
453
-
454
- rt = h1r + wr * h2r - wi * h2i;
455
- it = h1i + wr * h2i + wi * h2r;
456
-
457
- Out[i] = rt * rt + it * it;
458
-
459
- rt = h1r - wr * h2r + wi * h2i;
460
- it = -h1i + wr * h2i + wi * h2r;
461
-
462
- Out[i3] = rt * rt + it * it;
463
-
464
- wr = (wtemp = wr) * wpr - wi * wpi + wr;
465
- wi = wi * wpr + wtemp * wpi + wi;
466
- }
467
-
468
- rt = (h1r = RealOut[0 ]) + ImagOut[0 ];
469
- it = h1r - ImagOut[0 ];
470
- Out[0 ] = rt * rt + it * it;
471
-
472
- rt = RealOut[Half / 2 ];
473
- it = ImagOut[Half / 2 ];
474
- Out[Half / 2 ] = rt * rt + it * it;
475
-
476
- delete[] tmpReal;
477
- delete[] tmpImag;
478
- delete[] RealOut;
479
- delete[] ImagOut;
480
- #endif // EXPERIMENTAL_USE_REALFFTF
481
341
}
482
342
483
343
/*
0 commit comments