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

📄 tstrayl.m

📁 数字通信第四版原书的例程
💻 M
字号:
function [ret,x0,str,ts,xts]=tstrayl(t,x,u,flag);
%TSTRAYL	is the M-file description of the SIMULINK system named TSTRAYL.
%	The block-diagram can be displayed by typing: TSTRAYL.
%
%	SYS=TSTRAYL(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 TSTRAYL 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 TSTRAYL with a FLAG of zero:
%	[SIZES]=TSTRAYL([],[],[],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',[45,414,461,634])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
set_param(sys,'Start time',    '0.0')
set_param(sys,'Stop time',     '999')
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/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'hide name',0,...
		'inputs','3',...
		'position',[270,32,305,88])


%     Subsystem  ['Rayleigh noise',13,'generator'].

new_system([sys,'/',['Rayleigh noise',13,'generator']])
set_param([sys,'/',['Rayleigh noise',13,'generator']],'Location',[276,459,835,574])

add_block('built-in/Outport',[sys,'/',['Rayleigh noise',13,'generator/out_1']])
set_param([sys,'/',['Rayleigh noise',13,'generator/out_1']],...
		'position',[490,50,510,70])

add_block('built-in/S-Function',[sys,'/',['Rayleigh noise',13,'generator/Array',13,'function']])
set_param([sys,'/',['Rayleigh noise',13,'generator/Array',13,'function']],...
		'function name','arysin',...
		'parameters','opr',...
		'Mask Display','Array\nFcn',...
		'Mask Type','Array function')
set_param([sys,'/',['Rayleigh noise',13,'generator/Array',13,'function']],...
		'Mask Dialogue','Multi-input/multi-output functions, such as sin, cos, tan,exp,asin, acos,ln,log10,sgn.|Operation (string):',...
		'Mask Translate','opr=@1;')
set_param([sys,'/',['Rayleigh noise',13,'generator/Array',13,'function']],...
		'Mask Help','The vector length of the output is the same as the input.',...
		'Mask Entries','''sqrt''\/',...
		'position',[370,38,445,82])

add_block('built-in/Sum',[sys,'/',['Rayleigh noise',13,'generator/Sum']])
set_param([sys,'/',['Rayleigh noise',13,'generator/Sum']],...
		'position',[315,44,340,71])

add_block('built-in/Demux',[sys,'/',['Rayleigh noise',13,'generator/Demux']])
set_param([sys,'/',['Rayleigh noise',13,'generator/Demux']],...
		'outputs','2',...
		'position',[235,41,275,74])

add_block('built-in/Product',[sys,'/',['Rayleigh noise',13,'generator/Product']])
set_param([sys,'/',['Rayleigh noise',13,'generator/Product']],...
		'position',[160,48,190,72])


%     Subsystem  ['Rayleigh noise',13,'generator/Gaussian',13,'noise'].

new_system([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise']])
set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise']],'Location',[500,540,848,745])

add_block('built-in/Outport',[sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise/out_1']])
set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise/out_1']],...
		'position',[295,85,315,105])

add_block('built-in/State-Space',[sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise/Matrix',13,'Gain']])
set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise/Matrix',13,'Gain']],...
		'A','[]',...
		'B','[]',...
		'C','[]',...
		'D','K',...
		'Mask Display','K',...
		'Mask Type','Matrix Gain')
set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise/Matrix',13,'Gain']],...
		'Mask Dialogue','Matrix Gain.|Gain matrix:',...
		'Mask Translate','K = @1;')
set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise/Matrix',13,'Gain']],...
		'Mask Help','Multiplies input vector by entered matrix to produce output vector (y=Au).',...
		'Mask Entries','d\/')
set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise/Matrix',13,'Gain']],...
		'position',[210,81,235,109])

add_block('built-in/White Noise',[sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise/Random',13,'Number']])
set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise/Random',13,'Number']],...
		'Seed','s',...
		'position',[45,77,90,113])
add_line([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise']],[95,95;205,95])
add_line([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise']],[240,95;290,95])
set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise']],...
		'Mask Display','Gaussian\nnoise',...
		'Mask Type','Gaussian noise.',...
		'Mask Dialogue','Gaussian distribution noise.|Mean value:|Variance:|Initial Seed(s):')
set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise']],...
		'Mask Translate','m=@1;d=@2;s=@3;[m,d,s]=gwnoise(m,d,s);')
set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise']],...
		'Mask Help','When the mean value, seed are vectors, the output of this block is a vector with the length of the vector same as the length of mean value vector or that of the seed.')
set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise']],...
		'Mask Entries','0\/alpha\/seed\/')


%     Finished composite block ['Rayleigh noise',13,'generator/Gaussian',13,'noise'].

set_param([sys,'/',['Rayleigh noise',13,'generator/Gaussian',13,'noise']],...
		'position',[45,40,120,80])
add_line([sys,'/',['Rayleigh noise',13,'generator']],[280,65;310,65])
add_line([sys,'/',['Rayleigh noise',13,'generator']],[280,50;310,50])
add_line([sys,'/',['Rayleigh noise',13,'generator']],[195,60;230,60])
add_line([sys,'/',['Rayleigh noise',13,'generator']],[125,60;135,60;135,55;155,55])
add_line([sys,'/',['Rayleigh noise',13,'generator']],[135,60;135,65;155,65])
add_line([sys,'/',['Rayleigh noise',13,'generator']],[345,60;365,60])
add_line([sys,'/',['Rayleigh noise',13,'generator']],[450,60;485,60])
set_param([sys,'/',['Rayleigh noise',13,'generator']],...
		'Mask Display','plot(0,0,100,100,x,y);Rayleigh',...
		'Mask Type','Rayleigh noise generator')
set_param([sys,'/',['Rayleigh noise',13,'generator']],...
		'Mask Dialogue','Generate Rayleigh distributed noise.The output vector size of this block is the same as the vector size of the seed.|sigma:|Initial seed:')
set_param([sys,'/',['Rayleigh noise',13,'generator']],...
		'Mask Translate','alpha=@1;alpha=alpha^2;seed=@2;seed=[seed(:);seed(:)+max(seed)];if length(alpha)>1, alpha=[alpha(:);alpha(:)];end;[x,y]=srcsicon(3);')
set_param([sys,'/',['Rayleigh noise',13,'generator']],...
		'Mask Help','This block generates Rayleigh noise with the given sigma value. The sigma value is the standard deviations of the zero mean Gaussian noise components in generating the Rayleigh noise. The output vector size of this block is the same as the vector size of the seed.')
set_param([sys,'/',['Rayleigh noise',13,'generator']],...
		'Mask Entries','1\/17658\/')


%     Finished composite block ['Rayleigh noise',13,'generator'].

set_param([sys,'/',['Rayleigh noise',13,'generator']],...
		'hide name',0,...
		'position',[30,28,110,72])


%     Subsystem  'Graph'.

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

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_block('built-in/Inport',[sys,'/','Graph/x'])
set_param([sys,'/','Graph/x'],...
		'position',[65,55,85,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 ''/'':|Sample time:')
set_param([sys,'/','Graph'],...
		'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = @5;')
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','20\/-.2\/2\/''y-/g--/y-./g:/m*/ro/b+''\/.1\/')


%     Finished composite block 'Graph'.

set_param([sys,'/','Graph'],...
		'hide name',0,...
		'position',[350,41,380,79])

add_block('built-in/Constant',[sys,'/','Expected value'])
set_param([sys,'/','Expected value'],...
		'Value','[sqrt(pi/2), (2-pi/2)]',...
		'position',[90,82,205,108])


%     Subsystem  'Mean and var'.

new_system([sys,'/','Mean and var'])
set_param([sys,'/','Mean and var'],'Location',[16,148,774,399])

add_block('built-in/Outport',[sys,'/',['Mean and var/Mean',13,'Squared',13,'Error1']])
set_param([sys,'/',['Mean and var/Mean',13,'Squared',13,'Error1']],...
		'Port','2',...
		'position',[700,135,720,155])

add_block('built-in/Fcn',[sys,'/','Mean and var/Fcn4'])
set_param([sys,'/','Mean and var/Fcn4'],...
		'Expr','u[1]*u[1]',...
		'position',[555,107,620,133])

add_block('built-in/Mux',[sys,'/','Mean and var/Mux2'])
set_param([sys,'/','Mean and var/Mux2'],...
		'inputs','2',...
		'position',[515,101,545,134])

add_block('built-in/Sum',[sys,'/','Mean and var/Sum'])
set_param([sys,'/','Mean and var/Sum'],...
		'inputs','-+',...
		'position',[645,135,665,155])

add_block('built-in/Fcn',[sys,'/','Mean and var/Fcn'])
set_param([sys,'/','Mean and var/Fcn'],...
		'Expr','(u[3]*(u[2]-1) + u[1]*u[1])/u[2]',...
		'position',[290,136,465,164])

add_block('built-in/Unit Delay',[sys,'/','Mean and var/Unit Delay'])
set_param([sys,'/','Mean and var/Unit Delay'],...
		'orientation',2,...
		'Sample time','Ts',...
		'position',[345,192,395,208])

add_block('built-in/Mux',[sys,'/','Mean and var/Mux'])
set_param([sys,'/','Mean and var/Mux'],...
		'inputs','3',...
		'position',[235,134,265,166])

add_block('built-in/Fcn',[sys,'/','Mean and var/Fcn3'])
set_param([sys,'/','Mean and var/Fcn3'],...
		'Expr','(u[3]*(u[2]-1) + u[1])/u[2]',...
		'position',[290,41,465,69])

add_block('built-in/Mux',[sys,'/','Mean and var/Mux1'])
set_param([sys,'/','Mean and var/Mux1'],...
		'inputs','3',...
		'position',[235,39,265,71])

add_block('built-in/Outport',[sys,'/','Mean and var/mean value'])
set_param([sys,'/','Mean and var/mean value'],...
		'position',[545,45,565,65])

add_block('built-in/Unit Delay',[sys,'/','Mean and var/Unit Delay1'])
set_param([sys,'/','Mean and var/Unit Delay1'],...
		'orientation',2,...
		'Sample time','Ts',...
		'position',[350,87,400,103])

add_block('built-in/Fcn',[sys,'/','Mean and var/Fcn2'])
set_param([sys,'/','Mean and var/Fcn2'],...
		'Expr','u[1]/Ts +1',...
		'position',[105,83,165,107])

add_block('built-in/Digital Clock',[sys,'/','Mean and var/Digital Clock'])
set_param([sys,'/','Mean and var/Digital Clock'],...
		'Sample time','Ts',...
		'position',[45,80,80,110])

add_block('built-in/Inport',[sys,'/','Mean and var/Actual'])
set_param([sys,'/','Mean and var/Actual'],...
		'position',[25,35,45,55])
add_line([sys,'/','Mean and var'],[670,145;695,145])
add_line([sys,'/','Mean and var'],[550,120;550,120])
add_line([sys,'/','Mean and var'],[170,95;190,95;190,150;230,150])
add_line([sys,'/','Mean and var'],[190,125;510,125])
add_line([sys,'/','Mean and var'],[470,55;540,55])
add_line([sys,'/','Mean and var'],[495,55;495,95;405,95])
add_line([sys,'/','Mean and var'],[495,95;495,110;510,110])
add_line([sys,'/','Mean and var'],[625,120;625,140;640,140])
add_line([sys,'/','Mean and var'],[470,150;480,150;480,200;400,200])
add_line([sys,'/','Mean and var'],[480,150;640,150])
add_line([sys,'/','Mean and var'],[50,45;230,45])
add_line([sys,'/','Mean and var'],[200,45;200,140;230,140])
add_line([sys,'/','Mean and var'],[345,95;210,95;210,65;230,65])
add_line([sys,'/','Mean and var'],[190,95;190,55;230,55])
add_line([sys,'/','Mean and var'],[270,55;285,55])
add_line([sys,'/','Mean and var'],[270,150;285,150])
add_line([sys,'/','Mean and var'],[340,200;220,200;230,160])
add_line([sys,'/','Mean and var'],[85,95;100,95])
set_param([sys,'/','Mean and var'],...
		'Mask Display','Mean\n& var',...
		'Mask Type','Running mean and var',...
		'Mask Dialogue','Output the running mean to 1st outport\nand running variant to 2nd outport.|Sample time (sec):')
set_param([sys,'/','Mean and var'],...
		'Mask Translate','Ts=@1;',...
		'Mask Help','This block updates the running mean and variant value at sampling time point. The mean and var values are outputted into 1st and 2nd outports respectively.')
set_param([sys,'/','Mean and var'],...
		'Mask Entries','.1\/')


%     Finished composite block 'Mean and var'.

set_param([sys,'/','Mean and var'],...
		'hide name',0,...
		'position',[150,28,230,72])

add_block('built-in/Note',[sys,'/','The mean of the Rayleigh noise is s*sqrt(pi//2).'])
set_param([sys,'/','The mean of the Rayleigh noise is s*sqrt(pi//2).'],...
		'position',[175,150,180,155])

add_block('built-in/Note',[sys,'/','The variance of the Rayleigh noise is s^2*(2-pi//2)'])
set_param([sys,'/','The variance of the Rayleigh noise is s^2*(2-pi//2)'],...
		'position',[185,170,190,175])

add_block('built-in/Note',[sys,'/','Assume the sigma value is s, then:'])
set_param([sys,'/','Assume the sigma value is s, then:'],...
		'position',[145,130,150,135])
add_line(sys,[235,40;265,40])
add_line(sys,[115,50;145,50])
add_line(sys,[310,60;345,60])
add_line(sys,[235,60;265,60])
add_line(sys,[210,95;230,95;230,80;265,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 + -