Audacity  2.2.0
FFT.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  FFT.h
4 
5  Dominic Mazzoni
6 
7  September 2000
8 
9  This file contains a few FFT routines, including a real-FFT
10  routine that is almost twice as fast as a normal complex FFT,
11  and a power spectrum routine which is more convenient when
12  you know you don't care about phase information. It now also
13  contains a few basic windowing functions.
14 
15  Some of this code was based on a free implementation of an FFT
16  by Don Cross, available on the web at:
17 
18  http://www.intersrv.com/~dcross/fft.html
19 
20  The basic algorithm for his code was based on Numerical Recipes
21  in Fortran. I optimized his code further by reducing array
22  accesses, caching the bit reversal table, and eliminating
23  float-to-double conversions, and I added the routines to
24  calculate a real FFT and a real power spectrum.
25 
26  Note: all of these routines use single-precision floats.
27  I have found that in practice, floats work well until you
28  get above 8192 samples. If you need to do a larger FFT,
29  you need to use doubles.
30 
31 **********************************************************************/
32 #ifndef __AUDACITY_FFT_H__
33 #define __AUDACITY_FFT_H__
34 
35 #include <wx/defs.h>
36 
37 /*
38  Salvo Ventura - November 2006
39  Added more window functions:
40  * 4: Blackman
41  * 5: Blackman-Harris
42  * 6: Welch
43  * 7: Gaussian(a=2.5)
44  * 8: Gaussian(a=3.5)
45  * 9: Gaussian(a=4.5)
46 */
47 
48 #include <wx/defs.h>
49 #include <wx/wxchar.h>
50 
51 #ifndef M_PI
52 #define M_PI 3.14159265358979323846 /* pi */
53 #endif
54 
55 /*
56  * This is the function you will use the most often.
57  * Given an array of floats, this will compute the power
58  * spectrum by doing a Real FFT and then computing the
59  * sum of the squares of the real and imaginary parts.
60  * Note that the output array is half the length of the
61  * input array, and that NumSamples must be a power of two.
62  */
63 
64 void PowerSpectrum(size_t NumSamples, const float *In, float *Out);
65 
66 /*
67  * Computes an FFT when the input data is real but you still
68  * want complex data as output. The output arrays are the
69  * same length as the input, but will be conjugate-symmetric
70  * NumSamples must be a power of two.
71  */
72 
73 void RealFFT(size_t NumSamples,
74  const float *RealIn, float *RealOut, float *ImagOut);
75 
76 /*
77  * Computes an Inverse FFT when the input data is conjugate symmetric
78  * so the output is purely real. NumSamples must be a power of
79  * two.
80  */
81 void InverseRealFFT(size_t NumSamples,
82  const float *RealIn, const float *ImagIn, float *RealOut);
83 
84 /*
85  * Computes a FFT of complex input and returns complex output.
86  * Currently this is the only function here that supports the
87  * inverse transform as well.
88  */
89 
90 void FFT(size_t NumSamples,
91  bool InverseTransform,
92  const float *RealIn, const float *ImagIn, float *RealOut, float *ImagOut);
93 
94 /*
95  * Multiply values in data by values of the chosen function
96  * DO NOT REUSE! Prefer NewWindowFunc instead
97  * This version was inconsistent whether the window functions were
98  * symmetrical about NumSamples / 2, or about (NumSamples - 1) / 2
99  * It remains for compatibility until we decide to upgrade all the old uses
100  * All functions have 0 in data[0] except Rectangular, Hamming and Gaussians
101  */
102 
104 {
116 };
117 
118 void WindowFunc(int whichFunction, size_t NumSamples, float *data);
119 
120 /*
121  * Multiply values in data by values of the chosen function
122  * All functions are symmetrical about NumSamples / 2 if extraSample is false,
123  * otherwise about (NumSamples - 1) / 2
124  * All functions have 0 in data[0] except Rectangular, Hamming and Gaussians
125  */
126 void NewWindowFunc(int whichFunction, size_t NumSamples, bool extraSample, float *data);
127 
128 /*
129  * Multiply values in data by derivative of the chosen function, assuming
130  * sampling interval is unit
131  * All functions are symmetrical about NumSamples / 2 if extraSample is false,
132  * otherwise about (NumSamples - 1) / 2
133  * All functions have 0 in data[0] except Rectangular, Hamming and Gaussians
134  */
135 void DerivativeOfWindowFunc(int whichFunction, size_t NumSamples, bool extraSample, float *data);
136 
137 /*
138  * Returns the name of the windowing function (for UI display)
139  */
140 
141 const wxChar *WindowFuncName(int whichFunction);
142 
143 /*
144  * Returns the number of windowing functions supported
145  */
146 
147 int NumWindowFuncs();
148 
149 void DeinitFFT();
150 
151 #endif
Definition: FFT.h:109
Definition: FFT.h:106
void NewWindowFunc(int whichFunction, size_t NumSamples, bool extraSample, float *data)
Definition: FFT.cpp:360
Definition: FFT.h:107
eWindowFunctions
Definition: FFT.h:103
int NumWindowFuncs()
Definition: FFT.cpp:328
void WindowFunc(int whichFunction, size_t NumSamples, float *data)
Definition: FFT.cpp:504
void DerivativeOfWindowFunc(int whichFunction, size_t NumSamples, bool extraSample, float *data)
Definition: FFT.cpp:527
Definition: FFT.h:110
Definition: FFT.h:114
void RealFFT(size_t NumSamples, const float *RealIn, float *RealOut, float *ImagOut)
Definition: FFT.cpp:229
Definition: FFT.h:113
Definition: FFT.h:112
Definition: FFT.h:115
void InverseRealFFT(size_t NumSamples, const float *RealIn, const float *ImagIn, float *RealOut)
Definition: FFT.cpp:267
void FFT(size_t NumSamples, bool InverseTransform, const float *RealIn, const float *ImagIn, float *RealOut, float *ImagOut)
Definition: FFT.cpp:130
Definition: FFT.h:105
void DeinitFFT()
Definition: FFT.cpp:113
void PowerSpectrum(size_t NumSamples, const float *In, float *Out)
Definition: FFT.cpp:303
Definition: FFT.h:111
Definition: FFT.h:108
const wxChar * WindowFuncName(int whichFunction)
Definition: FFT.cpp:333