📄 filters.m
字号:
function [ret,x0,str]=filters(t,x,u,flag);
%FILTERS is the M-file description of the SIMULINK system named FILTERS.
% The block-diagram can be displayed by typing: FILTERS.
%
% SYS=FILTERS(T,X,U,FLAG) returns depending on FLAG certain
% system values given time point, T, current state vector, X,
% and input vector, U.
% FLAG is used to indicate the type of output to be returned in SYS.
%
% Setting FLAG=1 causes FILTERS to return state derivitives, FLAG=2
% discrete states, FLAG=3 system outputs and FLAG=4 next sample
% time. For more information and other options see SFUNC.
%
% Calling FILTERS with a FLAG of zero:
% [SIZES]=FILTERS([],[],[],0), returns a vector, SIZES, which
% contains the sizes of the state vector and other parameters.
% SIZES(1) number of states
% SIZES(2) number of discrete states
% SIZES(3) number of outputs
% SIZES(4) number of inputs.
% For the definition of other parameters in SIZES, see SFUNC.
% See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.
% Copyright (c) 1990-94 by The MathWorks, Inc.
% Note: This M-file is only used for saving graphical information;
% after the model is loaded into memory an internal model
% representation is used.
% the system will take on the name of this mfile:
sys = mfilename;
new_system(sys)
simver(1.3)
if(0 == (nargin + nargout))
set_param(sys,'Location',[0,0,591,426])
open_system(sys)
end;
set_param(sys,'algorithm', 'Linear')
set_param(sys,'Start time', '0.0')
set_param(sys,'Stop time', '999999')
set_param(sys,'Min step size', '0.0001')
set_param(sys,'Max step size', '0.1')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars', '')
add_block('built-in/Zero-Pole',[sys,'/','LP filter (impulse)'])
set_param([sys,'/','LP filter (impulse)'],...
'Font Size',12,...
'Zeros','z',...
'Poles','p',...
'Gain','k',...
'Mask Display','plot(t,y,[0;max(t)],[0;0])',...
'Mask Type','Lp filter')
set_param([sys,'/','LP filter (impulse)'],...
'Mask Dialogue','Butterworth low pass filter.\n(Requires Signal Processing Toolbox)|Cutoff frequency (rad/sec)|Order')
set_param([sys,'/','LP filter (impulse)'],...
'Mask Translate','[z,p,k]=buttap(@2); z=@1*z; p=@1*p; k=prod(p)/prod(z); [a,b,c,d]=zp2ss(z,p,k); t=[0:0.2:3*@2]/@1; [y,x]=impulse(a,b,c,d,1,t);')
set_param([sys,'/','LP filter (impulse)'],...
'Mask Help','Butterworth low pass filter using MATLAB''s butter command.',...
'Mask Entries','10\/10\/',...
'position',[195,223,355,277])
add_block('built-in/Scope',[sys,'/','Scope3'])
set_param([sys,'/','Scope3'],...
'Vgain','1.000000',...
'Hgain','11.000000',...
'Vmax','2.000000',...
'Hmax','22.000000',...
'Window',[100,100,380,320],...
'position',[170,308,200,342])
add_block('built-in/Scope',[sys,'/','Scope1'])
set_param([sys,'/','Scope1'],...
'Vgain','1.000000',...
'Hgain','11.000000',...
'Vmax','2.000000',...
'Hmax','22.000000',...
'Window',[100,100,380,320],...
'position',[405,138,435,172])
add_block('built-in/Scope',[sys,'/','Scope2'])
set_param([sys,'/','Scope2'],...
'Vgain','1.000000',...
'Hgain','11.000000',...
'Vmax','2.000000',...
'Hmax','22.000000',...
'Window',[100,100,380,320],...
'position',[410,233,440,267])
add_block('built-in/Zero-Pole',[sys,'/','Lp filter (frequency)'])
set_param([sys,'/','Lp filter (frequency)'],...
'Zeros','z',...
'Poles','p',...
'Gain','k',...
'Mask Display','plot(w+100, mag+100)',...
'Mask Type','Lp filter')
set_param([sys,'/','Lp filter (frequency)'],...
'Mask Dialogue','Butterworth low pass filter|Cutoff frequency (rad/sec)|Order')
set_param([sys,'/','Lp filter (frequency)'],...
'Mask Translate','[z,p,k]=buttap(@2); z=@1*z; p=@1*p; [a,b,c,d]=zp2ss(z,p,k); w = @1/1000:@1/50:2*@1; [mag,phase]=bode(a,b,c,d,1,w);')
set_param([sys,'/','Lp filter (frequency)'],...
'Mask Help','Low pass butterworth filter Mask Block. Enter coefficients for filter order and frequency.',...
'Mask Entries','1\/4\/',...
'position',[195,128,355,182])
add_block('built-in/Scope',[sys,'/','Scope'])
set_param([sys,'/','Scope'],...
'Vgain','1.000000',...
'Hgain','11.000000',...
'Vmax','2.000000',...
'Hmax','22.000000',...
'Window',[100,100,380,320],...
'position',[405,33,435,67])
add_block('built-in/Transfer Fcn',[sys,'/','Lp filter'])
set_param([sys,'/','Lp filter'],...
'Numerator','num',...
'Denominator','den',...
'Mask Display','dpoly(num,den,''s'')',...
'Mask Type','Lp filter',...
'Mask Dialogue','Butterworth low pass filter|Cutoff frequency (rad/sec)|Order')
set_param([sys,'/','Lp filter'],...
'Mask Translate','[z,p,k]=buttap(@2); [num,den]=zp2tf(@1*z, @1*p, k);',...
'Mask Help','Low pass butterworth filter Mask Block. Enter coefficients for filter order and frequency.')
set_param([sys,'/','Lp filter'],...
'Mask Entries','1\/3\/',...
'position',[200,17,365,83])
add_block('built-in/Outport',[sys,'/','Outport'])
set_param([sys,'/','Outport'],...
'Port','3',...
'position',[470,290,490,310])
add_block('built-in/Inport',[sys,'/','Inport'])
set_param([sys,'/','Inport'],...
'Port','1',...
'position',[15,140,35,160])
add_block('built-in/Outport',[sys,'/','Outport1'])
set_param([sys,'/','Outport1'],...
'Port','1',...
'position',[470,90,490,110])
add_block('built-in/Outport',[sys,'/','Outport2'])
set_param([sys,'/','Outport2'],...
'Port','2',...
'position',[470,195,490,215])
add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
'inputs','++',...
'position',[115,145,135,165])
add_block('built-in/Signal Generator',[sys,'/','Signal Gen.2'])
set_param([sys,'/','Signal Gen.2'],...
'Peak','1.000000',...
'Peak Range','5.000000',...
'Freq','1.000000',...
'Freq Range','5.000000',...
'Wave','Sin',...
'Units','Rads',...
'position',[40,203,85,237])
add_line(sys,[140,155;140,325;165,325])
add_line(sys,[360,250;405,250])
add_line(sys,[380,250;380,300;465,300])
add_line(sys,[360,155;400,155])
add_line(sys,[380,155;380,205;465,205])
add_line(sys,[370,50;400,50])
add_line(sys,[380,50;380,100;465,100])
add_line(sys,[140,155;165,155;165,250;190,250])
add_line(sys,[140,155;165,155;165,50;195,50])
add_line(sys,[140,155;190,155])
add_line(sys,[90,220;95,220;95,160;110,160])
add_line(sys,[40,150;110,150])
% Return any arguments.
if (nargin | nargout)
% Must use feval here to access system in memory
if (nargin > 3)
if (flag == 0)
eval(['[ret,x0,xstr]=',sys,'(t,x,u,flag);'])
else
eval(['ret =', sys,'(t,x,u,flag);'])
end
else
[ret,x0,str] = feval(sys);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -