📄 rbfbianshi.m
字号:
clear all
%%%%%% 建立窗体 %%%%%%
h0=figure('toolbar','none',...
'position',[70 56 700 450],...
'name','永磁体直流电机模型辨识');
h1=axes('parent',h0,...
'position',[0.08 0.48 0.85 0.5],...
'visible','on');
%%%%%% 永磁体直流电机模型 %%%%%%
Ra=1.75;
La=2.83e-3;
kv=0.093;
kt=0.0924;
Jeq=30.e-6;
Beq=5.0e-3;
num=kt/(La*Jeq);
den=[1 (Ra*Jeq+La*Beq)/(La*Jeq) (Ra*Beq+kt*kv)/(La*Jeq)];
sys=tf(num,den);
%
t=linspace(0,4*pi,100);
r=sin(t).*cos(t)+(0.1*rand(size(t)));
y=lsim(sys,r,t);
%
goal=0.01; %误差指标
sp=1; %扩展常数
mn=20; %神经元的最多个数
net=newrb(r,y',goal,sp,mn);
pause(0.5)
yy=sim(net,r);
plyy=plot(t,yy,'ro');
hold on
plr=plot(t,r,'k:');
ply=plot(t,y,'b-');
legend('辨识模型','参考输入','系统输出',5);
%%%%%%%%%% 网格控制 %%%%%%%%%
grid on
ptGridon=uicontrol('parent',h0,...
'units','points',...
'tag','ptGridon',...
'style','radio',...
'string',['显示网格'],...
'position',[420 200 60 20],...
'backgroundcolor',[0.75 0.75 0.75],...
'value',1,...
'callback',[...
'grid on,',...
'set(ptGridon,''value'',1);,',...
'set(ptGridoff,''value'',0);,']);
ptGridoff=uicontrol('parent',h0,...
'units','points',...
'tag','ptGridoff',...
'style','radio',...
'string',['隐藏网格'],...
'position',[420 175 60 20],...
'backgroundcolor',[0.75 0.75 0.75],...
'value',0,...
'callback',[...
'grid off,',...
'set(ptGridoff,''value'',1);,',...
'set(ptGridon,''value'',0);,']);
%%%%%%%%% 有无干扰控制 %%%%%%%
txtDist=uicontrol('parent',h0,...
'units','points',...
'tag','txtDist',...
'style','text',...
'string',['电机干扰设定'],...
'position',[30 100 60 10],...
'backgroundcolor',[0.75 0.75 0.75],...
'fontsize',5);
ptDistOn=uicontrol('parent',h0,...
'units','points',...
'tag','ptDistOn',...
'style','radio',...
'string','有干扰',...
'position',[30 80 60 15],...
'backgroundcolor',[0.75 0.75 0.75],...
'value',1,...
'callback',[...
'DIST=1;',...
'set(ptDistOn,''value'',1);',...
'set(ptDistOff,''value'',0)']);
ptDistOff=uicontrol('parent',h0,...
'units','points',...
'tag','ptDistOff',...
'style','radio',...
'string','无干扰',...
'position',[30 60 60 15],...
'backgroundcolor',[0.75 0.75 0.75],...
'value',0,...
'callback',[...
'DIST=0;',...
'set(ptDistOff,''value'',1);',...
'set(ptDistOn,''value'',0)']);
%%%%%%%% 神经网络参数 %%%%%%%%
txtNN=uicontrol('parent',h0,...
'units','points',...
'tag','txtNN',...
'style','text',...
'string',['神经网络参数'],...
'position',[170 100 80 10],...
'backgroundcolor',[0.75 0.75 0.75],...
'fontsize',5);
txtNNgoal=uicontrol('parent',h0,...
'units','points',...
'tag','txtNNgoal',...
'style','text',...
'string',['误差指标'],...
'position',[128 80 50 15],...
'backgroundcolor',[0.75 0.75 0.75],...
'fontsize',5);
sldNNgoal=uicontrol('parent',h0,...
'units','points',...
'tag','sldNNgoal',...
'style','slider',...
'value',0.01,...
'position',[180 80 150 15],...
'backgroundcolor',[0.75 0.75 0.75],...
'max',0.1,...
'min',0,...
'callback',[...
'goal=get(sldNNgoal,''value'');',...
'set(edtNNgoal,''string'',num2str(goal));']);
edtNNgoal=uicontrol('parent',h0,...
'style','edit',...
'units','points',...
'string',num2str(get(sldNNgoal,'value')),...
'position',[340 80 50 15],...
'callback',[...
'goal=str2num(get(edtNNgoal,''string''));',...
'set(sldNNgoal,''value'',goal);']);
txtNNnum=uicontrol('parent',h0,...
'units','points',...
'tag','txtNNnum',...
'style','text',...
'string',['神经元数'],...
'position',[128 60 50 15],...
'backgroundcolor',[0.75 0.75 0.75],...
'fontsize',5);
sldNNnum=uicontrol('parent',h0,...
'units','points',...
'tag','sldNNnum',...
'style','slider',...
'value',10,...
'position',[180 60 150 15],...
'backgroundcolor',[0.75 0.75 0.75],...
'max',100,...
'min',0,...
'callback',[...
'sp=get(sldNNnum,''value'');',...
'set(edtNNnum,''string'',num2str(sp));']);
edtNNnum=uicontrol('parent',h0,...
'style','edit',...
'units','points',...
'string',num2str(get(sldNNnum,'value')),...
'position',[340 60 50 15],...
'callback',[...
'sp=str2num(get(edtNNnum,''string''));',...
'set(sldNNnum,''value'',sp);']);
%%%%%%% 关闭按钮 %%%%%%%
btClose=uicontrol('parent',h0,...
'units','points',...
'tag','btClose',...
'style','pushbutton',...
'string','关闭',...
'position',[290 20 80 20],...
'backgroundcolor',[0.75 0.75 0.75],...
'fontsize',15,...
'callback','close');
%%%%%%%% 辨识按钮 %%%%%%%
btDraw=uicontrol('parent',h0,...
'units','points',...
'tag','btDraw',...
'style','pushbutton',...
'string','辨识',...
'position',[200 20 80 20],...
'backgroundcolor',[0.75 0.75 0.75],...
'fontsize',15,...
'callback',[...
'if DIST==1;',...
'delete(plyy);',...
'delete(ply);',...
'delete(plr);',...
'r=sin(t).*cos(t)+(0.1*rand(size(t)));',...
'y=lsim(sys,r,t);',...
'net=newrb(r,y'',goal,sp,mn);',...
'pause(0.2);',...
'yy=sim(net,r);',...
'plyy=plot(t,yy,''ro'');',...
'hold on;',...
'plr=plot(t,r,''k:'');',...
'ply=plot(t,y,''b-'');',...
'legend(''辨识模型'',''参考输入'',''系统输出'',5);',...
'else;',...
'delete(plyy);',...
'delete(ply);',...
'delete(plr);',...
'r=sin(t).*cos(t);',...
'y=lsim(sys,r,t);',...
'net=newrb(r,y'',goal,sp,mn);',...
'pause(0.3);',...
'yy=sim(net,r);',...
'plyy=plot(t,yy,''ro'');',...
'hold on;',...
'plr=plot(t,r,''k:'');',...
'ply=plot(t,y,''b-'');',...
'legend(''辨识模型'',''参考输入'',''系统输出'',5);',...
'end;']);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -