Skip to content

Commit 3f72d63

Browse files
authored
Improved computing of vsBinIndex values
1 parent f3d1ec1 commit 3f72d63

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
@@ -186,9 +186,7 @@ GraphSpectrumCalc._dataLoadFrequencyVsX = function(vsFieldNames, minValue = Infi
186186
}
187187
// Translate the average vs value to a bin index
188188
const avgVsValue = sumVsValues / fftChunkLength;
189-
let vsBinIndex = Math.round(NUM_VS_BINS * (avgVsValue - flightSamples.minValue) / (flightSamples.maxValue - flightSamples.minValue));
190-
// ensure that avgVsValue == flightSamples.maxValue does not result in an out of bounds access
191-
if (vsBinIndex >= NUM_VS_BINS) { vsBinIndex = NUM_VS_BINS - 1; }
189+
const vsBinIndex = Math.round((NUM_VS_BINS - 1) * (avgVsValue - flightSamples.minValue) / (flightSamples.maxValue - flightSamples.minValue));
192190
numberSamples[vsBinIndex]++;
193191

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

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

0 commit comments

Comments
 (0)