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

📄 go4.m

📁 这是一个优化IIR滤波器的源码,能设计出8个极点8个零点的IIR优化滤波器
💻 M
字号:
%% Matlab script to run the optimization%% Code Generated by Mathematica packages written by Brian L. Evans%% Copyright 1993 by the Regents of the University of California%% @(#)go4.m	1.5	10/30/01function foo = go2(fileid,a,b,c,d,e,f,g,h,ii,j,k,l,wmin,fmax,tmin,tmax,npts)%% This program uses the following global variables:global dp ds maxO wmax Wmp Wms Wmt WO wp Wph WQ ws tpeak1;%% The following constants have been given default values:Wmp = a;             %% weight on mag. response in passbandWmt = b;             %% weight on mag. response in transition bandWms = c;             %% weight on mag. response in stopbandWph = d;           %% weight on deviation from linear phaseWQ = e;              %% weight on quality factor costWO = f;              %% weight on percent overshoot costwp = g;             %% end of passband frequencyws = h;             %% start of stopband frequencywmax = wp;           %% max. frequency for filter to exhibit linear phasemaxO = j;           %% max. percent overshoot of the step responsedp = k;           %% allowable mag. error in the passbandds = l;           %% allowable mag. error in the stopband%% The program uses one global variable that is updated at each iteration:%%	tpeak1 the time at which the peak in the step response occurs%% Debugging codeglobal numtimes weights;weights = [0 0 0 0];numtimes = 0;x0=[-8107.2614 -5483.3416 -2751.9711 -802.3032 -3836.7800 -9646.0115 -12507.3953 -13554.1190  -9.0949e-13 -9.0949e-13 -9.0949e-13 -9.0949e-13 -17813.1598 -76471.8605 -28205.4248 -20117.5622];tpeak1 = fmin( 'stepresp', 0, max([-(pi./x0(5)), -(pi./x0(6)), -(pi./x0(7)), -(pi./x0(8))]), [], x0(1:4), x0(5:8),x0(9:12),x0(13:16), -1 );if ( stepresp(tpeak1, x0(1:4), x0(5:8), x0(9:12),x0(13:16) , 1) - 1 ) > maxO./100  fprintf(1, '  overshoot for the initial guess is higher than minimum.\n');end%% Do 10 iterations at a time and quit when the first three %%   digits of the value of the cost function remain constantoptions = foptions;options(1) = 2;options(9) = 1;options(14) = 100;errvec = [-100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps, -100.*eps];[root, options] = constr('filcost4', x0, options, [], errvec, 'costder4');lastcost = filcost4(x0);while ( abs( (lastcost - options(8) ) / lastcost) > 1e-3 ),  lastcost = options(8);  [root, options] = constr('filcost4', root, options, [], errvec, 'costder4');end;disp('The conjugate zero pairs are located at:');zeroloc = root(9:12) +i*root(13:16);disp(zeroloc);disp('The conjugate pole pairs are located at:');poleloc = root(1:4) +i*root(5:8);disp(poleloc);%% Normalized weight vectorweights / numtimesmag = magphase(fileid,poleloc(1:1),poleloc(2:2),poleloc(3:3),poleloc(4:4),zeroloc(1:1),zeroloc(2:2),zeroloc(3:3),zeroloc(4:4),fmax,wmin,npts)step = stepresp([tmin :((tmax-tmin)/npts):tmax], [real(poleloc(1:1)) real(poleloc(2:2)) real(poleloc(3:3)) real(poleloc(4:4))],[imag(poleloc(1:1)) imag(poleloc(2:2)) imag(poleloc(3:3)) imag(poleloc(4:4))], [real(zeroloc(1:1)) real(zeroloc(2:2)) real(zeroloc(3:3)) real(zeroloc(4:4))],[imag(zeroloc(1:1)) imag(zeroloc(2:2)) imag(zeroloc(3:3)) imag(zeroloc(4:4))],1)fid = fopen(fileid,'w');for i = 1 : length(mag)   fprintf(fid,'%f\t%f\t%f\n',mag(1,i),mag(2,i),step(i));endfprintf(fid,'%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f\n%f',real(poleloc(1:1)),imag(poleloc(1:1)),real(poleloc(2:2)),imag(poleloc(2:2)),real(poleloc(3:3)),imag(poleloc(3:3)),real(poleloc(4:4)),imag(poleloc(4:4)),real(zeroloc(1:1)),imag(zeroloc(1:1)),real(zeroloc(2:2)),imag(zeroloc(2:2)),real(zeroloc(3:3)),imag(zeroloc(3:3)),real(zeroloc(4:4)), imag(zeroloc(4:4)))fclose(fid);foo = 4;end

⌨️ 快捷键说明

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