Skip to content

Commit 6b496cf

Browse files
committed
Code refactoring
1 parent 18060f9 commit 6b496cf

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/graph_spectrum_calc.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,11 @@ GraphSpectrumCalc._dataLoadFrequencyVsX = function(vsFieldNames, minValue = Infi
152152
const matrixFftOutput = new Array(NUM_VS_BINS).fill(null).map(() => new Float64Array(fftBufferSize * 2));
153153
const numberSamples = new Uint32Array(NUM_VS_BINS); // Number of samples in each vs value, used to average them later.
154154
const fft = new FFT.complex(fftBufferSize, false);
155+
const fftInput = new Float64Array(fftBufferSize);
156+
const fftOutput = new Float64Array(fftBufferSize * 2);
155157

156158
for (let fftChunkIndex = 0; fftChunkIndex + fftChunkLength < flightSamples.samples.length; fftChunkIndex += fftChunkWindow) {
157159

158-
const fftInput = new Float64Array(fftBufferSize);
159-
let fftOutput = new Float64Array(fftBufferSize * 2);
160-
161160
const samples = flightSamples.samples.slice(fftChunkIndex, fftChunkIndex + fftChunkLength);
162161
fftInput.set(samples);
163162

@@ -168,10 +167,9 @@ GraphSpectrumCalc._dataLoadFrequencyVsX = function(vsFieldNames, minValue = Infi
168167

169168
fft.simple(fftOutput, fftInput, 'real');
170169

171-
fftOutput = fftOutput.slice(0, fftBufferSize); // The fft output contains two side spectrum, we use the first part only to get one side
172-
const magnitudes = new Float64Array(magnitudeLength);
173-
174170
// Compute magnitude
171+
// The fftOutput contains two side spectrum, we use the first part only to get one side
172+
const magnitudes = new Float64Array(magnitudeLength);
175173
for (let i = 0; i < magnitudeLength; i++) {
176174
const re = fftOutput[2 * i],
177175
im = fftOutput[2 * i + 1];

0 commit comments

Comments
 (0)