matlab-巴特沃兹,数字滤波器的简单使用

资源:matlab-巴特沃兹,数字滤波器的简单应用-Matlab文档类资源-CSDN下载巴特沃兹,数字滤波器的简单使用(低通,高通,带通,带阻)更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/SmithCGauss/85576562

巴特沃兹滤波器:

%巴特沃兹滤波器

%---低通
wp1=0.4;ws1=0.6;ap1=1;as1=40;
[g1,wn1]=buttord(wp1,ws1,ap1,as1);
[b1,a1]=butter(g1,wn1,'low');
[h1,w1]=freqz(b1,a1);
%---高通
wp2=0.4;ws2=0.6;ap2=1;as2=40;
[g2,wn2]=buttord(wp2,ws2,ap2,as2);
[b2,a2]=butter(g2,wn2,'high');
[h2,w2]=freqz(b2,a2);
%---带通
wp3=[0.5 0.6];ws3=[0.4 0.7];ap3=1;as3=40;
[g3,wn3]=buttord(wp3,ws3,ap3,as3);
[b3,a3]=butter(g3,wn3);
[h3,w3]=freqz(b3,a3);
%---带阻
wp4=[0.3 0.8];ws4=[0.45 0.65];ap4=1;as4=40;
[g4,wn4]=buttord(wp4,ws4,ap4,as4);
[b4,a4]=butter(g4,wn4,'stop');
[h4,w4]=freqz(b4,a4);
%归一化之后的结果
subplot(2,2,1);plot(w1/pi,abs(h1));axis([0 1 0 1.2]);title('lowpass filter');
subplot(2,2,2);plot(w2/pi,abs(h2));axis([0 1 0 1.2]);title('highpass filter');
subplot(2,2,3);plot(w3/pi,abs(h3));axis([0 1 0 1.2]);title('bandpass filter');
subplot(2,2,4);plot(w4/pi,abs(h4));axis([0 1 0 1.2]);title('bandstop filter');

数字滤波器:

%数字滤波器(fir1)
figure(1);
N=40;%阶数
%---低通
wp1=0.4;ws1=0.6;
wc1=(wp1+ws1)/2;
b1=fir1(N,wc1);
[h1,w1]=freqz(b1,1);
%---高通
wp2=0.5;ws2=0.7;
wc2=(wp2+ws2)/2;
b2=fir1(N,wc2,'high');
[h2,w2]=freqz(b2,1);
%---带通
wp3=[0.5 0.7];ws3=[0.4 0.8];
wc3=(wp3+ws3)/2;
b3=fir1(N,wc3);
[h3,w3]=freqz(b3,1);
%---带阻
wp4=[0.4 0.75];ws4=[0.5 0.65];
wc4=(wp4+ws4)/2;
b4=fir1(N,wc4,'stop');
[h4,w4]=freqz(b4,1);
%归一化之后的结果
subplot(2,2,1);plot(w1/pi,abs(h1));axis([0 1 0 1.2]);title('lowpass filter');
subplot(2,2,2);plot(w2/pi,abs(h2));axis([0 1 0 1.2]);title('highpass filter');
subplot(2,2,3);plot(w3/pi,abs(h3));axis([0 1 0 1.2]);title('bandpass filter');
subplot(2,2,4);plot(w4/pi,abs(h4));axis([0 1 0 1.2]);title('bandstop filter');



%数字滤波器(fir2)
figure(2);
%---低通
f1=[0 0.2 0.2 0.3 0.3 0.4 0.4 0.6 0.6 1];
m1=[1 1 0.8 0.8 0.7 0.7 0.6 0.6 0 0];
b1=fir2(60,f1,m1);
[h1,w1]=freqz(b1,1);
%---高通
f2=[0 0.6 0.6 0.65 0.65 0.7 0.7 0.75 0.75 1];
m2=[0 0 0.1 0.1 0.3 0.3 0.8 0.8 1 1];
b2=fir2(60,f2,m2);
[h2,w2]=freqz(b2,1);
%---带通
f3=[0 0.2 0.2 0.3 0.3 0.35 0.35 0.4 0.4 0.6 0.6 0.65 0.65 0.7 0.7 0.8 0.8 1];
m3=[0 0 0.2 0.2 0.7 0.7 0.8 0.8 1 1 0.8 0.8 0.7 0.7 0.2 0.2 0 0];
b3=fir2(60,f3,m3);
[h3,w3]=freqz(b3,1);
%---带阻
f4=[0 0.2 0.2 0.25 0.25 0.35 0.35 0.65 0.65 0.75 0.75 0.8 0.8 1];
m4=[1 1 0.8 0.8 0.2 0.2 0 0 0.2 0.2 0.8 0.8 1 1];
b4=fir2(60,f4,m4);
[h4,w4]=freqz(b4,1);
%归一化之后的结果(波形画的不好,但基本就是这样)
subplot(2,2,1);plot(f1,m1,w1/pi,abs(h1));axis([0 1 0 1.2]);title('lowpass filter');
subplot(2,2,2);plot(f2,m2,w2/pi,abs(h2));axis([0 1 0 1.2]);title('highpass filter');
subplot(2,2,3);plot(f3,m3,w3/pi,abs(h3));axis([0 1 0 1.2]);title('bandpass filter');
subplot(2,2,4);plot(f4,m4,w4/pi,abs(h4));axis([0 1 0 1.2]);title('bandstop filter');

其他还有很多功能, 有待探索

你可能感兴趣的:(matlab,matlab,开发语言)