在下面的代碼中,我試圖在運行代碼之後獲得非固定信號x
的spectrogram
,我期望看到諸如發佈的日程「image_2」,頻率與時間表示之類的東西。但是發佈的代碼的結果是image_1
。如何獲得非平穩信號的正確頻譜圖?
可以任何一個請引導我得到正確的spectrogram
?
代碼
% Time specifications:
Fs = 8000; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 1; % seconds
t = (0:dt:StopTime-dt); % seconds
t1 = (0:dt:.25);
t2 = (.25:dt:.50);
t3 = (.5:dt:.75);
t4 = (.75:dt:1);
%get a full-length example of each signal component
x1 = (10)*sin(2*pi*100*t);
x2 = (10)*sin(2*pi*200*t);
x3 = (10)*sin(2*pi*300*t);
x4 = (10)*sin(2*pi*400*t);
%construct a composite signal
x = zeros(size(t));
I = find((t >= t1(1)) & (t <= t1(end)));
x(I) = x1(I);
I = find((t >= t2(1)) & (t <= t2(end)));
x(I) = x2(I);
I = find((t >= t3(1)) & (t <= t3(end)));
x(I) = x3(I);
I = find((t >= t4(1)) & (t <= t4(end)));
x(I) = x4(I);
NFFT = 2^nextpow2(length(t)); % Next power of 2 from length of y
Y = fft(x, NFFT);
f = Fs/2 * linspace(0, 1, NFFT/2 + 1);
figure;
plot(f(1:200), 2 * abs(Y(1:200)));
T = 0:.001:1;
spectrogram(x,10,9);
ylabel('Frequency');
axis(get(gcf,'children'), [0, 1, 1, 100]);
張貼代碼的結果:Spectrogram_Image_1:
什麼,我試圖讓:IMAGE_2:
Update_1,圖像 代碼:
%now call the spectrogram
spectrogram(x, window, noverlap, Nfft, Fs);
ylabel('Frequency');
axis(get(gcf,'children'), [0, 1]);
比你的答案,這似乎是正確的,但軸NEDD進行調整。你能否告訴我如何正確調整軸?我希望水平軸是時間,垂直軸是頻率,帶有適當的採樣「引腳」。請參見上面發佈的update_1部分 – rmaik
在matlab譜圖文檔(http://www.mathworks.com/help/signal/ref/spectrogram.html)中,其示例根據您的需要在垂直軸上顯示頻率。它說要將函數「yaxis」添加到函數調用中。我上面編輯了我的代碼。我還增加了重疊以使光譜圖看起來更平滑。 – chipaudette
另外,你需要刪除你的'axis'命令,它會截斷y軸(很快就是「頻率」軸),從而只能從零到赫茲。那也是現在。一旦你對'spectrogram'調用進行了編輯,你會想用'ylim([0 1000]);''這樣簡單的東西替換你的'axis'命令。 – chipaudette