Why does frequency spectrum gets flipped in STFT compared to the one generated from FFT?

19 vues (au cours des 30 derniers jours)
I picked out a signal of 200 temporal samples and processed it separately with STFT and FFT. The data is attached as .mat file.
The code for STFT is listed below (the first dimension of Matrix has 200 temporal samples and I plot the spectrogram of first signal segment):
[s,f,t] = stft(Matrix',5000/3,Window=rectwin(32),OverlapLength=ceil(0.8*32),FFTLength=200); % Full map
s_amp = abs(s);
The code for FFT is shown here (I get the first 32 temporal samples and do the FFT, then the spectrum is zero centered):
FreqSpec_temp = fft(squeeze(Matrix(1,1:32)),[]);
FreqSpec_shift = fftshift(FreqSpec_temp);
The plots of STFT (left) and FFT (right) are displayed. One can easily spot out that the frequency spectrum of STFT is horizontally flipped compared to the spectrum of FFT. Why is this the case? Which method should I use to get an accurate frequency spectrum? I will need to calculate the mean frequency of the signal based on the spectrum.
Besides, how could the spectrum from STFT has 200 points? How does it work out the interpolation? Thank you for your help!
  2 commentaires
Edward le 31 Août 2023
Hi Paul,
Thank you for your comments. I just uploaded the .mat file for you to try out.
For FFT, when it takes in 32 temporal samples, the frequency spectrum will also have 32 points for representing the spectrum. But for STFT, it takes in 32 temporal samples for processing 1 temporal segment, while the frequency spectrum has 200 points. What I wonder was certain interpolation was done in generating the frequency spectrum, but the process was not specified in the page of STFT. I would like to know what kind of interpolation was used to get 200 points from an input of 32 points.

Connectez-vous pour commenter.

Réponse acceptée

Paul le 31 Août 2023
Using random data
Matrix = rand(1000,1);
Compute the stft
[s,f,t] = stft(Matrix,5000/3,Window=rectwin(32),OverlapLength=ceil(0.8*32),FFTLength=200); % Full map
s_amp = abs(s);
plot amplitude vs frequency
Compute the fft, zero pad to 200 to match FFTLength
FreqSpec_temp = fft(squeeze(Matrix(1:32,1,1)),200);
FreqSpec_shift = fftshift(FreqSpec_temp);
Plot amplitude vs frequency, matches first column of stft
hold on
  3 commentaires
Edward le 1 Sep 2023
Modifié(e) : Edward le 1 Sep 2023
Thank you, Paul! Yes, you're right. I wanted to use transpose (.') only, but I didn't realize ' actually represents as conjugate transpose. It was my coding mistake. And thank you for explaining the difference between the 2 curves!

Connectez-vous pour commenter.

Plus de réponses (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by