1.求 matlab 中bode源代码
2.MATLAB里bd_asymp函数源代码是物流物流什么?
求 matlab 中bode源代码
function [magout,phase,w] = bode(a,b,c,d,iu,w)
%BODE Bode frequency response of LTI models.
%
% BODE(SYS) draws the Bode plot of the LTI model SYS (created with
% either TF, ZPK, SS, or FRD). The frequency range and number of
% points are chosen automatically.
%
% BODE(SYS,{ WMIN,WMAX}) draws the Bode plot for frequencies
% between WMIN and WMAX (in radians/second).
%
% BODE(SYS,W) uses the user-supplied vector W of frequencies, in
% radian/second, at which the Bode response is to be evaluated.
% See LOGSPACE to generate logarithmically spaced frequency vectors.
%
% BODE(SYS1,SYS2,...,W) graphs the Bode response of multiple LTI
% models SYS1,SYS2,... on a single plot. The frequency vector W
% is optional. You can specify a color, line style, and marker
% for each model, as in
% bode(sys1,'r',sys2,'y--',sys3,'gx').
%
% [MAG,PHASE] = BODE(SYS,W) and [MAG,PHASE,W] = BODE(SYS) return the
% response magnitudes and phases in degrees (along with the frequency
% vector W if unspecified). No plot is drawn on the screen.
% If SYS has NY outputs and NU inputs, MAG and PHASE are arrays of
% size [NY NU LENGTH(W)] where MAG(:,:,k) and PHASE(:,:,k) determine
% the response at the frequency W(k). To get the magnitudes in dB,
% type MAGDB = *log(MAG).
%
% For discrete-time models with sample time Ts, BODE uses the
% transformation Z = exp(j*W*Ts) to map the unit circle to the
% real frequency axis. The frequency response is only plotted
% for frequencies smaller than the Nyquist frequency pi/Ts, and
% the default value 1 (second) is assumed when Ts is unspecified.
%
% See also BODEMAG, NICHOLS, NYQUIST, SIGMA, FREQRESP, LTIVIEW, LTIMODELS.
% Old help
%warning(['This calling syntax for ' mfilename ' will not be supported in the future.'])
%BODE Bode frequency response for continuous-time linear systems.
% BODE(A,B,C,D,IU) produces a Bode plot from the single input IU to
% all the outputs of the continuous state-space system (A,B,C,D).
% IU is an index into the inputs of the system and specifies which
% input to use for the Bode response. The frequency range and
% number of points are chosen automatically.
%
% BODE(NUM,DEN) produces the Bode plot for the polynomial transfer
% function G(s) = NUM(s)/DEN(s) where NUM and DEN contain the
% polynomial coefficients in descending powers of s.
%
% BODE(A,B,C,D,IU,W) or BODE(NUM,DEN,W) uses the user-supplied
% frequency vector W which must contain the frequencies, in
% radians/sec, at which the Bode response is to be evaluated. See
% LOGSPACE to generate logarithmically spaced frequency vectors.
% When invoked with left hand arguments,
% [MAG,PHASE,W] = BODE(A,B,C,D,...)
% [MAG,PHASE,W] = BODE(NUM,DEN,...)
% returns the frequency vector W and matrices MAG and PHASE (in
% degrees) with as many columns as outputs and length(W) rows. No
% plot is drawn on the screen.
%
% See also LOGSPACE, SEMILOGX, MARGIN, NICHOLS, and NYQUIST.
% J.N. Little --
% Revised A.C.W.Grace 8--, 2-4-, 6--
% Revised Clay M. Thompson 7-9-
% Revised A.Potvin -1-
% Copyright - The MathWorks, Inc.
% $Revision: 1.1.8.2 $ $Date: // :: $
ni = nargin;
no = nargout;
% Check for demo and quick exit
if ni==0,
eval('exresp(''bode'')')
return
end
error(nargchk(2,6,ni));
% Determine which syntax is being used
switch ni
case 2
if size(a,1)>1,
% SIMO syntax
a = num2cell(a,2);
den = b;
b = cell(size(a,1),1);
b(:) = { den};
end
sys = tf(a,b);
w = [];
case 3
% Transfer function form with time vector
if size(a,1)>1,
% SIMO syntax
a = num2cell(a,2);
den = b;
b = cell(size(a,1),1);
b(:) = { den};
end
sys = tf(a,b);
w = c;
case 4
% State space system without iu or time vector
sys = ss(a,b,c,d);
w = [];
otherwise
% State space system, with iu but w/o time vector
if min(size(iu))>1,
error('IU must be a vector.');
elseif isempty(iu),
iu = 1:size(d,2);
end
sys = ss(a,b(:,iu),c,d(:,iu));
if ni<6,
w = [];
end
end
if no==0,
bode(sys,w)
else
[magout,phase,w] = bode(sys,w);
[Ny,Nu,lw] = size(magout);
magout = reshape(magout,[Ny*Nu lw]).';
phase = reshape(phase,[Ny*Nu lw]).';
end
% end bode
MATLAB里bd_asymp函数源代码是什么?
具体函数如下所示,
function [wpos,源码应用phpstudy怎么用源码ypos]=bd_asymp(G,w)
G1=zpk(G); Gtf=tf(G);
if nargin==1,
w=freqint2(Gtf.num{ 1},Gtf.den{ 1},);
end
zer=G1.z{ 1}; pol=G1.p{ 1}; gain=G1.k;
wpos=[]; pos1=[];
for i=1:length(zer);
if isreal(zer(i))
wpos=[wpos, abs(zer(i))];
pos1=[pos1,];
else
if imag(zer(i))>0
wpos=[wpos, abs(zer(i))];
pos1=[pos1,];
end, end, end
for i=1:length(pol);
if isreal(pol(i))
wpos=[wpos, abs(pol(i))];
pos1=[pos1,-];
else
if imag(pol(i))>0
wpos=[wpos, abs(pol(i))];
pos1=[pos1,-];
end, end, end
wpos=[wpos w(1) w(length(w))];
pos1=[pos1,0,0];
[wpos,ii]=sort(wpos); pos1=pos1(ii);
ii=find(abs(wpos)<eps); kslp=0;
w_start=*eps;
if length(ii)>0,
kslp=sum(pos1(ii));
ii=(ii(length(ii))+1):length(wpos);
wpos=wpos(ii); pos1=pos1(ii);
end
while 1
[ypos1,pp]=bode(G,w_start);
if isinf(ypos1), w_start=w_start*;
else, break; end
end
wpos=[w_start wpos];
ypos(1)=*log(ypos1);
pos1=[kslp pos1];
for i=2:length(wpos)
kslp=sum(pos1(1:i-1));
ypos(i)=ypos(i-1)+...
kslp*log(wpos(i)/wpos(i-1));
end
ii=find(wpos>=w(1)&wpos<=w(length(w)));
wpos=wpos(ii); ypos=ypos(ii);