用matlab设计的IIR滤波器源程序-IIR一阶低通/高通

2012-02-11 13:02:37来源: 互联网 关键字:IIR  matlab
   

matlab设计的IIR滤波器源程序

(1)IIR一阶低通滤波器 P576

clear;

fi=1;fs=10;Gc2=0.9;

wc=2*pi*fi/fs;     

omegac=tan(wc/2);

alpha=(sqrt(Gc2)/sqrt(1-Gc2))*omegac;

a=(1-alpha)/(1+alpha);

b=(1-a)/2;

w=0:pi/300:pi;     

Hw2=alpha^2./(alpha^2+(tan(w/2)).^2);

plot(w/pi,Hw2);

grid;

hold on;

 (2)一阶高通滤波器 P581

clear;

fi=1;fs=10;Gc2=0.5;

wc=2*pi*fi/fs;

omegac=tan(wc/2);

alpha=(sqrt(1-Gc2)/(sqrt(Gc2)))*omegac;

a=(1-alpha)/(1+alpha);

b=(1+a)/2;

w=0:pi/300:pi;

Hw2=(tan(w/2).^2)./(alpha^2+(tan(w/2)).^2);

plot(w/pi,Hw2);

grid;

hold on;

(3)Notch 嵌波滤波器

clear;

Gb2=0.5;

w0=0.35*pi;

deltaw=0.1*pi;

b=1/(1+tan(deltaw/2)*(sqrt(1-Gb2)/sqrt(Gb2)));

B=[1 -2*cos(w0) 1].*b;

A=[1 -2*b*cos(w0) (2*b-1)];

w=0:pi/500:pi;

H=freqz(B,A,w);

plot(w/pi,abs(H));

grid;

(4)Peak 滤波器

clear;

Ac=3;

Gb2=10^(-Ac/10);

w0=0.35*pi;

deltaw=0.1*pi;

b=1/(1+tan(deltaw/2)*(sqrt(Gb2)/sqrt(1-Gb2)));

B=[1 0 -1].*(1-b);

A=[1 -2*b*cos(w0) (2*b-1)];

w=0:pi/500:pi;

H=freqz(B,A,w);

plot(w/pi,abs(H));

grid;

(5)IIR低通滤波(Butterworth)

% IIR Lowpass Use Butterworth

% copyright by Etual

clear;

fs=20;fpass=4;fstop=5;

Ap=0.5;As=10;

wp=2*pi*fpass/fs;ws=2*pi*fstop/fs;

omegap=tan(wp/2);omegas=tan(ws/2);

ep=sqrt(10^(Ap/10)-1);

es=sqrt(10^(As/10)-1);

N=ceil(log(es/ep)/log(omegas/omegap));

omega0=omegap/ep^(1/N);

K=floor(N/2);

for i=1:K

    theta(i)=pi*(N-1+2*i)/(2*N);

end

for i=1:K

    G(i)=omega0^2/(1-2*omega0*cos(theta(i))+omega0^2);

end

for i=1:K

    a1(i)=2*(omega0^2-1)/(1-2*omega0*cos(theta(i))+omega0^2);

end

for i=1:K

    a2(i)=(1+2*omega0*cos(theta(i))+omega0^2)/(1-2*omega0*cos(theta(i))+omega0^2);

end

if K<(N/2)

    G0=omega0/(omega0+1);a0=(omega0-1)/(omega0+1);

end

w=0:pi/300:pi;

Hw2=1./(1+(tan(w/2)/omega0).^(2*N));

plot(w/pi,Hw2);

grid;

(6)IIR高通滤波(Butterworth)

% IIR Hightpass Use Butterworth

% copyright by Etual

clear;

fs=20;fpass=5;fstop=4;

Ap=0.5;As=10;

wp=2*pi*fpass/fs;ws=2*pi*fstop/fs;

omegap=cot(wp/2);omegas=cot(ws/2);

ep=sqrt(10^(Ap/10)-1);

es=sqrt(10^(As/10)-1);

N=ceil(log(es/ep)/log(omegas/omegap));

omega0=omegap/ep^(1/N);

K=floor(N/2);

for i=1:K

    theta(i)=pi*(N-1+2*i)/(2*N);

end

for i=1:K

    G(i)=omega0^2/(1-2*omega0*cos(theta(i))+omega0^2);

end

for i=1:K

    a1(i)=-2*(omega0^2-1)/(1-2*omega0*cos(theta(i))+omega0^2);

end

for i=1:K

    a2(i)=(1+2*omega0*cos(theta(i))+omega0^2)/(1-2*omega0*cos(theta(i))+omega0^2);

end

if K<(N/2)

    G0=omega0/(omega0+1);a0=-(omega0-1)/(omega0+1);

end

w=(0+eps):pi/300:pi;

Hw2=1./(1+(cot(w/2)/omega0).^(2*N));

plot(w/pi,Hw2);

grid;

(7)IIR带通滤波(Butterworth)

