Nsound
0.9.4
|
A Class that performes the Fast Fouier Transfrom on a Buffer. More...
#include <Nsound/FFTransform.h>
Public Member Functions | |
FFTransform (const float64 &sample_rate) | |
~FFTransform () | |
Destructor. More... | |
Buffer | fft (const Buffer &time_domain) const |
Transforms the time_domain signal and calculates the FFT. More... | |
FFTChunkVector | fft (const Buffer &input, int32 n_order, int32 n_overlap=0) const |
Performs the FFT of size N on the input Buffer of overlaping frames. More... | |
Buffer | ifft (const FFTChunkVector &input) const |
Peforms an inverse FFT on each FFTChunk and concatenates the output. More... | |
Buffer | ifft (const Buffer &frequency_domain) const |
Peforms an inverse FFT on the input Buffer. More... | |
void | setWindow (WindowType type) |
A window is multiplied by the input prior to performing the transform, this help reduce artifacts near the edges. More... | |
Static Public Member Functions | |
static int32 | roundUp2 (int32 raw) |
Returns nearest power of 2 >= raw. More... | |
Protected Attributes | |
uint32 | sample_rate_ |
Samples per second. More... | |
Private Member Functions | |
void | fft (Buffer &real, Buffer &img, int32 n_order) const |
Peforms an inplace, nth order Fast Fouier Transform on the Buffers. More... | |
Private Attributes | |
WindowType | type_ |
A Class that performes the Fast Fouier Transfrom on a Buffer.
Implementing the fft algorithm on page 235 of the book: "Digital Signal Processing: A Practical Guide for Engineers and Scientists"
ISBN-13: 978-0-7506-7444-7
ISBN-10: 0-7506-7444-X
Definition at line 57 of file FFTransform.h.
FFTransform::FFTransform | ( | const float64 & | sample_rate | ) |
Creates an FFTTransform instance. The sample rate here is only used to tell the FFTChunk objects how to plot the spectrum, otherwise it does play a role.
Definition at line 41 of file FFTransform.cc.
|
inline |
Transforms the time_domain signal and calculates the FFT.
The size of the FFT is determined to be a power of 2 greater than or equal to the length of time_domain. If time_domain is less than a power of 2, the Buffer is padded with zeros until it is exactly a power of 2.
Definition at line 50 of file FFTransform.cc.
References Nsound::Buffer::getLength(), Nsound::Buffer::getSpeedUp(), roundUp2(), and sample_rate_.
Referenced by Nsound::Spectrogram::computeMagnitude(), fft(), FFTransform_UnitTest(), Nsound::Filter::getFrequencyResponse(), Nsound::Filter::getPhaseResponse(), ifft(), main(), my_main(), Nsound::Stretcher::searchForBestMatch(), and Nsound::Spectrogram::Spectrogram().
FFTChunkVector FFTransform::fft | ( | const Buffer & | input, |
int32 | n_order, | ||
int32 | n_overlap = 0 |
||
) | const |
Performs the FFT of size N on the input Buffer of overlaping frames.
The size of the FFT is specifed by n_order. The input Buffer is broken up into frames of size n_order, the returned FFTChunkVector is the result for each frame. If n_overlap is > 0, the frames will overlap by that number of samples.
Let n_order = 16 and n_overlap = 0, this how the input is split into frames.
The returned FFTChunkVector will have 3 FFTChunk objects that represent the FFT for each of the frames above, note that the last frame will be padded out to compile a 16-point FFT.
Let n_order = 16 and n_overlap = 4, this how the input is split into frames.
The returned FFTChunkVector will have 4 FFTChunk objects that represent the FFT for each of the frames above, note that the these frames contain overlapping samples as specified. Also note that the last frame in this case has a large number of padded zeros.
Definition at line 75 of file FFTransform.cc.
References Nsound::Generator::drawWindow(), fft(), Nsound::Buffer::getLength(), roundUp2(), sample_rate_, Nsound::Generator::silence(), Nsound::Buffer::subbuffer(), and type_.
Buffer FFTransform::ifft | ( | const FFTChunkVector & | input | ) | const |
Peforms an inverse FFT on each FFTChunk and concatenates the output.
This transforms the frequency domain signals held in the FFTChunkVector back to the time domain. If the FFTChunkVector was created with non-overlapping frames, the resulting output Buffer will be nearly identical to the original input (there will be some small round-off error).
Definition at line 207 of file FFTransform.cc.
References Nsound::Buffer::begin(), fft(), Nsound::FFTChunk::imag_, Nsound::FFTChunk::isPolar(), Nsound::FFTChunk::real_, roundUp2(), Nsound::Buffer::subbuffer(), and Nsound::FFTChunk::toCartesian().
Referenced by FFTransform_UnitTest(), ifft(), and main().
Peforms an inverse FFT on the input Buffer.
This transforms the frequency domain signal held in the input Buffer back to the time domain. The input signal will get padded so its length is exactly a power of 2.
Definition at line 248 of file FFTransform.cc.
References Nsound::Buffer::getLength(), Nsound::Buffer::getReverse(), ifft(), roundUp2(), sample_rate_, and Nsound::Buffer::subbuffer().
Returns nearest power of 2 >= raw.
Definition at line 274 of file FFTransform.cc.
Referenced by fft(), Nsound::Filter::getFrequencyAxis(), ifft(), and Nsound::Spectrogram::Spectrogram().
void FFTransform::setWindow | ( | WindowType | type | ) |
A window is multiplied by the input prior to performing the transform, this help reduce artifacts near the edges.
Definition at line 292 of file FFTransform.cc.
References type_.
Peforms an inplace, nth order Fast Fouier Transform on the Buffers.
Definition at line 130 of file FFTransform.cc.
|
protected |
|
private |
Definition at line 228 of file FFTransform.h.
Referenced by fft(), and setWindow().