📄 lp2af.m
字号:
function [nn1,dd1] = lp2af(ty1,nn,dd,wsc,wbw)
% LP2AF Frequency transformation of LP analog filter.
%
% [N,D] = LP2AF(TY,NLP,DLP,WSC,B) Transforms LPF to other types
% TY = 'lp, 'hp, 'bp', or 'bs'
% NLP, DLP = num and den of LPF TF H(s) in descending powers of s
% WSC = scaling frequency (RAD/s) for 'lp' or 'hp'
% WSC = center frequency (RAD/s) for 'bp' and 'bs'
% If ty = 'bp', or 'bs', B = bandwidth (RAD/s)
% N, D return the num and den of the actual filter transfer function
%
% LP2AF (with no input arguments) invokes the following example:
%
% % Convert the LPF H(s)=1/(s+1) to a BP filter with f0=12.5Hz & B=5Hz
% >>[nbp,dbp] = lp2af('bp',[0 1],[1 1],12.5*2*pi,5*2*pi) %w in rad/s
% % To plot the magnitude response to 30Hz
% >>tfplot('s',nbp,dbp,[0 30],0,1); % requires freq in Hz
% ADSP Toolbox: Version 2.0
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998
if nargin==0,help lp2af,disp('Strike a key to see results of the example')
pause,[nbp,dbp]=lp2af('bp',[0 1],[1 1],12.5*2*pi,5*2*pi),
tfplot('s',nbp,dbp,[0 30],0,1);return,end
ty1=ty1(1:2);
if nargin<5, if ty1=='bp'|ty1=='bs'
error('No bandwidth specified for BP or BS filter'),return,
end,end
i=find(abs(dd)>0);i=i(1);nn=nn/dd(i);dd=dd/dd(i);
az=length(dd)-length(nn);
if az>0,nn=[zeros(1,az) nn];end
if az<0,dd=[zeros(1,-az) dd];end,
n=length(dd)-1;
if ty1=='bp'|ty1=='bs';n=2*n;end,
aa=wsc.^(0:n);
%DENORMALIZATION
if ty1=='lp',
nn1=nn.*aa;dd1=dd.*aa;
elseif ty1=='hp',
nn1=nn(n+1:-1:1).*aa;dd1=dd(n+1:-1:1).*aa;
elseif ty1=='bp',
[nn1,dd1]=polymap(nn,dd,[1 0 1],[0 wbw/wsc 0]);tol=1e-10;
nn1=round(nn1).*(abs(nn1-round(nn1))<=tol)+nn1.*(abs(nn1-round(nn1))>tol);
dd1=round(dd1).*(abs(dd1-round(dd1))<=tol)+dd1.*(abs(dd1-round(dd1))>tol);
if abs(dd1(1)-round(dd1(1)))<1e-8,nn1=nn1/dd1(1);dd1=dd1/dd1(1);end
nn1=nn1.*aa;dd1=dd1.*aa;
elseif ty1=='bs',
[nn1,dd1]=polymap(nn,dd,[0 wbw/wsc 0],[1 0 1]);tol=1e-10;
nn1=round(nn1).*(abs(nn1-round(nn1))<=tol)+nn1.*(abs(nn1-round(nn1))>tol);
dd1=round(dd1).*(abs(dd1-round(dd1))<=tol)+dd1.*(abs(dd1-round(dd1))>tol);
if abs(dd1(1)-round(dd1(1)))<1e-8,nn1=nn1/dd1(1);dd1=dd1/dd1(1);end
nn1=nn1.*aa;dd1=dd1.*aa;
else, error('Unknown type: Use lp,hp,bp or bs'),return,
end
i=find(abs(dd1)>0);i=i(1);nn1=nn1/dd1(i);dd1=dd1/dd1(i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -