📄 sdm.m
字号:
function [ret,x0,str,ts,xts]=sdm(t,x,u,flag);
%SDM is the M-file description of the SIMULINK system named SDM.
% The block-diagram can be displayed by typing: SDM.
%
% SYS=SDM(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 SDM to return state derivatives, FLAG=2
% discrete states, FLAG=3 system outputs and FLAG=4 next sample
% time. For more information and other options see SFUNC.
%
% Calling SDM with a FLAG of zero:
% [SIZES]=SDM([],[],[],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
% SIZES(5) number of roots (currently unsupported)
% SIZES(6) direct feedthrough flag
% SIZES(7) number of sample times
%
% For the definition of other parameters in SIZES, see SFUNC.
% See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.
% 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',[3000,3000,3160,3024])
open_system(sys)
end;
set_param(sys,'algorithm', 'Linear')
set_param(sys,'Start time', '0.0')
set_param(sys,'Stop time', '2')
set_param(sys,'Min step size', '1/512000')
set_param(sys,'Max step size', '1/512000')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars', '')
set_param(sys,'AssignWideVectorLines','on');
% Subsystem 'Sign'.
new_system([sys,'/','Sign'])
set_param([sys,'/','Sign'],'Location',[159,417,467,586])
add_block('built-in/Outport',[sys,'/','Sign/out_1'])
set_param([sys,'/','Sign/out_1'],...
'position',[265,70,285,90])
add_block('built-in/Inport',[sys,'/','Sign/in_1'])
set_param([sys,'/','Sign/in_1'],...
'position',[35,30,55,50])
add_block('built-in/Relational Operator',[sys,'/',['Sign/Relational',13,'Operator']])
set_param([sys,'/',['Sign/Relational',13,'Operator']],...
'Operator','>',...
'position',[140,32,170,63])
add_block('built-in/Sum',[sys,'/','Sign/Sum'])
set_param([sys,'/','Sign/Sum'],...
'inputs','+-',...
'position',[215,64,235,91])
add_block('built-in/Relational Operator',[sys,'/',['Sign/Relational',13,'Operator1']])
set_param([sys,'/',['Sign/Relational',13,'Operator1']],...
'Operator','<',...
'position',[140,92,170,123])
add_block('built-in/Constant',[sys,'/','Sign/Constant'])
set_param([sys,'/','Sign/Constant'],...
'Value','0',...
'position',[65,105,85,125])
add_line([sys,'/','Sign'],[60,40;135,40])
add_line([sys,'/','Sign'],[95,40;95,100;135,100])
add_line([sys,'/','Sign'],[90,115;135,115])
add_line([sys,'/','Sign'],[110,115;110,55;135,55])
add_line([sys,'/','Sign'],[175,110;185,110;185,85;210,85])
add_line([sys,'/','Sign'],[175,50;185,50;185,70;210,70])
add_line([sys,'/','Sign'],[240,80;260,80])
set_param([sys,'/','Sign'],...
'Mask Display','plot(-50,-50,50,50,[-50,50],[0,0],[0,0],[-50,50],[-40,0],[-30,-30],[0,40],[30,30])',...
'Mask Type','Sign',...
'Mask Dialogue','y = sign(x)')
set_param([sys,'/','Sign'],...
'Mask Help','Sign Function:\n\t\t\ty = 1 if x > 0\n\t\t\ty = 0 if x = 0\n\t\t\ty = -1 if x < 0')
% Finished composite block 'Sign'.
set_param([sys,'/','Sign'],...
'position',[390,112,420,138])
add_block('built-in/Scope',[sys,'/','Scope2'])
set_param([sys,'/','Scope2'],...
'Vgain','1.500000',...
'Hgain','0.000050',...
'Vmax','3.000000',...
'Hmax','0.000100',...
'Window',[0,197,770,397],...
'position',[555,30,585,60])
add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
'inputs','+-',...
'position',[280,115,300,135])
add_block('built-in/Gain',[sys,'/','Gain'])
set_param([sys,'/','Gain'],...
'Gain','.8',...
'position',[170,105,200,135])
% Subsystem ['Repeating',13,'Sequence'].
new_system([sys,'/',['Repeating',13,'Sequence']])
set_param([sys,'/',['Repeating',13,'Sequence']],'Location',[5,40,315,196])
add_block('built-in/Clock',[sys,'/',['Repeating',13,'Sequence/Clock']])
set_param([sys,'/',['Repeating',13,'Sequence/Clock']],...
'position',[45,60,65,80])
add_block('built-in/Fcn',[sys,'/',['Repeating',13,'Sequence/Fcn1']])
set_param([sys,'/',['Repeating',13,'Sequence/Fcn1']],...
'Expr','rem(u[1],period)',...
'position',[110,60,150,80])
add_block('built-in/Look Up Table',[sys,'/',['Repeating',13,'Sequence/Look-Up Table']])
set_param([sys,'/',['Repeating',13,'Sequence/Look-Up Table']],...
'Input_Values','t',...
'Output_Values','y',...
'position',[210,58,250,82])
add_block('built-in/Outport',[sys,'/',['Repeating',13,'Sequence/out_1']])
set_param([sys,'/',['Repeating',13,'Sequence/out_1']],...
'position',[285,60,305,80])
add_line([sys,'/',['Repeating',13,'Sequence']],[155,70;205,70])
add_line([sys,'/',['Repeating',13,'Sequence']],[70,70;105,70])
add_line([sys,'/',['Repeating',13,'Sequence']],[255,70;280,70])
set_param([sys,'/',['Repeating',13,'Sequence']],...
'Mask Display','plot([t,t+period,t+2*period],[y,y,y])',...
'Mask Type','Repeating table')
set_param([sys,'/',['Repeating',13,'Sequence']],...
'Mask Dialogue','Repeating table.\nEnter values of time and output for first cycle.|Time values:|Output values:',...
'Mask Translate','period = max(@1); t = @1; y = @2;')
set_param([sys,'/',['Repeating',13,'Sequence']],...
'Mask Help','Repeats cycle given in table. Time values should be monotonically increasing.',...
'Mask Entries','[0 .005 .005 .015 .015 .02]\/[1 1 -1 -1 1 1]\/')
% Finished composite block ['Repeating',13,'Sequence'].
set_param([sys,'/',['Repeating',13,'Sequence']],...
'position',[25,102,50,138])
add_block('built-in/Zero-Pole',[sys,'/',['Analog',13,'Butterworth',13,'LP Filter']])
set_param([sys,'/',['Analog',13,'Butterworth',13,'LP Filter']],...
'Zeros','z',...
'Poles','p',...
'Gain','k',...
'Mask Display','plot(20*log10(w),20*log10(abs(h)))',...
'Mask Type','buttap')
set_param([sys,'/',['Analog',13,'Butterworth',13,'LP Filter']],...
'Mask Dialogue','Analog Butterworth low pass filter.\n\n(Requires Signal Processing Toolbox)|Cutoff frequency (rad/sec)|Order')
set_param([sys,'/',['Analog',13,'Butterworth',13,'LP Filter']],...
'Mask Translate','[z,p,k]=buttap(@2); z=@1*z; p=@1*p; k=real(prod(-p)); [num,den]=zp2tf(z,p,k); w=logspace(log10(@1/10),log10(10*@1),20); h=freqs(num,den,w); ')
set_param([sys,'/',['Analog',13,'Butterworth',13,'LP Filter']],...
'Mask Help','Butterworth low pass filter using MATLAB''s butter command.',...
'Mask Entries','400*2*pi\/5\/',...
'position',[100,97,140,143])
add_block('built-in/Scope',[sys,'/','Scope3'])
set_param([sys,'/','Scope3'],...
'Vgain','1.500000',...
'Hgain','0.010000',...
'Vmax','3.000000',...
'Hmax','0.020000',...
'Window',[381,0,770,198],...
'position',[795,20,825,50])
% Subsystem 'Decimation'.
new_system([sys,'/','Decimation'])
set_param([sys,'/','Decimation'],'Location',[129,578,559,704])
add_block('built-in/Zero-Order Hold',[sys,'/',['Decimation/Zero-Order',13,'Hold']])
set_param([sys,'/',['Decimation/Zero-Order',13,'Hold']],...
'Sample time','ts*r',...
'position',[225,39,260,71])
add_block('built-in/Inport',[sys,'/','Decimation/in_1'])
set_param([sys,'/','Decimation/in_1'],...
'position',[45,45,65,65])
add_block('built-in/Outport',[sys,'/','Decimation/out_1'])
set_param([sys,'/','Decimation/out_1'],...
'position',[290,45,310,65])
add_block('built-in/Discrete State-Space',[sys,'/',['Decimation/Chebyshev Type I',13,'IIR Lowpass']])
set_param([sys,'/',['Decimation/Chebyshev Type I',13,'IIR Lowpass']],...
'A','a',...
'B','b',...
'C','c',...
'D','d',...
'Sample time','ts',...
'Mask Display','plot(1:64,abs(h))',...
'Mask Type','cheby1')
set_param([sys,'/',['Decimation/Chebyshev Type I',13,'IIR Lowpass']],...
'Mask Dialogue','IIR Chebychev type I low pass filter.|Cutoff frequency (0 to 1):|Order:|Db ripple in passband:|Sample time:')
set_param([sys,'/',['Decimation/Chebyshev Type I',13,'IIR Lowpass']],...
'Mask Translate','[a,b,c,d]=cheby1(@2,@3,@1); ts=@4; [num,den]=ss2tf(a,b,c,d,1); if (@2 <= 8), [a,b,c,d]=tf2ss(num,den); end; h=freqz(num,den,64); ')
set_param([sys,'/',['Decimation/Chebyshev Type I',13,'IIR Lowpass']],...
'Mask Help','IIR Chebychev type I low pass filter designed using MATLAB''s cheby1 command. Implemented in state-space form. Filters of order 8 or less are implemented in controller canonical form for improved efficiency.')
set_param([sys,'/',['Decimation/Chebyshev Type I',13,'IIR Lowpass']],...
'Mask Entries','0.8/r\/8\/.05\/ts\/',...
'position',[130,41,165,69])
add_line([sys,'/','Decimation'],[265,55;285,55])
add_line([sys,'/','Decimation'],[70,55;125,55])
add_line([sys,'/','Decimation'],[170,55;220,55])
set_param([sys,'/','Decimation'],...
'Mask Display','x[nR]',...
'Mask Type','Decimate',...
'Mask Dialogue','Decimate input by integer factor.|Decimation factor R:|Input sample time:',...
'Mask Translate','r=@1;ts=@2;')
set_param([sys,'/','Decimation'],...
'Mask Help','Passes the input signal through an 8th order Chebyshev Type I IIR Lowpass filter with passband ripple of 0.05 dB to reduce aliasing. Subsamples the filtered signal at a rate R times slower than the base sample rate defined by the Sample time.')
set_param([sys,'/','Decimation'],...
'Mask Entries','4\/1/512000\/')
% Finished composite block 'Decimation'.
set_param([sys,'/','Decimation'],...
'position',[550,109,590,141])
% Subsystem ['Dirty Square',13,'Wave1'].
new_system([sys,'/',['Dirty Square',13,'Wave1']])
set_param([sys,'/',['Dirty Square',13,'Wave1']],'Location',[125,385,604,706])
add_block('built-in/Sum',[sys,'/',['Dirty Square',13,'Wave1/Sum']])
set_param([sys,'/',['Dirty Square',13,'Wave1/Sum']],...
'BackGround',3,...
'inputs','+++++',...
'position',[355,52,375,108])
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -