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

📄 ttrigwks.m

📁 数字通信第四版原书的例程
💻 M
字号:
function [ret,x0,str,ts,xts]=ttrigwks(t,x,u,flag);
%TTRIGWKS	is the M-file description of the SIMULINK system named TTRIGWKS.
%	The block-diagram can be displayed by typing: TTRIGWKS.
%
%	SYS=TTRIGWKS(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 TTRIGWKS 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 TTRIGWKS with a FLAG of zero:
%	[SIZES]=TTRIGWKS([],[],[],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',[52,457,473,589])
     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/Stop Simulation',[sys,'/','Stop Simulation'])
set_param([sys,'/','Stop Simulation'],...
		'hide name',0,...
		'position',[340,18,380,52])

add_block('built-in/Relational Operator',[sys,'/',['Relational',13,'Operator']])
set_param([sys,'/',['Relational',13,'Operator']],...
		'hide name',0,...
		'position',[270,23,300,47])


%     Subsystem  ['Triggered write',13,'to wksp'].

new_system([sys,'/',['Triggered write',13,'to wksp']])
set_param([sys,'/',['Triggered write',13,'to wksp']],'Location',[105,608,345,754])

add_block('built-in/Inport',[sys,'/',['Triggered write',13,'to wksp/in_2']])
set_param([sys,'/',['Triggered write',13,'to wksp/in_2']],...
		'Port','2',...
		'position',[15,75,35,95])

add_block('built-in/Inport',[sys,'/',['Triggered write',13,'to wksp/in_1']])
set_param([sys,'/',['Triggered write',13,'to wksp/in_1']],...
		'position',[15,60,35,80])

add_block('built-in/Mux',[sys,'/',['Triggered write',13,'to wksp/Mux']])
set_param([sys,'/',['Triggered write',13,'to wksp/Mux']],...
		'inputs','2',...
		'position',[65,61,100,94])

add_block('built-in/S-Function',[sys,'/',['Triggered write',13,'to wksp/S-function']])
set_param([sys,'/',['Triggered write',13,'to wksp/S-function']],...
		'function name','swritwks',...
		'parameters','filename, datatype, nump, max_rec, cut_type, threshold',...
		'position',[135,70,185,90])
add_line([sys,'/',['Triggered write',13,'to wksp']],[40,85;60,85])
add_line([sys,'/',['Triggered write',13,'to wksp']],[40,70;60,70])
add_line([sys,'/',['Triggered write',13,'to wksp']],[105,80;130,80])
set_param([sys,'/',['Triggered write',13,'to wksp']],...
		'Mask Display','plot(0,0,100,100,x,y,v,w);Wt wksp',...
		'Mask Type','Write to workspace')
set_param([sys,'/',['Triggered write',13,'to wksp']],...
		'Mask Dialogue','The rising edge of the signal from the\nsecond port triggers the block to write\nanother row into the specified\nworkspace variable.|Variable name (string variable, include extension):|Data type (''ascii'', ''data''):|Number of trigger pulses between saved data:|Maximum row number:|Section to keep after max row (0: begin,1: end):|Threshold in detecting trigger signal:')
set_param([sys,'/',['Triggered write',13,'to wksp']],...
		'Mask Translate','filename=@1;datatype=@2;nump=@3;max_rec=@4;cut_type=@5;threshold=@6;[x,y]=srcsicon(9);[v,w]=trigicon(0,25,get_param(gcb,''orientation''),2);')
set_param([sys,'/',['Triggered write',13,'to wksp']],...
		'Mask Help','This block writes the data inputted from the first port to the next row of the specified workspace variable at the rising edge of the second input trigger pulse. The first pulse triggers to write the first record. You can specify the number of pulses between writting records. When you specify ASCII format, there is no return added between two records.')
set_param([sys,'/',['Triggered write',13,'to wksp']],...
		'Mask Entries','''XX''\/''data''\/0\/100\/0\/.5\/')


%     Finished composite block ['Triggered write',13,'to wksp'].

set_param([sys,'/',['Triggered write',13,'to wksp']],...
		'hide name',0,...
		'position',[260,68,340,112])

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','10.000000',...
		'Freq Range','50.000000',...
		'Wave','Sin',...
		'Units','Rads')
set_param([sys,'/',['Signal',13,'generator1']],...
		'position',[20,83,65,117])

add_block('built-in/S-Function',[sys,'/',['Triggered read',13,'from wksp1']])
set_param([sys,'/',['Triggered read',13,'from wksp1']],...
		'function name','trigwksp',...
		'parameters','var,thd,cyclFlag,ini',...
		'Mask Display','plot(0,0,100,100,x,y,v,w);   Rd wksp',...
		'Mask Type','Read from workspace')
set_param([sys,'/',['Triggered read',13,'from wksp1']],...
		'Mask Dialogue','The rising edge of the input pulse triggers\nthe block to output the next row from the specified workspace variable.|Workspace variable:|Threshold for the input trigger pulse:|Repeat flag (1: repeat read, 0: output zeros after eof):|Output value before first trigger:')
set_param([sys,'/',['Triggered read',13,'from wksp1']],...
		'Mask Translate','var=@1;thd=@2;cyclFlag=@3;ini=@4;[x,y]=srcsicon(7);[v,w]=trigicon(0,50,get_param(gcb,''orientation''),2);')
set_param([sys,'/',['Triggered read',13,'from wksp1']],...
		'Mask Help','This block reads the data from a workspace variable. The output is refreshed at the rising edge of the input pulse. When the end of the variable is reached, you can have the block output all zeros or start from the beginning of the variable.')
set_param([sys,'/',['Triggered read',13,'from wksp1']],...
		'Mask Entries','[10:-1:0;1:11]''\/.1\/1\/10\/',...
		'position',[110,18,190,62])
add_line(sys,[70,100;255,100])
add_line(sys,[85,100;85,40;105,40])
add_line(sys,[195,40;265,40])
add_line(sys,[305,35;335,35])
add_line(sys,[215,40;215,80;255,80])

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