Reputation: 63
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:
Spectogram at 25 kHz:
Upvotes: 4
Views: 1773
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.
% 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])
Upvotes: 5