Skip to content

Commit 7fd3a08

Browse files
committed
spectrum samples: ensure powers of two
**Explanation of Changes Made (in the working modification):** This core change was to ensure that data segments fed into Fast Fourier Transform (FFT) operations have lengths that are powers of two. This was achieved by: 1. Introducing a helper function `_getLargestPowerOfTwoLeq(n)` to find the largest power of two less than or equal to a given number `n`. 2. Applying this function to determine the `effectiveSampleCount` in `dataLoadFrequency`, the `pointsPerSegment` in `dataLoadPSD`, and the `fftChunkLength` in `_dataLoadFrequencyVsX`. 3. Adding a `MIN_FFT_POINTS` constant and checks to prevent FFTs on overly small data segments, returning empty/default results if necessary. 4. Adjusting the initialization and processing of `matrixFftOutput` in `_dataLoadFrequencyVsX` to correctly handle the (potentially modified) power-of-2 `fftChunkLength`, especially concerning the dimensions of the output matrix and the averaging loop. The original logic of slicing the complex FFT output and processing its first `fftChunkLength` elements was maintained, but now `fftChunkLength` is a power of two. **Overall Function & Impact of Changes:** `GraphSpectrumCalc` is an object responsible for performing various signal processing calculations on flight log data, primarily to analyze frequency spectrums and noise characteristics. Its key functions include: * Calculating standard FFTs on selected data channels (`dataLoadFrequency`). * Computing Power Spectral Density (PSD) using Welch's method (`dataLoadPSD`). * Generating frequency-vs-throttle or frequency-vs-RPM heatmaps by performing FFTs on short, overlapping time chunks of data and correlating them with throttle/RPM values (`_dataLoadFrequencyVsX`). * Analyzing PID error relative to setpoint values (`dataLoadPidErrorVsSetpoint`). This commit specifically ensures FFT input lengths are powers of two, primarily impact the **performance and potentially the numerical stability/accuracy** of the FFT calculations within these functions. FFT algorithms are often highly optimized for power-of-two input sizes. By adhering to this, the browser's JavaScript engine or the underlying FFT library (`FFT.js`) can execute these computations much more efficiently, reducing processing time and potentially alleviating UI stalls or slowdowns previously experienced when analyzing large datasets or performing many FFTs (as in the heatmap generation). The introduction of `MIN_FFT_POINTS` also adds robustness by preventing calculations on impractically small data segments. The core analytical goals remain the same, but they are now achieved with potentially improved computational speed.
1 parent cd62b52 commit 7fd3a08

File tree

1 file changed

+205
-91
lines changed

1 file changed

+205
-91
lines changed

0 commit comments

Comments
 (0)