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

📄 tsthammc.m

📁 数字通信第四版原书的例程
💻 M
📖 第 1 页 / 共 2 页
字号:
function [ret,x0,str,ts,xts]=tsthammc(t,x,u,flag);
%TSTHAMMC	is the M-file description of the SIMULINK system named TSTHAMMC.
%	The block-diagram can be displayed by typing: TSTHAMMC.
%
%	SYS=TSTHAMMC(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 TSTHAMMC 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 TSTHAMMC with a FLAG of zero:
%	[SIZES]=TSTHAMMC([],[],[],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',[48,493,854,629])
     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/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','4\/2\/',...
		'position',[130,53,210,97])


%     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/Outport',[sys,'/',['Random-integer',13,'generator1/out_1']])
set_param([sys,'/',['Random-integer',13,'generator1/out_1']],...
		'position',[165,55,185,75])

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_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:')
set_param([sys,'/',['Random-integer',13,'generator1']],...
		'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','16\/[12345]\/')


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

set_param([sys,'/',['Random-integer',13,'generator1']],...
		'hide name',0,...
		'position',[15,53,95,97])


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

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

add_block('built-in/Inport',[sys,'/',['Binary vector',13,'Hamming encode/in_1']])
set_param([sys,'/',['Binary vector',13,'Hamming encode/in_1']],...
		'position',[30,35,50,55])

add_block('built-in/State-Space',[sys,'/',['Binary vector',13,'Hamming encode/Matrix',13,'Gain']])
set_param([sys,'/',['Binary vector',13,'Hamming 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,'Hamming 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,'Hamming encode/Matrix',13,'Gain']],...
		'position',[110,31,135,59])

add_block('built-in/S-Function',[sys,'/',['Binary vector',13,'Hamming encode/Modulus',13,'operation']])
set_param([sys,'/',['Binary vector',13,'Hamming encode/Modulus',13,'operation']],...
		'function name','arymodu',...
		'parameters','md',...
		'Mask Display','Modulo',...
		'Mask Type','Modulo')
set_param([sys,'/',['Binary vector',13,'Hamming encode/Modulus',13,'operation']],...
		'Mask Dialogue','Modulus operation:|Modulus base:',...
		'Mask Translate','md = @1;')
set_param([sys,'/',['Binary vector',13,'Hamming 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,'Hamming encode/Modulus',13,'operation']],...
		'Mask Entries','2\/',...
		'position',[180,26,240,64])

add_block('built-in/Outport',[sys,'/',['Binary vector',13,'Hamming encode/out_1']])
set_param([sys,'/',['Binary vector',13,'Hamming encode/out_1']],...
		'position',[290,35,310,55])
add_line([sys,'/',['Binary vector',13,'Hamming encode']],[55,45;105,45])
add_line([sys,'/',['Binary vector',13,'Hamming encode']],[140,45;175,45])
add_line([sys,'/',['Binary vector',13,'Hamming encode']],[245,45;285,45])
set_param([sys,'/',['Binary vector',13,'Hamming encode']],...
		'Mask Display','plot(0,0,100,100,x,y);Hamming en',...
		'Mask Type','Vector I/O Hamming encode')
set_param([sys,'/',['Binary vector',13,'Hamming encode']],...
		'Mask Dialogue','Hamming encode with input message vector length K=2^M-M-1, output codeword vector length N=2^M-1, where M is a >=3 integer.|Codeword length N:|Message length K, or M-degree primitive polynomial:')
set_param([sys,'/',['Binary vector',13,'Hamming encode']],...
		'Mask Translate','n=@1;k=@2;if length(k)>1,p=k;k=n-length(k)+1;else,p=gfprimdf(n-k);end;[h,G]=hammgen(n-k,p);G=G'';[x,y]=codeicon(1);')
set_param([sys,'/',['Binary vector',13,'Hamming encode']],...
		'Mask Help','This block encodes length K binary vector message input into length N binary vector codeword output using Hamming code. Use function GFPRIMDF or GFPRIMFD to find M-degree primitive polynomials.')
set_param([sys,'/',['Binary vector',13,'Hamming encode']],...
		'Mask Entries','7\/gfprimfd(3,''min'')\/')


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

set_param([sys,'/',['Binary vector',13,'Hamming encode']],...
		'hide name',0,...
		'position',[230,53,310,97])


%     Subsystem  ['Max-err lmtd',13,'b-err channel'].

new_system([sys,'/',['Max-err lmtd',13,'b-err channel']])
set_param([sys,'/',['Max-err lmtd',13,'b-err channel']],'Location',[124,322,430,428])


%     Subsystem  ['Max-err lmtd',13,'b-err channel/B-n'].

new_system([sys,'/',['Max-err lmtd',13,'b-err channel/B-n']])
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/B-n']],'Location',[36,445,326,560])

add_block('built-in/Outport',[sys,'/',['Max-err lmtd',13,'b-err channel/B-n/out_1']])
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/B-n/out_1']],...
		'position',[190,35,210,55])

add_block('built-in/S-Function',[sys,'/',['Max-err lmtd',13,'b-err channel/B-n/S-function']])
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/B-n/S-function']],...
		'function name','srandbit',...
		'parameters','n, prob, seed',...
		'position',[90,35,140,55])
add_line([sys,'/',['Max-err lmtd',13,'b-err channel/B-n']],[145,45;185,45])
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/B-n']],...
		'Mask Display','B-vector\ngenerator',...
		'Mask Type','Binary noise generator')
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/B-n']],...
		'Mask Dialogue','Generate a binary vector with the probability of "1"s in the vector being specified.|Vector length(can''t be changed during simulation):|Probability of a "one", two "ones",three "ones"...:|Seed:')
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/B-n']],...
		'Mask Translate','n=@1;prob=@2;seed=@3;')
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/B-n']],...
		'Mask Help','This block outputs a zero vector with "1"s randomly distributed the vector. The maximum number of "1"s in the vector is the same as the length of the vector probability. The value of ith element of the probability is the probability of i number of "1"s in the vector.')
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/B-n']],...
		'Mask Entries','leng\/prob\/seed\/')


