⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 firlen.m

📁 很多matlab的源代码
💻 M
字号:
function N = firlen(ty,a,sf,fp,fs)
% FIRLEN Approximate FIR filter length for optimal design.
%
%       N = FIRLEN(TY, A,SF,FP,FS) Approximate FIR filter length
%	TY can be 'lp', 'hp', 'bp', or 'bs',
%       If A = [Ap As] = [passband stopband] attenuation in dB
%	FP and FS are the passband & stopband edge(s) in HERTZ
%	NOTE: FP and FS will have two elements for 'bp' and 'bs' filters.
%
%	N returns the approximate filter length.
%
%       FIRLEN (with no input arguments) invokes the following example:
%
%       >>len = firlen('bs',[3 50],100,[10 40],[20 30])


% 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 firlen,disp('Strike a key to see results of the example')
pause,len=firlen('bs',[3 50],100,[10 40],[20 30]),return,end

%ERROR CHECK
ty=ty(1:2);if ty=='bp'|ty=='bs',if length(fp)~=2|length(fs)~=2
error('BP or BS filters require fp and fs as two elements'),return,end,end
e=0;if ty=='lp',if fp>fs,e=1;end
elseif ty=='hp',if fs>fp,e=1;end
elseif ty=='bp',pp=abs(diff(fp));ss=abs(diff(fs));if pp>ss,e=1;end
elseif ty=='bs',pp=abs(diff(fp));ss=abs(diff(fs));if ss>pp,e=1;end
else,error('Unknown type. Use lp hp bp or bs in single quotes'),return,end
if e==1,error('Passband and stopband switched'),return,end

%COMPUTE RIPPLES
ap=a(1);as=a(2);
dp=[(10)^(0.05*ap)-1]/[(10)^(0.05*ap)+1];ds=(10)^(-0.05*as);

fp=fp/sf;fs=fs/sf;odd=0;if ty=='bs',odd=1;end

%COMPUTE APPROXIMATE FILTER LENGTH N
if ty=='lp'| ty=='hp',df=abs(fs-fp);
else,df1=abs(fp(1)-fs(1));df2=abs(fs(2)-fp(2));
df=min(df1,df2);end
N=ceil(1-(10*log10(dp*ds)+13)/(2.324*2*pi*df));

if rem(N,2)==0,if odd==1,N=N+1;end;end,N=max(3,N);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -