数字信号处理实验(五)——IIR滤波器的设计

一、使用自编函数设计IIR滤波器

1、冲激响应法

(1)注给出的数字滤波器指标先化成模拟指标image

(2)设计出模拟滤波器:

image

(3)使用冲激响应法转化成数字滤波器

image

(4)一个demo

clear all;
wp=0.2*pi; %数字指标
ws=0.3*pi;
Rp=1;
As=15;
T=1;Fs=1/T;
%冲激响应法
[cs,ds]=afd_butt(wp/T,ws/T,Rp,As);
[b,a]=imp_invr(cs,ds,T);
[C,B,A]=dir2par(b,a)
[db,mag,pha,grd,w]=freqz_m(b,a); 

figure(1)
subplot(2,2,1),plot(w/pi,mag);title('幅度');grid;axis([0,1,0,1.1]);
subplot(2,2,2),plot(w/pi,db);title('幅度 in db');grid;axis([0,1,-30,5]);
subplot(2,2,3),plot(w/pi,pha/pi);title('相位');grid;axis([0,1,-1,1]);
subplot(2,2,4),plot(w/pi,grd),title('群延时');grid;axis([0,1,0,10]);

 

2、双线性法设计IIR

(1)预畸变:

image

(2)设计低通滤波器

image

(3)转化成数字滤波器

image

(4)一个demo

%双线性法
OmegaP = (2/T)*tan(wp/2); 
OmegaS = (2/T)*tan(ws/2);            

% Analog Butterworth Prototype Filter Calculation:
[cs,ds] = afd_butt(OmegaP,OmegaS,Rp,As);
% Bilinear transformation:
[b,a] = bilinear(cs,ds,Fs);
[C,B,A] = dir2cas(b,a)
[db,mag,pha,grd,w]=freqz_m(b,a);

 

二、MATLAB自带函数进行设计

1、模拟低通滤波器转数字滤波器设计

(1)根据数字指标设计出模拟滤波器的阶数n和截止频率Wn

image

(2)求出低通模拟原型滤波器

image

(3)由于所得的结果为零极点型,还必须转成b/a型,可用函数zp2tf

[bap,aap]=zp2tf(z,p,k)

(4)将模拟滤波器转换成数字滤波器

(低通,高通,带通,带阻)可用函数lp2lp, lp2hp,lp2bs, lp2bp。

image

(5)求出滤波器幅频,相频和冲激响应

image

(6)一个demo

Wp=0.2*pi;Rp=1;Ws=0.3*pi;As=15;
[n,Wn]=buttord(Wp,Ws,Rp,As,'s')
[z,p,k]=buttap(n);
[bap,aap]=zp2tf(z,p,k)
[b,a]=lp2lp(bap,aap,Wn);
[db,mag,pha,w]=freqs_m(b,a,0.5*pi);
[ha,x,t]=impulse(b,a);
figure(1)
subplot(2,2,1),plot(w/pi,mag);title('幅度'); 
subplot(2,2,2),plot(w/pi,db);title('幅度 in db');
subplot(2,2,3),plot(w/pi,pha/pi);title('相位'); 
subplot(2,2,4),plot(t,ha),title('冲激响应');
figure(2)
freqs(b,a);

 

2、直接进行数字滤波器设计

(1)根据给定指标得出,低通模拟原型滤波器的阶数和截止频率:

[n,wn]=buttord(wp,ws,Rp,As)
[n,wn]=cheb1ord(wp,ws,Rp,As)

(2)直接求出数字滤波器,利用函数butter,cheby1,cheby2。

[b,a]=butter(n,wn,’ftype’)
[b,a]=cheby1(n, Rp,wn,’ftype’)  ;‘ftype’指的是:’low’,’bandpass’,’high’,’stop’

(3)求出滤波器的幅频,相频及群延时

[db,mag,pha,grd,w]=freqz_m(b,a);(P258)
直接画出幅频特性和相频特性:freqz(b,a) (matlab自带)

(4)一个demo

wp=0.2;Rp=1;ws=0.3;As=15;
[n,wn]=buttord(wp,ws,Rp,As)
[b,a]=butter(n,wn);
[db,mag,pha,grd,w]=freqz_m(b,a);
figure(3)
subplot(2,2,1),plot(w/pi,mag);title('幅度');grid; subplot(2,2,2),plot(w/pi,db);title('幅度 in db');grid; subplot(2,2,3),plot(w/pi,pha/pi);title('相位');grid;
subplot(2,2,4),plot(w/pi,grd),title('群延时');grid;
figure(4);freqz(b,a)
PS:

matlab中数字角频率进行了归一化,即0-1表示0-pi

频率以Hz给出,均表示模拟频率,因此利用matlab直接设计滤波器时,先要化成数字频率。

例:wp=[100 200]*2/fs

原文地址:https://www.cnblogs.com/BlueMountain-HaggenDazs/p/5046158.html