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

📄 compage2.m

📁 数字通信第四版原书的例程
💻 M
字号:
function [ret,x0,str,ts,xts]=compage2(t,x,u,flag);
%COMPAGE2	is the M-file description of the SIMULINK system named COMPAGE2.
%	The block-diagram can be displayed by typing: COMPAGE2.
%
%	SYS=COMPAGE2(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 COMPAGE2 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 COMPAGE2 with a FLAG of zero:
%	[SIZES]=COMPAGE2([],[],[],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',[129,72,891,497])
     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',   '')
set_param(sys,'Load callback',['if exist(''compage1''), bdclose(''compage1'');end;']);

add_block('built-in/Note',[sys,'/','FUNCTIONALITIES'])
set_param([sys,'/','FUNCTIONALITIES'],...
		'ForeGround',2,...
		'Font Name','Arial',...
		'Font Weight','bold',...
		'Font Size',14,...
		'position',[375,10,380,15])

add_block('built-in/Note',[sys,'/','Source//Sink:'])
set_param([sys,'/','Source//Sink:'],...
		'Font Weight','bold',...
		'position',[60,55,65,60])

add_block('built-in/Note',[sys,'/','Data input; Store data; Data conversion; Data representation // display'])
set_param([sys,'/','Data input; Store data; Data conversion; Data representation // display'],...
		'position',[405,55,410,60])

add_block('built-in/Note',[sys,'/','An eye-pattern diagram example:'])
set_param([sys,'/','An eye-pattern diagram example:'],...
		'ForeGround',4,...
		'position',[300,90,305,95])

add_block('built-in/Note',[sys,'/','x = rcosflt(x,1,10);'])
set_param([sys,'/','x = rcosflt(x,1,10);'],...
		'ForeGround',4,...
		'position',[335,125,340,130])

add_block('built-in/Note',[sys,'/','x = randint(200,1,4);'])
set_param([sys,'/','x = randint(200,1,4);'],...
		'ForeGround',4,...
		'position',[340,110,345,115])

add_block('built-in/Note',[sys,'/','eyescat(x, .5, 10, 4);'])
set_param([sys,'/','eyescat(x, .5, 10, 4);'],...
		'ForeGround',4,...
		'position',[340,140,345,145])

add_block('built-in/Note',[sys,'/','Source coding:'])
set_param([sys,'/','Source coding:'],...
		'Font Weight','bold',...
		'position',[60,185,65,190])

add_block('built-in/Note',[sys,'/','Sampling; Analog-to-Digital conversion; Data compression.'])
set_param([sys,'/','Sampling; Analog-to-Digital conversion; Data compression.'],...
		'position',[370,185,375,190])

add_block('built-in/Note',[sys,'/','For example: to compress a sin signal  using delta-modulation method.'])
set_param([sys,'/','For example: to compress a sin signal  using delta-modulation method.'],...
		'ForeGround',4,...
		'position',[405,210,410,215])

add_block('built-in/Note',[sys,'/','x = sin([0 : .1 : 40]);'])
set_param([sys,'/','x = sin([0 : .1 : 40]);'],...
		'ForeGround',4,...
		'Font Name','Times New Roman',...
		'position',[331,235,336,240])

add_block('built-in/Note',[sys,'/','[p_tran, codebook, partition] = dpcmopt(x, 1, 8);'])
set_param([sys,'/','[p_tran, codebook, partition] = dpcmopt(x, 1, 8);'],...
		'ForeGround',4,...
		'Font Name','Times New Roman',...
		'position',[406,255,411,260])

add_block('built-in/Note',[sys,'/','sig=sin(x*pi//3);'])
set_param([sys,'/','sig=sin(x*pi//3);'],...
		'ForeGround',4,...
		'Font Name','Times New Roman',...
		'position',[321,275,326,280])

add_block('built-in/Note',[sys,'/','indx = dpcmenco(sig, codebook, partition, p_tran); '])
set_param([sys,'/','indx = dpcmenco(sig, codebook, partition, p_tran); '],...
		'ForeGround',4,...
		'Font Name','Times New Roman',...
		'position',[416,295,421,300])

add_block('built-in/Note',[sys,'/','quant = dpcmdeco(indx, codebook, p_tran);'])
set_param([sys,'/','quant = dpcmdeco(indx, codebook, p_tran);'],...
		'ForeGround',4,...
		'Font Name','Times New Roman',...
		'position',[396,320,401,325])

add_block('built-in/Note',[sys,'/',['subplot(212); plot([sig; quant]'')']])
set_param([sys,'/',['subplot(212); plot([sig; quant]'')']],...
		'ForeGround',4,...
		'Font Name','Times New Roman',...
		'position',[361,370,366,375])

add_block('built-in/Note',[sys,'/','subplot(211); plot(indx);'])
set_param([sys,'/','subplot(211); plot(indx);'],...
		'ForeGround',4,...
		'Font Name','Times New Roman',...
		'position',[341,345,346,350])


%     Subsystem  ['Click to see',13,'results'].

new_system([sys,'/',['Click to see',13,'results']])
set_param([sys,'/',['Click to see',13,'results']],'Location',[111,168,452,354])
set_param([sys,'/',['Click to see',13,'results']],...
		'Mask Display','DPCM\nexample')
set_param([sys,'/',['Click to see',13,'results']],...
		'Mask Dialogue','eval(''x=sin([0:.1:40]);[pt,co,pa]=dpcmopt(x,1,8);sig=sin(x*pi/3);id=dpcmenco(sig,co,pa,pt);qu=dpcmdeco(id,co,pt);subplot(211);plot(id);subplot(212);plot([sig;qu]'''');'')')


%     Finished composite block ['Click to see',13,'results'].

set_param([sys,'/',['Click to see',13,'results']],...
		'BackGround',7,...
		'hide name',0,...
		'position',[650,218,720,271])


%     Subsystem  ['Click to see',13,'results1'].

new_system([sys,'/',['Click to see',13,'results1']])
set_param([sys,'/',['Click to see',13,'results1']],'Location',[111,168,452,354])
set_param([sys,'/',['Click to see',13,'results1']],...
		'Mask Display','Eye\ndiagram\nexample',...
		'Mask Dialogue','eval(''x=randint(200,1,4);x=rcosflt(x,1,10);eyescat(x,.5,10,4);'')')


%     Finished composite block ['Click to see',13,'results1'].

set_param([sys,'/',['Click to see',13,'results1']],...
		'BackGround',7,...
		'hide name',0,...
		'position',[645,88,715,141])

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