% IIR Bandpass Use Butterworth

% copyright by Etual

clear;

fs=20;fpa=2;fpb=4;fsa=1.5;fsb=4.5;

Ap=0.0877;As=16.9897;

wpa=2*pi*fpa/fs;wpb=2*pi*fpb/fs;wsa=2*pi*fsa/fs;wsb=2*pi*fsb/fs;

c=sin(wpa+wpb)/(sin(wpa)+sin(wpb));

omegap=abs((c-cos(wpb))/sin(wpb));

omegasa=(c-cos(wsa))/sin(wsa);omegasb=(c-cos(wsb))/sin(wsb);

omegas=min(abs(omegasa),abs(omegasb));

ep=sqrt(10^(Ap/10)-1);es=sqrt(10^(As/10)-1);

N=ceil(log(es/ep)/log(omegas/omegap));

omega0=omegap/ep^(1/N);

K=floor(N/2);

for i=1:K

    theta(i)=pi*(N-1+2*i)/(2*N);

end

for i=1:K

    G(i)=omega0^2/(1-2*omega0*cos(theta(i))+omega0^2);

end

for i=1:K

    a1(i)=4*c*(omega0*cos(theta(i))-1)/(1-2*omega0*cos(theta(i))+omega0^2);

end

for i=1:K

    a2(i)=2*(2*c^2+1-omega0^2)/(1-2*omega0*cos(theta(i))+omega0^2);

end

for i=1:K

    a3(i)=-(4*c*(omega0*cos(theta(i))+1))/(1-2*omega0*cos(theta(i))+omega0^2);

end

for i=1:K

    a4(i)=(1+2*omega0*cos(theta(i))+omega0^2)/(1-2*omega0*cos(theta(i))+omega0^2);

end

if K<(N/2)

    G0=omega0/(1+omega0);a0(1)=-2*c/(1+omega0);a0(2)=(1-omega0)/(1+omega0);

end

w=(0+eps):pi/300:pi;

Hw2=1./(1+((c-cos(w))./(omega0*sin(w))).^(2*N));

plot(w/pi,Hw2);

grid;

(8)IIR带阻滤波(Butterworth)

% IIR Bandstop Use Butterworth

% copyright by Etual

clear;

fs=20;fpa=1.5;fpb=4.5;fsa=2;fsb=4;

Ap=0.5;As=10;

wpa=2*pi*fpa/fs;wpb=2*pi*fpb/fs;wsa=2*pi*fsa/fs;wsb=2*pi*fsb/fs;

c=sin(wpa+wpb)/(sin(wpa)+sin(wpb));

omegap=abs(sin(wpb)/(c-cos(wpb)));

omegasa=sin(wsa)/(cos(wsa)-c);omegasb=sin(wsb)/(cos(wsb)-c);

omegas=min(abs(omegasa),abs(omegasb));

ep=sqrt(10^(Ap/10)-1);es=sqrt(10^(As/10)-1);

N=ceil(log(es/ep)/log(omegas/omegap));

omega0=omegap/ep^(1/N);

K=floor(N/2);

theta=zeros(1,K);

for i=1:K

    theta(i)=pi*(N-1+2*i)/(2*N);

end

G=zeros(1,K);a1=zeros(1,K);a2=zeros(1,K);

for i=1:K

    G(i)=omega0^2/(1-2*omega0*cos(theta(i))+omega0^2);

end

for i=1:K

    a1(i)=2*(omega0^2-1)/(1-2*omega0*cos(theta(i))+omega0^2);

end

for i=1:K

    a2(i)=(1+2*omega0*cos(theta(i))+omega0^2)/(1-2*omega0*cos(theta(i))+omega0^2);

end

if K<(N/2)

    G0=omega0/(omega0+1);a0=(omega0-1)/(omega0+1);

end

w=(0+eps):pi/300:pi;

Hw2=1./(1+(sin(w)./(omega0*(c-cos(w)))).^(2*N));

plot(w/pi,Hw2);

grid;

(9)IIR低通滤波(chebyshev 1)

% IIR Lowpass Use Chebyshev Type 1

% copyright by Etual

clear;

fs=20;fpass=4;fstop=5;

Ap=0.5;As=10;

wp=2*pi*fpass/fs;ws=2*pi*fstop/fs;

omegap=tan(wp/2);omegas=tan(ws/2);

ep=sqrt(10^(Ap/10)-1);

es=sqrt(10^(As/10)-1);

e=es/ep;w=omegas/omegap;

N=ceil(log(e+sqrt(e^2-1))/log(w+sqrt(w^2-1)));

a=log(1/ep+sqrt(1/ep^2+1))/N;

omega0=omegap*sinh(a);

K=floor(N/2);

theta=zeros(1,K);omega=zeros(1,K);

for i=1:K

    theta(i)=pi*(N-1+2*i)/(2*N);

end

for i=1:K

    omega(i)=omegap*sin(theta(i));

end

G=zeros(1,K);a1=zeros(1,K);a2=zeros(1,K);

for i=1:K

    G(i)=(omega0^2+omega(i)^2)/(1-2*omega0*cos(theta(i))+omega0^2+omega(i)^2);

end

for i=1:K

    a1(i)=2*(omega0^2+omega(i)^2-1)/(1-2*omega0*cos(theta(i))+omega0^2+omega(i)^2);

end

for i=1:K

    a2(i)=(1+2*omega0*cos(theta(i))+omega0^2+omega(i)^2)/(1-2*omega0*cos(theta(i))+omega0^2+omega(i)^2);

end

if K<(N/2)

    G0=omega0/(omega0+1);a0=(omega0-1)/(omega0+1);  

else

    H0=sqrt(1/(1+ep^2));

end

f=0:1/300:10;

Hf2=1./(1+ep^2*(cheby(N,tan(pi*f/fs)/omegap)).^2);

plot(f,abs(Hf2));

grid;

 (9)IIR低通滤波(chebyshev 1)

% IIR Lowpass Use Chebyshev Type 2

% copyright by Etual

clear;

fs=20;fpass=4;fstop=5;

Ap=0.5;As=10;

wp=2*pi*fpass/fs;ws=2*pi*fstop/fs;

omegap=tan(wp/2);omegas=tan(ws/2);

ep=sqrt(10^(Ap/10)-1);

es=sqrt(10^(As/10)-1);

e=es/ep;w=omegas/omegap;

N=ceil(log(e+sqrt(e^2-1))/log(w+sqrt(w^2-1)));

a=log(es+sqrt(es^2+1))/N;

omega0=omegas/sinh(a);

K=floor(N/2);

for i=1:K

    theta(i)=pi*(N-1+2*i)/(2*N);

end

for i=1:K

    omega(i)=omegas/sin(theta(i));

end

for i=1:K

    G(i)=(1+omega(i)^-2)/(1-2*omega0^-1*cos(theta(i))+omega0^-2+omega(i)^-2);

end

for i=1:K

    a1(i)=2*(1-omega0^-2+omega(i)^-2)/(1-2*omega0^-1*cos(theta(i))+omega0^-2+omega(i)^-2);

end

for i=1:K

    a2(i)=(1+2*omega0^-1*cos(theta(i))+omega0^-2+omega(i)^-2)/(1-2*omega0^-1*cos(theta(i))+omega0^-2+omega(i)^-2);

end

for i=1:K

    b1(i)=2*(1-omega(i))/(1+omega(i));

end

if K<(N/2)

    G0=omega0/(omega0+1);a0=(omega0-1)/(omega0+1);  

else

    H0=sqrt(1/(1+ep^2));

end

f=(0+eps):1/100:10;

Hf2=(cheby(N,omegas./tan(pi*f/fs))).^2./((cheby(N,omegas./tan(pi*f/fs))).^2+es^2);

plot(f,abs(Hf2));

grid;

(10)chebyshev 中用到的函数 cheby.m

function CN=cheby(N,x)

if x<=1

    CN=cos(N*acos(x));

else

    CN=cosh(N*log(x+sqrt(x.^2-1)));

end

关键字:IIR  matlab

编辑:北极风 引用地址:http://www.eeworld.com.cn/FPGA/2012/0211/article_2868.html
本网站转载的所有的文章、图片、音频视频文件等资料的版权归版权所有人所有,本站采用的非本站原创文章及图片等内容无法一一联系确认版权者。如果本网所选内容的文章作者及编辑认为其作品不宜公开自由传播,或不应无偿使用,请及时通过电子邮件或电话通知我们,以迅速采取适当措施,避免给双方造成不必要的经济损失。

上一篇:用MATLAB设计FIR滤波器的方法
下一篇:Cadence基于Xilinx Zynq-7000 EPP的虚拟平台量产发行

关注eeworld公众号 快捷获取更多信息
关注eeworld公众号
快捷获取更多信息
关注eeworld服务号 享受更多官方福利
关注eeworld服务号
享受更多官方福利
推荐阅读
全部
IIR
matlab

小广播

独家专题更多

2017东芝PCIM在线展会
2017东芝PCIM在线展会
TI车载信息娱乐系统的音视频解决方案
TI车载信息娱乐系统的音视频解决方案
汇总了TI汽车信息娱乐系统方案、优质音频解决方案、汽车娱乐系统和仪表盘参考设计相关的文档、视频等资源
迎接创新的黄金时代 无创想,不奇迹
迎接创新的黄金时代 无创想,不奇迹
​TE工程师帮助将不可能变成可能,通过技术突破,使世界更加清洁、安全和美好。

夏宇闻老师专栏

你问我答FPGA设计

北京航空航天大学教授,国内最早从事复杂数字逻辑和嵌入式系统设计的专家。

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号 电信业务审批[2006]字第258号函 京公海网安备110108001534 Copyright © 2005-2017 EEWORLD.com.cn, Inc. All rights reserved