[n,Omgc]=buttord(Omgp,Omgs,Rp,As,'s') %计算阶数n和截止频率:if nargin == 4 %如果输入变量数是4opt = 'z';elseif nargin == 5if strcmp(opt,'z') & strcmp(opt,'s')error('Invalid option for final argument.');endendmsg=freqchk(wp,ws,opt);er
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 12:23:05
[n,Omgc]=buttord(Omgp,Omgs,Rp,As,'s') %计算阶数n和截止频率:if nargin == 4 %如果输入变量数是4opt = 'z';elseif nargin == 5if strcmp(opt,'z') & strcmp(opt,'s')error('Invalid option for final argument.');endendmsg=freqchk(wp,ws,opt);er
[n,Omgc]=buttord(Omgp,Omgs,Rp,As,'s') %计算阶数n和截止频率:
if nargin == 4 %如果输入变量数是4
opt = 'z';
elseif nargin == 5
if strcmp(opt,'z') & strcmp(opt,'s')
error('Invalid option for final argument.');
end
end
msg=freqchk(wp,ws,opt);
error(msg);
ftype = 2*(length(wp) - 1);
if wp(1) < ws(1)
ftype = ftype + 1; % low (1) or reject (3)
else
ftype = ftype + 2; % high (2) or pass (4)
end
% first,prewarp frequencies from digital (unit circle) to analog (imag.axis):
if strcmp(opt,'z') % digital
WP=tan(pi*wp/2);
WS=tan(pi*ws/2);
else % don't have to if analog already
WP=wp;
WS=ws;
end
%note - on old systems that are NOT case sensitive,this will still work OK
% next,transform to low pass prototype with passband edge of 1 and stopband
% edges determined by the following:(see Rabiner and Gold,p.258)
if ftype == 1 % low
WA=WS/WP;
elseif ftype == 2 % high
WA=WP/WS;
elseif ftype == 3 % stop
fo = optimset('display','none');
wp1 = lclfminbnd('bscost',WP(1),WS(1)-1e-12,fo,1,WP,WS,rs,rp,'butter');
WP(1) = wp1;
wp2 = lclfminbnd('bscost',WS(2)+1e-12,WP(2),fo,2,WP,WS,rs,rp,'butter');
WP(2) = wp2;
WA=(WS*(WP(1)-WP(2)))./(WS.^2 - WP(1)*WP(2));
elseif ftype == 4 % pass
WA=(WS.^2 - WP(1)*WP(2))./(WS*(WP(1)-WP(2)));
end
% find the minimum order b'worth filter to meet the more demanding spec:
WA=min(abs(WA));
order = ceil( log10( (10 .^ (0.1*abs(rs)) - 1)./ ...
(10 .^ (0.1*abs(rp)) - 1) ) / (2*log10(WA)) );
% next find the butterworth natural frequency W0 (or,the "3dB frequency")
% to give exactly rs dB at WA.W0 will be between 1 and WA:
W0 = WA / ( (10^(.1*abs(rs)) - 1)^(1/(2*(abs(order)))));
% now convert this frequency back from lowpass prototype
% to the original analog filter:
if ftype == 1 % low
WN=W0*WP;
elseif ftype == 2 % high
WN=WP/W0;
elseif ftype == 3 % stop
WN(1) = ( (WP(2)-WP(1)) + sqrt((WP(2)-WP(1))^2 + ...
4*W0.^2*WP(1)*WP(2)))./(2*W0);
WN(2) = ( (WP(2)-WP(1)) - sqrt((WP(2)-WP(1))^2 + ...
4*W0.^2*WP(1)*WP(2)))./(2*W0);
WN=sort(abs(WN));
elseif ftype == 4 % pass
W0=[-W0 W0]; % need both left and right 3dB frequencies
WN= -W0*(WP(2)-WP(1))/2 + sqrt( W0.^2/4*(WP(2)-WP(1))^2 + WP(1)*WP(2) );
WN=sort(abs(WN));
end
% finally,transform frequencies from analog to digital if necessary:
if strcmp(opt,'z') % digital
wn=(2/pi)*atan(WN); % bilinear transform
else
wn=WN;
end
希望能解释下各条语句的含义.这是巴特洛夫函数求低通滤波器阶数和截止频率的题,将这个函数调出,
[n,Omgc]=buttord(Omgp,Omgs,Rp,As,'s') %计算阶数n和截止频率:if nargin == 4 %如果输入变量数是4opt = 'z';elseif nargin == 5if strcmp(opt,'z') & strcmp(opt,'s')error('Invalid option for final argument.');endendmsg=freqchk(wp,ws,opt);er
1.matlab不支持中文的名字.
m文件可以取任何英文名字
2.randn(1,length(t))是生成一个随机分布的1×(t的长度)的正态分布的数组.
3.最后一个是生成P是一个Y.×Y的共轭矩阵.
首先要知道里面的函数的含义,以后再遇到什么问题去查查matlab函数库查询字典吧
参考资料:函数库