MCPcopy Create free account
hub / github.com/FastLED/FastLED / generateSyntheticFFT

Function generateSyntheticFFT

tests/fl/audio/test_helpers.h:157–169  ·  view source on GitHub ↗

Generate synthetic FFT bin data with a peak at specified frequency. Uses linear bin spacing (for use with FrequencyBinMapper and raw FFT data). @param numBins Number of frequency bins @param peakFrequency Frequency where the peak should occur (Hz) @param sampleRate Sample rate in Hz @return Vector of float magnitudes (one per bin)

Source from the content-addressed store, hash-verified

155/// @param sampleRate Sample rate in Hz
156/// @return Vector of float magnitudes (one per bin)
157inline vector<float> generateSyntheticFFT(size numBins, float peakFrequency, u32 sampleRate) {
158 vector<float> bins;
159 bins.reserve(numBins);
160 float binWidth = sampleRate / (2.0f * numBins);
161 for (size i = 0; i < numBins; ++i) {
162 float binFreq = i * binWidth;
163 // Gaussian-like peak centered at peakFrequency
164 float distance = fl::abs(binFreq - peakFrequency) / binWidth;
165 float magnitude = fl::exp(-distance * distance / 2.0f);
166 bins.push_back(magnitude);
167 }
168 return bins;
169}
170
171/// Generate synthetic CQ-spaced FFT bin data with a peak at specified frequency.
172/// Uses CQ log-spaced frequency layout matching the actual CQ kernel.

Callers 1

Calls 4

expFunction · 0.85
absFunction · 0.50
reserveMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected