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

📄 tstdist.m

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


%     Subsystem  ['Triggered',13,'signal switch'].

new_system([sys,'/',['Triggered',13,'signal switch']])
set_param([sys,'/',['Triggered',13,'signal switch']],'Location',[672,516,1052,680])

add_block('built-in/S-Function',[sys,'/',['Triggered',13,'signal switch/S-function']])
set_param([sys,'/',['Triggered',13,'signal switch/S-function']],...
		'function name','stdmamux',...
		'parameters','sw,ke,in,tt',...
		'position',[205,60,275,90])

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

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

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

add_block('built-in/Inport',[sys,'/',['Triggered',13,'signal switch/in_1']])
set_param([sys,'/',['Triggered',13,'signal switch/in_1']],...
		'position',[65,20,85,40])
add_line([sys,'/',['Triggered',13,'signal switch']],[280,75;315,75])
add_line([sys,'/',['Triggered',13,'signal switch']],[180,75;200,75])
add_line([sys,'/',['Triggered',13,'signal switch']],[85,85;140,85])
add_line([sys,'/',['Triggered',13,'signal switch']],[90,30;120,30;120,65;140,65])
set_param([sys,'/',['Triggered',13,'signal switch']],...
		'Mask Display','plot(0,0,100,100,v,w);Vct re-arr',...
		'Mask Type','Vector signal re-distribution')
set_param([sys,'/',['Triggered',13,'signal switch']],...
		'Mask Dialogue','The rising edge from the 2nd inport\ntriggers the output of this block to follow the rule of the next row in the switch box.|Switch box (column number equals block output length):|Keeping value (flag 0 element in switch box):|Initial value (before the 1st trigger is detected):|Trigger threshold:')
set_param([sys,'/',['Triggered',13,'signal switch']],...
		'Mask Translate','sw=@1;ke=@2;in=@3;tt=@4;[v,w]=trigicon(0,25,get_param(gcb,''orientation''),2);')
set_param([sys,'/',['Triggered',13,'signal switch']],...
		'Mask Help','When the ith element in the current row of the switch box is j, the ith element in the output vector equals jth input element. When j=0, the output keeps the last output value if keep_value >= 0; it equals ini_val otherwise. The switch box column number must be same as the lengths of output, keep_value, and init_value. The rising edge of the 2nd inport triggers the distribution pattern to follow the next row of the switch box.')
set_param([sys,'/',['Triggered',13,'signal switch']],...
		'Mask Entries','[1 2 3;2 3 1;3 1 2]\/[-1 -1 -1]\/[0 0 0]\/.1\/')


%     Finished composite block ['Triggered',13,'signal switch'].

set_param([sys,'/',['Triggered',13,'signal switch']],...
		'hide name',0,...
		'position',[245,63,325,107])

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

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'hide name',0,...
		'inputs','3',...
		'position',[155,58,190,92])

add_block('built-in/Signal Generator',[sys,'/',['Signal',13,'generator1']])
set_param([sys,'/',['Signal',13,'generator1']],...
		'ForeGround',4,...
		'hide name',0,...
		'Peak','1.000000',...
		'Peak Range','2.000000',...
		'Freq','3.000000',...
		'Freq Range','5.000000',...
		'Wave','Sin',...
		'Units','Rads')
set_param([sys,'/',['Signal',13,'generator1']],...
		'position',[35,58,80,92])

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


%     Subsystem  ['Pulses divide',13,'same sample time'].

new_system([sys,'/',['Pulses divide',13,'same sample time']])
set_param([sys,'/',['Pulses divide',13,'same sample time']],'Location',[55,192,283,286])

add_block('built-in/Outport',[sys,'/',['Pulses divide',13,'same sample time/Outport']])
set_param([sys,'/',['Pulses divide',13,'same sample time/Outport']],...
		'position',[160,35,180,55])

add_block('built-in/S-Function',[sys,'/',['Pulses divide',13,'same sample time/S-function1']])
set_param([sys,'/',['Pulses divide',13,'same sample time/S-function1']],...
		'function name','homopuls',...
		'parameters','samp_time, out_divid, offset',...
		'position',[40,31,105,59])
add_line([sys,'/',['Pulses divide',13,'same sample time']],[110,45;155,45])
set_param([sys,'/',['Pulses divide',13,'same sample time']],...
		'Mask Display','plot(0,0,100,100,x,y);Pulse',...
		'Mask Type','Pulse generator')
set_param([sys,'/',['Pulses divide',13,'same sample time']],...
		'Mask Dialogue','Vector pulses with sample rate of each pulse as Sample_time / Divider.|Sample time (scalar, sec):|Divider (integer vector):|Offset (same length as Divider):')
set_param([sys,'/',['Pulses divide',13,'same sample time']],...
		'Mask Translate','samp_time=@1;out_divid=@2;offset=@3;[x,y]=srcsicon(2);')
set_param([sys,'/',['Pulses divide',13,'same sample time']],...
		'Mask Help','This block generates a vector pulse. The output length is the same as the divider vector length. The ith element of the output has the sample time Sample_time/Divider(i). All elements in divider must be integers.')
set_param([sys,'/',['Pulses divide',13,'same sample time']],...
		'Mask Entries','1\/1\/1\/')


%     Finished composite block ['Pulses divide',13,'same sample time'].

set_param([sys,'/',['Pulses divide',13,'same sample time']],...
		'hide name',0,...
		'position',[115,113,195,157])

add_block('built-in/Mux',[sys,'/','Mux1'])
set_param([sys,'/','Mux1'],...
		'hide name',0,...
		'inputs','3',...
		'position',[370,49,400,91])


%     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','10\/-1.1\/1.1\/''y-/g-/c-/r-./b-./m-./w--''\/')


%     Finished composite block 'Graph'.

set_param([sys,'/','Graph'],...
		'hide name',0,...
		'position',[430,51,460,89])
add_line(sys,[85,30;95,30;95,65;150,65])
add_line(sys,[85,75;150,75])
add_line(sys,[85,120;100,120;100,85;150,85])
add_line(sys,[195,75;240,75])
add_line(sys,[200,135;210,135;210,95;240,95])
add_line(sys,[330,85;340,85;340,70;365,70])
add_line(sys,[405,70;425,70])
add_line(sys,[200,135;350,135;350,85;365,85])
add_line(sys,[215,75;215,55;365,55])

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