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

📄 tstbchsq.m

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

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'hide name',0,...
		'inputs','2',...
		'position',[595,81,625,114])


%     Subsystem  ['Placed and',13,'detected errors'].

new_system([sys,'/',['Placed and',13,'detected errors']])
set_param([sys,'/',['Placed and',13,'detected errors']],'Location',[0,59,274,252])

add_block('built-in/Inport',[sys,'/',['Placed and',13,'detected errors/x']])
set_param([sys,'/',['Placed and',13,'detected errors/x']],...
		'position',[65,55,85,75])

add_block('built-in/S-Function',[sys,'/',['Placed and',13,'detected errors/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['Placed and',13,'detected errors/S-function',13,'M-file which plots',13,'lines',13,'']],...
		'function name','sfuny',...
		'parameters','ax, color,dt',...
		'position',[130,55,180,75])
add_line([sys,'/',['Placed and',13,'detected errors']],[90,65;125,65])
set_param([sys,'/',['Placed and',13,'detected errors']],...
		'Mask Display','plot(0,0,100,100,[90,10,10,10,90,90,10],[65,65,90,40,40,90,90],[90,78,69,54,40,31,25,10],[77,60,48,46,56,75,81,84])',...
		'Mask Type','Graph scope.')
set_param([sys,'/',['Placed and',13,'detected errors']],...
		'Mask Dialogue','Graph scope using MATLAB graph window.\nEnter plotting ranges and line type.|Time range:|y-min:|y-max:|Line type (rgbw-:*). Seperate each plot by ''/'':')
set_param([sys,'/',['Placed and',13,'detected errors']],...
		'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
set_param([sys,'/',['Placed and',13,'detected errors']],...
		'Mask Help','This block plots to the MATLAB graph window and can be used as an improved version of the Scope block. Look at the m-file sfuny.m to see how it works. This block can take scalar or vector input signal.')
set_param([sys,'/',['Placed and',13,'detected errors']],...
		'Mask Entries','5\/-1.1\/5\/''r-/g--/c-./w:/m*/ro/b+''\/')


%     Finished composite block ['Placed and',13,'detected errors'].

set_param([sys,'/',['Placed and',13,'detected errors']],...
		'position',[650,81,680,119])


%     Subsystem  'Error rate1'.

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

add_block('built-in/Inport',[sys,'/','Error rate1/in_2'])
set_param([sys,'/','Error rate1/in_2'],...
		'Port','2',...
		'position',[15,60,35,80])

add_block('built-in/Inport',[sys,'/','Error rate1/in_1'])
set_param([sys,'/','Error rate1/in_1'],...
		'position',[15,45,35,65])

add_block('built-in/Mux',[sys,'/','Error rate1/Mux'])
set_param([sys,'/','Error rate1/Mux'],...
		'inputs','2',...
		'position',[65,46,100,79])

add_block('built-in/S-Function',[sys,'/','Error rate1/S-function'])
set_param([sys,'/','Error rate1/S-function'],...
		'function name','sbiterr',...
		'parameters','num_lin, K, TDelay, Sample',...
		'position',[130,52,195,78])
add_line([sys,'/','Error rate1'],[40,70;60,70])
add_line([sys,'/','Error rate1'],[40,55;60,55])
add_line([sys,'/','Error rate1'],[105,65;125,65])
set_param([sys,'/','Error rate1'],...
		'Mask Display','Error\nmeter',...
		'Mask Type','Symbol/bit error counter')
set_param([sys,'/','Error rate1'],...
		'Mask Dialogue','Use the input data from the 1st port as the reference signal to detect the number of errors and error rate of the 2nd port inputted signal.|Bit per symbol:|Number of digits on display:|Delay between input (1st port) and output (2nd port):|Sampling time (sec):')
set_param([sys,'/','Error rate1'],...
		'Mask Translate','K=@1;num_lin=@2;TDelay=@3;Sample=@4;')
set_param([sys,'/','Error rate1'],...
		'Mask Help','The signal from the first port must be a scalar. The second input port can be a vector with a same-time delay to the input signal. The comparison happens only at the sampling point.')
set_param([sys,'/','Error rate1'],...
		'Mask Entries','1\/20\/2\/1/K_bch_demo\/')


%     Finished composite block 'Error rate1'.

set_param([sys,'/','Error rate1'],...
		'hide name',0,...
		'position',[530,23,610,67])


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

new_system([sys,'/',['Binary sequence',13,'BCH decode']])
set_param([sys,'/',['Binary sequence',13,'BCH decode']],'Location',[88,100,698,253])


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

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

add_block('built-in/Memory',[sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode/Memory']])
set_param([sys,'/',['Binary sequence',13,'BCH decode/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 sequence',13,'BCH decode/Binary-vector',13,'BCH decode/Switch']])
set_param([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode/Switch']],...
		'Threshold','0.5',...
		'position',[295,44,325,76])

add_block('built-in/S-Function',[sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode/S-function']])
set_param([sys,'/',['Binary sequence',13,'BCH decode/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 sequence',13,'BCH decode/Binary-vector',13,'BCH decode/Mux']])
set_param([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode/Mux']],...
		'inputs','[n, 1]',...
		'position',[80,41,115,74])

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

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

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

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

add_block('built-in/Outport',[sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode/out_2']])
set_param([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode/out_2']],...
		'Port','2',...
		'position',[495,95,515,115])
add_line([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],[330,60;390,60])
add_line([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],[360,60;360,110;340,110])
add_line([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],[290,110;255,110;255,70;290,70])
add_line([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],[240,30;255,30;255,50;290,50])
add_line([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],[45,25;60,25;60,50;75,50])
add_line([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],[120,60;150,60;150,30;165,30])
add_line([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],[35,110;200,110;200,60;290,60])
add_line([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],[60,110;60,65;75,65])
add_line([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],[440,50;455,50;455,40;490,40])
add_line([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],[440,65;455,65;455,105;490,105])
set_param([sys,'/',['Binary sequence',13,'BCH decode/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 sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],...
		'Mask Dialogue','Codeword length N, message length K, T\nerror-correction BCH decode. (N,K,T) must be a valid BCH code combination.|Codeword length (N=2^M-1. M is a >2 integer):|Message length K (check BCHPOLY for valid K):|Error-correction capability (0 for unknown):')
set_param([sys,'/',['Binary sequence',13,'BCH decode/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 sequence',13,'BCH decode/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 only if the enable signal at the second inport is high. The second outport outputs the error detected in the process. A negative output indicates more error than the capability.')
set_param([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],...
		'Mask Entries','n\/k\/t\/')


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

set_param([sys,'/',['Binary sequence',13,'BCH decode/Binary-vector',13,'BCH decode']],...
		'hide name',0,...
		'position',[275,26,345,64])

add_block('built-in/Outport',[sys,'/',['Binary sequence',13,'BCH decode/out_2']])
set_param([sys,'/',['Binary sequence',13,'BCH decode/out_2']],...
		'hide name',0,...
		'Port','2',...
		'position',[370,45,390,65])


%     Subsystem  ['Binary sequence',13,'BCH decode/Triggered',13,'buffer down'].

new_system([sys,'/',['Binary sequence',13,'BCH decode/Triggered',13,'buffer down']])
set_param([sys,'/',['Binary sequence',13,'BCH decode/Triggered',13,'buffer down']],'Location',[306,291,744,461])

add_block('built-in/Outport',[sys,'/',['Binary sequence',13,'BCH decode/Triggered',13,'buffer down/out_1']])
set_param([sys,'/',['Binary sequence',13,'BCH decode/Triggered',13,'buffer down/out_1']],...
		'position',[390,60,410,80])

⌨️ 快捷键说明

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