Skip to content

Power spectral density curves settings impromement #844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ <h4>Workspace</h4>
/>
<input id="analyserZoomY" class="onlyFullScreen" type="range" name="analyserZoomY" value="100" min="10" max="1000" step="10" list="analyserZoomYTicks"
/>
<input id="analyserSegmentLengthPSD" class="onlyFullScreen" type="number" name="analyserSegmentLengthPSD" value="512" min="64" max="1048576" step="1"
/>
<input id="analyserLowLevelPSD" class="onlyFullScreen" type="number" name="analyserLowLevelPSD" value="-40" min="-40" max="10" step="5"
/>
<input id="analyserMaxPSD" class="onlyFullScreen" type="number" name="analyserMaxPSD" value="10" min="-35" max="100" step="5"
Expand All @@ -508,6 +510,9 @@ <h4>Workspace</h4>
<label id="analyserLowLevelPSDLabel" name="analyserLowLevelPSDLabel" class="onlyFullScreen" >
Limit&nbsp;dBm
</label>
<label id="analyserSegmentLengthPSDLabel" name="analyserSegmentLengthPSDLabel" class="onlyFullScreen" >
Segments&nbsp;length
</label>

<datalist id="analyserZoomXTicks">
<option>100</option>
Expand Down
20 changes: 19 additions & 1 deletion src/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,9 @@ html.has-analyser-fullscreen.has-analyser
.analyser input#analyserMaxPSD::-webkit-inner-spin-button,
.analyser input#analyserMaxPSD::-webkit-outer-spin-button,
.analyser input#analyserLowLevelPSD::-webkit-inner-spin-button,
.analyser input#analyserLowLevelPSD::-webkit-outer-spin-button {
.analyser input#analyserLowLevelPSD::-webkit-outer-spin-button,
.analyser input#analyserSegmentLengthPSD::-webkit-inner-spin-button,
.analyser input#analyserSegmentLengthPSD::-webkit-outer-spin-button {
-webkit-appearance: auto !important;
-moz-appearance: auto !important;
appearance: auto !important;
Expand Down Expand Up @@ -744,6 +746,22 @@ html.has-analyser-fullscreen.has-analyser
font-size: 12px;
}

.analyser input#analyserSegmentLengthPSD {
width: 80px;
height: 20px;
left: 0px;
top: 50px;
}

.analyser label#analyserSegmentLengthPSDLabel {
position:absolute;
color:gray;
width: 50px;
height: 20px;
left: 0px;
top: 28px;
}

.analyser input.onlyFullScreen {
display: none;
padding: 3px;
Expand Down
68 changes: 58 additions & 10 deletions src/graph_spectrum.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
const that = this,
prefs = new PrefStorage(),
DEFAULT_PSD_HEATMAP_MIN = -40,
DEFAULT_PSD_HEATMAP_MAX = 10;
DEFAULT_PSD_HEATMAP_MAX = 10,
DEFAULT_PSD_SEGMENT_LENGTH = 512;
let analyserZoomX = 1.0 /* 100% */,
analyserZoomY = 1.0 /* 100% */,
dataReload = false,
Expand All @@ -35,6 +36,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
const analyserMinPSD = $("#analyserMinPSD");
const analyserMaxPSD = $("#analyserMaxPSD");
const analyserLowLevelPSD = $("#analyserLowLevelPSD");
const analyserSegmentLengthPSD = $("#analyserSegmentLengthPSD");


const spectrumToolbarElem = $("#spectrumToolbar");
Expand Down Expand Up @@ -117,6 +119,12 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
$("#analyserLowLevelPSDLabel", parentElem).css({
left: `${newSize.width - 155}px`,
});
$("#analyserSegmentLengthPSD", parentElem).css({
left: `${newSize.width - 150}px`,
});
$("#analyserSegmentLengthPSDLabel", parentElem).css({
left: `${newSize.width - 170}px`,
});
};

const dataLoad = function (fieldIndex, curve, fieldName) {
Expand Down Expand Up @@ -147,6 +155,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {

case SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY:
fftData = GraphSpectrumCalc.dataLoadPSD(analyserZoomY);
analyserSegmentLengthPSD.prop("max", fftData.maximalSegmentsLength);
break;

case SPECTRUM_TYPE.FREQUENCY:
Expand Down Expand Up @@ -213,11 +222,6 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
debounce(100, function () {
analyserZoomY = 1 / (analyserZoomYElem.val() / 100);
GraphSpectrumPlot.setZoom(analyserZoomX, analyserZoomY);
// Recalculate PSD with updated samples per segment count
if (userSettings.spectrumType == SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY) {
dataLoad();
GraphSpectrumPlot.setData(fftData, userSettings.spectrumType);
}
that.refresh();
}),
)
Expand Down Expand Up @@ -246,9 +250,7 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
saveOneUserSetting("psdHeatmapMin", min);
analyserLowLevelPSD.prop("min", min);
analyserMaxPSD.prop("min", min + 5);
if (analyserLowLevelPSD.val() < min) {
analyserLowLevelPSD.val(min).trigger("input");
}
analyserLowLevelPSD.val(min).trigger("input");
that.refresh();
}),
)
Expand Down Expand Up @@ -297,6 +299,42 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
})
.val(analyserMinPSD.val());

