Skip to content

Commit 16b2fd1

Browse files
committed
Resolved issue wrong PSD values matrix size
1 parent a06a209 commit 16b2fd1

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/graph_spectrum_calc.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,10 @@ GraphSpectrumCalc._dataLoadPowerSpectralDensityVsX = function(vsFieldNames, minV
237237
const fftChunkWindow = Math.round(fftChunkLength / FREQ_VS_THR_WINDOW_DIVISOR);
238238

239239
let maxNoise = 0; // Stores the maximum amplitude of the fft over all chunks
240-
const psdLength = Math.floor(fftChunkLength / 2);
240+
let psdLength = 0;
241241
// Matrix where each row represents a bin of vs values, and the columns are amplitudes at frequencies
242242
const BACKGROUND_PSD_VALUE = -200;
243-
const matrixPsdOutput = new Array(NUM_VS_BINS)
244-
.fill(null)
245-
.map(() => (new Float64Array(psdLength)).fill(BACKGROUND_PSD_VALUE));
243+
let matrixPsdOutput = undefined;
246244

247245
const numberSamples = new Uint32Array(NUM_VS_BINS); // Number of samples in each vs value, used to average them later.
248246

@@ -251,6 +249,13 @@ GraphSpectrumCalc._dataLoadPowerSpectralDensityVsX = function(vsFieldNames, minV
251249
const fftInput = flightSamples.samples.slice(fftChunkIndex, fftChunkIndex + fftChunkLength);
252250
const psd = this._psd(fftInput, fftChunkLength, 0, 'density'); // Using the one segment with all chunks fftChunkLength size, it will extended at power at 2 size inside _psd() - _fft_segmented()
253251
maxNoise = Math.max(psd.max, maxNoise);
252+
// The _psd() can extend fft data size. Set psdLength and create matrix by first using
253+
if (matrixPsdOutput == undefined) {
254+
psdLength = psd.psdOutput.length;
255+
matrixPsdOutput = new Array(NUM_VS_BINS)
256+
.fill(null)
257+
.map(() => (new Float64Array(psdLength)).fill(BACKGROUND_PSD_VALUE));
258+
}
254259
// calculate a bin index and put the fft value in that bin for each field (e.g. eRPM[0], eRPM[1]..) sepparately
255260
for (const vsValueArray of flightSamples.vsValues) {
256261
// Calculate average of the VS values in the chunk

0 commit comments

Comments
 (0)