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

📄 test_fm2.m

📁 数字通信第四版原书的例程
💻 M
📖 第 1 页 / 共 3 页
字号:
function [ret,x0,str,ts,xts]=test_fm2(t,x,u,flag);
%TEST_FM2	is the M-file description of the SIMULINK system named TEST_FM2.
%	The block-diagram can be displayed by typing: TEST_FM2.
%
%	SYS=TEST_FM2(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 TEST_FM2 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 TEST_FM2 with a FLAG of zero:
%	[SIZES]=TEST_FM2([],[],[],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',[465,332,989,549])
     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.01')
set_param(sys,'Max step size', '0.01')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')
set_param(sys,'Load callback','ts=.01;[num,den]=butter(2,100/pi/2*ts);');

add_block('built-in/Signal Generator',[sys,'/',['Signal',13,'generator']])
set_param([sys,'/',['Signal',13,'generator']],...
		'ForeGround',5,...
		'hide name',0,...
		'Peak','1.000000',...
		'Peak Range','5.000000',...
		'Freq','3.000000',...
		'Freq Range','6.000000',...
		'Wave','Saw',...
		'Units','Rads')
set_param([sys,'/',['Signal',13,'generator']],...
		'position',[30,43,75,77])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'hide name',0,...
		'inputs','3',...
		'position',[385,35,420,85])


%     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 ''/'':|Sample time:')
set_param([sys,'/','Graph'],...
		'Mask Translate','color = @4; ax = [0, @1, @2, @3]; dt = @5;')
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','4\/-1.5\/1.5\/''y-/g--/r-/m:/w-/r:/b+''\/ts\/')


%     Finished composite block 'Graph'.

set_param([sys,'/','Graph'],...
		'hide name',0,...
		'position',[450,41,480,79])


%     Subsystem  ['FM',13,'passband'].

new_system([sys,'/',['FM',13,'passband']])
set_param([sys,'/',['FM',13,'passband']],'Location',[451,587,939,737])

add_block('built-in/Sum',[sys,'/',['FM',13,'passband/Sum']])
set_param([sys,'/',['FM',13,'passband/Sum']],...
		'position',[130,42,150,78])

add_block('built-in/S-Function',[sys,'/',['FM',13,'passband/Scheduled',13,'reset-int']])
set_param([sys,'/',['FM',13,'passband/Scheduled',13,'reset-int']],...
		'function name','schdint',...
		'parameters','td, ts, limit',...
		'Mask Display','Schdld\nreset-int',...
		'Mask Type','Scheduled reset integration.')
set_param([sys,'/',['FM',13,'passband/Scheduled',13,'reset-int']],...
		'Mask Dialogue','Reset the state to be zero(s) at the scheduled reset point.|Scheduled reset time inteval and offset:|Sample time and offset:|Modulo bound:')
set_param([sys,'/',['FM',13,'passband/Scheduled',13,'reset-int']],...
		'Mask Translate','td=@1;ts=@2;limit=@3;')
set_param([sys,'/',['FM',13,'passband/Scheduled',13,'reset-int']],...
		'Mask Help','This block resets the state(s) to be zero(s) at the begining of reset time inteval. The reset inteval can be a two elements vector with the second element being offset.')
set_param([sys,'/',['FM',13,'passband/Scheduled',13,'reset-int']],...
		'Mask Entries','td\/ts\/Inf/2\/',...
		'position',[200,39,260,81])

add_block('built-in/Constant',[sys,'/',['FM',13,'passband/Constant']])
set_param([sys,'/',['FM',13,'passband/Constant']],...
		'Value','Fc',...
		'position',[40,85,60,105])

add_block('built-in/Fcn',[sys,'/',['FM',13,'passband/sin']])
set_param([sys,'/',['FM',13,'passband/sin']],...
		'Expr','cos(u[1]*pi2+Ph)',...
		'position',[290,45,430,75])

add_block('built-in/Outport',[sys,'/',['FM',13,'passband/out_1']])
set_param([sys,'/',['FM',13,'passband/out_1']],...
		'position',[465,50,485,70])

add_block('built-in/Inport',[sys,'/',['FM',13,'passband/in_1']])
set_param([sys,'/',['FM',13,'passband/in_1']],...
		'position',[60,40,80,60])
add_line([sys,'/',['FM',13,'passband']],[85,50;125,50])
add_line([sys,'/',['FM',13,'passband']],[65,95;90,95;90,70;125,70])
add_line([sys,'/',['FM',13,'passband']],[155,60;195,60])
add_line([sys,'/',['FM',13,'passband']],[265,60;285,60])
add_line([sys,'/',['FM',13,'passband']],[435,60;460,60])
set_param([sys,'/',['FM',13,'passband']],...
		'Mask Display','plot(0,0,100,100,x,y);FM',...
		'Mask Type','Passband FM')
set_param([sys,'/',['FM',13,'passband']],...
		'Mask Dialogue','Modulate the input signal using FM method.|Carrier frequency (Hz):|Initial phase (rad):|Sample time (sec):|Symbol interval (sec; Use Inf for analog mod);')
set_param([sys,'/',['FM',13,'passband']],...
		'Mask Translate','Fc=@1;Ph=@2;pi2=2*pi;ts=@3;td=@4;if isinf(td),td=inf;end;[x,y]=moduicon(3);')
set_param([sys,'/',['FM',13,'passband']],...
		'Mask Help','This block modulates the input signal using frequency modulation method. The frequency of the output of the carrier signal depends on the amplitude of the input signal.')
set_param([sys,'/',['FM',13,'passband']],...
		'Mask Entries','100/2/pi\/pi/4\/ts\/Inf\/')


%     Finished composite block ['FM',13,'passband'].

set_param([sys,'/',['FM',13,'passband']],...
		'ForeGround',3,...
		'hide name',0,...
		'position',[135,38,215,82])


%     Subsystem  ['FDM',13,'passband'].

new_system([sys,'/',['FDM',13,'passband']])
set_param([sys,'/',['FDM',13,'passband']],'Location',[30,490,489,666])

add_block('built-in/Inport',[sys,'/',['FDM',13,'passband/in_1']])
set_param([sys,'/',['FDM',13,'passband/in_1']],...
		'position',[25,30,45,50])

add_block('built-in/Outport',[sys,'/',['FDM',13,'passband/out_1']])
set_param([sys,'/',['FDM',13,'passband/out_1']],...
		'position',[420,35,440,55])


%     Subsystem  ['FDM',13,'passband/Discrete-time',13,'VCO'].

new_system([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO']])
set_param([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO']],'Location',[93,129,873,276])

add_block('built-in/Inport',[sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/in_1']])
set_param([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/in_1']],...
		'position',[35,20,55,40])

add_block('built-in/Unit Delay',[sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Unit Delay']])
set_param([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Unit Delay']],...
		'Sample time','ts',...
		'position',[300,25,350,45])

add_block('built-in/Sum',[sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Sum1']])
set_param([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Sum1']],...
		'position',[230,25,250,45])

add_block('built-in/Gain',[sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Sensitivity']])
set_param([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Sensitivity']],...
		'Gain','Kc',...
		'position',[105,15,155,45])

add_block('built-in/Clock',[sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Clock']])
set_param([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Clock']],...
		'position',[180,80,200,100])

add_block('built-in/Gain',[sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Sensitivity2']])
set_param([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Sensitivity2']],...
		'Gain','Fc',...
		'position',[255,75,300,105])

add_block('built-in/Sum',[sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Sum']])
set_param([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Sum']],...
		'inputs','+++',...
		'position',[465,27,485,63])

add_block('built-in/Constant',[sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Phase']])
set_param([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Phase']],...
		'Value','Ph',...
		'position',[400,100,420,120])

add_block('built-in/Fcn',[sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/sin']])
set_param([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/sin']],...
		'Expr','cos(u[1])',...
		'position',[510,32,585,58])

add_block('built-in/Gain',[sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Sensitivity3']])
set_param([sys,'/',['FDM',13,'passband/Discrete-time',13,'VCO/Sensitivity3']],...
		'Gain','Ac',...

⌨️ 快捷键说明

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