@@ -119,22 +119,17 @@ GraphSpectrumCalc.dataLoadPSD = function(analyserZoomY) {
119119 pointsPerSegment = Math . min ( pointsPerSegment , flightSamples . samples . length ) ;
120120 const overlapCount = pointsPerSegment / 2 ;
121121
122- const psd = this . _psd ( flightSamples . samples , this . _blackBoxRate , pointsPerSegment , overlapCount ) ;
123- let min = 1e6 ,
124- max = - 1e6 ;
125- for ( const value of psd ) {
126- min = Math . min ( value , min ) ;
127- max = Math . max ( value , max ) ;
128- }
122+ const psd = this . _psd ( flightSamples . samples , pointsPerSegment , overlapCount ) ;
129123
130124 const psdData = {
131125 fieldIndex : this . _dataBuffer . fieldIndex ,
132126 fieldName : this . _dataBuffer . fieldName ,
133- psdLength : psd . length ,
134- psdOutput : psd ,
127+ psdLength : psd . psdOutput . length ,
128+ psdOutput : psd . psdOutput ,
135129 blackBoxRate : this . _blackBoxRate ,
136- minimum : min ,
137- maximum : max ,
130+ minimum : psd . min ,
131+ maximum : psd . max ,
132+ maxNoiseIdx : psd . maxNoiseIdx ,
138133 } ;
139134 return psdData ;
140135} ;
@@ -525,7 +520,7 @@ GraphSpectrumCalc._normalizeFft = function(fftOutput, fftLength) {
525520/**
526521 * Compute PSD for data samples by Welch method follow Python code
527522 */
528- GraphSpectrumCalc . _psd = function ( samples , samplesRate , pointsPerSegment , overlapCount , scaling = 'density' ) {
523+ GraphSpectrumCalc . _psd = function ( samples , pointsPerSegment , overlapCount , scaling = 'density' ) {
529524// Compute FFT for samples segments
530525 const fftOutput = this . _fft_segmented ( samples , pointsPerSegment , overlapCount ) ;
531526
@@ -543,7 +538,7 @@ GraphSpectrumCalc._psd = function(samples, samplesRate, pointsPerSegment, overl
543538 for ( const value of window ) {
544539 skSum += value ** 2 ;
545540 }
546- scale = 1 / ( samplesRate * skSum ) ;
541+ scale = 1 / ( this . _blackBoxRate * skSum ) ;
547542 } else if ( scaling == 'spectrum' ) {
548543 let sum = 0 ;
549544 for ( const value of window ) {
@@ -558,6 +553,12 @@ GraphSpectrumCalc._psd = function(samples, samplesRate, pointsPerSegment, overl
558553 }
559554
560555// Compute average for scaled power
556+ let min = 1e6 ,
557+ max = - 1e6 ;
558+ const maxFrequency = ( this . _blackBoxRate / 2.0 ) ;
559+ const noiseLowEndIdx = 100 / maxFrequency * dataCount ;
560+ let maxNoiseIdx = 0 ;
561+ let maxNoise = 0 ;
561562 for ( let i = 0 ; i < dataCount ; i ++ ) {
562563 psdOutput [ i ] = 0.0 ;
563564 for ( let j = 0 ; j < segmentsCount ; j ++ ) {
@@ -572,9 +573,22 @@ GraphSpectrumCalc._psd = function(samples, samplesRate, pointsPerSegment, overl
572573 let avg = psdOutput [ i ] / segmentsCount ;
573574 avg = Math . max ( avg , min_avg ) ;
574575 psdOutput [ i ] = 10 * Math . log10 ( avg ) ;
576+ min = Math . min ( psdOutput [ i ] , min ) ;
577+ max = Math . max ( psdOutput [ i ] , max ) ;
578+ if ( i > noiseLowEndIdx && psdOutput [ i ] > maxNoise ) {
579+ maxNoise = psdOutput [ i ] ;
580+ maxNoiseIdx = i ;
581+ }
575582 }
576583
577- return psdOutput ;
584+ const maxNoiseFrequency = maxNoiseIdx / dataCount * maxFrequency ;
585+
586+ return {
587+ psdOutput : psdOutput ,
588+ min : min ,
589+ max : max ,
590+ maxNoiseIdx : maxNoiseFrequency ,
591+ } ;
578592} ;
579593
580594
0 commit comments