Skip to content

Commit 800eadb

Browse files
committed
Improved computing of vsBinIndex values
1 parent 743a293 commit 800eadb

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/graph_spectrum_calc.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ GraphSpectrumCalc._dataLoadFrequencyVsX = function(vsFieldNames, minValue = Infi
188188
}
189189
// Translate the average vs value to a bin index
190190
const avgVsValue = sumVsValues / fftChunkLength;
191-
let vsBinIndex = Math.round(NUM_VS_BINS * (avgVsValue - flightSamples.minValue) / (flightSamples.maxValue - flightSamples.minValue));
192-
// ensure that avgVsValue == flightSamples.maxValue does not result in an out of bounds access
193-
if (vsBinIndex >= NUM_VS_BINS) { vsBinIndex = NUM_VS_BINS - 1; }
191+
const vsBinIndex = Math.round((NUM_VS_BINS - 1) * (avgVsValue - flightSamples.minValue) / (flightSamples.maxValue - flightSamples.minValue));
194192
numberSamples[vsBinIndex]++;
195193

196194
// add the output from the fft to the row given by the vs value bin index
@@ -260,9 +258,7 @@ GraphSpectrumCalc._dataLoadPowerSpectralDensityVsX = function(vsFieldNames, minV
260258
}
261259
// Translate the average vs value to a bin index
262260
const avgVsValue = sumVsValues / fftChunkLength;
263-
let vsBinIndex = Math.floor(NUM_VS_BINS * (avgVsValue - flightSamples.minValue) / (flightSamples.maxValue - flightSamples.minValue));
264-
// ensure that avgVsValue == flightSamples.maxValue does not result in an out of bounds access
265-
if (vsBinIndex === NUM_VS_BINS) { vsBinIndex = NUM_VS_BINS - 1; }
261+
const vsBinIndex = Math.round((NUM_VS_BINS - 1) * (avgVsValue - flightSamples.minValue) / (flightSamples.maxValue - flightSamples.minValue));
266262
numberSamples[vsBinIndex]++;
267263

268264
// add the output from the fft to the row given by the vs value bin index

0 commit comments

Comments
 (0)