1
$\begingroup$

In some textbooks and websites, circular shift operation is done before doing FFT of windowed data, in the explaination, circular shift is to ensure zero-phase. But in other textbooks and websites(I would say most), circular shift operation is ignored in the implementation. So what is the correct way to do STFT and Why?

$\endgroup$

2 Answers 2

1
$\begingroup$

There's no universally "correct" or "incorrect" way to do STFT, as the choice to apply a circular shift depends on the specific application and requirements. For many applications, the phase distortion introduced by not applying a circular shift might be negligible or can be ignored. In some cases, the phase information might not even be of interest at all, and only the magnitudes of the STFT are used.

So, whether or not to apply a circular shift in the STFT depends on your specific application and the importance of phase information in your analysis. The idea is to apply a window function (e.g., Hamming, Hann, or Blackman window) that is centered around the zero phase. This is helpful in minimizing the phase distortion, which can potentially improve the clarity of the resulting spectrogram or be beneficial for certain applications like the inverse STFT.

All in all, it depends strictly on your application and perhaps limitations!

$\endgroup$
3
  • $\begingroup$ Thanks a lot. So technically speaking, if my application is phase sensetive(i.e accurate phase value is needed, for example, phase vocoder), circular shift operation is strictly needed to correct phase distortion? $\endgroup$
    – Xiong
    Jun 25, 2023 at 11:18
  • $\begingroup$ For that matter, in applications where the FFT and the data collection are co-resident, the shift may be done implicitly, just by where the collected data gets stuck as it is collected. $\endgroup$
    – TimWescott
    Jun 25, 2023 at 21:52
  • 1
    $\begingroup$ "if my application is phase sensetive ... circular shift operation is strictly needed" the effect of shifting (or not) is very predictable, and can be taken out in the frequency-domain output. $\endgroup$
    – TimWescott
    Jun 25, 2023 at 23:36
1
$\begingroup$

Yes, shift. For the spectrogram $|\texttt{STFT}|$, however, it makes no difference.

For most (if not all) non-spectrogram applications, the shifting step is either done directly or compensated for in post-processing. Major ones are instantaneous frequency/amplitude localization (and their applications, including denoising and decomposition), phase vocoding (audio stretching, pitch-shifting, other), and advanced spectral manipulation (modifying STFT and inverting) due to losing one-integral inverse.

Advantages to not shifting are limited: easier to code efficiently, and easier for most practitioners to understand since most view STFT as "windowed Fourier transform". There may be a few others I'm missing, including applications, but I wager they're few.

The reason is simple: not shifting largely invalidates STFT as a time-frequency representation. This is understood from Equivalence between "windowed Fourier transform" and STFT as convolutions/filtering, which also explains the rest of my answer.

It's implemented in ssqueezepy (I'm author), and includes CPU and GPU acceleration.

$\endgroup$
1
  • $\begingroup$ I'm in agreement with this. Perhaps for reasons that OLGD would not agree with. Remember that the DFT is circular, not linear. The second half is really the negative half. The middle of the window should be at index 0. $\endgroup$ Jun 27, 2023 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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