|
Krotos Modules 3
|
Apply STFT analysis to a full audio signal offline. More...
#include <ShortTimeFourierTransform.h>
Classes | |
| struct | BinParams |
| struct | DFTParams |
Public Types | |
| enum | fftMode { freqMagOnly = 0 , realOnly , complex , modeNUM_MODES } |
| enum class | FrequencyRange { Whole , Half } |
Public Member Functions | |
| ShortTimeFourierTransform (int winSizeSamples, int fftSizeSamples, int hopSize, WindowType winMethod, fftMode mode, int sampleRate) | |
| std::vector< std::vector< float > > | stft (const AudioSampleBuffer &inputSignal) |
| Eigen::MatrixXf | processSignal (const Eigen::VectorXf inputSignal) |
| std::vector< float > | istft (std::vector< std::vector< float > > stftMatrix) |
| void | drawSpectrogram (juce::Image &image, const std::vector< std::vector< float > > &stftMatrix) |
| std::vector< float > | getBinsSTL (ShortTimeFourierTransform::FrequencyRange freqRange) |
| Eigen::VectorXf | getBins (ShortTimeFourierTransform::FrequencyRange freqRange) |
| Calculates and returns the frequency bins for a given frequency range within the context of a short-time Fourier transform analysis. This function computes the frequency resolution based on the FFT size and sample rate, adjusts the frequency bins for odd or even number of points, and then selects the appropriate range of bins to return based on the specified frequency range. | |
| std::vector< float > | getColumnsSTL () |
| Eigen::VectorXf | getColumns () |
| Computes and returns the time indices for the center of each STFT window. | |
| float | getFFTBinSize () const |
Public Attributes | |
| enum krotos::ShortTimeFourierTransform::fftMode | m_mode |
| struct krotos::ShortTimeFourierTransform::DFTParams | dftParams |
Private Member Functions | |
| void | NPTSinfo (float NPTS) |
| Eigen::VectorXf | finalGrid (const Eigen::VectorXf &w1, float Nyq, bool centerDC, ShortTimeFourierTransform::FrequencyRange freqRange) |
Private Attributes | |
| struct krotos::ShortTimeFourierTransform::BinParams | binParams |
| juce::dsp::FFT | m_fft |
| std::vector< float > | m_window |
| std::vector< float > | m_sigFrame |
| Eigen::VectorXf | sigFrame |
| int | m_numFrames {0} |
| const float | m_scalingConstant = 0.1f |
| int | m_inputSize {0} |
Apply STFT analysis to a full audio signal offline.
This class implements the STFT analysis on an audio signal. Depending on the frame size and hop size it segments the signal into overlapping windowed frames and performs an fft on each one, depending on the value fftMode has been set to. Also includes a spectrogram drawing function for debugging purposes and an istft routine. Window for now uses n+1 samples for perfect signal reconstruction(hann Window + overlap = 50%)
|
strong |
| krotos::ShortTimeFourierTransform::ShortTimeFourierTransform | ( | int | winSizeSamples, |
| int | fftSizeSamples, | ||
| int | hopSize, | ||
| WindowType | winMethod, | ||
| fftMode | mode, | ||
| int | sampleRate ) |
| void krotos::ShortTimeFourierTransform::drawSpectrogram | ( | juce::Image & | image, |
| const std::vector< std::vector< float > > & | stftMatrix ) |
Draws a simple spectrogram for POC purposes. Assumes we have already produced the STFT matrix using the stft() above.
| image | the Image component whose pixels we want to colour according to the mag of the bins. TODO: write a better scaling algorithm and average the signal magnitudes. |
| stftMatrix | the STFT matrix in mxn dimensions where m: mth frame, n: nth bin. NOTE: you should call repaint after this so that the new Image appears. |
|
private |
| Eigen::VectorXf krotos::ShortTimeFourierTransform::getBins | ( | ShortTimeFourierTransform::FrequencyRange | freqRange | ) |
Calculates and returns the frequency bins for a given frequency range within the context of a short-time Fourier transform analysis. This function computes the frequency resolution based on the FFT size and sample rate, adjusts the frequency bins for odd or even number of points, and then selects the appropriate range of bins to return based on the specified frequency range.
| freqRange | Specifies the frequency range for which the bins should be calculated. This can be WHOLE, HALF, or any other defined range within the FrequencyRange enum. |
| std::vector< float > krotos::ShortTimeFourierTransform::getBinsSTL | ( | ShortTimeFourierTransform::FrequencyRange | freqRange | ) |
| Eigen::VectorXf krotos::ShortTimeFourierTransform::getColumns | ( | ) |
Computes and returns the time indices for the center of each STFT window.
This function calculates the column offsets for the short-time Fourier transform (STFT) output based on the input size, window size, overlap, and hop size. The time indices represent the center of each STFT window, normalized by the sample rate to convert from samples to seconds. These indices can be used to understand the temporal positioning of each column in the STFT result.
m_inputSize). This function relies on the assumption that m_inputSize, dftParams.winSize, dftParams.nOverlap, and dftParams.hopSize are properly initialized and represent the actual parameters used in the STFT computation. | std::vector< float > krotos::ShortTimeFourierTransform::getColumnsSTL | ( | ) |
| float krotos::ShortTimeFourierTransform::getFFTBinSize | ( | ) | const |
| std::vector< float > krotos::ShortTimeFourierTransform::istft | ( | std::vector< std::vector< float > > | stftMatrix | ) |
Performs an inverse STFT. Assumes we have already produced the STFT matrix using the stft() above. This means that the frames retrieved from the istft are not windowed again and the mode is real only fft. TODO: If needed write version that rewindows the frames.
| stftMatrix | the STFT matrix in mxn dimensions where m: mth frame, n: nth bin. returns a vector of floats representing the reconstructed signal |
|
private |
| Eigen::MatrixXf krotos::ShortTimeFourierTransform::processSignal | ( | const Eigen::VectorXf | inputSignal | ) |
| std::vector< std::vector< float > > krotos::ShortTimeFourierTransform::stft | ( | const AudioSampleBuffer & | inputSignal | ) |
Performs a forward STFT. Depending on the mode of the FFT we want to use it either performs a real only or a freqMagnitude only FFT. TODO: Extract information from the complex number fft.
| buffer | the whole input Sample we want to analyse frame by frame. returns a vector of vectors where each column is a different frame and each row a frequency bin. TODO:: stl removal |
|
private |
| struct krotos::ShortTimeFourierTransform::DFTParams krotos::ShortTimeFourierTransform::dftParams |
|
private |
|
private |
| enum krotos::ShortTimeFourierTransform::fftMode krotos::ShortTimeFourierTransform::m_mode |
|
private |
|
private |
|
private |
|
private |
|
private |