?? window.m
字號:
function [x,n,string]=window(N)
n=0:N-1;
k=input('請選擇窗的類型(1、矩形窗(boxcar) 2、漢寧窗(hanning) 3、漢明窗(hamming) 4、布拉克曼窗(blackman) 5、凱澤窗(Kaiser)(1,2,3,4,5):');
switch k
case 1
x=juxing(0,N-1,0,N-1);
figure,subplot(2,1,1);stem(n,x,'.');xlabel('n');ylabel('x');string=['Boxcar時域圖形','N=',num2str(N)];text((0.6*N),0.8,string);
[H,m]=freqz(x,[1],1024,'whole'); %求其頻率響應
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(2,1,2); plot(m/pi,db);xlabel('w/pi');ylabel('dB');title('矩形窗的幅度特性(db)');axis([0,1,-100,0]);
string=['Boxcar','N=',num2str(N)];
case 2
x=juxing(0,N-1,0,N-1);
x=(0.5-0.5*cos(2*pi*n/(N-1))).*x;
figure,subplot(2,1,1);stem(n,x,'.');xlabel('n');ylabel('x');string=['Hanning時域圖形','N=',num2str(N)];text((0.6*N),0.8,string);
[H,m]=freqz(x,[1],1024,'whole'); %求其頻率響應
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(2,1,2); plot(m/pi,db);xlabel('w/pi');ylabel('dB');title('漢寧窗的幅度特性(db)');axis([0,1,-100,0]);
string=['Hanning','N=',num2str(N)];
case 3
x=juxing(0,N-1,0,N-1);
x=(0.54-0.46*cos(2*pi*n/(N-1))).*x;
figure,subplot(2,1,1);stem(n,x,'.');xlabel('n');ylabel('x');string=['Hamming時域圖形','N=',num2str(N)];text((0.6*N),0.8,string);
[H,m]=freqz(x,[1],1024,'whole'); %求其頻率響應
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(2,1,2); plot(m/pi,db);xlabel('w/pi');ylabel('dB');title('漢明窗的幅度特性(db)');axis([0,1,-100,0]);
string=['Hamming','N=',num2str(N)];
case 4
x=juxing(0,N-1,0,N-1);
x=(0.42-0.5*cos(2*pi*n/(N-1))+0.08*cos(4*pi*n/(N-1))).*x;
figure,subplot(2,1,1);stem(n,x,'.');xlabel('n');ylabel('x');string=['Blackman時域圖形','N=',num2str(N)];text((0.6*N),0.8,string);
[H,m]=freqz(x,[1],1024,'whole'); %求其頻率響應
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(2,1,2); plot(m/pi,db);xlabel('w/pi');ylabel('dB');title('布拉克曼窗的幅度特性(db)');axis([0,1,-100,0]);
string=['Blackman','N=',num2str(N)];
otherwise
x=juxing(0,N-1,0,N-1);
a=input('請輸入a(典型值為4<a<9)=');
b=a*sqrt(1-(2*n/(N-1)-1).^2);
x=(besseli(0,b)/besseli(0,a)).*x;
figure,subplot(2,1,1);stem(n,x,'.');xlabel('n');ylabel('x');string=['Kaiser時域圖形','N=',num2str(N)];text((0.6*N),0.8,string);
[H,m]=freqz(x,[1],1024,'whole'); %求其頻率響應
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
subplot(2,1,2); plot(m/pi,db);xlabel('w/pi');ylabel('dB');title('凱澤窗的幅度特性(db)');axis([0,1,-100,0]);
string=['Kaiser','N=',num2str(N)];
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -