Monday, September 8, 2014

Adaptive ARMA : Matlab Source Code and Simulink Simulation

Dexter / / 0
This is an example of ARMA (Adaptive Recursive Moving Average) . You can see the simulation result on the below of the page..here is the source code and diagram block of ARMA in simulink.

function Yo=P2SRO(inp)
global ym um arrYK arrUK arrTime Q status Teta startTime ZTeta YK ZData Teta_rata2;
% Penyelesaian Persamaan Simultan Parameter Total
ym = inp(1);
um = inp(2);
uTime = inp(3);

na = inp(4);
nb = inp(5);
Horizon  = inp(6);


Yo=zeros(1,6);
%inisialisasi saat t=0
if uTime==0
   arrYK=[];
   arrUK=[];
   arrTime=[];
   arrYK=[arrYK,ym];
   arrUK=[arrUK,um];   
   arrTime=[arrTime,uTime];  
   status=0;
   startTime=0;
   Teta_rata2=zeros(6,5);
elseif uTime<=Horizon/10         
    arrYK=[arrYK,ym];
    arrUK=[arrUK,um];
    arrTime=[arrTime,uTime];
   
elseif uTime>(Horizon/10) 
  
    Q=[];
    ZData =Horizon;
    for i=1:na
        YK=arrYK((na-i+1):ZData-(i));
        Q=[Q,YK'];
    end   
    for i=1:na
        UK=arrUK((na-i+1):ZData-(i));       
        Q=[Q,UK'];
    end        
       YK=arrYK((na+1):ZData);
       Teta=pinv(Q'*Q)*Q'*YK';                 %Dapatkan Nilai Teta
       Teta_rata2=[Teta_rata2,Teta];
       ZTeta=zeros(6,1);
       for i=1:6
       ZTeta = ZTeta + Teta_rata2(:,i);
       end
      
       rata_rata =ZTeta/6;
      
       save('data','Teta','YK','Q');     
       Yo=rata_rata;     
       
       arrYK(:,[1])=[];                                  %Hapus data pertama arrYK dan UK
       arrUK(:,[1])=[]; 
       arrYK=[arrYK,ym];                                 %ganti dengan data baru
       arrUK=[arrUK,um]; 
       Teta_rata2(:,[1])=[];
       save('dataTotal','arrYK','arrUK','Teta_rata2','Teta');
end
end

and the simulink diagram block


  


The Result :



0 comments:

Latest