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

📄 tstrcos.m

📁 数字通信第四版原书的例程
💻 M
📖 第 1 页 / 共 5 页
字号:
function [ret,x0,str,ts,xts]=tstrcos(t,x,u,flag);
%TSTRCOS	is the M-file description of the SIMULINK system named TSTRCOS.
%	The block-diagram can be displayed by typing: TSTRCOS.
%
%	SYS=TSTRCOS(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 TSTRCOS 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 TSTRCOS with a FLAG of zero:
%	[SIZES]=TSTRCOS([],[],[],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',[83,130,948,342])
     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  ['Sampled read with',13,'synchronized pulse'].

new_system([sys,'/',['Sampled read with',13,'synchronized pulse']])
set_param([sys,'/',['Sampled read with',13,'synchronized pulse']],'Location',[355,527,737,674])

add_block('built-in/S-Function',[sys,'/',['Sampled read with',13,'synchronized pulse/Message source']])
set_param([sys,'/',['Sampled read with',13,'synchronized pulse/Message source']],...
		'BackGround',5,...
		'function name','trigwksp',...
		'parameters','var,thd,cyclFlag,ini',...
		'Mask Display','Triggered\nread')
set_param([sys,'/',['Sampled read with',13,'synchronized pulse/Message source']],...
		'Mask Type','Read from workspace')
set_param([sys,'/',['Sampled read with',13,'synchronized pulse/Message source']],...
		'Mask Dialogue','The raising edge of input pulse trigger the block output the next row from the workspace variable.|Read the variable:|Threshold for the input pulse:|Cyclic read variable (1) or amend zeros (0).|Output before first trigger:')
set_param([sys,'/',['Sampled read with',13,'synchronized pulse/Message source']],...
		'Mask Translate','var=@1;thd=@2;cyclFlag=@3;ini=@4;')
set_param([sys,'/',['Sampled read with',13,'synchronized pulse/Message source']],...
		'Mask Help','This block reads the data from a workspace variable. The output is refreshed at the raising edge of the input pulse.')
set_param([sys,'/',['Sampled read with',13,'synchronized pulse/Message source']],...
		'Mask Entries','var\/.1\/cyc\/ini\/',...
		'position',[180,53,255,97])

add_block('built-in/Outport',[sys,'/',['Sampled read with',13,'synchronized pulse/out_2']])
set_param([sys,'/',['Sampled read with',13,'synchronized pulse/out_2']],...
		'Port','2',...
		'position',[195,115,215,135])

add_block('built-in/Outport',[sys,'/',['Sampled read with',13,'synchronized pulse/out_1']])
set_param([sys,'/',['Sampled read with',13,'synchronized pulse/out_1']],...
		'position',[295,65,315,85])


%     Subsystem  ['Sampled read with',13,'synchronized pulse/Pulses deivide',13,'same sample time1'].

new_system([sys,'/',['Sampled read with',13,'synchronized pulse/Pulses deivide',13,'same sample time1']])
set_param([sys,'/',['Sampled read with',13,'synchronized pulse/Pulses deivide',13,'same sample time1']],'Location',[55,192,283,286])

add_block('built-in/Outport',[sys,'/',['Sampled read with',13,'synchronized pulse/Pulses deivide',13,'same sample time1/Outport']])
set_param([sys,'/',['Sampled read with',13,'synchronized pulse/Pulses deivide',13,'same sample time1/Outport']],...
		'position',[160,35,180,55])

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


%     Finished composite block ['Sampled read with',13,'synchronized pulse/Pulses deivide',13,'same sample time1'].

set_param([sys,'/',['Sampled read with',13,'synchronized pulse/Pulses deivide',13,'same sample time1']],...
		'position',[50,56,110,94])
add_line([sys,'/',['Sampled read with',13,'synchronized pulse']],[115,75;175,75])
add_line([sys,'/',['Sampled read with',13,'synchronized pulse']],[135,75;135,125;190,125])
add_line([sys,'/',['Sampled read with',13,'synchronized pulse']],[260,75;290,75])
set_param([sys,'/',['Sampled read with',13,'synchronized pulse']],...
		'Mask Display','plot(0,0,100,100,x,y,v,w);Rd wksp',...
		'Mask Type','Read from workspace')
set_param([sys,'/',['Sampled read with',13,'synchronized pulse']],...
		'Mask Dialogue','Read from a workspace variable at\nsampling time point.|Variable (column_number=block_output_length):|Data output sample time (sec):|Cyclic control (1: cyclic read, 0: output zeros after eof).|Initial output:')
set_param([sys,'/',['Sampled read with',13,'synchronized pulse']],...
		'Mask Translate','var=@1;td=@2;ts=td(1);if (length(td)>=2),off=td(2);else off=0;end;cyc=@3;ini=@4;[x,y]=srcsicon(7);[v,w]=trigicon(1,75,get_param(gcb,''orientation''),2);')
set_param([sys,'/',['Sampled read with',13,'synchronized pulse']],...
		'Mask Help','This block reads from a workspace variable at a given sample time. The column number is the block output vector length. When the simulation reaches the end of the variable (eof) row, the block will cyclically output from the first row of the variable or output zeros based on the cyclic control entree. The second output is the synchronization pulse, which outputs a spike when the data is refreshed.')
set_param([sys,'/',['Sampled read with',13,'synchronized pulse']],...
		'Mask Entries','randint(100,1,M)\/td\/1\/0\/')


%     Finished composite block ['Sampled read with',13,'synchronized pulse'].

set_param([sys,'/',['Sampled read with',13,'synchronized pulse']],...
		'hide name',0,...
		'position',[5,68,85,112])


%     Subsystem  ['Raised cosine',13,'filter'].

new_system([sys,'/',['Raised cosine',13,'filter']])
set_param([sys,'/',['Raised cosine',13,'filter']],'Location',[131,545,589,761])


%     Subsystem  ['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1'].

new_system([sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1']])
set_param([sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1']],'Location',[55,192,283,286])

add_block('built-in/S-Function',[sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1/S-function1']])
set_param([sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1/S-function1']],...
		'function name','homopuls',...
		'parameters','samp_time, out_divid, offset',...
		'position',[40,31,105,59])

add_block('built-in/Outport',[sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1/Outport']])
set_param([sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1/Outport']],...
		'position',[160,35,180,55])
add_line([sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1']],[110,45;155,45])
set_param([sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1']],...
		'Mask Display','Vector\nPulse',...
		'Mask Type','Pulse generator')
set_param([sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1']],...
		'Mask Dialogue','Vector pulses with sample rate of each pulse as Sample_time ./Divider. |Sample time (scalar, sec):|Divider (integer vector):|Offset (have same dimension as Divider:')
set_param([sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1']],...
		'Mask Translate','samp_time=@1;out_divid=@2;offset=@3;')
set_param([sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1']],...
		'Mask Help','This block generator a vector pulses. The output length is the same as the vector defined in "Divider". The ith element of the output has the sample time Sample_time/Divider(i). All elements in "Divider" must be integers.')
set_param([sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1']],...
		'Mask Entries','td\/1\/off\/')


%     Finished composite block ['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1'].

set_param([sys,'/',['Raised cosine',13,'filter/Pulses deivide',13,'same sample time1']],...
		'position',[35,71,95,109])

add_block('built-in/Inport',[sys,'/',['Raised cosine',13,'filter/in_1']])
set_param([sys,'/',['Raised cosine',13,'filter/in_1']],...
		'position',[35,30,55,50])

add_block('built-in/Outport',[sys,'/',['Raised cosine',13,'filter/out_1']])
set_param([sys,'/',['Raised cosine',13,'filter/out_1']],...
		'position',[330,40,350,60])

add_block('built-in/Filter',[sys,'/',['Raised cosine',13,'filter/Filter']])
set_param([sys,'/',['Raised cosine',13,'filter/Filter']],...
		'Numerator','num',...
		'Denominator','den',...
		'Sample time','ts',...
		'position',[255,31,310,69])


%     Subsystem  ['Raised cosine',13,'filter/Memory Impulse'].

new_system([sys,'/',['Raised cosine',13,'filter/Memory Impulse']])
set_param([sys,'/',['Raised cosine',13,'filter/Memory Impulse']],'Location',[541,520,939,745])

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


%     Subsystem  ['Raised cosine',13,'filter/Memory Impulse/discrete',13,'Rising edge',13,'detector'].

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

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

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

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

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

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

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

add_block('built-in/Relational Operator',[sys,'/',['Raised cosine',13,'filter/Memory Impulse/discrete',13,'Rising edge',13,'detector/Relational',13,'Operator']])
set_param([sys,'/',['Raised cosine',13,'filter/Memory Impulse/discrete',13,'Rising edge',13,'detector/Relational',13,'Operator']],...
		'position',[135,18,165,42])
add_line([sys,'/',['Raised cosine',13,'filter/Memory Impulse/discrete',13,'Rising edge',13,'detector']],[35,25;130,25])
add_line([sys,'/',['Raised cosine',13,'filter/Memory Impulse/discrete',13,'Rising edge',13,'detector']],[45,25;45,95;115,95])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -