Demo entry 6642662

MATLAB

   

Submitted by anonymous on Sep 25, 2017 at 03:44
Language: Matlab. Code size: 960 Bytes.

function [Rs,Ld,Lq,P_new] = RLS_Identfication(ud, uq, id, iq)
%#codegen
persistent id_1;
persistent iq_1;
persistent uq_1;
persistent ud_1;
persistent theta;
persistent P;
T=RSL_types('double');
lambda=0.99;
h=0.0001;
if isempty(theta)    
    id_1=cast(0,'like',T.id_1);
    iq_1=cast(0,'like',T.iq_1);
    uq_1=cast(0,'like',T.uq_1);
    ud_1=cast(0,'like',T.ud_1);
    theta=cast([0 0;0 0;0 0;0 0],'like',T.theta);
    P=cast(1*eye(4),'like',T.P);
    
else
end
    y=[id iq];
    phi=[id_1;iq_1;ud_1;uq_1];
    E=(y-phi'*theta);
    L=P*phi/(lambda*1+phi'*P*phi);    
    P=((eye(4)-L*phi')*P)/lambda;
    theta=theta+L*E;
    P_new = P;
    
    id_1=id;
    iq_1=iq;
    ud_1=ud;
    uq_1=uq;
    if((theta(3,1)~=0) && (theta(4,2)~=0))
        Rs=(2-theta(1,1)-theta(2,2))/(theta(3,1)+theta(4,2));
        Ld=h/theta(3,1);
        Lq=h/theta(4,2);
    else
        Rs=0;
        Ld=0;
        Lq=0;
    end
end

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).