如何在2个谱图之间进行减法,然后在MATLAB中绘制一个新的谱图

时间:2012-02-25 12:10:13

标签: matlab spectrogram

两个光谱图的尺寸相同。 我尝试S = spectrogram()来获取向量S,但我不知道如何用它绘制回频谱图。

1 个答案:

答案 0 :(得分:1)

documentation中,它表示使用命令surf(T,F,10*log10(abs(P)));绘制图像。例如,您可以使用以下方法绘制其中两个图像的差异:

%# make some data
T = 0:0.001:2;
X1 = chirp(T,100,1,200,'q');
X2 = chirp(T,150,1,200,'q');

%# plot the first spectrogram
subplot(3,1,1);
spectrogram(X1,128,120,128,1E3);
title('Quadratic chirp 100Hz')

%# plot the second spectrogram
subplot(3,1,2);
spectrogram(X2,128,120,128,1E3);
title('Quadratic chirp 150Hz')

%# plot their difference
subplot(3,1,3);
[~,F1,T1,P1]=spectrogram(X1,128,120,128,1E3);
[~,F2,T2,P2]=spectrogram(X2,128,120,128,1E3);
%# just use the difference of the above two plot's z-values:
surf(T2,F2,10*(log10(abs(P2))-log10(abs(P1))),'edgecolor','none');
%# this is actually a 3D plot, so we set the viewing
%# angle as straight up and rotated by 90 to match the previous plots
view(90,-90);
axis tight;
title('Difference of Plots (2nd - 1st)')
ylabel('Freq (Hz)');
xlabel('Time');

此代码如下图:

Difference of Spectrograms Example