Skip to content

Commit c179844

Browse files
committed
Using power at 2 fft inputsize to compute PSD ws throttle and RPM
1 parent 535bf2a commit c179844

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
@@ -248,7 +248,7 @@ GraphSpectrumCalc._dataLoadPowerSpectralDensityVsX = function(vsFieldNames, minV
248248
for (let fftChunkIndex = 0; fftChunkIndex + fftChunkLength < flightSamples.samples.length; fftChunkIndex += fftChunkWindow) {
249249

250250
const fftInput = flightSamples.samples.slice(fftChunkIndex, fftChunkIndex + fftChunkLength);
251-
const psd = this._psd(fftInput, fftChunkLength, 0, 'density');
251+
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()
252252
maxNoise = Math.max(psd.max, maxNoise);
253253
// calculate a bin index and put the fft value in that bin for each field (e.g. eRPM[0], eRPM[1]..) sepparately
254254
for (const vsValueArray of flightSamples.vsValues) {
@@ -712,16 +712,27 @@ GraphSpectrumCalc._psd = function(samples, pointsPerSegment, overlapCount, scal
712712
* Compute FFT for samples segments by lenghts as pointsPerSegment with overlapCount overlap points count
713713
*/
714714
GraphSpectrumCalc._fft_segmented = function(samples, pointsPerSegment, overlapCount) {
715-
const samplesCount = samples.length,
716-
fftLength = Math.floor(pointsPerSegment / 2);
715+
const samplesCount = samples.length;
717716
const output = [];
717+
718718
for (let i = 0; i <= samplesCount - pointsPerSegment; i += pointsPerSegment - overlapCount) {
719-
const fftInput = samples.slice(i, i + pointsPerSegment);
719+
let fftInput = samples.slice(i, i + pointsPerSegment);
720720

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

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

0 commit comments

Comments
 (0)