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

📄 tstrscbv.m

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

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'hide name',0,...
		'position',[360,60,380,80])


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

new_system([sys,'/',['Binary vector',13,'RS encode']])
set_param([sys,'/',['Binary vector',13,'RS encode']],'Location',[160,111,633,282])

add_block('built-in/Outport',[sys,'/',['Binary vector',13,'RS encode/out_1']])
set_param([sys,'/',['Binary vector',13,'RS encode/out_1']],...
		'position',[425,60,445,80])

add_block('built-in/Inport',[sys,'/',['Binary vector',13,'RS encode/in_2']])
set_param([sys,'/',['Binary vector',13,'RS encode/in_2']],...
		'Port','2',...
		'position',[20,110,40,130])

add_block('built-in/Inport',[sys,'/',['Binary vector',13,'RS encode/in_1']])
set_param([sys,'/',['Binary vector',13,'RS encode/in_1']],...
		'position',[30,25,50,45])

add_block('built-in/Mux',[sys,'/',['Binary vector',13,'RS encode/Mux']])
set_param([sys,'/',['Binary vector',13,'RS encode/Mux']],...
		'inputs','2',...
		'position',[90,51,125,84])

add_block('built-in/S-Function',[sys,'/',['Binary vector',13,'RS encode/S-function']])
set_param([sys,'/',['Binary vector',13,'RS encode/S-function']],...
		'function name','simrscbv',...
		'parameters','n, k, pg,tp,dim',...
		'position',[180,30,245,50])

add_block('built-in/Switch',[sys,'/',['Binary vector',13,'RS encode/Switch']])
set_param([sys,'/',['Binary vector',13,'RS encode/Switch']],...
		'Threshold','0.5',...
		'position',[305,54,335,86])

add_block('built-in/Memory',[sys,'/',['Binary vector',13,'RS encode/Memory']])
set_param([sys,'/',['Binary vector',13,'RS encode/Memory']],...
		'orientation',2,...
		'x0','zeros(1,n*dim)',...
		'position',[305,105,345,135])
add_line([sys,'/',['Binary vector',13,'RS encode']],[45,120;210,120;210,70;300,70])
add_line([sys,'/',['Binary vector',13,'RS encode']],[70,120;70,75;85,75])
add_line([sys,'/',['Binary vector',13,'RS encode']],[130,70;160,70;160,40;175,40])
add_line([sys,'/',['Binary vector',13,'RS encode']],[55,35;70,35;70,60;85,60])
add_line([sys,'/',['Binary vector',13,'RS encode']],[250,40;265,40;265,60;300,60])
add_line([sys,'/',['Binary vector',13,'RS encode']],[300,120;265,120;265,80;300,80])
add_line([sys,'/',['Binary vector',13,'RS encode']],[340,70;420,70])
add_line([sys,'/',['Binary vector',13,'RS encode']],[370,70;370,120;350,120])
set_param([sys,'/',['Binary vector',13,'RS encode']],...
		'Mask Display','plot(0,0,100,100,x,y,v,w);B-RS en',...
		'Mask Type','Binary vector I/O RS encode')
set_param([sys,'/',['Binary vector',13,'RS encode']],...
		'Mask Dialogue','Reed-Solomon encode with binary input\nvector length K*M and binary output\nvector length N*M.|Code length N=2^M-1 (M is a >2 integer):|Message length K (< N):')
set_param([sys,'/',['Binary vector',13,'RS encode']],...
		'Mask Translate','n=@1;k=@2;if length(k)>1,pg=k;k=n-length(pg)-1;else,pg=rspoly(n,k);end;dim=3;p_dim=7;while p_dim<n,dim=dim+1;p_dim=2^dim-1;end;tp=gftuple([-1:n-1]'',dim);[x,y]=codeicon(1);[v,w]=trigicon(0,25,get_param(gcb,''orientation''));')
set_param([sys,'/',['Binary vector',13,'RS encode']],...
		'Mask Help','This block encodes length K*M binary vector input into length N*M binary vector output. The codeword length is N=2^M-1. M is a integer larger than 2. The message length is K<N. The block refreshes its encoding output when the enable signal at the second inport has positive value.')
