📄 example4.m
字号:
function [ret,x0,str,ts,xts]=example4(t,x,u,flag);%EXAMPLE4 is the M-file description of the SIMULINK system named EXAMPLE4.% The block-diagram can be displayed by typing: EXAMPLE4.%% SYS=EXAMPLE4(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 EXAMPLE4 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 EXAMPLE4 with a FLAG of zero:% [SIZES]=EXAMPLE4([],[],[],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',[4,58,672,527]) open_system(sys)end;set_param(sys,'algorithm', 'RK-45')set_param(sys,'Start time', '0.0')set_param(sys,'Stop time', '40')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', '')set_param(sys,'AssignWideVectorLines','on');% Subsystem 'Text'.new_system([sys,'/','Text'])set_param([sys,'/','Text'],'Location',[147,145,576,495])add_block('built-in/Note',[sys,'/','Text/4) The noise level (the gain in the Noise Source block)'])set_param([sys,'/','Text/4) The noise level (the gain in the Noise Source block)'],... 'position',[225,250,230,255])add_block('built-in/Note',[sys,'/',['Text/3) The transfer function W(s) in the receiver and in the',13,'Estimator block']])set_param([sys,'/',['Text/3) The transfer function W(s) in the receiver and in the',13,'Estimator block']],... 'position',[225,210,230,215])add_block('built-in/Note',[sys,'/','Text/2) The normalization gain alpha in the Estimator block'])set_param([sys,'/','Text/2) The normalization gain alpha in the Estimator block'],... 'position',[225,170,230,175])add_block('built-in/Note',[sys,'/','Text/1) The adaptive gain (gain_a1, gain_a2 in the Estimator block)'])set_param([sys,'/','Text/1) The adaptive gain (gain_a1, gain_a2 in the Estimator block)'],... 'position',[255,135,260,140])add_block('built-in/Note',[sys,'/',['Text/You can use Start//Stop in the Simulation pull-down',13,'menu to run the program. Or you can change the',13,'following parameters to see how they affect the',13,'simulation results:',13,'']])set_param([sys,'/',['Text/You can use Start//Stop in the Simulation pull-down',13,'menu to run the program. Or you can change the',13,'following parameters to see how they affect the',13,'simulation results:',13,'']],... 'position',[220,60,225,65])add_block('built-in/Note',[sys,'/',['Text/This program simulates the estimation algorithm',13,'discussed in Example 4.3.1. Please refer to page',13,'181 of the textbook for details. ']])set_param([sys,'/',['Text/This program simulates the estimation algorithm',13,'discussed in Example 4.3.1. Please refer to page',13,'181 of the textbook for details. ']],... 'position',[215,0,220,5])set_param([sys,'/','Text'],... 'Mask Display','Double click here\nfor help to run\nthe simulation')% Finished composite block 'Text'.set_param([sys,'/','Text'],... 'Drop Shadow',4,... 'position',[387,310,520,386])% Subsystem 'Signal Reconstruction'.new_system([sys,'/','Signal Reconstruction'])set_param([sys,'/','Signal Reconstruction'],'Location',[14,79,489,361])add_block('built-in/Fcn',[sys,'/','Signal Reconstruction/Phase'])set_param([sys,'/','Signal Reconstruction/Phase'],... 'Expr','acos(u(1)/sqrt(u(1)*u(1)+u(2)*u(2)))',... 'Mask Display','P',... 'position',[65,120,105,140])add_block('built-in/Fcn',[sys,'/','Signal Reconstruction/magnitude'])set_param([sys,'/','Signal Reconstruction/magnitude'],... 'Expr','sqrt(u(1)*u(1)+u(2)*u(2))',... 'Mask Display','A',... 'position',[65,22,105,48])add_block('built-in/Outport',[sys,'/','Signal Reconstruction/est_mag'])set_param([sys,'/','Signal Reconstruction/est_mag'],... 'BackGround',2,... 'position',[395,25,415,45])add_block('built-in/Outport',[sys,'/','Signal Reconstruction/est_phase'])set_param([sys,'/','Signal Reconstruction/est_phase'],... 'BackGround',2,... 'Port','2',... 'position',[400,85,420,105])add_block('built-in/Inport',[sys,'/','Signal Reconstruction/theta'])set_param([sys,'/','Signal Reconstruction/theta'],... 'BackGround',3,... 'position',[10,65,30,85])add_block('built-in/Fcn',[sys,'/','Signal Reconstruction/hat_y'])set_param([sys,'/','Signal Reconstruction/hat_y'],... 'Expr','u(1)*sin(2*u(3)+u(2))',... 'Mask Display','Asin(wt+p)',... 'position',[310,151,370,179])add_block('built-in/Outport',[sys,'/','Signal Reconstruction/est_signal'])set_param([sys,'/','Signal Reconstruction/est_signal'],... 'BackGround',2,... 'Port','3',... 'position',[405,155,425,175])add_block('built-in/Mux',[sys,'/','Signal Reconstruction/Mux2'])set_param([sys,'/','Signal Reconstruction/Mux2'],... 'inputs','3',... 'Mask Display','',... 'position',[235,145,275,185])add_block('built-in/Clock',[sys,'/','Signal Reconstruction/Clock1'])set_param([sys,'/','Signal Reconstruction/Clock1'],... 'position',[195,210,215,230])add_line([sys,'/','Signal Reconstruction'],[280,165;305,165])add_line([sys,'/','Signal Reconstruction'],[220,220;230,180])add_line([sys,'/','Signal Reconstruction'],[35,75;50,75;60,130])add_line([sys,'/','Signal Reconstruction'],[110,130;150,130;150,165;230,165])add_line([sys,'/','Signal Reconstruction'],[110,35;165,35;165,150;230,150])add_line([sys,'/','Signal Reconstruction'],[150,130;150,95;395,95])add_line([sys,'/','Signal Reconstruction'],[165,35;390,35])add_line([sys,'/','Signal Reconstruction'],[50,75;60,35])add_line([sys,'/','Signal Reconstruction'],[375,165;400,165])set_param([sys,'/','Signal Reconstruction'],... 'Mask Display','plot(sin([0.0:0.1:6.3]))')% Finished composite block 'Signal Reconstruction'.set_param([sys,'/','Signal Reconstruction'],... 'Drop Shadow',4,... 'position',[425,154,485,206])add_block('built-in/Clock',[sys,'/','Clock'])set_param([sys,'/','Clock'],... 'orientation',1,... 'position',[520,80,540,100])add_block('built-in/Mux',[sys,'/','Mux'])set_param([sys,'/','Mux'],... 'inputs','5',... 'position',[565,98,605,172])add_block('built-in/To Workspace',[sys,'/','To Workspace'])set_param([sys,'/','To Workspace'],... 'mat-name','yout',... 'buffer','5000',... 'position',[630,118,685,152])% Subsystem 'Estimator'.new_system([sys,'/','Estimator'])set_param([sys,'/','Estimator'],'Location',[14,110,696,615])add_block('built-in/Outport',[sys,'/','Estimator/estimates_'])set_param([sys,'/','Estimator/estimates_'],... 'position',[615,110,635,130])add_block('built-in/Gain',[sys,'/','Estimator/gain_a2'])set_param([sys,'/','Estimator/gain_a2'],... 'position',[405,130,430,160])add_block('built-in/Integrator',[sys,'/','Estimator/int_a2'])set_param([sys,'/','Estimator/int_a2'],... 'position',[460,126,485,164])add_block('built-in/Fcn',[sys,'/','Estimator/ns'])set_param([sys,'/','Estimator/ns'],... 'Expr','u(1)*u(1)+u(2)*u(2)',... 'Mask Display','phi ''phi',... 'position',[155,314,210,346])add_block('built-in/Demux',[sys,'/','Estimator/Demux'])set_param([sys,'/','Estimator/Demux'],... 'outputs','2',... 'position',[80,85,120,120])add_block('built-in/Product',[sys,'/','Estimator/Product1'])set_param([sys,'/','Estimator/Product1'],... 'position',[340,127,370,158])add_block('built-in/Gain',[sys,'/','Estimator/gain_a1'])set_param([sys,'/','Estimator/gain_a1'],... 'position',[405,65,430,95])add_block('built-in/Product',[sys,'/','Estimator/Product'])set_param([sys,'/','Estimator/Product'],... 'position',[340,63,370,92])add_block('built-in/Demux',[sys,'/','Estimator/Demux1'])set_param([sys,'/','Estimator/Demux1'],... 'outputs','2',... 'position',[85,215,125,250])add_block('built-in/Inport',[sys,'/','Estimator/z'])set_param([sys,'/','Estimator/z'],... 'position',[15,195,35,215])add_block('built-in/Inport',[sys,'/','Estimator/phi'])set_param([sys,'/','Estimator/phi'],... 'Port','2',... 'position',[15,245,35,265])add_block('built-in/Transfer Fcn',[sys,'/','Estimator/W(s)'])set_param([sys,'/','Estimator/W(s)'],... 'Numerator','[2]',... 'Denominator','[1 2]',... 'position',[220,218,255,252])add_block('built-in/Sum',[sys,'/','Estimator/Sum'])set_param([sys,'/','Estimator/Sum'],... 'inputs','+--',... 'position',[290,218,315,252])add_block('built-in/Transfer Fcn',[sys,'/','Estimator/W(s)_'])set_param([sys,'/','Estimator/W(s)_'],...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -