Skip to content

Commit f00b0aa

Browse files
committed
revert Calculate proper complex magnitudes due to merge-master.
1 parent 6f6d279 commit f00b0aa

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/graph_spectrum_calc.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,15 @@ GraphSpectrumCalc._dataLoadFrequencyVsX = function(vsFieldNames, minValue = Infi
245245

246246
fft.simple(fftOutputComplex, fftInput, 'real');
247247

248-
// The original code sliced fftOutputComplex (complex) to its first fftChunkLength float values.
249-
// This behavior is preserved. fftOutputProcessed will store these abs values.
250-
const fftOutputProcessed = new Float64Array(fftChunkLength);
251-
for (let i = 0; i < fftChunkLength; i++) {
252-
fftOutputProcessed[i] = Math.abs(fftOutputComplex[i]); // This processes Re0, Im0, Re1, Im1 ...
253-
maxNoise = Math.max(fftOutputProcessed[i], maxNoise);
248+
// Calculate proper complex magnitudes.
249+
const bins = fftChunkLength / 2 + 1;
250+
const fftOutputProcessed = new Float64Array(bins);
251+
for (let bin = 0; bin < bins; bin++) {
252+
const re = fftOutputComplex[2 * bin];
253+
const im = fftOutputComplex[2 * bin + 1];
254+
const mag = Math.hypot(re, im);
255+
fftOutputProcessed[bin] = mag;
256+
maxNoise = Math.max(maxNoise, mag);
254257
}
255258

256259
// Calculate a bin index and add the processed fft values to that bin

0 commit comments

Comments
 (0)