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

📄 tstbide.m

📁 数字通信第四版原书的例程
💻 M
字号:
function [ret,x0,str,ts,xts]=tstbide(t,x,u,flag);
%TSTBIDE	is the M-file description of the SIMULINK system named TSTBIDE.
%	The block-diagram can be displayed by typing: TSTBIDE.
%
%	SYS=TSTBIDE(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 TSTBIDE 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 TSTBIDE with a FLAG of zero:
%	[SIZES]=TSTBIDE([],[],[],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',[16,59,509,318])
     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',   '')


%     Subsystem  'Graph1'.

new_system([sys,'/','Graph1'])
set_param([sys,'/','Graph1'],'Location',[0,59,274,252])

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

add_block('built-in/Inport',[sys,'/','Graph1/x'])
set_param([sys,'/','Graph1/x'],...
		'position',[65,55,85,75])
add_line([sys,'/','Graph1'],[90,65;125,65])
set_param([sys,'/','Graph1'],...
		'Mask Display','plot(0,0,100,100,[90,10,10,10,90,90,10],[65,65,90,40,40,90,90],[90,78,69,54,40,31,25,10],[77,60,48,46,56,75,81,84])',...
		'Mask Type','Graph scope.')
set_param([sys,'/','Graph1'],...
		'Mask Dialogue','Graph scope using MATLAB graph window.\nEnter plotting ranges and line type.|Time range:|y-min:|y-max:|Line type (rgbw-:*). Seperate each plot by ''/'':')
set_param([sys,'/','Graph1'],...
		'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
set_param([sys,'/','Graph1'],...
		'Mask Help','This block plots to the MATLAB graph window and can be used as an improved version of the Scope block. Look at the m-file sfuny.m to see how it works. This block can take scalar or vector input signal.')
set_param([sys,'/','Graph1'],...
		'Mask Entries','100\/-.2\/4.2\/''y-/g--/r-./w:/m*/ro/b+''\/')


%     Finished composite block 'Graph1'.

set_param([sys,'/','Graph1'],...
		'position',[305,176,335,214])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'position',[240,185,260,205])

add_block('built-in/Constant',[sys,'/','Constant'])
set_param([sys,'/','Constant'],...
		'Value','[0 1 2 3]',...
		'position',[105,190,155,210])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'inputs','2',...
		'position',[350,121,385,154])

add_block('built-in/To Workspace',[sys,'/','To Workspace1'])
set_param([sys,'/','To Workspace1'],...
		'mat-name','y',...
		'position',[250,112,300,128])


%     Subsystem  'Graph'.

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

add_block('built-in/Inport',[sys,'/','Graph/x'])
set_param([sys,'/','Graph/x'],...
		'position',[65,55,85,75])

add_block('built-in/S-Function',[sys,'/',['Graph/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['Graph/S-function',13,'M-file which plots',13,'lines',13,'']],...
		'function name','sfuny',...
		'parameters','ax, color,dt',...
		'position',[130,55,180,75])
add_line([sys,'/','Graph'],[90,65;125,65])
set_param([sys,'/','Graph'],...
		'Mask Display','plot(0,0,100,100,[90,10,10,10,90,90,10],[65,65,90,40,40,90,90],[90,78,69,54,40,31,25,10],[77,60,48,46,56,75,81,84])',...
		'Mask Type','Graph scope.')
set_param([sys,'/','Graph'],...
		'Mask Dialogue','Graph scope using MATLAB graph window.\nEnter plotting ranges and line type.|Time range:|y-min:|y-max:|Line type (rgbw-:*). Seperate each plot by ''/'':')
set_param([sys,'/','Graph'],...
		'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
set_param([sys,'/','Graph'],...
		'Mask Help','This block plots to the MATLAB graph window and can be used as an improved version of the Scope block. Look at the m-file sfuny.m to see how it works. This block can take scalar or vector input signal.')
set_param([sys,'/','Graph'],...
		'Mask Entries','100\/-.2\/16.2\/''y-/g--/r-./w:/m*/ro/b+''\/')


%     Finished composite block 'Graph'.

set_param([sys,'/','Graph'],...
		'position',[425,121,455,159])

add_block('built-in/To Workspace',[sys,'/','To Workspace'])
set_param([sys,'/','To Workspace'],...
		'mat-name','z',...
		'position',[400,42,450,58])


%     Subsystem  ['Random-number',13,'generator'].

new_system([sys,'/',['Random-number',13,'generator']])
set_param([sys,'/',['Random-number',13,'generator']],'Location',[115,400,471,569])

add_block('built-in/White Noise',[sys,'/',['Random-number',13,'generator/Random',13,'Number']])
set_param([sys,'/',['Random-number',13,'generator/Random',13,'Number']],...
		'Seed','seed',...
		'position',[40,27,85,63])

add_block('built-in/Relational Operator',[sys,'/',['Random-number',13,'generator/Relational',13,'Operator']])
set_param([sys,'/',['Random-number',13,'generator/Relational',13,'Operator']],...
		'position',[155,38,185,62])

add_block('built-in/Outport',[sys,'/',['Random-number',13,'generator/out_1']])
set_param([sys,'/',['Random-number',13,'generator/out_1']],...
		'position',[310,40,330,60])

add_block('built-in/State-Space',[sys,'/',['Random-number',13,'generator/Matrix',13,'Gain']])
set_param([sys,'/',['Random-number',13,'generator/Matrix',13,'Gain']],...
		'A','[]',...
		'B','[]',...
		'C','[]',...
		'D','K',...
		'Mask Display','K',...
		'Mask Type','Matrix Gain',...
		'Mask Dialogue','Matrix Gain.|Gain matrix:')
set_param([sys,'/',['Random-number',13,'generator/Matrix',13,'Gain']],...
		'Mask Translate','K = @1;',...
		'Mask Help','Multiplies input vector by entered matrix to produce output vector (y=Au).',...
		'Mask Entries','ones(1,N-1)\/')
set_param([sys,'/',['Random-number',13,'generator/Matrix',13,'Gain']],...
		'position',[230,35,275,65])

add_block('built-in/Constant',[sys,'/',['Random-number',13,'generator/Constant']])
set_param([sys,'/',['Random-number',13,'generator/Constant']],...
		'Value','x',...
		'position',[65,105,95,125])
add_line([sys,'/',['Random-number',13,'generator']],[280,50;305,50])
add_line([sys,'/',['Random-number',13,'generator']],[190,50;225,50])
add_line([sys,'/',['Random-number',13,'generator']],[100,115;115,115;115,55;150,55])
add_line([sys,'/',['Random-number',13,'generator']],[90,45;150,45])
set_param([sys,'/',['Random-number',13,'generator']],...
		'Mask Display','Random\nNumber',...
		'Mask Type','Random number generator',...
		'Mask Dialogue','Random number generator:|M-ary number:|Seed:')
set_param([sys,'/',['Random-number',13,'generator']],...
		'Mask Translate','N=@1;x=[(2-N)/N:2/N:(N-2)/N];seed=@2;')
set_param([sys,'/',['Random-number',13,'generator']],...
		'Mask Help','This block generate integer number 0 to M-1, where M is a integer. The probability of the apperance for each number is not guaranteed to be the same.')
set_param([sys,'/',['Random-number',13,'generator']],...
		'Mask Entries','16\/1234\/')


%     Finished composite block ['Random-number',13,'generator'].

set_param([sys,'/',['Random-number',13,'generator']],...
		'BackGround',3,...
		'position',[30,30,90,70])

add_block('built-in/S-Function',[sys,'/',['Integer vector  ',13,'to scalar',13,'converter']])
set_param([sys,'/',['Integer vector  ',13,'to scalar',13,'converter']],...
		'function name','simbi2de',...
		'parameters','p',...
		'Mask Display','Vec to sca\nconverter',...
		'Mask Type','Vectro to scalar converter')
set_param([sys,'/',['Integer vector  ',13,'to scalar',13,'converter']],...
		'Mask Dialogue','Positive integer vector to scalar decimal integer converter:|Input element base:',...
		'Mask Translate','p=@1;')
set_param([sys,'/',['Integer vector  ',13,'to scalar',13,'converter']],...
		'Mask Help','This block converts a binary vector to a scalar decimal integer. The block takes the first element input as the lowest binary bit. For example, if u(1)=1 and u(2)=0, the block outputs y=1; if u(1)=0 and u(2)=1, the block outputs y=2.')
set_param([sys,'/',['Integer vector  ',13,'to scalar',13,'converter']],...
		'Mask Entries','2\/',...
		'position',[240,28,315,72])

add_block('built-in/S-Function',[sys,'/',['Integer scalar',13,'to vector',13,'converter']])
set_param([sys,'/',['Integer scalar',13,'to vector',13,'converter']],...
		'function name','simde2bi',...
		'parameters','len, p',...
		'Mask Display','Sca to vec\nconverter',...
		'Mask Type','Scalar integer  to vector converter')
set_param([sys,'/',['Integer scalar',13,'to vector',13,'converter']],...
		'Mask Dialogue','Positive decimal interger to binary converter.|Output vector length:|Output element base:',...
		'Mask Translate','len=@1;p=@2;')
set_param([sys,'/',['Integer scalar',13,'to vector',13,'converter']],...
		'Mask Help','This block converts scaler positive decimal integer input to an arbitrary base integer  vector output with specified vector length and output element base. The first element of the output vector is the lowest binary bit. For example, for a length two binary output, y(1)=0, y(2)=1 means the input is 1; y(0)=1, y(2)=0 means the input is 2.')
set_param([sys,'/',['Integer scalar',13,'to vector',13,'converter']],...
		'Mask Entries','4\/2\/',...
		'position',[125,28,200,72])
add_line(sys,[95,50;120,50])
add_line(sys,[205,50;235,50])
add_line(sys,[390,140;420,140])
add_line(sys,[104,50;105,45;110,47;110,145;345,145])
add_line(sys,[265,195;300,195])
add_line(sys,[160,200;235,200])
add_line(sys,[215,50;215,190;235,190])
add_line(sys,[320,50;330,50;330,130;345,130])
add_line(sys,[215,120;245,120])
add_line(sys,[330,50;395,50])

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 + -