Skip to content

Commit 141c329

Browse files
committed
Using power at 2 fft inputsize to compute PSD ws throttle and RPM
1 parent c088b4d commit 141c329

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/graph_spectrum_calc.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ GraphSpectrumCalc._dataLoadPowerSpectralDensityVsX = function(vsFieldNames, minV
246246
for (let fftChunkIndex = 0; fftChunkIndex + fftChunkLength < flightSamples.samples.length; fftChunkIndex += fftChunkWindow) {
247247

248248
const fftInput = flightSamples.samples.slice(fftChunkIndex, fftChunkIndex + fftChunkLength);
249-
const psd = this._psd(fftInput, fftChunkLength, 0, 'density');
249+
const psd = this._psd(fftInput, fftChunkLength, 0, 'density'); // Using the one segment with all chunks fftChunkLength size, it will extended at power at 2 size inside _psd() - _fft_segmented()
250250
maxNoise = Math.max(psd.max, maxNoise);
251251
// calculate a bin index and put the fft value in that bin for each field (e.g. eRPM[0], eRPM[1]..) sepparately
252252
for (const vsValueArray of flightSamples.vsValues) {
@@ -710,16 +710,27 @@ GraphSpectrumCalc._psd = function(samples, pointsPerSegment, overlapCount, scal
710710
* Compute FFT for samples segments by lenghts as pointsPerSegment with overlapCount overlap points count
711711
*/
712712
GraphSpectrumCalc._fft_segmented = function(samples, pointsPerSegment, overlapCount) {
713-
const samplesCount = samples.length,
714-
fftLength = Math.floor(pointsPerSegment / 2);
713+
const samplesCount = samples.length;
715714
const output = [];
715+
716716
for (let i = 0; i <= samplesCount - pointsPerSegment; i += pointsPerSegment - overlapCount) {
717-
const fftInput = samples.slice(i, i + pointsPerSegment);
717+
let fftInput = samples.slice(i, i + pointsPerSegment);
718718

719719
if (userSettings.analyserHanning) {
720720
this._hanningWindow(fftInput, pointsPerSegment);
721721
}
722722

723+
let fftLength;
724+
if (pointsPerSegment != samplesCount) {
725+
fftLength = Math.floor(pointsPerSegment / 2);
726+
} else { // Extend the one segment input on power at 2 size
727+
const fftSize = this.getNearPower2Value(pointsPerSegment);
728+
const power2Input = new Float64Array(fftSize);
729+
power2Input.set(fftInput);
730+
fftInput = power2Input;
731+
fftLength = fftSize / 2;
732+
}
733+
723734
const fftComplex = this._fft(fftInput);
724735
const magnitudes = new Float64Array(fftLength);
725736
for (let i = 0; i < fftLength; i++) {

0 commit comments

Comments
 (0)