psambit9791 / jdsp

A Java Library for Digital Signal Processing
https://jdsp.dev
MIT License
247 stars 43 forks source link

Bug: STFT and inverse STFT not working for frame length not perfectly divisible by signal length #32

Closed psambit9791 closed 2 years ago

psambit9791 commented 2 years ago

On running the test: testInverseShortTimeFourierLongSignal1() under TestInverShortTmeFourier, we use the electrocardiogram signal (length = 108000). On using a frame length of 6000, the tests pass; however, if I use a length of 20000, the test fails since the array length differs. The result has a length of 100000 while the expected is 108000.

psambit9791 commented 2 years ago

@SiboVG Could you take a look at this please?

SiboVG commented 2 years ago

There is nothing that you can do about this really :/ it's inherent to the (I)STFT algorithm; you split the entire signal up into frames and shift that frame to the end. But if the last portion of the signal does not have enough samples to fill an entire frame, it gets discarded. You can see this in the drawing below; in the beginning of the signal, you can make 3 frames, f0, f1 en f2, but for the end there aren't enough samples to make an entire frame, so this part of the signal is discarded.

image