td_dat.m

来自「FISMAT accommodates different arithmetic」· M 代码 · 共 108 行

M
108
字号
echo off% td_dat.m%% Analysis of the fuzzy controller regulating a first order plant (T=1) and% a dead time of two seconds. Sampling period equals one second.% For details of plant and discrete PI controller design see Ogata: % 'Discrete-Time Control Systems', Prentice Hall, 1987, p.444% The digital PI controller has the following pulse transfer function:% G(z)=Kp+Ki/(1-z^-1). The controller is designed such that the dominant% cloosed-loop poles have a damping ratio of 0.5 and the number of samples% per cycle of damped sinusoidal oscillation is 10.% From Ogata Ki=0.2088 and Kp=0.2982%% FSTB - Fuzzy Systems Toolbox for MATLAB% Copyright (c) 1993-1996 by Olaf Wolkenhauer% Control Systems Centre at UMIST% Manchester M60 1QD, UK%% 10-May-1994 clear allclear globaldec1='y';Ae=[0]; Ade=Ae;while dec1=='y',  ERROR=[-1 0 1];  RATE=[-1 0 1];  DOUT=[-1 -0.1 0 0.1 1];  global ERROR RATE DOUT  ERROR,RATE,DOUT  dec=input('Changing fuzzy sets ? y/n [n] : ','s');  if dec=='y',    disp('Type <return> to continue.');    keyboard  end;  % initializing for single plant and PI controller:  c1=0; u1=0; u2=0; u3=0; e1=0; ck=0; rk=1;  % initializing for single plant and fuzzy PI controller:  fc1=0; fu1=0; fu2=0; fu3=0; fe1=0; fck=0;   kv=0:1:20;  ck=zeros(1,21); uk=ck; fuk=uk; fck=uk;  dec=input('stepping throug run ? y/n [n] : ','s');  if dec=='y',    f1=figure;    f2=figure;  end;  % Calculating the step response:  for k=0:20,    % Implementation of the plant for the PI controller:    ck(k+1)=0.3679*c1+0.6321*u3;    ek=rk-ck(k+1);    % Implementation discrete PI-controller:    uk(k+1)=u1+0.5070*ek-0.5070*0.5881*e1;    c1=ck(k+1); u3=u2; u2=u1; u1=uk(k+1); e1=ek;     % Implementation of the fuzzy PI controller:    fck(k+1)=0.3679*fc1+0.6321*fu3;    fek=rk-fck(k+1);    % Implementation of the fuzzy PI controller:    e=[fek (fek-fe1)];    x=[0]; ts=1;    do=feval('td_dem_c',e,x,ts);    fuk(k+1)=do+fu1;    fc1=fck(k+1); fu3=fu2; fu2=fu1; fu1=fuk(k+1); fe1=fek;    %disp([k,uk(k+1),ck(k+1),fuk(k+1),fck(k+1)])    if dec=='y',      % Plot current values:      figure(f1);clf      subplot(2,2,1);plot(kv,ck);title('conv. PI c(k)'); grid on      subplot(2,2,2);plot(kv,uk);title('conv. PI u(k)'); grid on      subplot(2,2,3);plot(kv,fck);title('fuzzy PI c(k)'); grid on      subplot(2,2,4);plot(kv,fuk);title('fuzzy PI u(k)'); grid on      figure(f2);clf      subplot(3,1,1), plot_set(ERROR);title('ERROR :');hold on      plot([fek fek],[0 1],'g'); ylabel(['error= ',num2str(fek)]);      subplot(3,1,2), plot_set(RATE);title('RATE :');hold on      plot([(fek-fe1) (fek-fe1)],[0 1],'g');       ylabel(['rate= ',num2str((fek-fe1))]);      subplot(3,1,3),plot(DOUT,zeros(1,length(DOUT)),'w');title('DOUT : ');      hold on;line([DOUT;DOUT],[zeros(1,length(DOUT));ones(1,length(DOUT))]);      plot([do do],[0 1],'g'); ylabel(['do= ',num2str(do)]);      xlabel(['u(k)= ',num2str(fuk(k+1))]); hold off      drawnow,pause    end;  end;  dec=input('table ? y/n [n] : ','s');  if dec=='y',    disp([kv' uk' ck' fuk' fck'])  end;  dec=input('plots ? y/n [n] : ','s');  if dec=='y',    clf    subplot(2,2,1);plot(kv,ck);title('conv. PI c(k) :');grid on    subplot(2,2,2);plot(kv,uk);title('conv. PI u(k) :');grid on    subplot(2,2,3);plot(kv,fck);title('fuzzy PI c(k) :');grid on    subplot(2,2,4);plot(kv,fuk);title('fuzzy PI u(k) :');grid on  end;  dec1=input('Another run ? y/n [n] : ','s');  if isempty(dec1); dec1='n';end;end;clear c1 c2 c3 c4 u3 u2 u1 uk e1 ek rk ck kclear fc1 fc2 fc3 fu3 fu2 fu1 fuk fe1 fek fck dec fuk do x ts e kv dec1clear Ae Ade f1 f2

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?