N1=30
N2=50;
L=512;
f1=50,f2=100;fs=600;
T=1/fs;ws=2*pi*fs;
t1=(0:N1-1)*T;t2=(0:N2-1)*T;
y1=cos(2*pi*f1*t1)+0.15*cos(2*pi*f2*t1);
y2=cos(2*pi*f1*t2)+0.15*cos(2*pi*f2*t2);
wh1=(hamming(N1))';
y11=y1.*wh1;wh2=(hamming(N2))';
y22=y2.*wh2;
Y1=fftshift(fft(y1,L));Y2=fftshift(fft(y2,L));
Y11=fftshift(fft(y11,L));Y22=fftshift(fft(y22,L));
w=(-ws/2+(0:L-1)*ws/L)/(2*pi);
subplot(2,2,1)
plot(w,abs(Y1));ylabel('幅度谱');xlabel('频率/Hz');
subplot(2,2,2)
plot(w,abs(Y11));ylabel('幅度谱');xlabel('频率/Hz');
subplot(2,2,3)
plot(w,abs(Y2));ylabel('幅度谱');xlabel('频率/Hz');
subplot(2,2,4)
plot(w,abs(Y22));ylabel('幅度谱');xlabel('频率/Hz');
评论0