?? flch7eg1.m
字號:
% initialization
clear
y0=0;y1=0;u0=0.1; ve=0.1;u2=0;u1=0.1;d=0;e=0.001;e0=0;e1=0;e2=0.001;u=1;M=200; N=3
d=randn(M,1);
for i=1:M %開始循環
d1=0.022*d(i);
u1=u;
for k=1:N %點循環
if e==-6 |e==-4 & ve==-6| ve==-4 %規則1
u=6; else, end
if e==-6 |e==-4 & ve==-4| ve==0 %規則2
u=6; else, end
if e==-6 |e==-4 & ve==4 %規則3
u=4;else, end
if e==-6 |e==-4 & ve==4| ve==6 %規則4
u=0; else, end
if e==-4 & ve==-6| ve==-4 %規則5
u=4;else, end
if e==-4 & ve==-4| ve==0 %規則6
u=4; else, end
if e==-4 & ve==4 %規則7
u=0; else, end
if e==-4 & ve==4| ve==6 %規則8
u=-2; else, end
if e==0 & ve==-6| ve==-4 %規則9
u=4; else, end
if e==0 & ve==-2 %規則10
u=2; else, end
if e==0 & ve==0 %規則11
u=0; else, end
if e==0 4 & ve==2 %規則12
u=-2; else, end
if e==0 & ve==4| ve==6 %規則13
u=-4; else, end
if e==2 & ve==-6| ve==-4 %規則14
u=2; else, end
if e==2 & ve==-2 %規則15
u=0; else, end
if e==2 & ve==0| ve==2 %規則16
u=-4; else, end
if e==2 & ve==4| ve==6 %規則17
u=-4; else, end
if e==4 |e==6 & ve==-6| ve==-4 %規則18
u=0; else, end
if e==4 |e==6 & ve==-2 %規則19
u=-4; else, end
if e==4 |e==6 & ve==0 %規則20
u=-6; else, end
if e==4 |e==6 & ve==4| ve==6 %規則21
u=-6; else, end
u1=u;
%y2=0.36*y1-0.132*y0+0.117*u1+0.076*u0+d1
y2=0.36*y1-0.132*y0+0.116*u1+0.076*u0+d1; %有噪聲系統
y3(i)=y2; %存儲系統輸出,標幺化系統最大輸出為1
up(i)=1; %系統輸入為1
d2(i)=d1; %存噪聲信號
e=(u1/6-y2)*6; %模糊規則中u(k)的范圍為{-6,6},處理再還原到6
e2(i)=e; %存儲放大6倍的誤差
ve=(e1-e0);
ve=round(ve); %取整數,以便模糊運算
e=round(e); %取整數,以便模糊運算
e0=e1;e1=e;
y0=y1;
y1=y2;
u0=u1;
if e<=0.001 break; %判斷誤差
else
end
end %對應for k=1:N
end %循環結束
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'); %圖標注
subplot(3,1,2)
e=0.5*(e2/6).^2 %求還原誤差的均方值
plot(e)
xlabel('k'),ylabel('誤差e')
subplot(3,1,3)
plot(d2)
xlabel('k'),ylabel('噪聲d')'
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -