how to implement spectrogram in matlab?
2 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (1 件)
Walter Roberson
2016 年 12 月 29 日
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 ?
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Time-Frequency Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!