Skip to content

Commit 8cf1521

Browse files
committed
Added drawing heat map for PSD values
1 parent 7a00c00 commit 8cf1521

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/graph_spectrum_plot.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) {
395395
canvasCtx.restore();
396396
};
397397

398-
GraphSpectrumPlot._drawFrequencyVsXGraph = function (canvasCtx) {
398+
GraphSpectrumPlot._drawFrequencyVsXGraph = function (canvasCtx, drawPSD = false) {
399399
const PLOTTED_BLACKBOX_RATE = this._fftData.blackBoxRate / this._zoomX;
400400

401401
const ACTUAL_MARGIN_LEFT = this._getActualMarginLeft();
@@ -407,7 +407,7 @@ GraphSpectrumPlot._drawFrequencyVsXGraph = function (canvasCtx) {
407407
canvasCtx.translate(LEFT, TOP);
408408

409409
if (this._cachedDataCanvas == null) {
410-
this._cachedDataCanvas = this._drawHeatMap();
410+
this._cachedDataCanvas = this._drawHeatMap(drawPSD);
411411
}
412412

413413
canvasCtx.drawImage(this._cachedDataCanvas, 0, 0, WIDTH, HEIGHT);
@@ -467,7 +467,7 @@ GraphSpectrumPlot._drawFrequencyVsXGraph = function (canvasCtx) {
467467
}
468468
};
469469

470-
GraphSpectrumPlot._drawHeatMap = function () {
470+
GraphSpectrumPlot._drawHeatMap = function (drawPSD = false) {
471471
const THROTTLE_VALUES_SIZE = 100;
472472
const SCALE_HEATMAP = 1.3; // Value decided after some tests to be similar to the scale of frequency graph
473473
// This value will be maximum color
@@ -485,9 +485,16 @@ GraphSpectrumPlot._drawHeatMap = function () {
485485
for (let j = 0; j < 100; j++) {
486486
// Loop for frequency
487487
for (let i = 0; i < this._fftData.fftLength; i++) {
488-
const valuePlot = Math.round(
489-
Math.min(this._fftData.fftOutput[j][i] * fftColorScale, 100)
490-
);
488+
if (drawPSD) {
489+
const min = -40, max = 10; //limit values dBm
490+
let valuePlot = Math.max(this._fftData.fftOutput[j][i], min);
491+
valuePlot = Math.min(this._fftData.fftOutput[j][i], max);
492+
valuePlot = Math.round((valuePlot - min) * 100 / (max - min));
493+
} else {
494+
const valuePlot = Math.round(
495+
Math.min(this._fftData.fftOutput[j][i] * fftColorScale, 100)
496+
);
497+
}
491498

492499
// The fillStyle is slow, but I haven't found a way to do this faster...
493500
canvasCtx.fillStyle = `hsl(360, 100%, ${valuePlot}%)`;

0 commit comments

Comments
 (0)