%     Finished composite block ['Max-err lmtd',13,'b-err channel/B-n'].

set_param([sys,'/',['Max-err lmtd',13,'b-err channel/B-n']],...
		'hide name',0,...
		'position',[30,38,110,82])

add_block('built-in/Outport',[sys,'/',['Max-err lmtd',13,'b-err channel/out_2']])
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/out_2']],...
		'hide name',0,...
		'Port','2',...
		'position',[275,50,295,70])

add_block('built-in/Inport',[sys,'/',['Max-err lmtd',13,'b-err channel/in_1']])
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/in_1']],...
		'hide name',0,...
		'position',[40,5,60,25])

add_block('built-in/Sum',[sys,'/',['Max-err lmtd',13,'b-err channel/S']])
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/S']],...
		'hide name',0,...
		'position',[150,20,170,40])

add_block('built-in/S-Function',[sys,'/',['Max-err lmtd',13,'b-err channel/Mdu']])
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/Mdu']],...
		'hide name',0,...
		'function name','arymodu',...
		'parameters','md',...
		'Mask Display','Modulo',...
		'Mask Type','Modulo')
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/Mdu']],...
		'Mask Dialogue','Modulus operation:|Modulus base:',...
		'Mask Translate','md = @1;')
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/Mdu']],...
		'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,'/',['Max-err lmtd',13,'b-err channel/Mdu']],...
		'Mask Entries','2\/',...
		'position',[195,11,255,49])

add_block('built-in/Outport',[sys,'/',['Max-err lmtd',13,'b-err channel/out_1']])
set_param([sys,'/',['Max-err lmtd',13,'b-err channel/out_1']],...
		'hide name',0,...
		'position',[275,20,295,40])
add_line([sys,'/',['Max-err lmtd',13,'b-err channel']],[65,15;90,15;90,25;145,25])
add_line([sys,'/',['Max-err lmtd',13,'b-err channel']],[115,60;270,60])
add_line([sys,'/',['Max-err lmtd',13,'b-err channel']],[115,60;130,60;130,35;145,35])
add_line([sys,'/',['Max-err lmtd',13,'b-err channel']],[260,30;270,30])
add_line([sys,'/',['Max-err lmtd',13,'b-err channel']],[175,30;190,30])
set_param([sys,'/',['Max-err lmtd',13,'b-err channel']],...
		'Mask Display','plot(0,0,100,100,x,y);Lmtd b-err',...
		'Mask Type','Limited binary error channel')
set_param([sys,'/',['Max-err lmtd',13,'b-err channel']],...

⌨️ 快捷键说明

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