下面的函数为四种低通滤波器的实现
function [b, a]=analogfile(Wp, Ws, alphamax, alphamin, Wmax, ind)if ind==1,[N,Wn]=buttord(Wp, Ws, alphamax, alphamin, 's');[b,a]=butter(N, Wn, 's');elseif ind==2,[N, Wn]=cheb1ord(Wp, Ws, alphamax, alphamin, 's');[b, a]=cheby1(N, alphamax, Wn, 's');elseif ind==3,[N, Wn]=cheb2ord(Wp, Ws, alphamax, alphamin, 's');[b, a]=cheby2(N, alphamin, Wn, 's');else[N, Wn]=ellipord(Wp, Ws, alphamax, alphamin, 's');[b, a]=ellip(N, alphamax, alphamin, Wn, 's');endW=0:0.001:Wmax;H=freqs(b, a, W);Hm=abs(H);Ha=unwrap(angle(H));N=length(W);alpha1=alphamax * ones(1, N);alpha2 = alphamin * ones(1, N);subplot(221);plot(W, Hm);grid;axis([0 Wmax 0 1.1*max(Hm)]);subplot(222);plot(W, Ha);grid;axis([0 Wmax 1.1*min(Ha) 1.1*max(Ha)]);subplot(223);splane(b, a);figure(1);subplot(224);plot(W, -20*log10(abs(H)));hold on;plot(W, alpha1, 'r', W, alpha2, 'r');grid;axis([0 max(W) -0.1 100]);hold off;end
其中使用到了:
unwrap 函数,推荐阅读:matlab之unwrap函数
freqs 函数,推荐阅读: matlab freqz-m,Matlab函数freqs和freqz
函数调用
clear all; clfalphamax=0.1;alphamin=60;Wp=10;Ws=15;Wmax=25;ind=4;%指定滤波器的种类[b, a]=analogfile(Wp, Ws, alphamax, alphamin, Wmax, ind);