|
Krotos Modules 3
|
FFT-based cochlear power spectrogram. More...
#include <ERB_FFTSpectrogram.h>
Public Member Functions | |
| ERB_FFTSpectrogram () | |
| void | setSampleRate (float fs) |
| std::vector< std::vector< float > > | filterSpectrum (std::vector< float > &inputSignal) |
| void | drawSpectrogram (juce::Image &image, const std::vector< std::vector< float > > &erbSTFTPowMatrix) |
| std::vector< float > | getERBSpace () |
Static Public Member Functions | |
| static std::vector< float > | erbs2Hz (const std::vector< float > &erbsVector) |
| static Eigen::VectorXf | erbs2Hz (const Eigen::VectorXf &erbsVector) |
| static std::vector< float > | hz2Erbs (const std::vector< float > &hzVector) |
| static Eigen::VectorXf | hz2Erbs (const Eigen::VectorXf &hzVector) |
| static float | hz2Erbs (const float hz) |
Private Member Functions | |
| std::vector< float > | applyEarFilter (std::vector< float > &inputSignal) |
| std::vector< float > | gtWindow (int numberOfPoints, float bParam, int order) |
| std::vector< float > | cferb (std::vector< float > cf) |
| float | cferb (const float cf) |
| double | cferb (const double cf) |
| std::vector< float > | erbSpace (float low, float hi, int N) |
| float | centroid (const std::vector< float > &x) |
| float | getNextPowerOfTwo (float value) |
| void | buildFilterBank (int startSamplesSize) |
| std::vector< std::vector< float > > | calculatePowerSpectrum (const std::vector< std::vector< float > > &inFrames) |
| void | writeMatrixToFile (const std::vector< std::vector< float > > &matrix, const std::string &filename) |
Private Attributes | |
| float | m_sampleRate {-1.0f} |
| std::vector< std::vector< double > > | m_wfunct |
| std::vector< float > | m_cfArray |
| EarFilter | m_earFilter |
| float | m_hopSizeSec = 0.0058f |
| int | m_hopSizeSamples |
| const float | m_exponent = 0.25f |
| float | m_lo = 30.0f |
| float | m_hi = 16000.0f |
| int | m_numChans = 77 |
| float | m_bw0 = 24.7f |
| float | m_b0 = 25.15274949f |
| float | m_ERD = 0.0196797f |
| int | m_wSize |
| std::vector< float > | m_gtWin |
| const float | m_scalingConstant = 0.1f |
| int | m_fftSize |
FFT-based cochlear power spectrogram.
Power spectrogram with same frequency resolution and scale as human ear. ERB_FFTSpectrogram splits the signal into overlapping frames and windows each with a function shaped like the time-reversed envelope of a gammatone impulse response with parameters appropriate for a low-frequency cochlear filter, with an equivalent rectangular duration (ERD) of about 20ms. The FFT size is set to the power of two immediately larger than twice that value (sr*0.040), and the windowed slices are Fourier transformed to obtain a power spectrum. The frequency resolution is that of a "cf=0 Hz" channel, ie narrower than even the lowest cf channels, and the frequency axis is linear. To get a resolution similar to the cochlea, and channels evenly spaced on an equal-resolution scale (Cambridge ERBs), the power spectrum is remapped. Each channel of the new spectrum is the weighted sum of power spectrum coefficients, obtained by forming the vector product with a weighting function so that the channel has its proper spectral width.
| krotos::ERB_FFTSpectrogram::ERB_FFTSpectrogram | ( | ) |
Constructor
Copyright Krotos LTD 2023
All rights reserved.
|
private |
Applies the outer/middle ear filter using the EarFilter object
| inputSignal | vector representing the input Signal |
|
private |
Builds the ERB scale Filterbank - saves result in m_wfunct. Casted to double to rectify float underflow!!
| startSampleSize | last hop index where the window will fit within the end of the signal |
|
private |
Calculates the power spectrum per column
| inFrames | matrix represting the overlapping window frames of signal |
|
private |
Centroid of matrix x
| x | matrix |
|
private |
|
private |
|
private |
| void krotos::ERB_FFTSpectrogram::drawSpectrogram | ( | juce::Image & | image, |
| const std::vector< std::vector< float > > & | erbSTFTPowMatrix ) |
Draws a simple spectrogram for POC purposes. Assumes we have already produced the STFT matrix using the filterSpectrum() 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. |
|
static |
|
static |
Create ERB - scale uniformly - spaced frequencies(in Hertz)
|
private |
Computes an array of N frequencies uniformly spaced between lo and hi in the ERB scale. For a definition of ERB, see Moore, B. C. J., and Glasberg, B. R. (1983). "Suggested formulae for calculating auditory-filter bandwidths and excitation patterns," J. Acoust. Soc. Am. 74, 750-753.
| low | Hz - lower limit of vector |
| hi | Hz - upper limit of vector |
| N | number of values to produce |
| std::vector< std::vector< float > > krotos::ERB_FFTSpectrogram::filterSpectrum | ( | std::vector< float > & | inputSignal | ) |
Performs the fft power filtering operation
| inputSignal | vector representing the input Signal |
|
inline |
|
private |
Next power of two of float
| value | number whose nextpow2 I'm looking for |
|
private |
Caclulates a window shaped like a time-reversed gammatone envelope
| numberOfPoints | number of points |
| bParam | b-parameter |
| order | order of function |
|
static |
|
static |
|
static |
Create frequency vector in Hz from the ERB equivalent vector
| void krotos::ERB_FFTSpectrogram::setSampleRate | ( | float | fs | ) |
Sets the sampling Rate
| fs | sampling Rate [Hz] |
|
inlineprivate |
This function exists as a debugging mechanism to compare the spectrogram created here with it's equivalent in MATLAB.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |