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

📄 tstquans.m

📁 数字通信第四版原书的例程
💻 M
字号:
function [ret,x0,str,ts,xts]=tstquans(t,x,u,flag);
%TSTQUANS	is the M-file description of the SIMULINK system named TSTQUANS.
%	The block-diagram can be displayed by typing: TSTQUANS.
%
%	SYS=TSTQUANS(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 TSTQUANS 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 TSTQUANS with a FLAG of zero:
%	[SIZES]=TSTQUANS([],[],[],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',[26,497,577,677])
     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/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',[20,98,65,132])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'hide name',0,...
		'inputs','2',...
		'position',[100,21,135,54])

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',[15,13,60,47])


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

new_system([sys,'/',['Sampled',13,'quantizer encode']])
set_param([sys,'/',['Sampled',13,'quantizer encode']],'Location',[37,120,369,253])

add_block('built-in/S-Function',[sys,'/',['Sampled',13,'quantizer encode/S-function']])
set_param([sys,'/',['Sampled',13,'quantizer encode/S-function']],...
		'function name','simquans',...
		'parameters','n, partition, codebook,sample_time',...
		'position',[80,55,135,75])

add_block('built-in/Demux',[sys,'/',['Sampled',13,'quantizer encode/Demux']])
set_param([sys,'/',['Sampled',13,'quantizer encode/Demux']],...
		'outputs','[n n n]',...
		'position',[175,47,215,83])

add_block('built-in/Inport',[sys,'/',['Sampled',13,'quantizer encode/in_1']])
set_param([sys,'/',['Sampled',13,'quantizer encode/in_1']],...
		'position',[15,55,35,75])

add_block('built-in/Outport',[sys,'/',['Sampled',13,'quantizer encode/out_1']])
set_param([sys,'/',['Sampled',13,'quantizer encode/out_1']],...
		'position',[260,20,280,40])

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

add_block('built-in/Outport',[sys,'/',['Sampled',13,'quantizer encode/out_3']])
set_param([sys,'/',['Sampled',13,'quantizer encode/out_3']],...
		'Port','3',...
		'position',[255,85,275,105])
add_line([sys,'/',['Sampled',13,'quantizer encode']],[40,65;75,65])
add_line([sys,'/',['Sampled',13,'quantizer encode']],[140,65;170,65])
add_line([sys,'/',['Sampled',13,'quantizer encode']],[220,55;235,55;235,30;255,30])
add_line([sys,'/',['Sampled',13,'quantizer encode']],[220,65;285,65])
add_line([sys,'/',['Sampled',13,'quantizer encode']],[220,75;235,75;235,95;250,95])
set_param([sys,'/',['Sampled',13,'quantizer encode']],...
		'Mask Display','Scalar\nquantizer',...
		'Mask Type','Scalar quantization encode')
set_param([sys,'/',['Sampled',13,'quantizer encode']],...
		'Mask Dialogue','Quantize an analog signal to (1)digital\nsignal, (2)quantization value, and (3)distor-\ntion at every sample time point.|Quantization partition:|Quantization codebook:|Input signal vector length:|Sample time (sec):')
set_param([sys,'/',['Sampled',13,'quantizer encode']],...
		'Mask Translate','partition=@1;codebook=@2;n=@3;sample_time=@4;')
set_param([sys,'/',['Sampled',13,'quantizer encode']],...
		'Mask Help','This block converts the input analog signal to digital signal (1st outport) with the quantized value (2nd outport), and distortion (3rd outport) at every sample point. The input signa can be a vector. When the sample time is a two-elements vector, the second element is the offset value. The length of the partition is one less than the length of codebook. Use LLOYDS to optimize the partition and codebook.')
set_param([sys,'/',['Sampled',13,'quantizer encode']],...
		'Mask Entries','[-.75 -.25 .25 .75]\/[-.825 -.5 0 .5 .825]\/2\/.1\/')


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

set_param([sys,'/',['Sampled',13,'quantizer encode']],...
		'hide name',0,...
		'position',[175,98,255,142])


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

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

add_block('built-in/Inport',[sys,'/',['Quantizer',13,'decode/in_1']])
set_param([sys,'/',['Quantizer',13,'decode/in_1']],...
		'position',[20,30,40,50])

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

add_block('built-in/S-Function',[sys,'/',['Quantizer',13,'decode/Index lookup',13,'table']])
set_param([sys,'/',['Quantizer',13,'decode/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,'decode/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,'decode/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,'decode/Index lookup',13,'table']],...
		'Mask Entries','codebook\/',...
		'position',[105,19,165,61])
add_line([sys,'/',['Quantizer',13,'decode']],[170,40;220,40])
add_line([sys,'/',['Quantizer',13,'decode']],[45,40;100,40])
set_param([sys,'/',['Quantizer',13,'decode']],...
		'Mask Display','Quantizer\ndecode',...
		'Mask Type','Scalar quantization decode')
set_param([sys,'/',['Quantizer',13,'decode']],...
		'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,'decode']],...
		'Mask Help','This block takes the quantized index as input and outputs the quantization value. The output vector size is the 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,'decode']],...
		'Mask Entries','[-.825 -.5 0, .5 .825]\/')


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

set_param([sys,'/',['Quantizer',13,'decode']],...
		'hide name',0,...
		'position',[295,48,375,92])

add_block('built-in/Mux',[sys,'/','Mux1'])
set_param([sys,'/','Mux1'],...
		'hide name',0,...
		'inputs','[2 2 2]',...
		'position',[435,33,470,67])


%     Subsystem  'Graph'.

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

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_block('built-in/Inport',[sys,'/','Graph/x'])
set_param([sys,'/','Graph/x'],...
		'position',[65,55,85,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'],...
		'hide name',0,...
		'position',[500,31,530,69])


%     Subsystem  'Graph1'.

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

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

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_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'],...
		'hide name',0,...
		'position',[420,116,450,154])
add_line(sys,[140,40;430,40])
add_line(sys,[150,40;150,120;170,120])
add_line(sys,[380,70;390,70;390,50;430,50])
add_line(sys,[65,30;95,30])
add_line(sys,[475,50;495,50])
add_line(sys,[70,115;75,115;75,45;95,45])
add_line(sys,[260,105;275,105;275,70;290,70])
add_line(sys,[260,120;400,120;400,60;430,60])
add_line(sys,[260,135;415,135])

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 + -