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

📄 tstsinc.m

📁 数字通信第四版原书的例程
💻 M
字号:
function [ret,x0,str,ts,xts]=tstsinc(t,x,u,flag);
%TSTSINC	is the M-file description of the SIMULINK system named TSTSINC.
%	The block-diagram can be displayed by typing: TSTSINC.
%
%	SYS=TSTSINC(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 TSTSINC 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 TSTSINC with a FLAG of zero:
%	[SIZES]=TSTSINC([],[],[],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',[93,97,605,308])
     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',   '')
set_param(sys,'Load callback','M=16;td=.1;ts=.01;Fc=100/pi/2;[num,den]=butter(5,Fc*2*ts);');


%     Subsystem  'Memory impulse'.

new_system([sys,'/','Memory impulse'])
set_param([sys,'/','Memory impulse'],'Location',[413,205,811,430])

add_block('built-in/Inport',[sys,'/','Memory impulse/in_2'])
set_param([sys,'/','Memory impulse/in_2'],...
		'Port','2',...
		'position',[25,30,45,50])


%     Subsystem  ['Memory impulse/discrete',13,'Rising edge',13,'detector'].

new_system([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']])
set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],'Location',[419,521,808,713])

add_block('built-in/Unit Delay',[sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/Unit Delay']])
set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/Unit Delay']],...
		'Sample time','ts',...
		'position',[120,87,170,103])

add_block('built-in/Outport',[sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/out_1']])
set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/out_1']],...
		'position',[340,25,360,45])

add_block('built-in/Relational Operator',[sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/Relational',13,'Operator1']])
set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/Relational',13,'Operator1']],...
		'position',[200,88,230,112])

add_block('built-in/Relational Operator',[sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/Relational',13,'Operator2']])
set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/Relational',13,'Operator2']],...
		'Operator','>',...
		'position',[265,23,295,47])

add_block('built-in/Constant',[sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/one1']])
set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/one1']],...
		'Value','thld',...
		'position',[30,135,60,155])

add_block('built-in/Inport',[sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/in_1']])
set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/in_1']],...
		'position',[10,15,30,35])

add_block('built-in/Relational Operator',[sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/Relational',13,'Operator']])
set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector/Relational',13,'Operator']],...
		'position',[135,18,165,42])
add_line([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],[35,25;130,25])
add_line([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],[45,25;45,95;115,95])
add_line([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],[175,95;195,95])
add_line([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],[65,145;100,145;100,35;130,35])
add_line([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],[100,145;180,145;180,105;195,105])
add_line([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],[170,30;260,30])
add_line([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],[235,100;240,100;240,40;260,40])
add_line([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],[300,35;335,35])
set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],...
		'Mask Display','Edge\nDetector',...
		'Mask Type','Edge Detection',...
		'Mask Dialogue','Rising edge detection:|Threshold:|Sampling time:')
set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],...
		'Mask Translate','thld=@1;ts=@2;')
set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],...
		'Mask Help','When the input signal rising edge passed the given shreshold, this block outputs one, otherwise outputs zero.',...
		'Mask Entries','thr\/ts\/')


%     Finished composite block ['Memory impulse/discrete',13,'Rising edge',13,'detector'].

set_param([sys,'/',['Memory impulse/discrete',13,'Rising edge',13,'detector']],...
		'position',[65,26,120,54])

add_block('built-in/Switch',[sys,'/','Memory impulse/Switch'])
set_param([sys,'/','Memory impulse/Switch'],...
		'Threshold','.5',...
		'position',[295,124,320,156])

add_block('built-in/Constant',[sys,'/','Memory impulse/Constant'])
set_param([sys,'/','Memory impulse/Constant'],...
		'Value','x',...
		'position',[210,155,230,175])

add_block('built-in/Outport',[sys,'/','Memory impulse/out_1'])
set_param([sys,'/','Memory impulse/out_1'],...
		'position',[355,130,375,150])

add_block('built-in/Product',[sys,'/','Memory impulse/Product'])
set_param([sys,'/','Memory impulse/Product'],...
		'position',[155,90,180,110])

add_block('built-in/Zero-Order Hold',[sys,'/',['Memory impulse/Zero-Order',13,'Hold']])
set_param([sys,'/',['Memory impulse/Zero-Order',13,'Hold']],...
		'Sample time','ts',...
		'position',[205,84,240,116])

add_block('built-in/Inport',[sys,'/','Memory impulse/in_1'])
set_param([sys,'/','Memory impulse/in_1'],...
		'position',[35,185,55,205])
add_line([sys,'/','Memory impulse'],[50,40;60,40])
add_line([sys,'/','Memory impulse'],[125,40;130,40;130,95;150,95])
add_line([sys,'/','Memory impulse'],[235,165;250,165;250,140;290,140])
add_line([sys,'/','Memory impulse'],[325,140;350,140])
add_line([sys,'/','Memory impulse'],[60,195;280,195;290,150])
add_line([sys,'/','Memory impulse'],[95,195;95,105;150,105])
add_line([sys,'/','Memory impulse'],[185,100;200,100])
add_line([sys,'/','Memory impulse'],[245,100;260,100;260,130;290,130])
set_param([sys,'/','Memory impulse'],...
		'Mask Display','plot(0,0,100,100,v,w);Sinc',...
		'Mask Type','Sinc filter')
set_param([sys,'/','Memory impulse'],...
		'Mask Dialogue','The rising edge of the second input\nsignal locks the signal value at the first inport for the period of holding time.|Holding time (sec):|Threshold for trigger pulse: ')
set_param([sys,'/','Memory impulse'],...
		'Mask Translate','ts=@1;thr=@2;x=thr>0;[v,w]=trigicon(0,25,get_param(gcb,''orientation''),2);')
set_param([sys,'/','Memory impulse'],...
		'Mask Help','When the threshold is greater than zero, this block outputs an impulse signal, which begins at the rising edge of the trigger signal from the second input port. The width of the impulse equals the holding time. The impulse holds a constant amplitude, which equals the amplitude of the first input at the rising edge of the trigger signal. When the threshold is less than or equal to zero, this block outputs the first input.')
set_param([sys,'/','Memory impulse'],...
		'Mask Entries','.1\/0.01\/')


%     Finished composite block 'Memory impulse'.

set_param([sys,'/','Memory impulse'],...
		'ForeGround',3,...
		'hide name',0,...
		'position',[150,48,230,92])

add_block('built-in/Signal Generator',[sys,'/',['Signal',13,'generator']])
set_param([sys,'/',['Signal',13,'generator']],...
		'ForeGround',5,...
		'hide name',0,...
		'Peak','1.000000',...
		'Peak Range','5.000000',...
		'Freq','1.000000',...
		'Freq Range','5.000000',...
		'Wave','Sin',...
		'Units','Rads')
set_param([sys,'/',['Signal',13,'generator']],...
		'position',[40,18,85,52])

add_block('built-in/Signal Generator',[sys,'/',['Signal',13,'generator1']])
set_param([sys,'/',['Signal',13,'generator1']],...
		'ForeGround',6,...
		'hide name',0,...
		'Peak','0.100000',...
		'Peak Range','5.000000',...
		'Freq','2.490000',...
		'Freq Range','5.000000',...
		'Wave','Sqr',...
		'Units','Rads')
set_param([sys,'/',['Signal',13,'generator1']],...
		'position',[40,88,85,122])


%     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-/m-/w:/m*/ro/b+''\/.1\/')


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

set_param([sys,'/',['Auto-Scale',13,'Graph']],...
		'hide name',0,...
		'position',[330,50,360,90])

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

add_block('built-in/Note',[sys,'/',['When the second input signal crosses from below the pulse threshold',13,'to above the pulse threshold, this block holds the input signal value of',13,'the first input port at time of the raising edge.                                  ']])
set_param([sys,'/',['When the second input signal crosses from below the pulse threshold',13,'to above the pulse threshold, this block holds the input signal value of',13,'the first input port at time of the raising edge.                                  ']],...
		'position',[220,125,225,130])

add_block('built-in/Note',[sys,'/',['The block outputs the held value for the interval of the Holding time         ',13,'specified in the block parameter. The block outputs zero at all other times.']])
set_param([sys,'/',['The block outputs the held value for the interval of the Holding time         ',13,'specified in the block parameter. The block outputs zero at all other times.']],...
		'position',[230,170,235,175])
add_line(sys,[90,35;115,35;115,60;145,60])
add_line(sys,[90,105;115,105;115,80;145,80])
add_line(sys,[235,70;270,70])
add_line(sys,[115,35;255,35;255,55;270,55])
add_line(sys,[115,105;255,105;255,85;270,85])
add_line(sys,[315,70;325,70])

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