Skip to content

Commit 2476e1d

Browse files
committed
Added points per segment count change from html input
1 parent ec62b9d commit 2476e1d

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

src/graph_spectrum.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
1717
const that = this,
1818
prefs = new PrefStorage(),
1919
DEFAULT_PSD_HEATMAP_MIN = -40,
20-
DEFAULT_PSD_HEATMAP_MAX = 10;
20+
DEFAULT_PSD_HEATMAP_MAX = 10,
21+
DEFAULT_PSD_SEGMENT_LENGTH = 512;
2122
let analyserZoomX = 1.0 /* 100% */,
2223
analyserZoomY = 1.0 /* 100% */,
2324
dataReload = false,
@@ -122,7 +123,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
122123
left: `${newSize.width - 150}px`,
123124
});
124125
$("#analyserSegmentLengthPSDLabel", parentElem).css({
125-
left: `${newSize.width - 150}px`,
126+
left: `${newSize.width - 170}px`,
126127
});
127128
};
128129

@@ -297,30 +298,41 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
297298
})
298299
.val(analyserMinPSD.val());
299300

300-
let previousSegLenValue = 512;
301+
let segmentLenghtPSD = DEFAULT_PSD_SEGMENT_LENGTH;
302+
GraphSpectrumCalc.setPointsPerSegmentPSD(segmentLenghtPSD);
301303
analyserSegmentLengthPSD
302304
.on(
303305
"input",
304306
function () {
305307
const currentValue = parseInt($(this).val());
306-
if (currentValue > previousSegLenValue) {
307-
previousSegLenValue *= 2;
308-
} else {
309-
previousSegLenValue /= 2;
308+
if (currentValue > segmentLenghtPSD) {
309+
segmentLenghtPSD *= 2;
310+
} else if (currentValue < segmentLenghtPSD){
311+
segmentLenghtPSD /= 2;
310312
}
311-
$(this).val(previousSegLenValue);
313+
$(this).val(segmentLenghtPSD);
312314
// Recalculate PSD with updated samples per segment count
315+
GraphSpectrumCalc.setPointsPerSegmentPSD(segmentLenghtPSD);
313316
dataLoad();
314317
GraphSpectrumPlot.setData(fftData, userSettings.spectrumType);
315318
that.refresh();
316319
},
317320
)
318321
.dblclick(function (e) {
319322
if (e.ctrlKey) {
320-
$(this).val(userSettings.psdHeatmapMax).trigger("input");
323+
segmentLenghtPSD = DEFAULT_PSD_SEGMENT_LENGTH;
324+
$(this).val(DEFAULT_PSD_SEGMENT_LENGTH).trigger("input");
321325
}
322326
})
323-
.val(512);
327+
.val(DEFAULT_PSD_SEGMENT_LENGTH);
328+
329+
analyserSegmentLengthPSD
330+
.on(
331+
"keydown",
332+
function (e) {
333+
e.preventDefault();
334+
}
335+
);
324336

325337
// Spectrum type to show
326338
userSettings.spectrumType =

src/graph_spectrum_calc.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const GraphSpectrumCalc = {
3535
_flightLog : null,
3636
_sysConfig : null,
3737
_motorPoles : null,
38+
_pointsPerSegmentPSD : 0,
3839
};
3940

4041
GraphSpectrumCalc.initialize = function(flightLog, sysConfig) {
@@ -112,16 +113,18 @@ GraphSpectrumCalc.dataLoadFrequency = function() {
112113
return fftData;
113114
};
114115

116+
GraphSpectrumCalc.setPointsPerSegmentPSD = function(pointsCount) {
117+
this._pointsPerSegmentPSD = pointsCount;
118+
};
119+
115120
GraphSpectrumCalc.dataLoadPSD = function(analyserZoomY) {
116121
const flightSamples = this._getFlightSamplesFreq(false);
117-
const multiplier = Math.floor(1 / analyserZoomY); // 0. ... 10
118-
let pointsPerSegment = 2 ** (8 + multiplier); //256, 512, 1024 ...
119-
120-
let overlapCount;
121-
if (pointsPerSegment > 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;
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;
124126
} else {
127+
pointsPerSegment = this._pointsPerSegmentPSD;
125128
overlapCount = pointsPerSegment / 2;
126129
}
127130

0 commit comments

Comments
 (0)