Skip to content

Commit a06a209

Browse files
committed
Resolved issues of using power at 2 values
1 parent c179844 commit a06a209

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
@@ -117,13 +117,14 @@ GraphSpectrumCalc.dataLoadPSD = function(analyserZoomY) {
117117
const multiplier = Math.floor(1 / analyserZoomY); // 0. ... 10
118118
let pointsPerSegment = 2 ** (8 + multiplier); //256, 512, 1024 ...
119119

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

125-
const overlapCount = pointsPerSegment / 2;
126-
127128
const psd = this._psd(flightSamples.samples, pointsPerSegment, overlapCount);
128129

129130
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)