Skip to content

Commit aa4beea

Browse files
committed
Resolved issue wrong PSD values matrix size
1 parent c45e202 commit aa4beea

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
@@ -235,12 +235,10 @@ GraphSpectrumCalc._dataLoadPowerSpectralDensityVsX = function(vsFieldNames, minV
235235
const fftChunkWindow = Math.round(fftChunkLength / FREQ_VS_THR_WINDOW_DIVISOR);
236236

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

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

@@ -249,6 +247,13 @@ GraphSpectrumCalc._dataLoadPowerSpectralDensityVsX = function(vsFieldNames, minV
249247
const fftInput = flightSamples.samples.slice(fftChunkIndex, fftChunkIndex + fftChunkLength);
250248
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()
251249
maxNoise = Math.max(psd.max, maxNoise);
250+
// The _psd() can extend fft data size. Set psdLength and create matrix by first using
251+
if (matrixPsdOutput == undefined) {
252+
psdLength = psd.psdOutput.length;
253+
matrixPsdOutput = new Array(NUM_VS_BINS)
254+
.fill(null)
255+
.map(() => (new Float64Array(psdLength)).fill(BACKGROUND_PSD_VALUE));
256+
}
252257
// calculate a bin index and put the fft value in that bin for each field (e.g. eRPM[0], eRPM[1]..) sepparately
253258
for (const vsValueArray of flightSamples.vsValues) {
254259
// Calculate average of the VS values in the chunk

0 commit comments

Comments
 (0)