window_function.m
来自「the magnitude responses in dB of the win」· M 代码 · 共 34 行
M
34 行
clear all
close all
M=input('input M=');
N=128; n=0:N-1;
w=pi*[0:1/127:1];
w_1=boxcar(2*M-1); w1=[w_1',zeros(1,N-2*M+1)];
w_2=bartlett(2*M-1); w2=[w_2',zeros(1,N-2*M+1)];
w_3=hamming(2*M-1);w3=[w_3',zeros(1,N-2*M+1)];
w_4=hann(2*M-1); w4=[w_4',zeros(1,N-2*M+1)];
for i=1:length(n)
W_1(i)=sum(w1.*exp(-j*w(i)*n));
W_2(i)=sum(w2.*exp(-j*w(i)*n));
W_3(i)=sum(w3.*exp(-j*w(i)*n));
W_4(i)=sum(w4.*exp(-j*w(i)*n));
end
wr=abs(W_1)/10.^(max(20*log10(abs(W_1)))/20);
wb=abs(W_2)/10.^(max(20*log10(abs(W_2)))/20);
wha=abs(W_3)/10.^(max(20*log10(abs(W_3)))/20);
whn=abs(W_4)/10.^(max(20*log10(abs(W_3)))/20);
figure(1),
subplot(221),plot(w,abs(W_1)); grid on; axis([0 1 0 100]);
xlabel('w');ylabel('wr');title('Rectangular window in frequency domain');
subplot(222),plot(w,abs(W_2)); grid on; axis([0 1 0 50]);
xlabel('w');ylabel('wb');title('Barttlett window in frequency domain');
subplot(223),plot(w,abs(W_3)); grid on; axis([0 1 0 50]);
xlabel('w');ylabel('wha');title('Hamming window in frequency domain');
subplot(224),plot(w,abs(W_4)); grid on; axis([0 1 0 50]);
xlabel('w');ylabel('whn');title('Hann window in frequency domain');
figure(2),
subplot(221),plot(w,20*log10(wr)),grid on; xlabel('w');ylabel('20*log10(wr)');title('Rectangular window in frequency domain');
subplot(222),plot(w,20*log10(wb)),grid on; axis([0,pi,-100,0]); xlabel('w');ylabel('20*log10(wb)');title('Barttlett window in frequency domain');
subplot(223),plot(w,20*log10(wha)),;grid on; axis([0,pi,-100,0]); xlabel('w');ylabel('20*log10(wha)');title('Hamming window in frequency domain');
subplot(224),plot(w,20*log10(whn)),grid on ;axis([0,pi,-100,0]); xlabel('w');ylabel('20*log10(whn)');title('Hann window in frequency domain');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?