set_param([sys,'/',['Binary vector',13,'RS encode']],...
		'Mask Entries','N_rs_demo\/K_rs_demo\/')


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

set_param([sys,'/',['Binary vector',13,'RS encode']],...
		'hide name',0,...
		'position',[235,43,315,87])


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

new_system([sys,'/',['Binary vector',13,'RS decode']])
set_param([sys,'/',['Binary vector',13,'RS decode']],'Location',[143,192,726,352])

add_block('built-in/Outport',[sys,'/',['Binary vector',13,'RS decode/out_2']])
set_param([sys,'/',['Binary vector',13,'RS decode/out_2']],...
		'Port','2',...
		'position',[495,95,515,115])

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

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

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

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

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

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

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

add_block('built-in/Memory',[sys,'/',['Binary vector',13,'RS decode/Memory']])
set_param([sys,'/',['Binary vector',13,'RS decode/Memory']],...
		'orientation',2,...
		'x0','zeros(1,k*dim+1)',...
		'position',[295,95,335,125])
add_line([sys,'/',['Binary vector',13,'RS decode']],[440,65;455,65;455,105;490,105])
add_line([sys,'/',['Binary vector',13,'RS decode']],[440,50;455,50;455,40;490,40])
add_line([sys,'/',['Binary vector',13,'RS decode']],[35,110;200,110;200,60;290,60])
add_line([sys,'/',['Binary vector',13,'RS decode']],[60,110;60,65;75,65])
add_line([sys,'/',['Binary vector',13,'RS decode']],[120,60;150,60;150,30;165,30])
add_line([sys,'/',['Binary vector',13,'RS decode']],[45,25;60,25;60,50;75,50])
add_line([sys,'/',['Binary vector',13,'RS decode']],[240,30;255,30;255,50;290,50])
add_line([sys,'/',['Binary vector',13,'RS decode']],[290,110;255,110;255,70;290,70])
add_line([sys,'/',['Binary vector',13,'RS decode']],[330,60;390,60])
add_line([sys,'/',['Binary vector',13,'RS decode']],[360,60;360,110;340,110])
set_param([sys,'/',['Binary vector',13,'RS decode']],...
		'Mask Display','plot(0,0,100,100,x,y,v,w);B-RS de',...
		'Mask Type','Binary vector I/O RS decode')
set_param([sys,'/',['Binary vector',13,'RS decode']],...
		'Mask Dialogue','Reed-Solomon decode with binary input\nvector length N*M and binary output\nvector length K*M.|Code length N=2^M-1 (M is a >2 integer):|Message length K (< N):')
set_param([sys,'/',['Binary vector',13,'RS decode']],...
		'Mask Translate','n=@1;k=@2;dim=3;p_d=7;while p_d<n,dim=dim+1;p_d=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,'RS decode']],...
		'Mask Help','This block decodes length N*M binary vector input into length K*M binary vector output. The codeword length is N=2^M-1. M>2. The message length is K<N. 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. If the codeword contains more errors than the correction capability, this output is negative.')
set_param([sys,'/',['Binary vector',13,'RS decode']],...
		'Mask Entries','N_rs_demo\/K_rs_demo\/')


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

set_param([sys,'/',['Binary vector',13,'RS decode']],...
		'ForeGround',6,...
		'hide name',0,...
		'position',[540,58,620,102])

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_rs_demo*M_rs_demo\/2\/',...
		'position',[120,33,200,77])


%     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_rs_demo*M_rs_demo)\/[12345]\/')


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

set_param([sys,'/',['Random-integer',13,'generator1']],...
		'hide name',0,...
		'position',[10,33,90,77])


%     Subsystem  'Error rate'.

new_system([sys,'/','Error rate'])
set_param([sys,'/','Error rate'],'Location',[255,368,509,510])

add_block('built-in/S-Function',[sys,'/','Error rate/S-function'])
set_param([sys,'/','Error rate/S-function'],...
		'function name','sbiterr',...
		'parameters','num_lin, K, TDelay, Sample',...
		'position',[130,52,195,78])

⌨️ 快捷键说明

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