how to implement spectrogram in matlab?
Afficher commentaires plus anciens
I am trying to plot the spectrogram of the following signal with following code
% Signal 2
fs = 40; % Sampling frequency
t2 = 0:( 1/fs ):6; % Time vector
S2 = [ sin( 2*pi*5*t2( t2<=2 ) ), sin( 2*pi*10*t2( 2<t2<4 ) ),sin( 2*pi*15*t2( t2>4 ) ) ];
% codes for spectrogram
X = S2 + 2*randn(size(t2)); % Defining the Entire Data Vector for Spectogram
NFFT = 2^nextpow2(402);
window = 100;
spectrogram(X,window,window/2,NFFT,fs);
I am not getting the right spectrogram plot. Can someone tell me where is the problem with the code?
Réponses (1)
Walter Roberson
le 29 Déc 2016
2<t2<4 is parsed as ((2<t2)<4). The 2<t2 part returns 0 (false) or 1 (true) and then <4 part compares that 0 or 1 to <4, which is always true. The fix is:
S2 = [ sin( 2*pi*5*t2( t2<=2 ) ), sin( 2*pi*10*t2( 2<t2 & t2<4 ) ),sin( 2*pi*15*t2( t2>4 ) ) ];
By the way: is there a reason that you want the sample at t2 == 4 exactly to be omitted ?
Catégories
En savoir plus sur Descriptive Statistics dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!