码迷,mamicode.com
首页 > 其他好文 > 详细

[Matlab]四种IIR滤波器纹波特性对比

时间:2018-06-05 21:12:17      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:pass   idt   范围   close   top   image   分享图片   波特   mat   

测试代码:

%FilterCompare.m
%对比相同阶数时四种IIR滤波器的波纹特性


close;
clear;
clc;


fs = 1000; %Hz


%低通滤波器对比
N1 = 8;
wp = 50 / ( fs / 2);
ws = 100 / ( fs / 2);
alpha_p = 1;
alpha_s = 20;

[ b1,a1] = butter( N1 , ws , ‘low‘ );
[ b2,a2] = cheby1( N1 , alpha_p , ws , ‘low‘ );
[ b3,a3] = cheby2( N1 , alpha_s , ws , ‘low‘ );
[ b4,a4] = ellip ( N1 , alpha_p,alpha_s , ws , ‘low‘ );



[H1,w1] = freqz(b1,a1,1024*4);
[H2,w2] = freqz(b2,a2,1024*4);
[H3,w3] = freqz(b3,a3,1024*4);
[H4,w4] = freqz(b4,a4,1024*4);
w1 = w1/pi *fs/2;
w2 = w2/pi *fs/2;
w3 = w3/pi *fs/2;
w4 = w4/pi *fs/2;
figure(1);
plot(w1,abs(H1),‘black‘,‘linewidth‘,0.5);
hold on;
plot(w2,abs(H2),‘red‘,‘linewidth‘,0.5);
plot(w3,abs(H3),‘green‘,‘linewidth‘,0.5);
plot(w4,abs(H4),‘blue‘,‘linewidth‘,0.5);
xlim([0 500]);
ylim([0 1.1]);
legend({ ‘butter‘ , ‘cheby1‘ , ‘cheby2‘ , ‘ellip‘});
title(‘同阶数(N=8),同截止频率(f_c=100Hz)的低通滤波器对比‘);


%高通滤波器
N1 = 8;
wp = 400 / ( fs / 2);
ws = 400 / ( fs / 2);
alpha_p = 1;
alpha_s = 20;
[ b1,a1] = butter( N1 , ws , ‘high‘ );
[ b2,a2] = cheby1( N1 , alpha_p , ws , ‘high‘ );
[ b3,a3] = cheby2( N1 , alpha_s , ws , ‘high‘ );
[ b4,a4] = ellip( N1 , alpha_p,alpha_s , ws , ‘high‘ );
[H1,w1] = freqz(b1,a1,1024*4);
[H2,w2] = freqz(b2,a2,1024*4);
[H3,w3] = freqz(b3,a3,1024*4);
[H4,w4] = freqz(b4,a4,1024*4);
w1 = w1/pi *fs/2;
w2 = w2/pi *fs/2;
w3 = w3/pi *fs/2;
w4 = w4/pi *fs/2;
figure(2);
plot(w1,abs(H1),‘black‘,‘linewidth‘,0.5);
hold on;
plot(w2,abs(H2),‘red‘,‘linewidth‘,0.5);
plot(w3,abs(H3),‘green‘,‘linewidth‘,0.5);
plot(w4,abs(H4),‘blue‘,‘linewidth‘,0.5);
xlim([0 500]);
ylim([0 1.1]);
legend({ ‘butter‘ , ‘cheby1‘ , ‘cheby2‘ , ‘ellip‘});
title(‘同阶数(N=8),同截止频率(f_c=400Hz)的高通滤波器对比‘);



%带通滤波器

