Mahindra Rautela
Mahindra Rautela

Reputation: 63

Spectrogram in matlab - time axis format

I have a tone burst signal from 0.20 ms to 0.40 ms. From 0 to 0.20ms and from 0.40ms to 3.27ms it is zero. I did fft which shows frequency content around 25 kHz. The number of fft points is 32768 which is also the length of the time-domain signal.

I am trying to plot spectrogram in Matlab with the following code snippet

nfft = 32768;
dT = 1e-6;
fs = 1/dT;
window = hamming(nfft)
spectrogram(signal,window,[],nfft,fs)

Using this I am getting accurate frequency description but the time axis is a problem.

Zoomed in time domain signal:

https://i.sstatic.net/gM2xw.png

Spectogram at 25 kHz:

enter image description here

Upvotes: 4

Views: 1773

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112769

You cannot get a representation that is accurate both in the time and frequency domains. This is the uncertainty principle of the Fourier transform.

What you can do is trade off time and frequency resolution by changing the window length. Compare the two spectrograms below, obtained with different window lengths. The signal (figure 1) is similar to that in your question.

  • The first spectrogram (figure 2) uses a long window, which gives good frequency resolution but poor time resolution. Note how the signal frequency of 10 Hz is resolved, but time information is very coarse.
  • Conversely, the second spectrogram (figure 3) uses a short window, which provides good time resolution but poor frequency resolution. As is seen, the signal frequency cannot be resolved, but its time location and shape are more accurate.

% Define signal
fs = 500; % sampling frequency
t = 0:1/fs:6; % time axis
fm = 10; % signal (carrier) frequency
s = cos(2*pi*fm*t).* exp(-5*(t-2).^2);
figure
plot(t,s)

% Spectrogram with long window
figure
nfft = 500;
window = hamming(nfft);
spectrogram(s,window,[],nfft,fs), view([90 -90])

% Spectrogram with short window
figure
nfft = 50;
window = hamming(nfft);
spectrogram(s,window,[],nfft,fs), view([90 -90])

enter image description here

enter image description here

enter image description here

Upvotes: 5

Related Questions