@@ -35,7 +35,7 @@ export const GraphSpectrumCalc = {
3535 _flightLog : null ,
3636 _sysConfig : null ,
3737 _motorPoles : null ,
38- _pointsPerSegmentPSD : 0 ,
38+ _pointsPerSegmentPSD : 64 ,
3939} ;
4040
4141GraphSpectrumCalc . initialize = function ( flightLog , sysConfig ) {
@@ -119,16 +119,15 @@ GraphSpectrumCalc.setPointsPerSegmentPSD = function(pointsCount) {
119119
120120GraphSpectrumCalc . dataLoadPSD = function ( analyserZoomY ) {
121121 const flightSamples = this . _getFlightSamplesFreq ( false ) ;
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 ;
126- } else {
127- pointsPerSegment = this . _pointsPerSegmentPSD ;
128- overlapCount = pointsPerSegment * 3 / 4 ;
129- }
130-
131- const psd = this . _psd ( flightSamples . samples , pointsPerSegment , overlapCount ) ;
122+ const totalCount = flightSamples . count ; // actual samples, not padded length
123+ let pointsPerSegment = Math . min ( this . _pointsPerSegmentPSD , totalCount ) ;
124+ // Non-overlapping when single full-segment; otherwise 75% overlap
125+ const overlapCount = ( pointsPerSegment === totalCount ) ? 0 : Math . floor ( pointsPerSegment * 3 / 4 ) ;
126+ // Avoid bias from zero-padded tail
127+ const samplesForPsd = ( flightSamples . samples . length === totalCount )
128+ ? flightSamples . samples
129+ : flightSamples . samples . slice ( 0 , totalCount ) ;
130+ const psd = this . _psd ( samplesForPsd , pointsPerSegment , overlapCount ) ;
132131
133132 const psdData = {
134133 fieldIndex : this . _dataBuffer . fieldIndex ,
@@ -139,7 +138,7 @@ GraphSpectrumCalc.dataLoadPSD = function(analyserZoomY) {
139138 minimum : psd . min ,
140139 maximum : psd . max ,
141140 maxNoiseFrequency : psd . maxNoiseFrequency ,
142- maximalSegmentsLength : this . getNearPower2Value ( flightSamples . samples . length ) ,
141+ maximalSegmentsLength : this . getNearPower2Value ( totalCount ) ,
143142 } ;
144143 return psdData ;
145144} ;
0 commit comments