Skip to content

Commit 8cec5a8

Browse files
committed
Resolved issue computing PSD for full file length segment size
1 parent b65c184 commit 8cec5a8

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/graph_spectrum.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,6 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
348348
})
349349
.val(DEFAULT_PSD_SEGMENT_LENGTH_POWER);
350350

351-
analyserSegmentLengthPowerAt2
352-
.on(
353-
"keydown",
354-
function (e) {
355-
e.preventDefault();
356-
},
357-
);
358351
// Spectrum type to show
359352
userSettings.spectrumType =
360353
userSettings.spectrumType || SPECTRUM_TYPE.FREQUENCY;

src/graph_spectrum_calc.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const GraphSpectrumCalc = {
3535
_flightLog : null,
3636
_sysConfig : null,
3737
_motorPoles : null,
38-
_pointsPerSegmentPSD : 0,
38+
_pointsPerSegmentPSD : 64,
3939
};
4040

4141
GraphSpectrumCalc.initialize = function(flightLog, sysConfig) {
@@ -119,16 +119,15 @@ GraphSpectrumCalc.setPointsPerSegmentPSD = function(pointsCount) {
119119

120120
GraphSpectrumCalc.dataLoadPSD = function(analyserZoomY) {
121121
const flightSamples = this._getFlightSamplesFreq(false);
122-
let pointsPerSegment, overlapCount;
123-
if (this._pointsPerSegmentPSD > flightSamples.samples.length) {
124-
pointsPerSegment = flightSamples.samples.length; // Use actual sample length. It will transform to power at 2 value inside the _psd() - fft_segmented
125-
overlapCount = 0;
126-
} else {
127-
pointsPerSegment = this._pointsPerSegmentPSD;
128-
overlapCount = pointsPerSegment * 3 / 4;
129-
}
130-
131-
const psd = this._psd(flightSamples.samples, pointsPerSegment, overlapCount);
122+
const totalCount = flightSamples.count; // actual samples, not padded length
123+
let pointsPerSegment = Math.min(this._pointsPerSegmentPSD, totalCount);
124+
// Non-overlapping when single full-segment; otherwise 75% overlap
125+
const overlapCount = (pointsPerSegment === totalCount) ? 0 : Math.floor(pointsPerSegment * 3 / 4);
126+
// Avoid bias from zero-padded tail
127+
const samplesForPsd = (flightSamples.samples.length === totalCount)
128+
? flightSamples.samples
129+
: flightSamples.samples.slice(0, totalCount);
130+
const psd = this._psd(samplesForPsd, pointsPerSegment, overlapCount);
132131

133132
const psdData = {
134133
fieldIndex : this._dataBuffer.fieldIndex,
@@ -139,7 +138,7 @@ GraphSpectrumCalc.dataLoadPSD = function(analyserZoomY) {
139138
minimum: psd.min,
140139
maximum: psd.max,
141140
maxNoiseFrequency: psd.maxNoiseFrequency,
142-
maximalSegmentsLength: this.getNearPower2Value(flightSamples.samples.length),
141+
maximalSegmentsLength: this.getNearPower2Value(totalCount),
143142
};
144143
return psdData;
145144
};

0 commit comments

Comments
 (0)