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

📄 tstquant.m

📁 数字通信第四版原书的例程
💻 M
字号:
function [ret,x0,str,ts,xts]=tstquant(t,x,u,flag);
%TSTQUANT	is the M-file description of the SIMULINK system named TSTQUANT.
%	TSTQUANT has a the following characteristics:
%		0 continuous states
%		8 discrete states
%		0 outputs
%		0 inputs
%		does not have direct feedthrough
%		1 sample times
%
%	The block-diagram can be displayed by typing: TSTQUANT.
%
%	SYS=TSTQUANT(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 TSTQUANT 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 TSTQUANT with a FLAG of zero:
%	[SIZES]=TSTQUANT([],[],[],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',[87,211,629,386])
     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',   '')

add_block('built-in/Signal Generator',[sys,'/',['Signal',13,'generator']])
set_param([sys,'/',['Signal',13,'generator']],...
		'hide name',0,...
		'Peak','1.000000',...
		'Peak Range','5.000000',...
		'Freq','1.000000',...
		'Freq Range','5.000000',...
		'Wave','Sin',...
		'Units','Rads',...
		'position',[20,18,65,52])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'hide name',0,...
		'inputs','2',...
		'position',[105,26,140,59])

add_block('built-in/Signal Generator',[sys,'/',['Signal',13,'generator1']])
set_param([sys,'/',['Signal',13,'generator1']],...
		'hide name',0,...
		'Peak','1.000000',...
		'Peak Range','5.000000',...
		'Freq','1.000000',...
		'Freq Range','5.000000',...
		'Wave','Rnd',...
		'Units','Rads')
set_param([sys,'/',['Signal',13,'generator1']],...
		'position',[25,103,70,137])


%     Subsystem  ['Enabled',13,'quantizer encode'].

new_system([sys,'/',['Enabled',13,'quantizer encode']])
set_param([sys,'/',['Enabled',13,'quantizer encode']],'Location',[37,101,520,257])

add_block('built-in/Outport',[sys,'/',['Enabled',13,'quantizer encode/out_3']])
set_param([sys,'/',['Enabled',13,'quantizer encode/out_3']],...
		'Port','3',...
		'position',[385,85,405,105])

add_block('built-in/Outport',[sys,'/',['Enabled',13,'quantizer encode/out_2']])
set_param([sys,'/',['Enabled',13,'quantizer encode/out_2']],...
		'Port','2',...
		'position',[420,55,440,75])

add_block('built-in/Outport',[sys,'/',['Enabled',13,'quantizer encode/out_1']])
set_param([sys,'/',['Enabled',13,'quantizer encode/out_1']],...
		'position',[385,20,405,40])

add_block('built-in/Demux',[sys,'/',['Enabled',13,'quantizer encode/Demux']])
set_param([sys,'/',['Enabled',13,'quantizer encode/Demux']],...
		'outputs','[n n n]',...
		'position',[280,47,320,83])

add_block('built-in/S-Function',[sys,'/',['Enabled',13,'quantizer encode/S-function']])
set_param([sys,'/',['Enabled',13,'quantizer encode/S-function']],...
		'function name','simquan',...
		'parameters','n, partition, codebook',...
		'position',[190,55,240,75])

add_block('built-in/Inport',[sys,'/',['Enabled',13,'quantizer encode/in_2']])
set_param([sys,'/',['Enabled',13,'quantizer encode/in_2']],...
		'Port','2',...
		'position',[40,105,60,125])

add_block('built-in/Mux',[sys,'/',['Enabled',13,'quantizer encode/Mux']])
set_param([sys,'/',['Enabled',13,'quantizer encode/Mux']],...
		'inputs','[n 1]',...
		'position',[115,46,150,79])

add_block('built-in/Inport',[sys,'/',['Enabled',13,'quantizer encode/in_1']])
set_param([sys,'/',['Enabled',13,'quantizer encode/in_1']],...
		'position',[40,45,60,65])
add_line([sys,'/',['Enabled',13,'quantizer encode']],[325,75;340,75;340,95;380,95])
add_line([sys,'/',['Enabled',13,'quantizer encode']],[325,65;415,65])
add_line([sys,'/',['Enabled',13,'quantizer encode']],[325,55;340,55;340,30;380,30])
add_line([sys,'/',['Enabled',13,'quantizer encode']],[245,65;275,65])
add_line([sys,'/',['Enabled',13,'quantizer encode']],[155,65;185,65])
add_line([sys,'/',['Enabled',13,'quantizer encode']],[65,115;80,115;80,70;110,70])
add_line([sys,'/',['Enabled',13,'quantizer encode']],[65,55;110,55])
set_param([sys,'/',['Enabled',13,'quantizer encode']],...
		'Mask Display','plot(0,0,100,100,v,w);Quantizer',...
		'Mask Type','Scalar quantization encode')
set_param([sys,'/',['Enabled',13,'quantizer encode']],...
		'Mask Dialogue','Triggered by 2nd input signal, this block\nquantize an analog signal to (1)digital\nsignal, (2)quantization value, (3)distortion.|Quantization partition:|Quantization codebook:|Input signal vector length:')
set_param([sys,'/',['Enabled',13,'quantizer encode']],...
		'Mask Translate','partition=@1;codebook=@2;n=@3;[v,w]=trigicon(0,25,get_param(gcb,''orientation''));')
set_param([sys,'/',['Enabled',13,'quantizer encode']],...
		'Mask Help','This block quantizes the first inport signal into quantization index (1st outport), quantized value (2nd outport), and distortion (3rd outport). This block uses scalar quantization method. The input signal to the 1st inport can be a vector. The operation of this block is enabled by the non-zero signal from the second inport. When the block is not enabled, the block keeps the last output value.')
set_param([sys,'/',['Enabled',13,'quantizer encode']],...
		'Mask Entries','[-.75 -.25 .25 .75]\/[-.825 -.5 0 .5 .825]\/2\/')


%     Finished composite block ['Enabled',13,'quantizer encode'].

set_param([sys,'/',['Enabled',13,'quantizer encode']],...
		'hide name',0,...
		'position',[170,88,250,132])

add_block('built-in/Constant',[sys,'/','Constant'])
set_param([sys,'/','Constant'],...
		'hide name',0,...
		'position',[120,110,140,130])


%     Subsystem  ['Quantizer',13,'decode2'].

new_system([sys,'/',['Quantizer',13,'decode2']])
set_param([sys,'/',['Quantizer',13,'decode2']],'Location',[596,274,888,411])

add_block('built-in/S-Function',[sys,'/',['Quantizer',13,'decode2/Index lookup',13,'table']])
set_param([sys,'/',['Quantizer',13,'decode2/Index lookup',13,'table']],...
		'function name','indxtabl',...
		'parameters','codebook',...
		'Mask Display','Index\nLookup tb',...
		'Mask Type','No-intepret Lookup table')
set_param([sys,'/',['Quantizer',13,'decode2/Index lookup',13,'table']],...
		'Mask Dialogue','Output one of the values in the look-up table.|Codebook:',...
		'Mask Translate','codebook=@1;')
set_param([sys,'/',['Quantizer',13,'decode2/Index lookup',13,'table']],...
		'Mask Help','When codebook is a matrix, the block input can only be a scalar. The block output the row with the column index provided in the input. When codebook is a vector, the block output the same length as the input vector. The output is one of the values in codebook with the index provided by the input.')
set_param([sys,'/',['Quantizer',13,'decode2/Index lookup',13,'table']],...
		'Mask Entries','codebook\/',...
		'position',[105,19,165,61])

add_block('built-in/Outport',[sys,'/',['Quantizer',13,'decode2/out_1']])
set_param([sys,'/',['Quantizer',13,'decode2/out_1']],...
		'position',[225,30,245,50])

add_block('built-in/Inport',[sys,'/',['Quantizer',13,'decode2/in_1']])
set_param([sys,'/',['Quantizer',13,'decode2/in_1']],...
		'position',[20,30,40,50])
add_line([sys,'/',['Quantizer',13,'decode2']],[45,40;100,40])
add_line([sys,'/',['Quantizer',13,'decode2']],[170,40;220,40])
set_param([sys,'/',['Quantizer',13,'decode2']],...
		'Mask Display','Quantizer\ndecode',...
		'Mask Type','Scalar quantization decode')
set_param([sys,'/',['Quantizer',13,'decode2']],...
		'Mask Dialogue','Output the value in the given codebook\nbased on the input index value.|Quantization codebook:',...
		'Mask Translate','codebook=@1;')
set_param([sys,'/',['Quantizer',13,'decode2']],...
		'Mask Help','This block takes the quantized index as input and outputs the quantization value. The output vector size the is same as the input vector size. Inputs 0, 1, ..., N-1 lead to CK(1), CK(2), .. CK(N) output.')
set_param([sys,'/',['Quantizer',13,'decode2']],...
		'Mask Entries','[-.825 -.5 0, .5 .825]\/')


%     Finished composite block ['Quantizer',13,'decode2'].

set_param([sys,'/',['Quantizer',13,'decode2']],...
		'hide name',0,...
		'position',[300,53,380,97])


%     Subsystem  'Graph1'.

new_system([sys,'/','Graph1'])
set_param([sys,'/','Graph1'],'Location',[0,59,274,252])

add_block('built-in/S-Function',[sys,'/',['Graph1/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['Graph1/S-function',13,'M-file which plots',13,'lines',13,'']],...
		'function name','sfuny',...
		'parameters','ax, color,dt',...
		'position',[130,55,180,75])

add_block('built-in/Inport',[sys,'/','Graph1/x'])
set_param([sys,'/','Graph1/x'],...
		'position',[65,55,85,75])
add_line([sys,'/','Graph1'],[90,65;125,65])
set_param([sys,'/','Graph1'],...
		'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,'/','Graph1'],...
		'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,'/','Graph1'],...
		'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
set_param([sys,'/','Graph1'],...
		'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,'/','Graph1'],...
		'Mask Entries','10\/.015\/.02\/''y-/g--/y*/g*/yo/go/b+''\/')


%     Finished composite block 'Graph1'.

set_param([sys,'/','Graph1'],...
		'position',[425,106,455,144])

add_block('built-in/Mux',[sys,'/','Mux1'])
set_param([sys,'/','Mux1'],...
		'hide name',0,...
		'inputs','[2 2 2]',...
		'position',[430,38,465,72])


%     Subsystem  'Graph'.

new_system([sys,'/','Graph'])
set_param([sys,'/','Graph'],'Location',[0,59,274,252])

add_block('built-in/Inport',[sys,'/','Graph/x'])
set_param([sys,'/','Graph/x'],...
		'position',[65,55,85,75])

add_block('built-in/S-Function',[sys,'/',['Graph/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['Graph/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,'/','Graph'],[90,65;125,65])
set_param([sys,'/','Graph'],...
		'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,'/','Graph'],...
		'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,'/','Graph'],...
		'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = -1;')
set_param([sys,'/','Graph'],...
		'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,'/','Graph'],...
		'Mask Entries','10\/-1.2\/1.2\/''y-/g--/y*/g*/yo/go/b+''\/')


%     Finished composite block 'Graph'.

set_param([sys,'/','Graph'],...
		'position',[490,36,520,74])
add_line(sys,[145,120;165,120])
add_line(sys,[75,120;80,120;80,50;100,50])
add_line(sys,[145,45;425,45])
add_line(sys,[255,110;405,110;405,65;425,65])
add_line(sys,[470,55;485,55])
add_line(sys,[70,35;100,35])
add_line(sys,[255,125;420,125])
add_line(sys,[255,95;270,95;270,75;295,75])
add_line(sys,[385,75;395,75;395,55;425,55])
add_line(sys,[155,45;165,100])

drawnow

% Return any arguments.
if (nargin | nargout)
	% Must use feval here to access system in memory
	if (nargin > 3)
		if (flag == 0)
			eval(['[ret,x0,str,ts,xts]=',sys,'(t,x,u,flag);'])
		else
			eval(['ret =', sys,'(t,x,u,flag);'])
		end
	else
		[ret,x0,str,ts,xts] = feval(sys);
	end
else
	drawnow % Flash up the model and execute load callback
end

⌨️ 快捷键说明

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