📄 fir2lpp.m
字号:
function [wp,ws,w0]=fir2lpp(ty,fp,fs,ff)
% FIR2LPP Convert specifications to LPP for FIR filter design.
%
% [FP,FS,F0] = FIR2LPP(TY,fp,fs,SF) FIR LPP from given specifications
% TY = 'lp', 'hp', 'bp' or 'bs', fp
% fp, fs = passband and stopband edge(s) in HERTZ
% SF = sampling frequency in HERTZ.
% FP, FS return the LPP passband and stopband DIGITAL FREQUENCY.
% F0 = center frequency for later trasnformation (for 'bp' & 'bs')
%
% NOTE: For HP2LP, the routine switches the passband and stopband.
% NOTE: FIR2LPP assumes a fixed passband for 'bp' and 'bs' filters.
% NOTE: Transformation rules for conversion to required filter are:
% LP: HLP(n) = 2*FC*sinc(2*n*FC) %FC = cutoff frequency (e.g. FP)
% HP: HHP(n) = udelta(n)-HLP(n)
% BP: HBP(n) = 2*cos(2*pi*n*F0)*HLP(n)
% BS: HBS(n) = udelta(n) - 2*cos(2*pi*n*F0)*HLP(n) = udelta(n)-HBP(n)
%
% FIR2LPP (with no input arguments) invokes the following example:
%
% % Find the LPP for a BP filter with sampling frequency = 200Hz
% % passband = [25 45]Hz and stopband = [10 65]Hz
% >>[dfp,dfs,df0] = fir2lpp('bp',[25 45],[10 65],200)
% 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 fir2lpp,disp('Strike a key to see results of the example')
pause,[dfp,dfs,df0]=fir2lpp('bp',[25 45],[10 65],200),return,end
wp=fp/ff;ws=fs/ff;if ty=='lp',return,end
lp=length(wp);ls=length(ws);
if ty=='hp',if lp>1 | ls>1,error('Too many frequencies')
else,ws0=ws;ws=wp;wp=ws0;return,end,end
if lp<2 | ls<2,error('too few frequencies'),return,end
ap=abs(diff(fp));as=abs(diff(fs));
if ty=='bs',if ap<=as,error('passband & stopband switched'),return,end,end
if ty=='bp',if as<=ap,error('passband & stopband switched'),return,end,end
dw1=abs(wp(1)-ws(1));
dw2=abs(wp(2)-ws(2));dw=min(dw1,dw2);
w0=.5*(wp(1)+wp(2));
wp=.5*(wp(2)-wp(1));
if ty=='bs',wp=wp-dw;end
ws=wp+dw;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -