Skip to content

Commit c45e202

Browse files
committed
Resolved issues of using power at 2 values
1 parent 141c329 commit c45e202

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/graph_spectrum_calc.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ GraphSpectrumCalc.dataLoadPSD = function(analyserZoomY) {
115115
const multiplier = Math.floor(1 / analyserZoomY); // 0. ... 10
116116
let pointsPerSegment = 2 ** (8 + multiplier); //256, 512, 1024 ...
117117

118-
// Use power 2 fft size what is not bigger flightSamples.samples.length
118+
let overlapCount;
119119
if (pointsPerSegment > flightSamples.samples.length) {
120-
pointsPerSegment = this.getNearPower2Value(flightSamples.samples.length);
120+
pointsPerSegment = flightSamples.samples.length; // Use actual sample length. It will transform to power at 2 value inside the _psd() - fft_segmented
121+
overlapCount = 0;
122+
} else {
123+
overlapCount = pointsPerSegment / 2;
121124
}
122125

123-
const overlapCount = pointsPerSegment / 2;
124-
125126
const psd = this._psd(flightSamples.samples, pointsPerSegment, overlapCount);
126127

127128
const psdData = {

src/graph_spectrum_plot.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,10 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) {
350350
// Allign y axis range by 10db
351351
const dbStep = 10;
352352
const minY = Math.floor(this._fftData.minimum / dbStep) * dbStep;
353-
const maxY = (Math.floor(this._fftData.maximum / dbStep) + 1) * dbStep;
353+
let maxY = (Math.floor(this._fftData.maximum / dbStep) + 1) * dbStep;
354+
if (minY == maxY) {
355+
maxY = minY + 1; // prevent divide by zero
356+
}
354357
const ticksCount = (maxY - minY) / dbStep;
355358
const scaleY = HEIGHT / (maxY - minY);
356359
//Store vsRange for _drawMousePosition

0 commit comments

Comments
 (0)