📄 dsmybodeb.m
字号:
if szsystem==2
dwmybodeb
else
if bodeabcd==1
windbode=figure('color',[.1,.7,.8],'position',[0.1*winw,0.1*winh,0.8*winw,0.8*winh],...
'name','离散系统S域闭环Bode图分析','numbertitle','off','menubar','figure',...
'resize','off');
end
if bodeabcd==0;
figure(windbode)
end
bodeabcd=0;
w=logspace(-2,2);
[mag,phase]=bode(bnum,bden,w);
subplot(2,1,1);
semilogx(w,20*log10(mag));hold on
grid on;hold on
if bodeabcd==1
ylabel('幅值/db');
legend('系统Bode图之幅值图',0);
end
subplot(2,1,2);
semilogx(w,phase);hold on
grid on;
if bodeabcd==1
ylabel('相位/deg');
legend('系统Bode图之相位图',0);
end
rr1=size(bnum);
rr2=size(bden);
finderr=0;
%判断是否为比例环节
if ((rr1(1,2)==1)&(rr2(1,2)==1)),
finderr=1;
strtext=[' 这是比例环节,零频值A(0)=' num2str(bnum/bden) ' 复现频率Wm ,谐振频率Wr ,载止频率Wb 趋向于无穷!谐振峰值Mr =1 '];
title(strtext);
mybode1235
else,
%判断是否为积分环节
findjf1=0;
findjf2=0;
for i=1:1:rr1(1,2)-1
if bnum(1,i)==0,
else,findjf1=1;break;
end
end
if bden(1,rr2(1,2))==0,
for i=1:1:rr2(1,2)-2
if bden(1,i)==0,
else,findjf2=1;break;
end
end
else,
findjf2=1;
end
if (findjf1==0&findjf2==0),
finderr=1;
strtext=[' 这是积分环节,零频值A(0)=无穷大,无谐振峰值Mr, 复现频率Wm ,谐振频率Wr ,载止频率Wb 无意义,斜率为-20db/dec'];
title(strtext);
mybode1235
end
end
if finderr==0,
%求频率响应函数
[z p]=tf2zp(bnum,bden);
ii=find(real(p)>0);n1=length(ii);
if (n1<=0),%系统稳定
syms x w;
l1=poly2sym(bnum,'s');l2=poly2sym(bden,'s');
fu=symop(l1,'/',l2);gu='j*w';gu1='-abs(w)';gu2='imag(w)/real(w)';gu3='atan(w)';gu4='abs(w)';
fun1=compose(fu,gu,'s','w');
fun2=compose(l2,gu,'s','w');
% fun2=compose(gu1,fun1);
fun3=compose(gu2,fun1);
fun4=compose(gu3,fun3);
fun5=compose(gu4,fun1);
% cmagfun=subs(fun2,'x','w');
cphasefun=subs(fun4,'x','w');
cphasefun=subs(cphasefun,'x','w');
cphasefun=subs(cphasefun,'x','w');
magfun=fun5;
phasefun=fun4;
magfun1=numeric(subs(fun2,'0','w'));
if numeric(subs(fun2,'0','w'))==0
mybode12345
else,
mybode1235
a0=numeric(subs(magfun,'0','w'));
[numlength1 numlength2]=size(bnum);
[denlength1 denlength2]=size(bden);
l3=['('];
for i=1:numlength2-1
l3=[l3 num2str(bnum(1,i)) '*(j*x)^' num2str(numlength2-i) '+'];
end;
l3=[l3 num2str(bnum(1,numlength2)) ')'];
l4=['('];
for i=1:denlength2-1
l4=[l4 num2str(bden(1,i)) '*(j*x)^' num2str(denlength2-i) '+'];
end;
l4=[l4 num2str(bden(1,denlength2)) ')'];
l5=[l3 '/' l4];
cmagfun=['-1*abs(' l5 ')'];
wbmagfun=['abs(' l5 ')-0.707*' num2str(a0)];
wmmagfun=['abs((abs(' l5 ')-' num2str(a0) ')/' num2str(a0) ')-0.02'];
%&&&&&&&&&&&&&
uicontrol(windbode,'style','push','string','零频值A(0)',...
'position',[0.06,0.01,0.11,0.05],'units','normalized',...
'callback','mybodepre_a0');
uicontrol(windbode,'style','push','string','复现频率Wm',...
'position',[0.23,0.01,0.11,0.05],'units','normalized',...
'callback','mybodepre_wm');
uicontrol(windbode,'style','push','string','谐振频率Wr及谐振峰值Mr',...
'position',[0.39,0.01,0.22,0.05],'units','normalized',...
'callback','mybodepre_mr');
uicontrol(windbode,'style','push','string','载止频率Wb',...
'position',[0.66,0.01,0.11,0.05],'units','normalized',...
'callback','mybodepre_wb');
uicontrol(windbode,'style','push','string','结束',...
'position',[0.83,0.01,0.11,0.05],'units','normalized',...
'callback','closebode');
end
else,
strtext=['系统不稳定,系统指标 A(0) , Wm , Wr , Mr , Wb 无法计算'];title(strtext);%系统不稳定
% mybode1234
msysk=tf(bnum,bden);
grid on
ltiview('bode',msysk);grid on
end
end
%else
% abcdefg=0;
% mfksys=tf(knum,kden);
% ltiview('bode',mfksys)
%end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -