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

📄 tstswitc.m

📁 数字通信第四版原书的例程
💻 M
字号:
function [ret,x0,str,ts,xts]=tstswitc(t,x,u,flag);
%TSTSWITC	is the M-file description of the SIMULINK system named TSTSWITC.
%	The block-diagram can be displayed by typing: TSTSWITC.
%
%	SYS=TSTSWITC(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 TSTSWITC 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 TSTSWITC with a FLAG of zero:
%	[SIZES]=TSTSWITC([],[],[],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',[36,150,536,376])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
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', '10')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')

add_block('built-in/Signal Generator',[sys,'/',['Signal',13,'generator']])
set_param([sys,'/',['Signal',13,'generator']],...
		'hide name',0,...
		'Peak','1.000000',...
		'Peak Range','5.000000',...
		'Freq','1.000000',...
		'Freq Range','5.000000',...
		'Wave','Sin',...
		'Units','Rads',...
		'position',[35,13,80,47])

add_block('built-in/Signal Generator',[sys,'/',['Signal',13,'generator2']])
set_param([sys,'/',['Signal',13,'generator2']],...
		'hide name',0,...
		'Peak','1.000000',...
		'Peak Range','5.000000',...
		'Freq','1.000000',...
		'Freq Range','5.000000',...
		'Wave','Saw',...
		'Units','Rads')
set_param([sys,'/',['Signal',13,'generator2']],...
		'position',[35,108,80,142])

add_block('built-in/Signal Generator',[sys,'/',['Signal',13,'generator1']])
set_param([sys,'/',['Signal',13,'generator1']],...
		'hide name',0,...
		'Peak','1.000000',...
		'Peak Range','5.000000',...
		'Freq','1.000000',...
		'Freq Range','5.000000',...
		'Wave','Sqr',...
		'Units','Rads',...
		'position',[35,63,80,97])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'hide name',0,...
		'inputs','3',...
		'position',[170,63,205,97])


%     Subsystem  'Signal switch'.

new_system([sys,'/','Signal switch'])
set_param([sys,'/','Signal switch'],'Location',[174,522,554,686])

add_block('built-in/S-Function',[sys,'/','Signal switch/S-function'])
set_param([sys,'/','Signal switch/S-function'],...
		'function name','switchbx',...
		'parameters','sw,df',...
		'position',[205,60,275,90])

add_block('built-in/Inport',[sys,'/','Signal switch/in_2'])
set_param([sys,'/','Signal switch/in_2'],...
		'Port','2',...
		'position',[60,75,80,95])

add_block('built-in/Outport',[sys,'/','Signal switch/out_1'])
set_param([sys,'/','Signal switch/out_1'],...
		'position',[320,65,340,85])

add_block('built-in/Mux',[sys,'/','Signal switch/Mux'])
set_param([sys,'/','Signal switch/Mux'],...
		'inputs','2',...
		'position',[145,54,175,96])

add_block('built-in/Inport',[sys,'/','Signal switch/in_1'])
set_param([sys,'/','Signal switch/in_1'],...
		'position',[65,20,85,40])
add_line([sys,'/','Signal switch'],[280,75;315,75])
add_line([sys,'/','Signal switch'],[180,75;200,75])
add_line([sys,'/','Signal switch'],[85,85;140,85])
add_line([sys,'/','Signal switch'],[90,30;120,30;120,65;140,65])
set_param([sys,'/','Signal switch'],...
		'Mask Display','Switch\nbox',...
		'Mask Type','Vector signal re-distribution')
set_param([sys,'/','Signal switch'],...
		'Mask Dialogue','The output distribution pattern follows the ith row of the switch box, where i is the input from the second port.|Switch box (column number equals block output length):|Default value:')
set_param([sys,'/','Signal switch'],...
		'Mask Translate','sw=@1;df=@2;')
set_param([sys,'/','Signal switch'],...
		'Mask Help','This block follows the switch pattern of ith row in the switch box when the second input port has value i.  When the value in the second input is larger than the switch box row number or less than 1, the block outputs the defualt value.')
set_param([sys,'/','Signal switch'],...
		'Mask Entries','[1 2;2 3;3 1]\/[0 0]\/')


%     Finished composite block 'Signal switch'.

set_param([sys,'/','Signal switch'],...
		'hide name',0,...
		'position',[255,68,335,112])


%     Subsystem  ['Auto-Scale',13,'Graph'].

new_system([sys,'/',['Auto-Scale',13,'Graph']])
set_param([sys,'/',['Auto-Scale',13,'Graph']],'Location',[0,59,274,252])

add_block('built-in/S-Function',[sys,'/',['Auto-Scale',13,'Graph/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['Auto-Scale',13,'Graph/S-function',13,'M-file which plots',13,'lines',13,'']],...
		'function name','sfunyst',...
		'parameters','ax, color, npts, dt',...
		'position',[130,55,180,75])

add_block('built-in/Inport',[sys,'/',['Auto-Scale',13,'Graph/x']])
set_param([sys,'/',['Auto-Scale',13,'Graph/x']],...
		'position',[65,55,85,75])
add_line([sys,'/',['Auto-Scale',13,'Graph']],[90,65;125,65])
set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'Mask Display','plot(0,0,100,100,[83,76,63,52,42,38,28,16,11,84,11,11,11,90,90,11],[75,58,47,54,72,80,84,74,65,65,65,90,40,40,90,90])',...
		'Mask Type','Storage scope.')
set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'Mask Dialogue','Storage scope using MATLAB graph window.\nEnter plotting ranges and line type.|Initial Time Range:|Initial y-min:|Initial y-max:|Storage pts.:|Line type (rgbw-.:xo):|Sample time:')
set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'Mask Translate','npts = @4; color = @5; ax = [0, @1, @2, @3]; dt=@6;')
set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'Mask Help','Uses MATLAB''s graph window.\nUse only one block per system.\nLine type must be in quotes.\nSee the M-file sfunyst.m.')
set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'Mask Entries','5\/-10\/10\/200\/''y-/g--/c-./w:/m*/ro/b+''\/.1\/')


%     Finished composite block ['Auto-Scale',13,'Graph'].

set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'hide name',0,...
		'position',[375,70,405,110])

add_block('built-in/Gain',[sys,'/',['Change',13,'this value']])
set_param([sys,'/',['Change',13,'this value']],...
		'ForeGround',2,...
		'Gain','0.678',...
		'Mask Display','0.678',...
		'Mask Dialogue','eval(''slideg(0,0.678,3,0)'');',...
		'position',[170,141,220,169])

add_block('built-in/Constant',[sys,'/','Constant'])
set_param([sys,'/','Constant'],...
		'hide name',0,...
		'position',[120,145,140,165])
add_line(sys,[85,30;140,30;140,70;165,70])
add_line(sys,[85,80;165,80])
add_line(sys,[85,125;130,125;130,90;165,90])
add_line(sys,[210,80;250,80])
add_line(sys,[340,90;370,90])
add_line(sys,[145,155;165,155])
add_line(sys,[225,155;230,155;230,100;250,100])

drawnow

% Return any arguments.
if (nargin | nargout)
	% Must use feval here to access system in memory
	if (nargin > 3)
		if (flag == 0)
			eval(['[ret,x0,str,ts,xts]=',sys,'(t,x,u,flag);'])
		else
			eval(['ret =', sys,'(t,x,u,flag);'])
		end
	else
		[ret,x0,str,ts,xts] = feval(sys);
	end
else
	drawnow % Flash up the model and execute load callback
end

⌨️ 快捷键说明

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