?? flch7eg2.m
字號:
% PID控制算法
clear
y0=0;y1=0;u0=0; ve=0.1;u2=0;u1=0;d=0;e=0.01;a=0.01;
e0=0;e1=0;e2=0.001;u=6;M=200; N=1;
d=randn(M,1);
for i=1:M %開始循環(huán)
d1=0.022*d(i);
u1=u/6;
for k=1:N
u2=u1+0.06*(1-0.5*e1+0.5*(1-2*e1+e0)/(1-e1));
u0=u1; u1=u2;
y2=0.36*y1-0.132*y0+0.66*u1+0.076*u0+d1; %有噪聲系統(tǒng)
y3(i)=y2;
up(i)=1;
e=0.5*(u1/6-y2).^2;
e2(i)=e;
ve=(e1-e0);
e0=e1;e1=e;
y0=y1;
y1=y2;
if e<=0.001 break; %判斷誤差
else
end
end %對應(yīng)for k=1:N
end %循環(huán)結(jié)束
M=i
%greapher
i=1:M;
subplot(3,1,1)
plot(i,up,i,y3,i,y3,'rx')
%title('step response of system'),
xlabel('k'),ylabel('up and y3')
legend('up is system input','y3 is system output'); %圖標(biāo)炷
subplot(3,1,2)
plot(e2)
xlabel('k'),ylabel('誤差e')
subplot(3,1,3)
plot(d*0.022)
xlabel('k'),ylabel('噪聲d')
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -