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

📄 tutbchcd.m

📁 数字通信第四版原书的例程
💻 M
📖 第 1 页 / 共 2 页
字号:
function [ret,x0,str,ts,xts]=tutbchcd(t,x,u,flag);
%TUTBCHCD	is the M-file description of the SIMULINK system named TUTBCHCD.
%	The block-diagram can be displayed by typing: TUTBCHCD.
%
%	SYS=TUTBCHCD(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 TUTBCHCD 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 TUTBCHCD with a FLAG of zero:
%	[SIZES]=TUTBCHCD([],[],[],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',[82,406,747,551])
     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',   '')


%     Subsystem  ['Binary vector',13,'BCH encode'].

new_system([sys,'/',['Binary vector',13,'BCH encode']])
set_param([sys,'/',['Binary vector',13,'BCH encode']],'Location',[235,592,599,711])

add_block('built-in/Outport',[sys,'/',['Binary vector',13,'BCH encode/out_1']])
set_param([sys,'/',['Binary vector',13,'BCH encode/out_1']],...
		'position',[290,35,310,55])

add_block('built-in/S-Function',[sys,'/',['Binary vector',13,'BCH encode/Modulus',13,'operation']])
set_param([sys,'/',['Binary vector',13,'BCH encode/Modulus',13,'operation']],...
		'function name','arymodu',...
		'parameters','md',...
		'Mask Display','Modulo',...
		'Mask Type','Modulo',...
		'Mask Dialogue','Modulus operation:|Modulus base:')
set_param([sys,'/',['Binary vector',13,'BCH encode/Modulus',13,'operation']],...
		'Mask Translate','md = @1;')
set_param([sys,'/',['Binary vector',13,'BCH encode/Modulus',13,'operation']],...
		'Mask Help','This block output modulus operation of the input signal with module base as specified in block entry. The length of the output vector is the same as the input vector.')
set_param([sys,'/',['Binary vector',13,'BCH encode/Modulus',13,'operation']],...
		'Mask Entries','2\/',...
		'position',[180,26,240,64])

add_block('built-in/State-Space',[sys,'/',['Binary vector',13,'BCH encode/Matrix',13,'Gain']])
set_param([sys,'/',['Binary vector',13,'BCH encode/Matrix',13,'Gain']],...
		'A','[]',...
		'B','[]',...
		'C','[]',...
		'D','K',...
		'Mask Display','K',...
		'Mask Type','Matrix Gain',...
		'Mask Dialogue','Matrix Gain.|Gain matrix:')
set_param([sys,'/',['Binary vector',13,'BCH encode/Matrix',13,'Gain']],...
		'Mask Translate','K = @1;',...
		'Mask Help','Multiplies input vector by entered matrix to produce output vector (y=Au).',...
		'Mask Entries','G\/')
set_param([sys,'/',['Binary vector',13,'BCH encode/Matrix',13,'Gain']],...
		'position',[110,31,135,59])

add_block('built-in/Inport',[sys,'/',['Binary vector',13,'BCH encode/in_1']])
set_param([sys,'/',['Binary vector',13,'BCH encode/in_1']],...
		'position',[30,35,50,55])
add_line([sys,'/',['Binary vector',13,'BCH encode']],[245,45;285,45])
add_line([sys,'/',['Binary vector',13,'BCH encode']],[140,45;175,45])
add_line([sys,'/',['Binary vector',13,'BCH encode']],[55,45;105,45])
set_param([sys,'/',['Binary vector',13,'BCH encode']],...
		'Mask Display','plot(0,0,100,100,x,y);BCH en',...
		'Mask Type','Vector I/O BCH encode')
set_param([sys,'/',['Binary vector',13,'BCH encode']],...
		'Mask Dialogue','BCH encode with input message vector\nlength K and output codeword vector length\nN. (N, K) must be a valid BCH code pair.|Codeword length N (N=2^M-1. M is a >2 integer):|Message length K (check BCHPOLY for valid K):')
set_param([sys,'/',['Binary vector',13,'BCH encode']],...
		'Mask Translate','n=@1;k=@2;pg = bchpoly(n,k);[h,G]=cyclgen(n,pg);G=G'';[x,y]=codeicon(1);')
set_param([sys,'/',['Binary vector',13,'BCH encode']],...
		'Mask Help','This block encodes length K binary vector message input into length N binary vector codeword output using BCH code. Use function BCHPOLY to view the valid N, K, and error-corr ection capability T combination.')
set_param([sys,'/',['Binary vector',13,'BCH encode']],...
		'Mask Entries','15\/5\/')


%     Finished composite block ['Binary vector',13,'BCH encode'].

set_param([sys,'/',['Binary vector',13,'BCH encode']],...
		'hide name',0,...
		'position',[120,78,200,122])


%     Subsystem  ['Sampled read',13,'from wksp'].

new_system([sys,'/',['Sampled read',13,'from wksp']])
set_param([sys,'/',['Sampled read',13,'from wksp']],'Location',[355,528,737,675])


%     Subsystem  ['Sampled read',13,'from wksp/Pulses deivide',13,'same sample time1'].

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

add_block('built-in/S-Function',[sys,'/',['Sampled read',13,'from wksp/Pulses deivide',13,'same sample time1/S-function1']])
set_param([sys,'/',['Sampled read',13,'from wksp/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,'/',['Sampled read',13,'from wksp/Pulses deivide',13,'same sample time1/Outport']])
set_param([sys,'/',['Sampled read',13,'from wksp/Pulses deivide',13,'same sample time1/Outport']],...
		'position',[160,35,180,55])
add_line([sys,'/',['Sampled read',13,'from wksp/Pulses deivide',13,'same sample time1']],[110,45;155,45])
set_param([sys,'/',['Sampled read',13,'from wksp/Pulses deivide',13,'same sample time1']],...
		'Mask Display','Vector\nPulse',...
		'Mask Type','Pulse generator')
set_param([sys,'/',['Sampled read',13,'from wksp/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',13,'from wksp/Pulses deivide',13,'same sample time1']],...
		'Mask Translate','samp_time=@1;out_divid=@2;offset=@3;')
set_param([sys,'/',['Sampled read',13,'from wksp/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',13,'from wksp/Pulses deivide',13,'same sample time1']],...
		'Mask Entries','ts\/1\/off\/')


%     Finished composite block ['Sampled read',13,'from wksp/Pulses deivide',13,'same sample time1'].

set_param([sys,'/',['Sampled read',13,'from wksp/Pulses deivide',13,'same sample time1']],...
		'position',[50,56,110,94])

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

add_block('built-in/S-Function',[sys,'/',['Sampled read',13,'from wksp/Message source']])
set_param([sys,'/',['Sampled read',13,'from wksp/Message source']],...
		'BackGround',5,...
		'function name','trigwksp',...
		'parameters','var,thd,cyclFlag,ini',...
		'Mask Display','Triggered\nread',...
		'Mask Type','Read from workspace')
set_param([sys,'/',['Sampled read',13,'from wksp/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',13,'from wksp/Message source']],...
		'Mask Translate','var=@1;thd=@2;cyclFlag=@3;ini=@4;')
set_param([sys,'/',['Sampled read',13,'from wksp/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.',...
		'Mask Entries','var\/.1\/cyc\/ini\/')
set_param([sys,'/',['Sampled read',13,'from wksp/Message source']],...
		'position',[180,53,255,97])
add_line([sys,'/',['Sampled read',13,'from wksp']],[260,75;290,75])
add_line([sys,'/',['Sampled read',13,'from wksp']],[115,75;175,75])
set_param([sys,'/',['Sampled read',13,'from wksp']],...
		'Mask Display','plot(0,0,100,100,x,y);Rd wksp',...
		'Mask Type','Read from workspace')
set_param([sys,'/',['Sampled read',13,'from wksp']],...
		'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',13,'from wksp']],...
		'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);')
set_param([sys,'/',['Sampled read',13,'from wksp']],...
		'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 reached 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.')
set_param([sys,'/',['Sampled read',13,'from wksp']],...
		'Mask Entries','randint(200,5)\/1\/1\/0\/')


%     Finished composite block ['Sampled read',13,'from wksp'].

set_param([sys,'/',['Sampled read',13,'from wksp']],...
		'hide name',0,...
		'position',[10,78,90,122])

add_block('built-in/Constant',[sys,'/','Constant'])
set_param([sys,'/','Constant'],...
		'hide name',0,...
		'position',[315,100,335,120])


%     Subsystem  ['Binary vector',13,'BCH decode'].

new_system([sys,'/',['Binary vector',13,'BCH decode']])
set_param([sys,'/',['Binary vector',13,'BCH decode']],'Location',[157,499,740,659])

add_block('built-in/Memory',[sys,'/',['Binary vector',13,'BCH decode/Memory']])
set_param([sys,'/',['Binary vector',13,'BCH decode/Memory']],...
		'orientation',2,...
		'x0','zeros(1,k+1)',...
		'position',[295,95,335,125])

add_block('built-in/Switch',[sys,'/',['Binary vector',13,'BCH decode/Switch']])
set_param([sys,'/',['Binary vector',13,'BCH decode/Switch']],...
		'Threshold','0.5',...
		'position',[295,44,325,76])

add_block('built-in/S-Function',[sys,'/',['Binary vector',13,'BCH decode/S-function']])
set_param([sys,'/',['Binary vector',13,'BCH decode/S-function']],...
		'function name','simbchdc',...
		'parameters','n, k, t,tp,dim',...
		'position',[170,20,235,40])

add_block('built-in/Mux',[sys,'/',['Binary vector',13,'BCH decode/Mux']])
set_param([sys,'/',['Binary vector',13,'BCH decode/Mux']],...
		'inputs','[n, 1]',...
		'position',[80,41,115,74])

add_block('built-in/Inport',[sys,'/',['Binary vector',13,'BCH decode/in_1']])
set_param([sys,'/',['Binary vector',13,'BCH decode/in_1']],...
		'position',[20,15,40,35])

add_block('built-in/Inport',[sys,'/',['Binary vector',13,'BCH decode/in_2']])
set_param([sys,'/',['Binary vector',13,'BCH decode/in_2']],...
		'Port','2',...
		'position',[10,100,30,120])

add_block('built-in/Demux',[sys,'/',['Binary vector',13,'BCH decode/Demux']])
set_param([sys,'/',['Binary vector',13,'BCH decode/Demux']],...
		'outputs','[k, 1]',...
		'position',[395,40,435,75])

add_block('built-in/Outport',[sys,'/',['Binary vector',13,'BCH decode/out_1']])

⌨️ 快捷键说明

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