0
$\begingroup$

I'm trying to understand STFT overlapping, why segments are concatenated and what are the consequences of this.

My implementation (from other questions and repositories found) of the STFT in Python is:

def stft(x, L, overlap, window): # Linear Spectrum (LS) [V]
opoints = int(L*overlap)
hopsize = L - opoints
X = np.array([(2 * np.abs(np.fft.fft(window*x[i:i+L])[:L//2])) / np.sum(window)
             for i in range(0,len(x)-L,hopsize)])
return X

where, x is the time-domain signal sampled at 44.1kHz, L is the FFT window size (4096), overlap is the overlapping factor [0, 1), and window is the window funtion used (Hanning). The absolute value of half the complex dft is scaled by 2/sum(win) so that the units of the linear spectrum are the same as for the input signal (V).

I used to understand the frequency resolution is fs/L and the width of the time slices or time resolution is L/fs, so that the number of time windows is N/L. However, if using overlapping (overlap!=0), the number of time windows increases ~(N/hopsize)-1.

  1. Why are overlapped segments concatenated instead of added and what are the consequences of this regarding the time axis? (See picture below)
  2. Is compressing the concatenated segments into the original duration of the signal correct? (i.e 3 segments of 1 second into 2 seconds, see picture below)

STFT concatenation

EDIT1:

Now, I do understand:

  • Overlap-shift and compression of the time axis of the overlapped segment into the original duration is one way to make a smoother spectrograph image

  • Overlap is needed in order to avoid lossy signals caused by the window

However, from @user31990 comment I still need to clarify:

  1. What's the difference between the different methods/implementations?

Implementations I've found/understood:

  • Overlap and concatenate side-by-side the overlapped blocks (increasing the number of time windows and compressing the x time axis to the original duration)
  • Overlap adding the segments of the block that are overlapped together (the number of time windows doesn't increase = N/L)
  • Overlap save (zero-pad the beginning of the block and discard the transformed segment, the number of time windows doesn't increase)
  • Overlap shift with zero-pad

    1. I don't totally understand the overlap shift with zero-pad, what is it doing?

My implementation is an example of the overlap and concatenate method.

  1. Are This and Google's pytfd stft implementations examples of the overlap shift with zero-pad method?

EDIT2:

I was confused about the methods, question is answered/solved.

Zero-padding is a method that can be used: 1. To obtain an FFT of size N of a window whose size is smaller 2. To increment the size of the FFT, interpolating values in the frequency axis and obtaining smoother data.

Overlap-add and overlap-save are methods for the synthesis of an IFFT output in order to recover the original signal x.

$\endgroup$
1
$\begingroup$

Compressing the time axis of the overlapped windows into the original duration is one way to make a smoother spectrograph image.

Also, bell-shaped windows are lossy near the edges (after re-quantization), but a 50% overlap of Von Hann windows recovers all that information in each overlap.

$\endgroup$
  • $\begingroup$ Thank you @hotpaw2, as I've added in the last edit of my question I'm not interested in neither representation or synthetisation of the signal (inverse fft), I'm just interested in the time-frequency information contained on the original input signal for sound recognition purposes. I do also care about computation cost. Therefore, do I actually need to apply overlapping? $\endgroup$ – Pedro Martinez Lopez Nov 15 '17 at 14:47
  • 1
    $\begingroup$ An informationally lossy process might be non-optimal for recognition. Overlapping reduces the loss. You need to test your particular chosen recognition method to see if reducing this loss is beneficial. $\endgroup$ – hotpaw2 Nov 15 '17 at 14:54
  • $\begingroup$ Thank you again @hotpaw2, I still have some doubts regarding the different overlap methods/implementations of the stft. I've added an edit and a 3rd question. I do want to find the different in between the different methods and which is optimum for my application. $\endgroup$ – Pedro Martinez Lopez Nov 16 '17 at 12:00
1
$\begingroup$

Overlap-shift and overlap-add yields the same results (once the necessary zero-padding is accounted for), but shifting is cheaper than adding.

$\endgroup$
  • $\begingroup$ In my implementation, no zero-adding is accounted, I'm just shifting, is that correct? As far as I'm understanding overlap-add is equivalent to overlap-shift with zero-padding. If possible, I would highly appreciate an implementation example or modification on my code to implement zero-padding. $\endgroup$ – Pedro Martinez Lopez Nov 15 '17 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.