/
FFT.h
134 lines (108 loc) · 4.32 KB
/
FFT.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
** Copyright (C) 2008, 2009 Ricard Marxer <email@ricardmarxer.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef FFT_H
#define FFT_H
#include "Typedefs.h"
#include "Debug.h"
#include <fftw3.h>
/**
* @class FFT
*
* @brief Algorithm to perform a Fast Fourier Transform of a vector of Real values.
*
* This class represents an object to perform Fast Fourier Transforms (FFT) on Real data.
* The FFT is a fast implementation of a Discrete Fourier Transform (DFT).
* The algorithm takes as input N-point vectors of Real values (N being the frame size)
* and returns (M / 2 + 1) point vectors of Complex values (M being the FFT size).
*
* Note that the algorithm works fastest when M is a power of 2.
*
* Since the input is Real valued, the FFT will be symmetric
* and only half of the output is needed.
* This processing unit will only return the (M / 2 + 1)-point array
* corresponding to positive frequencies of the FFT.
*
* When M is different than N the input data is zero padded at the end.
* Alternatively the algorithm can perform an N/2 rotation and zero pad the center
* before the FFT to allow a zero phase transform.
* This is done by using the setZeroPhase() method.
*
* @author Ricard Marxer
*
* @sa FFTComplex, IFFT, IFFTComplex
*/
class FFT{
protected:
int _fftSize;
bool _zeroPhase;
int _halfSize;
Real* _in;
fftwf_complex* _out;
fftwf_plan _fftplan;
public:
/**
Constructs an FFT object with the specified @a fftSize and @a
zeroPhase setting.
@param fftSize size of the FFT transform must be > 0,
it is the target size of the transform.
The algorithm performs faster for sizes which are a power of 2.
@param zeroPhase determines whether
or not to perform the zero phase transform.
*/
FFT(int fftSize = 1024, bool zeroPhase = true);
/**
Destroys the FFT algorithm and frees its resources.
*/
~FFT();
/**
Performs a Fast Fourier Transform on each of the rows of @a frames and
puts the resulting FFT in the rows of @a fft.
@param frames matrix of Real values. The number of columns of @a frames must
be smaller or equal to the fftSize property.
@param fft pointer to a matrix of Complex values for the output. The matrix should
have the same number of rows as @a frames and (fftSize / 2) + 1 columns.
Note that if the output matrix is not of the required size it will be resized,
reallocating a new memory space if necessary.
*/
void process(const MatrixXR& frames, MatrixXC* fft);
void setup();
void reset();
/**
Returns the size of the FFT to be performed. The default is 1024.
@sa setFftSize()
*/
int fftSize() const;
/**
Specifies the @a size of the FFT to be performed.
The given @a size must be higher than 0.
Note that if @a size is a power of 2 will perform faster.
@sa fftSize()
*/
void setFftSize( int size, bool callSetup = true );
/**
Returns the zero phase setting. The default is True.
@sa setZeroPhase()
*/
bool zeroPhase() const;
/**
Specifies the @a zeroPhase setting.
@sa zeroPhase()
*/
void setZeroPhase( bool zeroPhase, bool callSetup = true );
};
#endif /* FFT_H */