let segmentLenghtPSD = DEFAULT_PSD_SEGMENT_LENGTH;
GraphSpectrumCalc.setPointsPerSegmentPSD(segmentLenghtPSD);
analyserSegmentLengthPSD
.on(
"input",
function () {
const currentValue = parseInt($(this).val());
if (currentValue > segmentLenghtPSD) {
segmentLenghtPSD *= 2;
} else if (currentValue < segmentLenghtPSD){
segmentLenghtPSD /= 2;
}
$(this).val(segmentLenghtPSD);
// Recalculate PSD with updated samples per segment count
GraphSpectrumCalc.setPointsPerSegmentPSD(segmentLenghtPSD);
dataLoad();
GraphSpectrumPlot.setData(fftData, userSettings.spectrumType);
that.refresh();
},
)
.dblclick(function (e) {
if (e.ctrlKey) {
segmentLenghtPSD = DEFAULT_PSD_SEGMENT_LENGTH;
$(this).val(DEFAULT_PSD_SEGMENT_LENGTH).trigger("input");
}
})
.val(DEFAULT_PSD_SEGMENT_LENGTH);

analyserSegmentLengthPSD
.on(
"keydown",
function (e) {
e.preventDefault();
}
);

// Spectrum type to show
userSettings.spectrumType =
userSettings.spectrumType || SPECTRUM_TYPE.FREQUENCY;
Expand All @@ -321,10 +359,16 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
const psdHeatMapSelected =
optionSelected === SPECTRUM_TYPE.PSD_VS_THROTTLE ||
optionSelected === SPECTRUM_TYPE.PSD_VS_RPM;
const psdCurveSelected =
optionSelected === SPECTRUM_TYPE.POWER_SPECTRAL_DENSITY;
overdrawSpectrumTypeElem.toggle(!pidErrorVsSetpointSelected);
analyserZoomYElem.toggleClass(
"onlyFullScreenException",
pidErrorVsSetpointSelected || psdHeatMapSelected,
pidErrorVsSetpointSelected || psdHeatMapSelected || psdCurveSelected,
);
analyserSegmentLengthPSD.toggleClass(
"onlyFullScreenException",
!psdCurveSelected,
);
analyserLowLevelPSD.toggleClass(
"onlyFullScreenException",
Expand All @@ -350,6 +394,10 @@ export function FlightLogAnalyser(flightLog, canvas, analyserCanvas) {
"onlyFullScreenException",
!psdHeatMapSelected,
);
$("#analyserSegmentLengthPSDLabel").toggleClass(
"onlyFullScreenException",
!psdCurveSelected,
);

$("#spectrumComparison").css("visibility", (optionSelected == 0 ? "visible" : "hidden"));
})
Expand Down
20 changes: 12 additions & 8 deletions src/graph_spectrum_calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const GraphSpectrumCalc = {
_flightLog : null,
_sysConfig : null,
_motorPoles : null,
_pointsPerSegmentPSD : 0,
};

GraphSpectrumCalc.initialize = function(flightLog, sysConfig) {
Expand Down Expand Up @@ -112,17 +113,19 @@ GraphSpectrumCalc.dataLoadFrequency = function() {
return fftData;
};

GraphSpectrumCalc.setPointsPerSegmentPSD = function(pointsCount) {
this._pointsPerSegmentPSD = pointsCount;
};

GraphSpectrumCalc.dataLoadPSD = function(analyserZoomY) {
const flightSamples = this._getFlightSamplesFreq(false);
const multiplier = Math.floor(1 / analyserZoomY); // 0. ... 10
let pointsPerSegment = 2 ** (8 + multiplier); //256, 512, 1024 ...

let overlapCount;
if (pointsPerSegment > flightSamples.samples.length) {
pointsPerSegment = flightSamples.samples.length; // Use actual sample length. It will transform to power at 2 value inside the _psd() - fft_segmented
overlapCount = 0;
let pointsPerSegment, overlapCount;
if (this._pointsPerSegmentPSD > flightSamples.samples.length) {
pointsPerSegment = flightSamples.samples.length; // Use actual sample length. It will transform to power at 2 value inside the _psd() - fft_segmented
overlapCount = 0;
} else {
overlapCount = pointsPerSegment / 2;
pointsPerSegment = this._pointsPerSegmentPSD;
overlapCount = pointsPerSegment * 3 / 4;
}

const psd = this._psd(flightSamples.samples, pointsPerSegment, overlapCount);
Expand All @@ -136,6 +139,7 @@ GraphSpectrumCalc.dataLoadPSD = function(analyserZoomY) {
minimum: psd.min,
maximum: psd.max,
maxNoiseFrequency: psd.maxNoiseFrequency,
maximalSegmentsLength: this.getNearPower2Value(flightSamples.samples.length),
};
return psdData;
};
Expand Down