**A. Computer program**

```
function [sys,x0]=EKF(t,x,u,flag)
global a1 a2 a3 a4 a5 b1;
global F C K R Q P Ts B n p;
if flag==0
% Machine parameters————————————————————————
Rs=2.2;Rr=2.68;M=0.217;Ls=0.229;Lr=0.229;p=2;
% Initiating the state error covariance matrix———————————————
P=eye(5);
% State noise covariance matrix————————————————————
Q=diag([1e-6 1e-6 1e-6 1e-6 1e6]);
% Measure noise covariance matrix———————————————————
R=diag([1e6 1e6]);
% Sampling period
Ts=1e-5;
% Defining A and B matrices——————————————————————
Tr=Lr/Rr;
Sigma=1-M^2/(Ls*Lr);
a1=-(Rs/(Sigma*Ls)+(1-Sigma)/(Sigma*Tr));
a2=M/(Sigma*Ls*Lr*Tr);
a3=M/(Sigma*Ls*Lr);
a4=M/Tr;
a5=-1/Tr;
b1=1/(Sigma*Ls);
% Input Matrix—————————————————————————————————
B=[b1 0;0 b1;0 0;0 0;0 0];
```

```
% Measure Matrix——————————————————————————
C=[1 0 0 0 0;0 1 0 0 0];
% Loop ———————————————————————————————
n=0;
x0=[0 0 0 0 0];
sys=[0,5,5,4,0,0];
elseif flag==2
n=n+1;
U=[u(1);u(2)];
Y=[u(3);u(4)];
F=eye(5)+Ts*A;
G=Ts*B;
% State prediction——————————————————————————
x_1=[F(1:4,1:4)*x(1:4);x(5)]+G*U;
% Covariance prediction———————————————————————
P_1=F*P*F'+Q;
% Kalman gain matrix—————————————————————————
K=P_1*C0
        /(C*P_1*C0
                  +R);
% State estimation——————————————————————————
x=x_1+K*(Y-C*x_1);
% State error covariance estimation———————————————————
P=P_1-K*C*P_1;
    sys=x;
elseif flag==3
    sys=x;
elseif flag==9
    sys=[];
end
```
**References**

[1] Brown RG. Introduction to Random Ssignal Analysis and Kalman Filtering.

*DOI: http://dx.doi.org/10.5772/intechopen.92871*

*Kalman Filtering Applied to Induction Motor State Estimation*

with fuzzy luenberger observer.

2018;**66**(4):22

Electrotehnica, Electronica, Automatica.

Schutter J. Nonlinear Kalman Filtering for Force-Controlled Robot Tasks. Vol 19. Berlin: Springer; 2005

Introduction to Random Signals and Applied Kalman Filtering. Vo. 3.

[4] Kron G. Generalized theory of electrical machinery. Transactions of the American Institute of Electrical Engineers. 1930;**49**(2):666-683

[5] Zahraoui Y, Fahassa C, Akherraz M, Bennassar A. Sensorless vector control of induction motor using an EKF and SVPWM algorithm. In: 5th International Conference on Multimedia Computing and Systems (ICMCS). Marrakech: IEEE; 2016. pp. 588-593. DOI: 10.1109/

[6] Ananthasayanam MR. A reference recursive recipe for tuning the statistics of the Kalman filter. In: de Oliveira Serra GL, editor. Kalman Filters—Theory for

[7] Zahraoui Y, Akherraz M, Fahassa C,

Advanced Applications. Rijeka: IntechOpen; 2018. DOI: 10.5772/

Elbadaoui S. Robust control of sensorless sliding mode controlled induction motor drive facing a large scale rotor resistance variation. In: Proceedings of the 4th International

Conference on Smart City

Morocco), Association for

pp. 1-6

**79**

Applications, SCA '19 (Casablanca,

[8] Tahar B, Bousmaha B, Ismail B, Houcine B. Speed sensorless fieldoriented control of induction motor

Computing Machinery, Oct. 2019; 2020.

Vol. 8. New York: Wiley; 1983

[2] Lefebvre T, Bruyninckx H,

[3] Brown RG, Hwang PYC.

New York: Wiley; 1992

ICMCS.2016.7905584

intechopen.71961
