how to implement spectrogram in matlab?
조회 수: 5 (최근 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!