N1 = 8;
wp = [ 100 , 400 ] / ( fs / 2);
ws = [ 100 , 400 ] / ( fs / 2);
alpha_p = 1;
alpha_s = 20;
[ b1,a1] = butter( N1 , ws , ‘bandpass‘ );
[ b2,a2] = cheby1( N1 , alpha_p , ws , ‘bandpass‘ );
[ b3,a3] = cheby2( N1 , alpha_s , ws , ‘bandpass‘ );
[ b4,a4] = ellip( N1 , alpha_p,alpha_s , ws , ‘bandpass‘ );
[H1,w1] = freqz(b1,a1,1024*4);
[H2,w2] = freqz(b2,a2,1024*4);
[H3,w3] = freqz(b3,a3,1024*4);
[H4,w4] = freqz(b4,a4,1024*4);
w1 = w1/pi *fs/2;
w2 = w2/pi *fs/2;
w3 = w3/pi *fs/2;
w4 = w4/pi *fs/2;
figure(3);
plot(w1,abs(H1),‘black‘,‘linewidth‘,0.5);
hold on;
plot(w2,abs(H2),‘red‘,‘linewidth‘,0.5);
plot(w3,abs(H3),‘green‘,‘linewidth‘,0.5);
plot(w4,abs(H4),‘blue‘,‘linewidth‘,0.5);
xlim([0 500]);
ylim([0 1.1]);
legend({ ‘butter‘ , ‘cheby1‘ , ‘cheby2‘ , ‘ellip‘});
title(‘同阶数(N=8),同截止频率(f_c_1=100Hz f_c_2 = 400Hz)的带通滤波器对比‘);



%带阻滤波器
N1 = 8;
wp = [ 100 , 400 ] / ( fs / 2);
ws = [ 100 , 400 ] / ( fs / 2);
alpha_p = 1;
alpha_s = 20;
[ b1,a1] = butter( N1 , ws , ‘stop‘ );
[ b2,a2] = cheby1( N1 , alpha_p , ws , ‘stop‘ );
[ b3,a3] = cheby2( N1 , alpha_s , ws , ‘stop‘ );
[ b4,a4] = ellip( N1 , alpha_p,alpha_s , ws , ‘stop‘ );
[H1,w1] = freqz(b1,a1,1024*4);
[H2,w2] = freqz(b2,a2,1024*4);
[H3,w3] = freqz(b3,a3,1024*4);
[H4,w4] = freqz(b4,a4,1024*4);
w1 = w1/pi *fs/2;
w2 = w2/pi *fs/2;
w3 = w3/pi *fs/2;
w4 = w4/pi *fs/2;
figure(4);
plot(w1,abs(H1),‘black‘,‘linewidth‘,0.5);
hold on;
plot(w2,abs(H2),‘red‘,‘linewidth‘,0.5);
plot(w3,abs(H3),‘green‘,‘linewidth‘,0.5);
plot(w4,abs(H4),‘blue‘,‘linewidth‘,0.5);
xlim([0 500]);
ylim([0 1.1]);
legend({ ‘butter‘ , ‘cheby1‘ , ‘cheby2‘ , ‘ellip‘});
title(‘同阶数(N=8),同截止频率(f_c_1=100Hz f_c_2 = 400Hz)的带阻滤波器对比‘);

  

现象:

低通滤波器

技术分享图片

高通滤波器

技术分享图片

带通滤波器

技术分享图片

带阻滤波器

技术分享图片

 

验证结果:

1、巴特沃斯滤波器的通带和阻带均是单调变化,频率响应最为平滑,若通带边缘满足指标要求,则通带内会有富余量,并不经济,更有效的方法是将指标的精度要求均匀分布在通带或阻带内,这样能设计出阶数较低的滤波器(意会,意会);

2、切比雪夫Ⅰ型滤波器的幅度特性在通带范围内是等波纹的,在阻带范围内时单调的;

3、切比雪夫Ⅱ型滤波器的幅度特性在阻带范围内是等波纹的,在通带范围内时单调的;

4、椭圆滤波器的幅度特性在通带和阻带范围内均是等波纹的。

[Matlab]四种IIR滤波器纹波特性对比

标签:pass   idt   范围   close   top   image   分享图片   波特   mat   

原文地址:https://www.cnblogs.com/alimy/p/9141679.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!