@@ -406,8 +406,10 @@ GraphSpectrumPlot._drawPowerSpectralDensityGraph = function (canvasCtx) {
406406} ;
407407
408408GraphSpectrumPlot . getPSDbyFreq = function ( frequency ) {
409- const freqIndex = Math . round ( 2 * frequency / this . _fftData . blackBoxRate * ( this . _fftData . psdOutput . length - 1 ) ) ;
410- return this . _fftData . psdOutput [ freqIndex ] ;
409+ let freqIndex = Math . round ( 2 * frequency / this . _fftData . blackBoxRate * ( this . _fftData . psdOutput . length - 1 ) ) ;
410+ freqIndex = Math . min ( freqIndex , this . _fftData . psdOutput . length - 1 ) ;
411+ freqIndex = Math . max ( freqIndex , 0 ) ;
412+ return this . _fftData . psdOutput . length ? this . _fftData . psdOutput [ freqIndex ] : 0 ;
411413} ;
412414
413415GraphSpectrumPlot . _drawFrequencyVsXGraph = function ( canvasCtx , drawPSD = false ) {
@@ -535,7 +537,9 @@ GraphSpectrumPlot.getValueFromMatrixFFT = function(frequency, vsArgument) {
535537 if ( vsArgumentIndex === NUM_VS_BINS ) {
536538 vsArgumentIndex = NUM_VS_BINS - 1 ;
537539 }
538- const freqIndex = Math . round ( 2 * frequency / matrixFFT . blackBoxRate * ( matrixFFT . fftLength - 1 ) ) ;
540+ let freqIndex = Math . round ( 2 * frequency / matrixFFT . blackBoxRate * ( matrixFFT . fftLength - 1 ) ) ;
541+ freqIndex = Math . max ( freqIndex , 0 ) ;
542+ freqIndex = Math . min ( freqIndex , matrixFFT . fftLength - 1 ) ;
539543 return matrixFFT . fftOutput [ vsArgumentIndex ] [ freqIndex ] ;
540544} ;
541545
@@ -1274,7 +1278,14 @@ GraphSpectrumPlot._drawInterestFrequency = function (
12741278 stroke ,
12751279 lineWidth
12761280) {
1277- const interestLabel = `${ label } ${ frequency . toFixed ( 0 ) } Hz` ;
1281+
1282+ let interestLabel = "" ;
1283+ if ( this . _spectrumType === SPECTRUM_TYPE . POWER_SPECTRAL_DENSITY && label != "" ) {
1284+ const psdValue = this . getPSDbyFreq ( frequency ) ;
1285+ interestLabel = `${ label } : (${ frequency . toFixed ( 0 ) } Hz, ${ psdValue . toFixed ( 0 ) } dBm/Hz)` ;
1286+ } else {
1287+ interestLabel = `${ label } ${ frequency . toFixed ( 0 ) } Hz` ;
1288+ }
12781289 return this . _drawVerticalMarkerLine (
12791290 canvasCtx ,
12801291 frequency ,
0 commit comments