EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
BP神经网络整定的PID控制算法matlab源程序,系统为二阶闭环系统。
7 R2 {, n$ U! `: [- t%BP based PID Control clear all; close all; ( X0 Y v0 g+ P
xite=0.28; alfa=0.001; # I5 o& J3 ~1 C1 a3 k' Y; \! E
* k, Q$ x/ P' @9 b! J7 eIN=4;H=5;Out=3; %NN Structure 2 K% S/ B' W9 i9 P% [
! [; w. A h/ s# z% w" {wi=0.50*rands(H,IN); wi_1=wi;wi_2=wi;wi_3=wi; ' `6 }+ p# y" y* K. ?/ t) n6 z- d
' ^6 q1 R* T' j9 Swo=0.50*rands(Out,H); wo_1=wo;wo_2=wo;wo_3=wo;
) a% C. s$ w/ i- ?/ y- g
: @4 S7 v& y: k6 {x=[0,0,0]; u_1=0;u_2=0;u_3=0;u_4=0;u_5=0; y_1=0;y_2=0;y_3=0;
$ G. e+ I, `, XOh=zeros(H,1); %Output from NN middle layer I=Oh; %Input to NN middle layer error_2=0; error_1=0;
& q; [: y ]4 uts=0.01; sys=tf(2.6126,[1,3.201,2.7225]); %建立被控对象传递函数 dsys=c2d(sys,ts,'z'); %把传递函数离散化 [num,den]=tfdata(dsys,'v'); %离散化后提取分子、分母 for k=1:1:2000 time(k)=k*ts; rin(k)=40; yout(k)=-den(2)*y_1-den(3)*y_2+num(2)*u_2+num(3)*u_3;%这一步是怎么推的(问题1) error(k)=rin(k)-yout(k);
' E; N1 D1 o" c& s2 s* e; b3 O$ qxi=[rin(k),yout(k),error(k),1];
2 P" I( k1 ^& |) Q" H" vx(1)=error(k)-error_1; x(2)=error(k); x(3)=error(k)-2*error_1+error_2;
$ x! n z) P; m- h3 `- h" H9 Gepid=[x(1);x(2);x(3)]; I=xi*wi'; for j=1:1:H Oh(j)=(exp(I(j))-exp(-I(j)))/(exp(I(j))+exp(-I(j))); %Middle Layer end K=wo*Oh; %Output Layer for l=1:1:Out K(l)=exp(K(l))/(exp(K(l))+exp(-K(l))); %Getting kp,ki,kd end kp(k)=K(1);ki(k)=K(2);kd(k)=K(3); Kpid=[kp(k),ki(k),kd(k)]; ' G5 X2 R5 |4 W* M
du(k)=Kpid*epid; u(k)=u_1+du(k); if u(k)>=45 % Restricting the output of controller u(k)=45; end if u(k)<=-45 u(k)=-45; end 7 q7 F8 U- u) V- |! d" N0 n/ q
dyu(k)=sign((yout(k)-y_1)/(u(k)-u_1+0.0000001)); ) |1 g( p. `0 W3 y1 {- I3 o
%Output layer for j=1:1:Out dK(j)=2/(exp(K(j))+exp(-K(j)))^2; end for l=1:1:Out delta3(l)=error(k)*dyu(k)*epid(l)*dK(l); end
- V, U8 ~( a: G+ g) H: @for l=1:1:Out for i=1:1:H d_wo=xite*delta3(l)*Oh(i)+alfa*(wo_1-wo_2); end end wo=wo_1+d_wo+alfa*(wo_1-wo_2);%这一步似乎有问题(问题2) %Hidden layer for i=1:1:H dO(i)=4/(exp(I(i))+exp(-I(i)))^2; end segma=delta3*wo; for i=1:1:H delta2(i)=dO(i)*segma(i); end 6 O- R8 P, H1 N2 O* o9 w
d_wi=xite*delta2'*xi; wi=wi_1+d_wi+alfa*(wi_1-wi_2); + W' M2 t9 q( x c6 ^# L" \4 U/ t* N( c
%Parameters Update u_5=u_4;u_4=u_3;u_3=u_2;u_2=u_1;u_1=u(k); y_2=y_1;y_1=yout(k); wo_3=wo_2; wo_2=wo_1; wo_1=wo; wi_3=wi_2; wi_2=wi_1; wi_1=wi;
& f+ [/ A- I( c1 l5 H5 Nerror_2=error_1; error_1=error(k); end figure(1); plot(time,rin,'r',time,yout,'b'); xlabel('time(s)');ylabel('rin,yout'); figure(2); plot(time,error,'r'); xlabel('time(s)');ylabel('error'); figure(3); plot(time,u,'r'); xlabel('time(s)');ylabel('u'); figure(4); subplot(311); plot(time,kp,'r'); xlabel('time(s)');ylabel('kp'); subplot(312); plot(time,ki,'g'); xlabel('time(s)');ylabel('ki'); subplot(313); plot(time,kd,'b'); xlabel('time(s)');ylabel('kd'); 问题(1)和问题(2)都标注出来了。还请各位帮忙看一下,尤其是问题(1),到底如何将已知的传递函数转换成,matlab的仿真模型呢 * g2 q5 J5 ?0 j: H4 [( B% N' m
|