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

📄 tstbchcd.m

📁 数字通信第四版原书的例程
💻 M
📖 第 1 页 / 共 2 页
字号:
function [ret,x0,str,ts,xts]=tstbchcd(t,x,u,flag);
%TSTBCHCD	is the M-file description of the SIMULINK system named TSTBCHCD.
%	The block-diagram can be displayed by typing: TSTBCHCD.
%
%	SYS=TSTBCHCD(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 TSTBCHCD 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 TSTBCHCD with a FLAG of zero:
%	[SIZES]=TSTBCHCD([],[],[],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',[4,90,858,319])
     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', '1')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')
set_param(sys,'Load callback','N_bch_demo=15;K_bch_demo=5;T_bch_demo=3;');


%     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/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_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/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/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_line([sys,'/',['Binary vector',13,'BCH encode']],[55,45;105,45])
add_line([sys,'/',['Binary vector',13,'BCH encode']],[140,45;175,45])
add_line([sys,'/',['Binary vector',13,'BCH encode']],[245,45;285,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','N_bch_demo\/K_bch_demo\/')


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

set_param([sys,'/',['Binary vector',13,'BCH encode']],...
		'hide name',0,...
		'position',[220,43,300,87])

add_block('built-in/S-Function',[sys,'/',['Integer scalar',13,'to vector']])
set_param([sys,'/',['Integer scalar',13,'to vector']],...
		'hide name',0,...
		'function name','simde2bi',...
		'parameters','len, p',...
		'Mask Display','Sca to vec\nconverter',...
		'Mask Type','Decimal to base M vector')
set_param([sys,'/',['Integer scalar',13,'to vector']],...
		'Mask Dialogue','Convert decimal integer input to base M\ninteger and output each position of the\nconverted integer using output vector.|Output vector length:|Conversion base M:')
set_param([sys,'/',['Integer scalar',13,'to vector']],...
		'Mask Translate','len=@1;p=@2;')
set_param([sys,'/',['Integer scalar',13,'to vector']],...
		'Mask Help','This block converts decimal integer scalar input to a base M integer. M must be a\npositive integer. The block outputs the base M integer using a vector. The 1st element in the output vector contains the 1''s position. The 2nd element in the output vector contains the M''s position, and so on. The output vector length is given by setting the parameter entry.')
set_param([sys,'/',['Integer scalar',13,'to vector']],...
		'Mask Entries','K_bch_demo\/2\/',...
		'position',[120,43,200,87])


%     Subsystem  ['Random-integer',13,'generator1'].

new_system([sys,'/',['Random-integer',13,'generator1']])
set_param([sys,'/',['Random-integer',13,'generator1']],'Location',[98,518,454,687])

add_block('built-in/S-Function',[sys,'/',['Random-integer',13,'generator1/Uniform',13,'number']])
set_param([sys,'/',['Random-integer',13,'generator1/Uniform',13,'number']],...
		'function name','srandint',...
		'parameters','seed,mul',...
		'position',[65,45,135,85])

add_block('built-in/Outport',[sys,'/',['Random-integer',13,'generator1/out_1']])
set_param([sys,'/',['Random-integer',13,'generator1/out_1']],...
		'position',[165,55,185,75])
add_line([sys,'/',['Random-integer',13,'generator1']],[140,65;160,65])
set_param([sys,'/',['Random-integer',13,'generator1']],...
		'Mask Display','plot(0,0,100,100,x,y);Random int',...
		'Mask Type','Random integer generator')
set_param([sys,'/',['Random-integer',13,'generator1']],...
		'Mask Dialogue','Generate integers randomly distributed in range [0, M-1], where M is the M-ary number.|M-ary number:|Seed:',...
		'Mask Translate','seed=@2;mul=@1;[x,y]=srcsicon(4);')
set_param([sys,'/',['Random-integer',13,'generator1']],...
		'Mask Help','This block generates an integer number in the range [0 M-1], where M is the M-ary number. The probability of the appearance for each number is equal.')
set_param([sys,'/',['Random-integer',13,'generator1']],...
		'Mask Entries','2^K_bch_demo\/[12345]\/')


%     Finished composite block ['Random-integer',13,'generator1'].

set_param([sys,'/',['Random-integer',13,'generator1']],...
		'hide name',0,...
		'position',[5,43,85,87])


%     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/Outport',[sys,'/',['Binary vector',13,'BCH decode/out_2']])
set_param([sys,'/',['Binary vector',13,'BCH decode/out_2']],...
		'Port','2',...
		'position',[495,95,515,115])

add_block('built-in/Outport',[sys,'/',['Binary vector',13,'BCH decode/out_1']])
set_param([sys,'/',['Binary vector',13,'BCH decode/out_1']],...
		'position',[495,30,515,50])

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/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/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/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/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/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/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_line([sys,'/',['Binary vector',13,'BCH decode']],[440,65;455,65;455,105;490,105])
add_line([sys,'/',['Binary vector',13,'BCH decode']],[440,50;455,50;455,40;490,40])
add_line([sys,'/',['Binary vector',13,'BCH decode']],[35,110;200,110;200,60;290,60])
add_line([sys,'/',['Binary vector',13,'BCH decode']],[60,110;60,65;75,65])
add_line([sys,'/',['Binary vector',13,'BCH decode']],[120,60;150,60;150,30;165,30])
add_line([sys,'/',['Binary vector',13,'BCH decode']],[45,25;60,25;60,50;75,50])
add_line([sys,'/',['Binary vector',13,'BCH decode']],[240,30;255,30;255,50;290,50])
add_line([sys,'/',['Binary vector',13,'BCH decode']],[290,110;255,110;255,70;290,70])
add_line([sys,'/',['Binary vector',13,'BCH decode']],[330,60;390,60])
add_line([sys,'/',['Binary vector',13,'BCH decode']],[360,60;360,110;340,110])
set_param([sys,'/',['Binary vector',13,'BCH decode']],...
		'Mask Display','plot(0,0,100,100,x,y,v,w);BCH de',...
		'Mask Type','Vector I/O BCH decode')
set_param([sys,'/',['Binary vector',13,'BCH decode']],...
		'Mask Dialogue','BCH decode with input codeword vector\nlength N, output message vector length K, and error-correction capability T. (N,K,T) must be a valid BCH code combination.|Codeword length N (N=2^M-1. M is a >2 integer):|Message length K (check BCHPOLY for valid K):|Error-correction capability T (0 for unknown):')
set_param([sys,'/',['Binary vector',13,'BCH decode']],...
		'Mask Translate','n=@1;k=@2;t=@3;if t<=0, [x1,x2,x3,x4,t]=bchpoly(n,k);end;dim=3;pow_dim=7;while pow_dim<n,dim=dim+1;pow_dim=2^dim-1;end;tp=gftuple([-1:n-1]'',dim);[x,y]=codeicon(2);[v,w]=trigicon(0,25,get_param(gcb,''orientation''));')
set_param([sys,'/',['Binary vector',13,'BCH decode']],...
		'Mask Help','This block decodes length N binary vector codeword input into length K binary vector message output using BCH code. The block refreshes its decoding output when the enable signal at the second inport has positive value. The second outport outputs the number of errors detected in the process. A negative value indicates the block found more error in the codeword than T.')
set_param([sys,'/',['Binary vector',13,'BCH decode']],...
		'Mask Entries','N_bch_demo\/K_bch_demo\/T_bch_demo\/')


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

set_param([sys,'/',['Binary vector',13,'BCH decode']],...
		'ForeGround',6,...
		'hide name',0,...
		'position',[530,43,610,87])

add_block('built-in/S-Function',[sys,'/',['Integer vector',13,'to scalar']])
set_param([sys,'/',['Integer vector',13,'to scalar']],...
		'hide name',0,...
		'function name','simbi2de',...
		'parameters','p',...
		'Mask Display','Vec to sca\nconverter',...
		'Mask Type','Base M vector to decimal integer')
set_param([sys,'/',['Integer vector',13,'to scalar']],...
		'Mask Dialogue','Convert base M integer with each\nposition in the input vector into scalar decimal output.|Input integer base M:',...
		'Mask Translate','p=@1;')
set_param([sys,'/',['Integer vector',13,'to scalar']],...
		'Mask Help','This block convert the base M vector into scalar decimal integer output. Each element of the input vector is one position of the digit of the base M integer. The 1st element in the input vector contains the 1''s position. The 2nd element in the input vector contains the M''s position.')
set_param([sys,'/',['Integer vector',13,'to scalar']],...
		'Mask Entries','2\/',...

⌨️ 快捷键说明

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