📄 spectf.m
字号:
function [ret,x0,str,ts,xts]=spectf(t,x,u,flag);
%SPECTF is the M-file description of the SIMULINK system named SPECTF.
% The block-diagram can be displayed by typing: SPECTF.
%
% SYS=SPECTF(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 SPECTF 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 SPECTF with a FLAG of zero:
% [SIZES]=SPECTF([],[],[],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.
% 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',[14,61,446,269])
open_system(sys)
end;
set_param(sys,'algorithm', 'Euler')
set_param(sys,'Start time', '0.0')
set_param(sys,'Stop time', '200')
set_param(sys,'Min step size', '1e16')
set_param(sys,'Max step size', '1e16')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars', '')
% Subsystem ['Averaging',13,' Spectrum analyzer'].
new_system([sys,'/',['Averaging',13,' Spectrum analyzer']])
set_param([sys,'/',['Averaging',13,' Spectrum analyzer']],'Location',[0,0,345,183])
add_block('built-in/Inport',[sys,'/',['Averaging',13,' Spectrum analyzer/system input']])
set_param([sys,'/',['Averaging',13,' Spectrum analyzer/system input']],...
'position',[35,35,55,55])
add_block('built-in/S-function',[sys,'/',['Averaging',13,' Spectrum analyzer/S-function block',13,'which calls M-file']])
set_param([sys,'/',['Averaging',13,' Spectrum analyzer/S-function block',13,'which calls M-file']],...
'function name','sfuntf',...
'parameters','fftpts,npts,HowOften,offset,ts,1',...
'position',[230,77,275,113])
add_block('built-in/Inport',[sys,'/',['Averaging',13,' Spectrum analyzer/system output']])
set_param([sys,'/',['Averaging',13,' Spectrum analyzer/system output']],...
'Port','2',...
'position',[35,115,55,135])
add_block('built-in/Mux',[sys,'/',['Averaging',13,' Spectrum analyzer/Mux']])
set_param([sys,'/',['Averaging',13,' Spectrum analyzer/Mux']],...
'inputs','2',...
'position',[125,76,155,109])
add_line([sys,'/',['Averaging',13,' Spectrum analyzer']],[160,95;225,95])
add_line([sys,'/',['Averaging',13,' Spectrum analyzer']],[60,45;90,45;90,85;120,85])
add_line([sys,'/',['Averaging',13,' Spectrum analyzer']],[60,125;90,125;90,100;120,100])
set_param([sys,'/',['Averaging',13,' Spectrum analyzer']],...
'Mask Display','plot(0,0,100,100,[12,92,92,12,12],[90,90,40,40,90],[80,72,63,54,47,40,32,20],[61,61,62,65,69,73,75,75])',...
'Mask Type','Spectrum analayser.')
set_param([sys,'/',['Averaging',13,' Spectrum analyzer']],...
'Mask Dialogue','Spectrum anlayser 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,'/',['Averaging',13,' Spectrum analyzer']],...
'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,'/',['Averaging',13,' Spectrum analyzer']],...
'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,'/',['Averaging',13,' Spectrum analyzer']],...
'Mask Entries','256\/256\/64\/0.1\/')
% Finished composite block ['Averaging',13,' Spectrum analyzer'].
set_param([sys,'/',['Averaging',13,' Spectrum analyzer']],...
'Drop Shadow',4,...
'position',[350,41,380,79])
add_block('built-in/Signal Generator',[sys,'/','Signal Gen.'])
set_param([sys,'/','Signal Gen.'],...
'Peak','1.000000',...
'Peak Range','5.000000',...
'Freq','2.000000',...
'Freq Range','6.250000',...
'Wave','Rnd',...
'Units','Rads',...
'position',[45,33,90,67])
add_block('built-in/Discrete State-Space',[sys,'/',['Chebychev type II',13,'IIR BP filter. ']])
set_param([sys,'/',['Chebychev type II',13,'IIR BP filter. ']],...
'A','a',...
'B','b',...
'C','c',...
'D','d',...
'Sample time','ts',...
'Mask Display','plot(1:64,abs(h))',...
'Mask Type','cheby2(BP)')
set_param([sys,'/',['Chebychev type II',13,'IIR BP filter. ']],...
'Mask Dialogue','Chebychev type II band pass filter.\n(Requires Signal Processing Toolbox)|Cutoff frequency (0 to 1):|Bandwidth (0 to 1):|Order:|Db ripple in stopband:|Sample time:')
set_param([sys,'/',['Chebychev type II',13,'IIR BP filter. ']],...
'Mask Translate','bw = @2/2; eval(''[a,b,c,d]=cheby2(@3,@4,[@1-bw,@1+bw]); ts=@5; [num,den]=ss2tf(a,b,c,d,1); h=freqz(num,den,64); '', ''disp(''''The Signal Processing toolbox is required to run this demo.''''); disp(lasterr)'')')
set_param([sys,'/',['Chebychev type II',13,'IIR BP filter. ']],...
'Mask Help','IIR Chebychev type II band pass filter using MATLAB''s cheby2 command.',...
'Mask Entries','0.5\/0.3\/2\/20\/0.1\/',...
'position',[190,71,250,119])
add_block('built-in/Note',[sys,'/','Note: The filter block requires the Signal Processing Toolbox.'])
set_param([sys,'/','Note: The filter block requires the Signal Processing Toolbox.'],...
'position',[225,155,230,160])
add_line(sys,[95,50;145,50;145,95;185,95])
add_line(sys,[145,50;345,50])
add_line(sys,[255,95;290,95;290,70;345,70])
% 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
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -