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

📄 xtsh.m

📁 信号实验常用的simulink模型和mfile,可直接在matlan下运行。
💻 M
字号:
function [ret,x0,str,ts,xts]=xtsh(t,x,u,flag);
%XTSH	is the M-file description of the SIMULINK system named XTSH.
%	The block-diagram can be displayed by typing: XTSH.
%
%	SYS=XTSH(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 XTSH 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 XTSH with a FLAG of zero:
%	[SIZES]=XTSH([],[],[],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',[9,141,401,427])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
set_param(sys,'Start time',    '0')
set_param(sys,'Stop time',     '4')
set_param(sys,'Min step size', '1e-6')
set_param(sys,'Max step size', '0.1')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')

add_block('built-in/Transfer Fcn',[sys,'/','二阶系统'])
set_param([sys,'/','二阶系统'],...
		'Font Name','宋体',...
		'Drop Shadow',4,...
		'Denominator','[L*C R*C 1]')
set_param([sys,'/','二阶系统'],...
		'Mask Display','plot([3 5 5 5],[2 2 1.5 2.5],[5 9],[2.5 2.5],[5 9],[1.5 1.5],[9 9],[2.5 1.5],[9 11],[2 2],[11:1/7:12],[2 2.5 2.707 2.866 2.866 2.707 2.5 2],[12:1/7:13],[2 2.5 2.707 2.866 2.866 2.707 2.5 2],[13:1/7:14],[2 2.5 2.707 2.866 2.866 2.707 2.5 2],[14:1/7:15],[2 2.5 2.707 2.866 2.866 2.707 2.5 2],[15 21],[2 2],[18 18 16 20],[2 0 0 0],[16 20],[-1 -1],[18 18 17 19],[-1 -3 -3 -3]);')
set_param([sys,'/','二阶系统'],...
		'Mask Type',' 单元7',...
		'Mask Dialogue',' 单元7|电阻值(欧):|电感值(亨):|电容值(法):',...
		'Mask Translate','R=@1;L=@2;C=@3;',...
		'Mask Entries','50\/1\/.0001\/')
set_param([sys,'/','二阶系统'],...
		'position',[155,202,245,248])

add_block('built-in/Scope',[sys,'/',['示波器',13,'(输出信号)']])
set_param([sys,'/',['示波器',13,'(输出信号)']],...
		'Font Name','宋体',...
		'Vgain','10.000000',...
		'Hgain','2.000000',...
		'Vmax','20.000000',...
		'Hmax','4.000000',...
		'Window',[292,238,635,441])
open_system([sys,'/',['示波器',13,'(输出信号)']])
set_param([sys,'/',['示波器',13,'(输出信号)']],...
		'position',[310,207,340,243])


%     Subsystem  ['频谱分析仪',13,'(系统的频率特性)'].

new_system([sys,'/',['频谱分析仪',13,'(系统的频率特性)']])
set_param([sys,'/',['频谱分析仪',13,'(系统的频率特性)']],'Location',[0,0,371,185])

add_block('built-in/Mux',[sys,'/',['频谱分析仪',13,'(系统的频率特性)/Mux']])
set_param([sys,'/',['频谱分析仪',13,'(系统的频率特性)/Mux']],...
		'inputs','2',...
		'position',[145,71,175,104])

add_block('built-in/Inport',[sys,'/',['频谱分析仪',13,'(系统的频率特性)/system output']])
set_param([sys,'/',['频谱分析仪',13,'(系统的频率特性)/system output']],...
		'Port','2',...
		'position',[55,110,75,130])

add_block('built-in/S-Function',[sys,'/',['频谱分析仪',13,'(系统的频率特性)/S-function block',13,'which calls M-file']])
set_param([sys,'/',['频谱分析仪',13,'(系统的频率特性)/S-function block',13,'which calls M-file']],...
		'function name','sfuntf',...
		'parameters','fftpts,npts,HowOften,offset,ts,0',...
		'position',[250,72,295,108])

add_block('built-in/Inport',[sys,'/',['频谱分析仪',13,'(系统的频率特性)/system input']])
set_param([sys,'/',['频谱分析仪',13,'(系统的频率特性)/system input']],...
		'position',[55,30,75,50])
add_line([sys,'/',['频谱分析仪',13,'(系统的频率特性)']],[80,120;110,120;110,95;140,95])
add_line([sys,'/',['频谱分析仪',13,'(系统的频率特性)']],[80,40;110,40;110,80;140,80])
add_line([sys,'/',['频谱分析仪',13,'(系统的频率特性)']],[180,90;245,90])
set_param([sys,'/',['频谱分析仪',13,'(系统的频率特性)']],...
		'Mask Display','plot(0,0,100,100,[11,93,93,11,11],[90,90,40,40,90],[90,80,72,64,55,45,41,36,20],[50,50,52,59,67,75,78,80,80])',...
		'Mask Type','Spectrum analyzer.')
set_param([sys,'/',['频谱分析仪',13,'(系统的频率特性)']],...
		'Mask Dialogue','Spectrum analyser using graph window.\nHook input 1 to system input.\nHook input 2 to system output.|Length of buffer:|Number of points for fft:|Plot after how many points:|Sample time:')
set_param([sys,'/',['频谱分析仪',13,'(系统的频率特性)']],...
		'Mask Translate','npts=@1; fftpts=@2; HowOften=@3; ts=@4(1); if length(@4) > 1, offset = @4(2), else, offset = 0; end')
set_param([sys,'/',['频谱分析仪',13,'(系统的频率特性)']],...
		'Mask Help','Hook the system''s input to the first port of this block and the system''s output to second port. Results are displayed as the frequency response of this system. Use signals with high harmonic content for best results. ')
set_param([sys,'/',['频谱分析仪',13,'(系统的频率特性)']],...
		'Mask Entries','1024\/1024\/200\/0.005\/')


%     Finished composite block ['频谱分析仪',13,'(系统的频率特性)'].

set_param([sys,'/',['频谱分析仪',13,'(系统的频率特性)']],...
		'Font Name','宋体',...
		'Drop Shadow',4,...
		'position',[310,142,340,178])


%     Subsystem  '信号1'.

new_system([sys,'/','信号1'])
set_param([sys,'/','信号1'],'Location',[4,224,189,379])

add_block('built-in/Constant',[sys,'/','信号1/常数'])
set_param([sys,'/','信号1/常数'],...
		'Font Name','宋体',...
		'position',[45,41,65,69])

add_block('built-in/Sine Wave',[sys,'/','信号1/调制信号1'])
set_param([sys,'/','信号1/调制信号1'],...
		'Font Name','宋体',...
		'frequency','10',...
		'position',[45,92,70,118])

add_block('built-in/Gain',[sys,'/','信号1/放大器'])
set_param([sys,'/','信号1/放大器'],...
		'Font Name','宋体',...
		'Gain','0.5',...
		'position',[85,90,110,120])

add_block('built-in/Sum',[sys,'/','信号1/加法器'])
set_param([sys,'/','信号1/加法器'],...
		'Font Name','宋体',...
		'position',[135,49,155,76])

add_block('built-in/Outport',[sys,'/','信号1/out_1'])
set_param([sys,'/','信号1/out_1'],...
		'position',[185,55,205,75])
add_line([sys,'/','信号1'],[70,55;130,55])
add_line([sys,'/','信号1'],[115,105;115,70;130,70])
add_line([sys,'/','信号1'],[75,105;80,105])
add_line([sys,'/','信号1'],[160,65;180,65])


%     Finished composite block '信号1'.

set_param([sys,'/','信号1'],...
		'position',[40,130,65,160])

add_block('built-in/Sine Wave',[sys,'/',' 载波'])
set_param([sys,'/',' 载波'],...
		'Font Name','宋体',...
		'frequency','100',...
		'position',[40,76,65,104])


%     Subsystem  '信号2'.

new_system([sys,'/','信号2'])
set_param([sys,'/','信号2'],'Location',[158,441,759,682])

add_block('built-in/Unit Delay',[sys,'/','信号2/Unit Delay1'])
set_param([sys,'/','信号2/Unit Delay1'],...
		'orientation',2,...
		'Sample time','[Ts,st2]',...
		'x0','ini',...
		'position',[140,165,190,185])

add_block('built-in/Unit Delay',[sys,'/','信号2/Unit Delay'])
set_param([sys,'/','信号2/Unit Delay'],...
		'orientation',2,...
		'Sample time','[Ts,st1]',...
		'position',[145,75,195,95])

add_block('built-in/Constant',[sys,'/','信号2/Constant'])
set_param([sys,'/','信号2/Constant'],...
		'position',[25,30,45,50])

add_block('built-in/Sum',[sys,'/','信号2/Sum'])
set_param([sys,'/','信号2/Sum'],...
		'hide name',0,...
		'inputs','+-',...
		'position',[135,35,155,55])

add_block('built-in/Sum',[sys,'/','信号2/Sum1'])
set_param([sys,'/','信号2/Sum1'],...
		'hide name',0,...
		'inputs','+-',...
		'position',[130,120,150,140])

add_block('built-in/Relational Operator',[sys,'/',['信号2/Relational',13,'operator']])
set_param([sys,'/',['信号2/Relational',13,'operator']],...
		'hide name',0,...
		'position',[370,102,400,133])

add_block('built-in/Clock',[sys,'/','信号2/Clock1'])
set_param([sys,'/','信号2/Clock1'],...
		'hide name',0,...
		'position',[295,100,315,120])

add_block('built-in/Constant',[sys,'/','信号2/Constant1'])
set_param([sys,'/','信号2/Constant1'],...
		'Value','stt',...
		'position',[295,149,320,171])

add_block('built-in/Logical Operator',[sys,'/',['信号2/Logical',13,'Operator']])
set_param([sys,'/',['信号2/Logical',13,'Operator']],...
		'Operator','XOR',...
		'position',[285,38,315,62])

add_block('built-in/Logical Operator',[sys,'/',['信号2/Logical',13,'Operator1']])
set_param([sys,'/',['信号2/Logical',13,'Operator1']],...
		'Operator','NOT',...
		'Number of Input Ports','1',...
		'position',[355,38,385,62])

add_block('built-in/Product',[sys,'/','信号2/Product'])
set_param([sys,'/','信号2/Product'],...
		'hide name',0,...
		'position',[455,105,480,125])

add_block('built-in/Gain',[sys,'/','信号2/Gain'])
set_param([sys,'/','信号2/Gain'],...
		'hide name',0,...
		'Gain','ht',...
		'position',[510,102,535,128])

add_block('built-in/Outport',[sys,'/','信号2/out_1'])
set_param([sys,'/','信号2/out_1'],...
		'hide name',0,...
		'position',[560,105,580,125])
add_line([sys,'/','信号2'],[155,130;245,130;245,55;280,55])
add_line([sys,'/','信号2'],[160,45;280,45])
add_line([sys,'/','信号2'],[50,40;70,40;70,125;125,125])
add_line([sys,'/','信号2'],[135,175;100,175;100,135;125,135])
add_line([sys,'/','信号2'],[155,130;210,130;210,175;195,175])
add_line([sys,'/','信号2'],[50,40;130,40])
add_line([sys,'/','信号2'],[160,45;230,45;230,85;200,85])
add_line([sys,'/','信号2'],[140,85;105,85;105,50;130,50])
add_line([sys,'/','信号2'],[320,110;365,110])
add_line([sys,'/','信号2'],[405,120;450,120])
add_line([sys,'/','信号2'],[485,115;505,115])
add_line([sys,'/','信号2'],[540,115;555,115])
add_line([sys,'/','信号2'],[325,160;345,160;345,125;365,125])
add_line([sys,'/','信号2'],[320,50;350,50])
add_line([sys,'/','信号2'],[390,50;430,50;430,110;450,110])
set_param([sys,'/','信号2'],...
		'Mask Display','plot(0,0,100,100,[90,75,75,60,60,35,35,20,20,10],[20,20,80,80,20,20,80,80,20,20])',...
		'Mask Type','Pulse Generator')
set_param([sys,'/','信号2'],...
		'Mask Dialogue','Pulse Generator.|Pulse period (secs):|Pulse width:|Pulse height:|Pulse start time:')
set_param([sys,'/','信号2'],...
		'Mask Translate','Ts=@1; du=@2; ht=@3; stt=@4; ini=ones(length(ht),1); st1=rem(stt,Ts); st2=rem(stt+du,Ts);if(Ts<=1.2*du),ini=zeros(length(ht),1);end;')
set_param([sys,'/','信号2'],...
		'Mask Help','Pulse generator which ensures pulse\ntransitions are hit. Provides a vector of pulses when the height is entered as a vector.\nUnmask to see how it works.',...
		'Mask Entries','1\/.5\/1\/0.1\/')


%     Finished composite block '信号2'.

set_param([sys,'/','信号2'],...
		'Font Name','宋体',...
		'position',[40,191,65,219])

add_block('built-in/Scope',[sys,'/',['示波器',13,'(输入信号)']])
set_param([sys,'/',['示波器',13,'(输入信号)']],...
		'Font Name','宋体',...
		'Vgain','2.000000',...
		'Hgain','2.000000',...
		'Vmax','4.000000',...
		'Hmax','4.000000',...
		'Window',[292,37,635,242])
open_system([sys,'/',['示波器',13,'(输入信号)']])
set_param([sys,'/',['示波器',13,'(输入信号)']],...
		'position',[310,82,340,118])

add_block('built-in/Product',[sys,'/','乘法器'])
set_param([sys,'/','乘法器'],...
		'Font Name','宋体',...
		'position',[105,80,125,115])

add_block('built-in/Note',[sys,'/','系统的谐振特性:'])
set_param([sys,'/','系统的谐振特性:'],...
		'Font Name','仿宋_GB2312',...
		'Font Size',16,...
		'position',[155,20,160,25])
add_line(sys,[130,100;305,100])
add_line(sys,[70,90;100,90])
add_line(sys,[140,100;150,225])
add_line(sys,[265,100;265,150;305,150])
add_line(sys,[250,225;305,225])
add_line(sys,[265,225;265,170;305,170])
add_line(sys,[70,145;80,145;80,105;100,105])

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