Bluetooth Applications

#### **Chapter 4**

## Bluetooth Low Energy Applications in MATLAB

*Septimiu Mischie*

#### **Abstract**

This chapter presents Bluetooth Low Energy (BLE) applications in MATLAB. Through these applications we acquire measurement data from BLE compatible sensors to PC. The sensors are CC2541 Keyfob and CC2650 Sensor Tag. The first one contains an accelerometer and a temperature sensor while the second one contains more sensors, but inertial sensors and magnetometer are invoked. The PC should be equipped with a general USB BLE adapter. The most important steps for implementing a BLE application are presented: scanning, connecting, configuring and data reading. Following this, more detailed applications are presented: a wireless sensor network for temperature measurement with three Keyfob-based nodes, an application that displays in real time accelerometer data and a heading computed method using either the gyroscope or the magnetometer of CC2650 Sensor Tag. The most important MATLAB elements that are used to implement these applications are different types of variables such as structure, table and object, methods to implement endless loops and real-time display of acquired data and using quaternions to handle 3D orientation of a device.

**Keywords:** MATLAB, Bluetooth low energy, temperature sensors, movement sensors, callback function, quaternion, 3D orientation

#### **1. Introduction**

MATLAB represents a programming language that is used for designing, simulating and testing of different technical systems [1]. This chapter provides examples of Bluetooth low energy (BLE) applications implemented in MATLAB. In this section, the main aspects regarding developing a BLE MATLAB application are presented. First of all, basics about BLE technology are presented [2–5]. BLE means exchange data between two or more devices by radio waves over short distances. Mainly, a BLE device can be scanner or advertiser. The advertiser signals its presence by sending its name and address. The scanner finds advertiser devices and can connect to one or more of them. Then the advertiser becomes a server and can send data to the scanner which is now a client. According to BLE architecture, the server can offer services to the client. Some examples of services are battery service, accelerometer service and heart rate measurements. Each service contains more characteristics. The most important attribute of a characteristic is its value, which in general represents sensor data. In addition, a characteristic has one or more of the following properties: read, write and notify.

Starting with 2019b release, MATLAB has introduced a set of functions that allow a simple implementation of BLE application [6]. The minimum setup involves a laptop having an embedded BLE adaptor or a desktop having an USB BLE adapter and some BLE compatible devices.

Scanning for BLE devices can be done using *blelist* function. Connecting to one device can then be done by *ble*() function, as in the examples of **Figure 1**.

It can be seen that three BLE devices have been discovered. The connection with Keyfobde99 is achieved, and b1 is a *ble* object having 5 fields, the last two being Services and Characteristics so in previous paragraph was presented. Then, in order to get data from a BLE device, the characteristics have to be accessed. **Figure 2** presents the last part of the Characteristics variable.

A characteristic can be accessed either by service name and characteristic name or by service universal unique identifier (UUID) and characteristic (UUID) [6]. According to the information from **Figure 2** it can be seen that only the second option can be used because there are more Custom services or characteristics.


#### **Figure 1.** *Using* blelist *and* ble*() functions.*


#### **Figure 2.**

*A part of services and characteristics of a* ble *variable.*

*Bluetooth Low Energy Applications in MATLAB DOI: http://dx.doi.org/10.5772/intechopen.95814*

Furthermore, there is no information about the functionalities of these services or characteristics. Therefore, to start the application, some information is necessary that can be obtained using another application such as BLE Device Monitor [7] or just Wikipedia [8]. Thus, **Table 1** presents service name and characteristic name among to UUID for a part of the positions of **Figure 2**.

In order to access a characteristic, the *characteristic* () function can be used, as in **Figure 3**. Then, after defining x variable, the returned value can be read by function *read*(x).

Another powerful features is *DataAvailbleFcn* than can be assigned to a characteristics that has the Notify attribute. This can be done as in **Figure 4**. When a new data is available, this callback function is called.


**Table 1.**

*UUID for a service and its characteristics.*

**Figure 3.**

*Using the* characteristic*() function.*

**Figure 4.** *Create the callback function.*

Each of the following sections contains an introduction where the basic function of the program is presented, which is then followed by the program and the results, mainly in graphical form.

#### **2. BLE network sensors for temperature monitoring**

This section presents a MATLAB application that uses three temperature sensors. CC2541 Keyfob [9] is a BLE compatible device that contains an accelerometer. Among its basic function, the accelerometer contains an 8-bit temperature sensor. To access the temperature sensor the accelerometer must be enabled first and then the temperature characteristic can be accessed according to **Table 1**. The period of reading temperature is 3 sec. according to the author publication [10].

At the beginning of the program a general scanning is executed and if none of the desired sensors are discovered the application is stopped through a suitable message on the screen. To do this, accessing the elements of a variable of table type, *list*, is performed.

Then, depending on the discovered number of sensors, which can be from one to any number (three in this application) the application gets temperature from them and displays it on a graphic. For this purpose, two structures, *s\_enable* and *s\_x*, having a variable number of fields have been created. Number of fields will be equal with the discovered number of sensors. The structure *s\_x* is used to assign a callback function for each discovered sensor, too. Furthermore, the number of matrix of small axes which are generated by subplot function is equal with the number of discovered sensors.

The structure of the program is presented below.

```
%%%%%%Measure the temperature by one, two or three
%%%%%Key-fob devices%%%%%%%%%%%%%%%%%
clear; close all;
global V_temp1;global V_temp2;global V_temp3
global V_time1;global V_time2;global V_time3
global N % the last N temperatures of each sensor
N=20;
V_temp1=zeros(1,N);V_temp2=zeros(1,N);V_temp3=zeros(1,N);
d=datetime;
V_time1=repmat(d,N,1);V_time2=repmat(d,N,1);V_time3=repmat(d,N,1);
list=blelist; %scan
L=size(list);
Nr=L(1);
disp(['Total number of BLE devices: ' num2str(Nr)])
if Nr==0
return
end
j=1;
for i=1:Nr
if (list.Address(i)=="84DD20C50B29" | list.Address(i)=="544A165E18AB" |
list.Address(i)=="20C38FD12605")
b(j)=ble(list.Address(i));
j=j+1;
end
end
Ng=j-1; % Number of Keyfobb devices
```
*Bluetooth Low Energy Applications in MATLAB DOI: http://dx.doi.org/10.5772/intechopen.95814*

```
disp(['Number of Keyfob devices: ' num2str(Ng)])
   if Ng==0
   disp('No devices')
   return
   end
   s_enable=struct; %initialize the structure
   tab='abcdef'; %the fields of the structure
   for i=1:Ng
   s_enable.(tab(i))=characteristic(b(i),"FFA0","FFA1");
   write( s_enable.(tab(i)),1);
   end
   s_x=struct; %initialize the structure
   for i=1:Ng
   s_x.(tab(i))=characteristic(b(i),"FFA0","FFA7");
   s_x.(tab(i)).DataAvailableFcn = eval(['@displayCharacteristicData_temp'
   num2str(i)]);
   end
   h=figure(1);
   while (ishandle(h))
   for i=1:Ng
   var =eval(['V_temp' num2str(i)]);
   timp =eval(['V_time' num2str(i)]);
   subplot(Ng,1,i);plot(timp,var,'*');grid;title(['sensor' num2str(i)]);ylim([0
30])
   xlabel('time')
   ylabel('temperature, C')
   drawnow;
   end
   pause(3)
   end
   clear b
   %One of the three callback functions:
   function displayCharacteristicData_temp1(src,evt)
   global V_temp1
   global V_time1
```
**Figure 5.** *The temperatures from the three sensors.*

global N [temp1] = read(src,'oldest'); time1=datetime(datestr(now,'HH:MM:SS.FFF')); %update the last N=20 samples of temperature and time V\_temp1(1:N-1)=V\_temp1(2:N); V\_temp1(N)=temp1; V\_time1(1:N-1)=V\_time1(2:N); V\_time1(N)=time1; end

The program runs in an endless loop and displays the last 20 values of the three temperatures in a MATLAB figure as in **Figure 5**. To stop the program, simply close the figure. In addition, the current date and time is displayed on the figure. One of the CC2541 Keyfob was on the outside sill of the window and therefore the resulting temperature was about 5 degree Celsius.

### **3. Using the accelerometer of CC2541Keyfob**

This section presents a MATLAB application that accesses the accelerometer of the CC2541 Keyfob to read the 8-bit accelerations corresponding to the three axes. The program is similar to that of the previous section. There are also three callback functions, one for each axes. The period of reading data is set to 100 ms.

```
%%%%%%%%%Display in real-time the last samples of three accelerations
%%%%%%%%%of each axis %%%%%%%%%%%%%%%%%%%
clear all; close all;
b=ble("84DD20C50B29"); %BLE connection with 84DD20C50B29
enable=characteristic(b,"FFA0","FFA1")
write(enable,1) %enable accelerometer
x=characteristic(b,"FFA0","FFA3")
y=characteristic(b,"FFA0","FFA4")
z=characteristic(b,"FFA0","FFA5")
per=characteristic(b,"FFA0","FFA6")
read_per=read(per);
write(per,10);%establish the reading period to 10*10ms
read_per1=read(per);
global vector_x;global vector_y;global vector_z
global N; %number of samples
N=200;
vector_x=zeros(1,N;vector_y=zeros(1,N);vector_z=zeros(1,N);
axa =1:N;
x.DataAvailableFcn = @displayCharacteristicData_x; %functii callback,
they are %executed when sensor data are available
y.DataAvailableFcn = @displayCharacteristicData_y;
z.DataAvailableFcn = @displayCharacteristicData_z;
h=figure(1); %create the figure
while(ishandle(h)) %while the figure does exist data is displayed plot(axa,
vector_x*19.62/128,axa,vector_y*19.62/128,axa,vector_z*19.62/128);grid;leg-
end('ax','ay','az')
ylabel('accel., m/s2')
xlabel(' The most recent samples')
drawnow;
```
*Bluetooth Low Energy Applications in MATLAB DOI: http://dx.doi.org/10.5772/intechopen.95814*

#### **Figure 6.**

*The variation of the three accelerations.*

end

clear b %clear the variable that represents the BLE connection or disconnect %One of the three callback functions: function displayCharacteristicData\_x(src,evt) global vector\_x global N [data,timestamp] = read(src,'oldest'); fprintf('Time1 %s\n', datestr(now,'HH:MM:SS.FFF')) if data>128 data=data-256; end %update the last N=200 samples of acceleration vector\_x(1:N-1)=vector\_x(2:N); vector\_x(N)=data; end

The program runs in an endless loop and displays the last N=200 samples of each the three axes. **Figure 6** presents a screenshot during the running of the program. During this time CC2541 Keyfob was moved such as one of the three axes was on the direction of gravitational force. Thus, most of the time one of the three axes has the absolute value close to g=9.81 m/s<sup>2</sup> while the other two are close to zero.

#### **4. Using the movement sensor of CC2650 Sensor Tag**

This section presents a MATLAB application that accesses the movement sensor of the device called CC2650 Sensor Tag. This movement sensor contains an accelerometer, a gyroscope and a magnetometer. If the accelerometer of the CC2541 Keyfob which was presented in the third section generates 8-bit data, all of the three sensors of CC2650 Sensor Tag generates 16-bit data.

The gyroscope is a three axis sensor that measures the angular rate, *ω*(*t*). By integrating the angular rate, the angular position *α*(*t*) is obtained as

$$a(t) = \int a(t)dt\tag{1}$$

Thus, Eq. (1) can be implemented by trapezoidal method by using samples of *ω*(*t*) by

$$a(t) = a(t-1) + \frac{o(t) - o(t-1)}{2}dt\tag{2}$$

where *dt* is reciprocal of sample rate.

This angle is considered in comparison with the initial position of the gyroscope which is unknown. Using the integration, it generates an error because the gyroscope has an offset. That means its output is different to zero when the gyroscope is still. Thus, by integration it follows that the angle is changed. Therefore this offset must be removed [11].

The magnetometer measures the magnetic field. Thus, if there are no other fields, it measures the magnetic field of the earth. When the magnetometer is placed horizontally, it can measure the angle from the north, *h*, by

$$h = \operatorname{atan} \frac{m\_{\text{y}}}{m\_{\text{x}}} \tag{3}$$

where *mx* and *my* are its readings. Thus, both gyroscope and magnetometer can measure the same angle but the magnetometer has a reference which is the north. For this reason this angle is also called heading. Similar to the gyroscope, the magnetometer has a drawback too. Thus, its reading must be corrected by a process called calibration [12]. Basically, this implies a rotation of 360 degrees around its z axis in both senses followed by computation of calibrated data *mxcal* and *mycal*,

$$m\_{\text{xcal}} = X\_{\text{g}} \cdot m\_{\text{x}} - X\_{\text{gf}} \tag{4}$$

and

$$m\_{\rm local} = Y\_{\rm g} \cdot m\_{\rm \gamma} - Y\_{\rm off} \tag{5}$$

where

$$X\_{\rm g} = \frac{\max\left\{ \left( m\_{\rm x \, max} - m\_{\rm x \, min} \right), \left( m\_{\rm y \, max} - m\_{\rm y \, min} \right) \right\}}{m\_{\rm x \, max} - m\_{\rm x \, min}} \tag{6}$$

and

$$X\_{\rm eff} = X\_{\rm g} \left( \frac{m\_{\rm x\\_max} + m\_{\rm x\\_min}}{2} \right) \tag{7}$$

while *Yg* and *Yoff* have similar expressions. Also the magnetometer is very sensitive to the magnetic perturbations that can be generated by other materials from its proximity.

Regarding BLE, CC2650 Sensor Tag offers more services. The service that allows accessing the accelerometer, the gyroscope and the magnetometer has three characteristics, as shown in **Table 2**, where also the UUID can be seen. The first one is


**Table 2.**

*UUID for the movement service and its characteristics.*

*Bluetooth Low Energy Applications in MATLAB DOI: http://dx.doi.org/10.5772/intechopen.95814*

used to read data. The second one is used to enable the sensors. Each axis of the gyroscope and accelerometer can individually be enabled while the magnetometer can be enabled only for all axes. The third characteristic allows to establish the period of data reading. The data is presented as an 18 bytes string, where each sensor has a field of 6 bytes, two bytes for each axis, in the order: gyroscope, accelerometer and magnetometer. Actually UUID contain more digits but only the different part is presented in **Table 2** [8].

Because in this case the MATLAB programs are much longer than previous ones only some parts of the achieved programs are presented. Mainly, such a program has three parts:


Two programs are achieved, depending of the content of the last part. In this case there is a script and only a callback function. The period of data reading is 200 ms.

*The first program* computes and displays basic results from gyroscope and magnetometer.

Mainly it computes:

om=[om\_x om\_y om\_z]; %%the vector with gyroscope readings A=[a\_x a\_y a\_z]; %%the vector with accelerometer readings M=[m\_x m\_y m\_z]; %%the vector with magnetometer readings ang\_z\_g %the angular position (angle) around z axis, by gyroscope ang\_z\_m %the angular position (angle) around z axis, by magnetometer

All the time the last N=200 samples of these measurements are available. A part of the script is presented in the following.

```
clear;
close all;
global i
i=0; %%this index is used inside the callback function
global ang_z_g; global om_z_prev; global ang_z_m
global offset_x; global offset_y; global offset_z;
ang_z_g=0; om_z_prev=0; ang_z_m=0
offset_x=0; offset_y=0; offset_z=0 ;
bb=ble("B0B448BD7E05");% the address of CC2650 Sensor Tag
%%%%the scaling constants, according to the range
sca_a=8*9.81/32768; %%the accelerometer range is +-8g
sca_m=4800/32768; %%the magnetometer range is +-4800 uT
sca_om=250/32768; %%the gyroscope range is +-250 deg/s
conf=characteristic(bb, "F000AA80-0451-4000-B000-000000000000" ,
"F000AA82-0451-4000-B000-000000000000" );
write(conf,[127 02]) %%enable all 9 axes, 01 111 111
```

```
per=characteristic(bb, "F000AA80-0451-4000-B000-000000000000" ,
"F000AA83-0451-4000-B000-000000000000" );
coef=20;T=10*coef*0.001; %%period of reading in seconds
write(per,coef) %%coef can be minimum 10
data=characteristic(bb, "F000AA80-0451-4000-B000-000000000000" ,
"F000AA81-0451-4000-B000-000000000000" );
data.DataAvailableFcn = @displayCharacteristicData_STag;
%A part of the callback function is presented in the following:
function displayCharacteristicData_STag(src,evt)
global i; global ang_z_g; global om_z_prev; global ang_z_m
global offset_x; global offset_y; global offset_z;
[data,timestamp] = read(src,'oldest'); %%read the current data
%%the gyroscope data
if data(2)>128
om_x=data(2)*256+data(1)-2^16;
else
om_x=data(2)*256+data(1);
end
if data(4)>128
om_y=data(4)*256+data(3)-2^16;
else
om_y=data(4)*256+data(3);
end
if data(6)>128
om_z=data(6)*256+data(5)-2^16;
else
om_z=data(6)*256+data(5);
end
om_x=om_x*sca_om;
om_y=om_y*sca_om;
om_z=om_z*sca_om;
%%correct the gyroscope's offset
if i<=200
offset_x=offset_x+om_x;
offset_y=offset_y+om_y;
offset_z=offset_z+om_z;
i=i+1;
end
om_x=om_x-offset_x/200;
om_y=om_y-offset_y/200;
om_z=om_z-offset_z/200;
om=[om_x om_y om_z]; %%the vector with gyroscope readings
if i>200
%compute the current angle by integration
ang_z_g=ang_z_g+(om_z+om_z_prev)*T/2; %T is reading period
om_z_prev=om_z; %previous value becomes current value
%%the accelerometer data
if data(8)>128
a_x=data(8)*256+data(7)-2^16;
else
a_x=data(8)*256+data(7);
end
if data(10)>128
```
*Bluetooth Low Energy Applications in MATLAB DOI: http://dx.doi.org/10.5772/intechopen.95814*

```
a_y=data(10)*256+data(9)-2^16;
else
a_y=data(10)*256+data(9);
end
if data(12)>128
a_z=data(12)*256+data(11)-2^16;
else
a_z=data(12)*256+data(11);
end
a_x=a_x*sca_a;
a_y=a_y*sca_a;
a_z=a_z*sca_a;
A=[a_x a_y a_z]; %%the vector with accelerometer readings
%%%%%the magnetometer data
if data(14)>128
m_x=data(14)*256+data(13)-2^16;
else
m_x=data(14)*256+data(13);
end
if data(16)>128
m_y=data(16)*256+data(15)-2^16;
else
m_y=data(16)*256+data(15);
end
if data(18)>128
m_z=data(18)*256+data(17)-2^16;
else
m_z=data(18)*256+data(17);
end
m_x=m_x*sca_m;
m_y=m_y*sca_m;
m_z=m_z*sca_m;
M=[m_x m_y m_z]; %%the vector with magnetometer readings
if i>400
%%compute the heading angle using magnetometer
AA= m_y*Ysf+Yoff; %Ysf and Yoff are constants for calibration
BB= m_x*Xsf+Xoff; %Xsf and Xoff are constants for calibration
%the part of the program that computes the above constants is not %
presented
ang_z_m=180/pi*atan2(AA,BB) %%the magnetometer-based heading %angle
end
end %%end if i>200
```
By running the previous program, the last 200 samples of some of the measurements obtained from the gyroscope and magnetometer are displayed in real-time.

Thus, the two waveforms of the top of **Figure 7** are achieved using the gyroscope while the other two from the bottom part are achieved using the magnetometer. In each case the heading is computed. The gyroscope-based angle around z axis or heading is computed using the angular rate around the z axis, see the second waveform. The heading computed by the magnetometer presented in the third waveform is based on its x and y reading which are presented in the last waveform. It can be seen that the two waveforms that represent the heading have the same variation, except at

**Figure 7.**

*Some measurements obtained from gyroscope (the two waveforms at the top) and magnetometer (the two waveforms at the bottom).*

the start. Thus the gyroscope-based heading starts from zero while magnetometerbased heading starts from about 60 degrees because it indicates the north.

By using the movement sensors, 3D orientation of a device can be computed [13–17]. This can be represented in three ways: quaternion, Direction Cosine Matrix (DCM) and Euler angles. The last representation means the rotational angles around the three axes, called pitch, roll and yaw but has a disadvantage because can reach in a singularity state. DCM does not have a singularity state but needs 3x3 elements. Thus the best representation is quaternion which represents a complex number having four components [13],

$$q = \left[\cos\frac{a}{2}\,\,\,e\_x\sin\frac{a}{2}\,\,e\_y\sin\frac{a}{2}\,\,\,e\_x\sin\frac{a}{2}\right] \tag{8}$$

where *α* is the rotation angle and *e* represents the rotation axis.

Using the accelerometer allows only computing pitch and roll angles because a rotation around z axis does not change any of the three outputs. Thus the four elements of the quaternion, denoted *qacc* can be computed by [13]

$$q\_{acc} = \begin{cases} \begin{bmatrix} \sqrt{\frac{a\_x + 1}{2}} & -\frac{a\_y}{\sqrt{2(a\_x + 1)}} & \frac{a\_x}{\sqrt{2(a\_x + 1)}} & 0 \\\\ -\frac{a\_y}{\sqrt{2(1 - a\_x)}} \sqrt{\frac{1 - a\_x}{2}} & 0 & \frac{a\_x}{\sqrt{2(1 - a\_x)}} \end{bmatrix}, & a\_x < 0 \end{cases} \tag{9}$$

Eq. (9) can be very easily implemented in MATLAB and then the quaternion can be generated by the function *quaternion*(). However, in order to compute the third angle (yaw) the magnetometer or gyroscope readings are necessary and more difficult equations are generated [13]. Thus, a better solution is using the functions from Sensor Fusion and Tracking Toolbox of MATLAB [18] that allows estimation of 3D orientation. The function *imufilter*() uses only accelerometer and gyroscope

#### *Bluetooth Low Energy Applications in MATLAB DOI: http://dx.doi.org/10.5772/intechopen.95814*

while the function *complementaryFilter*() uses all the three sensors. Thus the **Figure 8** presents in the top panel the angles obtained by MATLAB implementation of Eq. (9) while in the bottom panel are presented the results obtained using the *imufilter*() function. It can be seen that the waveforms are very similar and also the angle around z axis is zero for the first or close to zero for the second as expected.

Both *imufilter*() and *complementaryFilter*() return the result as an object. Then the object can be called as a function having the sensor measurements as arguments and returns a quaternion. If this quaternion becomes the argument of the *viewer*() function [16] it follows the display of a cube that moves in real-time that imitates the moving of the CC2650 Sensor Tag, as in **Figure 9**. However, two files,

#### **Figure 8.**

*The Euler angles computed by Eq. (9), top, and by imufilter(), bottom; the sensor was moved around x and y axis.*

#### **Figure 9.**

*The cube that imitates the moving of the CC2650 Sensor Tag, the initial position-left, the position after a 45 degrees rotation around z axis-right.*

**Figure 10.**

*The Euler angles computed by* imufilter*(), top, and by* complementaryFilter*(), bottom; the sensor was moved around all the three axes.*

HelperOrientationViewer.m and HelperBox.m, must be in the current folder in order to use the function *viewer*() [18].

On the other hand, using the function *eulerd*(), the quaternion form can be converted in pitch, roll and yaw angles (Euler angles) that can be represented as waveforms. This method was used to obtain the results in **Figure 8**. Now **Figure 10** presents the three angles computed using *imufilter*(), in the top part and *complementaryFilter*(), in the bottom part. It can be seen that the angles have the same variation except that the heading around the z axis starts with zero at the top and by about 80 degrees in the bottom. This is because the *complementaryFilter*() uses the magnetometer and thus indicates the angle with respect to the north.

*The program* that implements these facilities is very similar to the previous one. In the following sections, only the new elements are presented.

First the new elements of the script are presented.

```
viewer = HelperOrientationViewer;
SRate=1/T;
ifilt_imu = imufilter('SampleRate', SRate);
ifilt_com = complementaryFilter('SampleRate', SRate);
h=figure(1);
while(ishandle(h))
plot(v_om');grid;legend('x','y','z') %%display the gyroscope readings
drawnow;
if i>200
viewer(qahrs_imu); %%imu quaternions are used to move the cube
end
end
```
%Then it follows the new elements of the callback function. %%%%%%%%%%%%%%%%%%%quaternion%%%%%%%%%%% *Bluetooth Low Energy Applications in MATLAB DOI: http://dx.doi.org/10.5772/intechopen.95814*

qahrs\_imu=ifilt\_imu(A,om\*pi/180); %% for imufilter qahrs\_com=ifilt\_com(A,om\*pi/180,M); %%for complementaryFilter eulerAnglesDegrees\_imu=eulerd(qahrs\_imu, 'ZYX','frame') eulerAnglesDegrees\_com=eulerd(qahrs\_com, 'ZYX','frame')

### **5. Conclusions**

The main MATLAB contributions of this chapter are:


#### **Author details**

Septimiu Mischie Politehnica University Timisoara, Timisoara, Romania

\*Address all correspondence to: septimiu.mischie@upt.ro

© 2021 The Author(s). Licensee IntechOpen. This chapter is distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/ by/3.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

### **References**

[1] Katsikis V, editor. MATLAB. A fundamental tool for scientific computing and engineering applications. Volume1. IntechOpen; 2012. DOI: 10.5772/2557, Volume 2. IntechOpen; 2012. DOI: 10.5772/3338, Volume 3 IntechOpen; 2012. DOI: 10.5772/3339

[2] Mohamad Omar Al Kalaa, Refai H. Bluetooth Standard v4.1: Simulation the Bluetooth Low Energy Data Channel Selection Algorithm. In: Proceedings of Globecom 2014 Workshop – Telecommunication Standards – From Research to Standards. P. 729-733

[3] Afaneh M. Bluetooth5 & Bluetooth Low Energy. A Developer's Guide, ebook, 2018. Available from: https:// www.novelbits.io/bluetooth-5-develope rs-e-book/ [Accessed: 2020-12-02]

[4] Bluetooth. Available from https:// www.bluetooth.com/ [Accessed: 2020-12-02]

[5] Wu Taiyang, Redoute J.M, Yuce M. A wireless Implantable Sensor Design with Subcutaneous Energy Harvesting for Long-Term IoT Healthcare Applications. In IEEE Access, vol. 6, 2018, p.35801-35808.

[6] MATLAB Bluetooth Low Energy. Available from https://www.math works.com/help/matlab/bluetoothlow-energy-communication.html [Accessed: 2020-12-02]

[7] BLE Device Monitor. Available from https://processors.wiki.ti.com/index. php/BLE\_Device\_Monitor\_User\_Guide [Accessed: 2020-12-02]

[8] CC2650 Sensor Tag. Available from https://processors.wiki.ti.com/index. php/CC2650\_SensorTag\_User%27s\_ Guide [Accessed: 2020-12-02]

[9] CC2541 Keyfob, Available from https://www.ti.com/tool/ CC2541KEYFOB-RD [Accessed: 2020-12-02]

[10] Mischie S. On the Development of Bluetooth Low Energy Devices. In: Proceedings of COMM 2018, Bucharest. p.339-344

[11] Mischie S. A MATLAB Graphical Interface to evaluate CC2650 Sensor Tag. In: Proceedings of 22nd IMEKO-TC4 International Symposium, Iasi, Romania, 2017

[12] Fang J, Sun H, Zhang X, Tao Y. A novel Calibration Method of Magnetic Compass Based on Ellipsoid Fitting. IEEE Trans. on Instrumentation and Measurement, vol. 60, no.6, June 2011, p. 2053-2061

[13] Valenti R, Dryanovski I, Xiao J. A Linear Kalman Filter for MARG Orientation Estimation Using the Algebraic Quaternion Algorithm. In IEEE Trans. On Instrumentation and Measurement, vol. 65, no.2 2016, p. 467-481, DOI:10.1109/ TIM.2015.2498998

[14] Yadav R.H, Bhattarai B., Gang H.S. Pyiun J.Y. Trusted K Nearest Batesian Estimation for Indoor Positioning System. In IEEE Access, vo. 7 2019, p.51484-51498. DOI: 10.1109/ ACCESS.2019.2910314

[15] Manos A., Kleian I., Hazan T. Gravity-Based Methods for Heading Computation in Pedestrian Dead Reckoning. In Sensors 2019, 19(5), 1170. DOI: 10.3390/s19051170

[16] Li G., Geng E. Ye Z., Xu Y., Lin J., Pang Y. Indoor Positioning Algorithm Based on the Improved RSSI Distance Model, In Sensors 2018, 18(9), 2820. DOI:10.3390/s18092820

*Bluetooth Low Energy Applications in MATLAB DOI: http://dx.doi.org/10.5772/intechopen.95814*

[17] Thomas C, editor. Sensor Fusion. Foundation and Applications. IntechOpen 2011. DOI: 10.5772/680

[18] MATLAB. Sensor Fusion. Tracking Toolbox, 2020. Available from https:// www.mathworks.com/products/sensorfusion-and-tracking.html [Accessed: 2020-12-02]

Section 5

## Fuzzy Control of Electric Drives

#### **Chapter 5**

## Matlab Program Library for Modeling and Simulating Control Systems for Electric Drives Based on Fuzzy Logic

*Constantin Volosencu*

### **Abstract**

Fuzzy control of the speed of electric drives is an alternative in the field of the control system. Modeling and simulation of electric drive control systems based on fuzzy logic is an important step in design and development. This chapter provides a complete means of modeling and simulation of fuzzy control systems for DC motors, induction motors, and permanent magnet synchronous motors, made in the Matlab/Simulink program environment, useful for performing complex analyzes. The functioning of the programs is demonstrated by an example of characteristics obtained practically, with a functioning regime often encountered in practice.

**Keywords:** simulation, modeling, control of electric drives, DC motors, induction motors, permanent magnet synchronous motors, fuzzy PI controllers

#### **1. Introduction**

Electric drives play an important role in the development of machine tools, production systems, means of transport, and many other practical applications. The purpose of using electric drive control systems is to ensure good performance indicators. The use of fuzzy logic in the control of electric drives ensures the realization of high-performance systems. Modeling and simulation of electric drive control systems based on fuzzy logic are an important means in their design. This chapter presents a library of Matlab/Simulink programs designed to model and simulate electrical drive control systems based on fuzzy speed PI controllers.

In the literature, the control of electric drives based on fuzzy logic is studied in many works. Several Matlab programs for modeling and simulating electric drive systems based on fuzzy logic are presented on the Matlab website as well. Programs for modeling and simulating fuzzy DC drive systems are presented in [1–3]. Programs for modeling and simulating fuzzy driving systems of induction motors are presented in [4, 5]. The Matlab software has the facilities for modeling and simulating fuzzy systems [6] and electric drive systems [7, 8]. The problem of intelligent control of electric drives has been addressed in numerous papers over the years, including application of expert systems, fuzzy logic and neural networks in electric drives [9], fuzzy control of switched reluctance motor drives [10], or fuzzy adaptive vector control of induction motor drives [11]. The basic management systems

of electric actuators have been treated in numerous works in the literature as well. The problem of using electric machines in variable speed control systems is treated in [12], principles of motion control with induction motors are presented in [13] and with permanent magnet, AC machines in [14], the issues of pulse-width modulation for electronic power conversion are presented in [15], principles of modeling and simulation of electric drive control systems are presented in [16]. The basic design of fuzzy PID controllers is shown in [17].

The author of this chapter published the results of his research in the field of fuzzy control of electric drives in specialized literature, addressing the following issues: speed control based on fuzzy PI controllers of DC machines [18], of synchronous machines with permanent magnets [19], of AC machines in general [20], demonstration of the robustness of fuzzy control systems of electric machines [21], analysis of the basic properties of fuzzy control systems [22, 23], tuning of fuzzy PID regulators [24, 25] and analysis of the stability of fuzzy control systems [26].

The chapter presents program libraries dedicated to fuzzy speed regulation of the main electric motors used in practice: direct current motors, induction motors, and permanent magnet synchronous motors, respectively in subsections 2, 3, and 4. For each element of the control systems are presented the equations used in modeling and the related subprograms. For each control system, the transient regime characteristics obtained by simulation are presented. Based on the transient regime characteristics, the values obtained for the performance indicators of the control systems are highlighted, such as overshoot, rise time, error, and others.

#### **2. Library programs**

#### **2.1 DC motor**

The developed programs solve the problem of speed control of the DC machine with the control system from **Figure 1**.

The speed control structure from **Figure 1** has the following components: MCC - DC motor, ML - load machine, CONV - power converter, RG-i - current controller, RF-Ω - fuzzy speed controller, Ti - current sensor, TΩ - speed sensor, CAN, CNA analog to digital and digital to analog converters, MM-ISI - DC motor with statespace equations, Lim - anti-wind-up circuit. The control system variables are: Ω\* speed reference, Ω - motor speed, Ω<sup>m</sup> - measured speed, M - motor torque, Ms - load torque, e<sup>Ω</sup> - speed error, i\* - current reference, iam - measured current, ei - current error, ui - command voltage, ua - motor armature voltage, ia - current motor, ue excitation voltage.

The Simulink block diagram of the speed control system of DC drives based on the fuzzy PI controller is presented in **Figure 2**.

**Figure 1.**

*Block diagram of the DC motor fuzzy speed control system structure.*

*Matlab Program Library for Modeling and Simulating Control Systems for Electric Drives… DOI: http://dx.doi.org/10.5772/intechopen.101488*

#### **Figure 2.**

*Simulink block diagram of the fuzzy control system of DC drive.*

#### **Figure 3.**

*Simulink diagram of current control loop* srcmcc.

The block *RF-w* in **Figure 1** represents the Simulink model of the fuzzy speed controller. The other part of the Simulink diagram is a conventional control part of a linear control system.

The block *srcmcc* is the internal current control loop and it has the Simulink block diagram from **Figure 3**.

The block *Mcc* represents the DC motor and it has the equations:

$$\begin{split} \frac{di\_a}{dt} &= -\frac{R\_d}{L\_a}i\_d - \frac{k\_t}{L\_a}\Omega + \frac{1}{L\_a}u\_d\\ \frac{d\Omega}{dt} &= \frac{k\_m}{J}i\_d - \frac{k\_f}{J}\Omega - \frac{1}{J}M\_s \end{split} \tag{1}$$

The power converter has the block *CONV* and the current sensor has the block *Ti*. Their transfer functions are presented in their blocks. The current controller has a PI linear transfer function. The armature voltage *u*<sup>a</sup> is limited. The speed sensor has the block *Tw*. The current controller has anti-windup protection. The current reference is limited. The simulation diagram allows simulations in four quadrants for speed and torque. The diagram calculates a quadratic performance criterion of speed error with the formula:

$$E = \int e^2 dt \tag{2}$$

A theoretic design for fuzzy speed control systems for DC drives is presented in [27].

#### **2.2 Induction motor**

The structure of the fuzzy control system of the induction machine is presented in **Figure 4**.

The meanings of the notations in the **Figure 4** are as follows: MAS - induction machine; ML- working machine; CONV- power electronic convertor; RG-i - stator phase current controllers; Ti—current sensor; Tθ—position sensor; TΩ—speed sensor; TCI—inverse Park coordinate transformation; BCC—block for calculating the reference currents in the vector control structure of the asynchronous machine with rotor flux orientation; RF-Ω—speed fuzzy PI controller; Ω—rotor speed; Ω\* speed reference; *M*\*—torque reference; фr\*—rotor flux reference; θs\*—stator phasor position reference; *i*d\*, *i*q\*—d, q stator current references; *i*s\*—stator current reference; Ωm—measured speed; θm—measured rotor position; *i*sm—measured stator currents; *e*Ω—speed error; *e*i—current error; *S*i—control signals for power converter switches with pulse width modulation; *V*cc—DC converter supply voltage; *u*s—stator voltages; *M*s—load torque. The induction motor is vector controlled with rotor flux orientation, with rotor flux reference ϕ\* <sup>r</sup> and torque reference *M*\* and the measured rotor position θm. The reference stator currents are calculated with the block TCI. The current regulators RG-i give the pulse width modulation signals *S*<sup>i</sup> for the electronic power converter CONV, fed from a DC voltage source *V*CC. The power converter CONV gives the stator voltages *u*s.

The speed control system of induction motors based on the fuzzy PI controller is presented in **Figure 5**.

The model from **Figure 5** implements an induction motor control structure with indirect field orientation in rotor coordinates [13, 28]. The block *mas* represents the induction motor and it has the Equations [13, 29, 30]:

**Figure 4.**

*Block diagram of the induction motor fuzzy speed control system structure.*

**Figure 5.** *Simulink diagram of the fuzzy control system of induction motors.*

*Matlab Program Library for Modeling and Simulating Control Systems for Electric Drives… DOI: http://dx.doi.org/10.5772/intechopen.101488*

$$\begin{aligned} \underline{\mathbf{u}}\_{\mathcal{f}} &= \underline{\mathbf{u}}\_{\mathcal{e}} e^{-j\boldsymbol{\theta}\_{f}}, \dot{\mathbf{i}}\_{\mathcal{f}} = \underline{\mathbf{i}}\_{\mathcal{e}} e^{-j\boldsymbol{\theta}\_{f}}, \underline{\mathbf{a}}\_{\mathcal{f}} = \underline{\mathbf{0}}\_{\mathcal{e}} e^{-j\boldsymbol{\theta}\_{f}}, \underline{\mathbf{u}}\_{\mathcal{f}} = \underline{\mathbf{u}}\_{\mathcal{e}} e^{-j\boldsymbol{\theta}\_{f} + \boldsymbol{\theta}}, \dot{\mathbf{i}}\_{\mathcal{f}} = \underline{\mathbf{i}}\_{\mathcal{e}} e^{-j\boldsymbol{\theta}\_{f} + \boldsymbol{\theta}}, \\ \underline{\mathbf{0}}\_{\mathcal{f}} &= \underline{\mathbf{0}}\_{\mathcal{e}} e^{-j\boldsymbol{\theta}\_{f} + \boldsymbol{\theta}}, \underline{\mathbf{u}}\_{\mathcal{f}} = R\_{i} \dot{\underline{\mathbf{i}}}\_{\mathcal{f}} + \frac{d\underline{\mathbf{Q}}\_{f}}{dt} + j\boldsymbol{\alpha}\_{f} \underline{\mathbf{Q}}\_{\mathcal{f}}, \end{aligned} \tag{3.10}$$
 
$$\underline{\mathbf{u}}\_{\mathcal{f}} = R\_{i} \dot{\underline{\mathbf{i}}}\_{\mathcal{f}} + \frac{d\underline{\mathbf{Q}}\_{f}}{dt} + j(\boldsymbol{\alpha}\_{f} - \boldsymbol{\alpha}) \underline{\mathbf{Q}}\_{\mathcal{f}}, \mathcal{M} = \frac{3}{2} n\_{p} L\_{m} \operatorname{Re} \left\{ j \, \underline{\mathbf{i}}\_{\mathcal{f}} \, \dot{\underline{\mathbf{i}}}\_{\mathcal{f}} \right\}, \boldsymbol{J} \frac{d\boldsymbol{\Omega}}{dt} = \boldsymbol{\mathcal{M}} - k\_{f} \boldsymbol{\Omega} - M\_{m} \tag{3.10}$$

The Eqs. (3) are written for the general flux, and in the case of vector control with rotor flux orientation, the flux is the rotor flux: θ<sup>f</sup> = θr. CONV is a power inverter functioning in comutation, TCI is the inverse Park coordinate transformation [30], BCC is for calculating the reference currents in the vector control structure of the asynchronous machine with rotor flux orientation. BCC has the block diagram from **Figure 6** [13, 30].

Where *n*<sup>p</sup> - the pole pair number, *L*m,r - magnetic and rotor inductances, *s* - slip frequency, *R*<sup>r</sup> - rotor resistance, ω<sup>s</sup> \* - stator frequency reference. Two-position current controllers RG-i with hysteresis are used.

#### **2.3 Permanent magnet synchronous motor**

The structure of the fuzzy control system of the permanent magnet synchronous motor is presented in **Figure 7**.

The meanings of the notations in **Figure 7** are the same as in **Figure 4**, and MSMP is the permanent magnet synchronous machine. The permanent magnet synchronous motor is vector controlled with rotor flux orientation with rotor q current *i* \* <sup>q</sup> as a torque reference, the rotor d current *i* \* <sup>d</sup> at zero as a flux reference ϕ\* r, and the measured rotor position θm.

The speed control system of induction motors based on the fuzzy PI controller is presented in **Figure 8**.

#### **Figure 6.**

*The block for calculating the reference currents in the vector control structure of the asynchronous machine with rotor flux orientation (BCC).*

**Figure 7.** *Block diagram of the induction motor fuzzy speed control system structure.*

**Figure 8.** *Simulink diagram of the fuzzy control system of permanent magnet synchronous motors.*

This diagram implements the rotor flux oriented control structure [14]. The block *msmp + csc* includes the permanent magnet synchronous motor, with Equations [14, 30]:

$$\begin{aligned} \underline{u}\_{\mathcal{f}} &= \underline{u}\_{\epsilon} e^{-j\theta}, \underline{i}\_{\mathcal{f}} = \underline{i}\_{\epsilon} e^{-j\theta}, \underline{\Phi}\_{\mathcal{f}} = \underline{\Phi}\_{\epsilon} e^{-j\theta}, \underline{u}\_{\mathcal{f}} = R\_i \underline{i}\_{\mathcal{f}} + \frac{d\underline{\Phi}\_{\mathcal{f}}}{dt} + j\alpha \underline{\Phi}\_{\mathcal{f}}, \\\ M &= \frac{3}{2} \operatorname{Re} \left\{ \left. j\underline{\Phi}\_{\mathcal{f}}, \underline{i}\_{\mathcal{f}} \right\} \right\} J \frac{d\Omega}{dt} = M - k\_f \Omega - M, \end{aligned} \tag{4}$$

The current controllers and the Park inverse coordinator transformation, like in the case of the induction motor.

#### **2.4 Fuzzy speed controller**

The Simulink diagram of fuzzy speed controller RF-w is presented in **Figure 9**. It is developed based on the block diagram of the fuzzy controller RG-F from **Figure 10**.

The fuzzy controller has Mamdani's structure with the fuzzification of the input variables *x*i, inference of the fuzzy values *x*f, with a rule base, and defuzzification of the fuzzy command *u*f. The fuzzy block gives the command *u*d. Different membership functions for the input and output variables, different inference methods, and different rule bases may be chosen [17, 19, 21, 22]. Here are some Matlab programs for fuzzy computing, as follows.

**Figure 9.**

*Simulink diagram of fuzzy speed controller RF-w.*

#### **Figure 10.**

*The block diagram of the fuzzy controller RG-F.*

*Matlab Program Library for Modeling and Simulating Control Systems for Electric Drives… DOI: http://dx.doi.org/10.5772/intechopen.101488*

A program for defining the function of triangle membership:

```
function [m]=triunghi(x,a,b,c)
% parameters: a<b<c / m(a)=m(c)=0, m(b)=1
n=length(x);
for i=1:n
    if x(i)<=a | x(i)>=c
         m(i)=0;
    elseif x(i)>a & x(i)<b
         m(i)=1/(b-a)*x(i)+a/(a-b);
    elseif x(i)==b
         m(i)=1;
    else
         m(i)=x(i)/(b-c)+c/(c-b);
end
end
```
A program for defining the function of decreasing trapezoidal membership:

```
function [m]=trapezd(x,a,b)
% parameters: a<b, m(a)=1, m(b)=0
n=length(x);
for i=1:n
    if x(i)<=a
         m(i)=1;
    elseif x(i)<b & x(i)>a
         m(i)=x(i)/(a-b)+b/(b-a);
    else
         m(i)=0;
end
end
```
A program for defining the function of increasing trapezoidal membership:

```
function [m]=trapezc(x,a,b)
% parameters: a<b, m(a)=0, m(b)=0
n=length(x);
for i=1:n
    if x(i)<=a
         m(i)=0;
    elseif x(i)>=b
         m(i)=1;
    else
         m(i)=x(i)/(b-a)+a/(a-b);
end
end
end
   A program for calculating the rule base 3–3 for DC motors:
```

```
% Loading control system parameters:
load pudmcc
% Calculating the margins of discourse universes:
diN=IN/Ki/5/Ti;
diM=IM/Ki/5/Ti;
```

```
ewM=KCAN*KTw*2*wb;
ewb=ewM/2;
deMt=KCAN*KTw/J*(MMt+kf*wb);
deMc=KCAN*KTw/J*(MMc+kf*wb);
pdi=diM/20;
pe=ewM/20;
pde=deMt/20;
% discourse universes:
udi=[-diM:pdi:diM];
ue=[-ewM:pe:ewM];
ude=[-deMt:pde:deMt];
% Definition of fuzzy values:
NBdi=trapezd(udi,-diN,0);
ZEdi=triunghi(udi,-diN,0,diN);
PBdi=trapezc(udi,0,diN);
NBe=trapezd(ue,-ewb,0);
ZEe=triunghi(ue,-ewb,0,ewb);
PBe=trapezc(ue,0,ewb);
NBde=trapezd(ude,-deMc,0);
ZEde=triunghi(ude,-deMc,0,deMc);
PBde=trapezc(ude,0,deMc);
% Normalization of discourse universes:
ue=ue/ewb;
ude=ude/deMc;
udi=udi/diN;
subplot(3,1,1),plot(ue,NBe,ue,ZEe,ue,PBe);
    xlabel('ew');ylabel('me');grid
subplot(3,1,2),plot(ude,NBde,ude,ZEde,ude,PBde);
    xlabel('de');ylabel('mde');grid
subplot(3,1,3),plot(udi,NBdi,udi,ZEdi,udi,PBdi);
    xlabel('di');ylabel('mdi');grid
% Table of rules
A1=[NBe; ZEe; PBe;
  NBe; ZEe; PBe;
  NBe; ZEe; PBe];
A2=[NBde; NBde; NBde;
    ZEde; ZEde; ZEde;
    PBde; PBde; PBde];
B=[NBdi; NBdi; ZEdi;
   NBdi; ZEdi; PBdi;
   ZEdi; PBdi; PBdi];
save daterf3 ue ude udi A1 A2 B ewM deMt
```
A program for fuzzy block implementation in Simulink scheme:

```
function [dip]=bdf(e,de,A1,ue,A2,ude,B,udi)
% Input variables: error e, error deivative: de
% Output variable: dip
% Inference with Larsen max-min method:
dif=infermm(A1,e,ue,A2,de,ude,B);
% Defuzzification with centre of gravity method:
dip=defzfir(dif,udi,1);
end
```
*Matlab Program Library for Modeling and Simulating Control Systems for Electric Drives… DOI: http://dx.doi.org/10.5772/intechopen.101488*

**Figure 11.**

*Speed characteristics for direct current machine a), induction machine b) and synchronous machine with permanent magnets c), for fuzzy regulation with continuous line and for conventional regulation with a dashed line.*

The fuzzy block RG-F has algebraic properties and the sector property presented in [22–24]. The fuzzy controller RF-w may be designed using a pseudo-equivalence with a linear PI controller with a grapho-analytical method [25–27], based on its input–output transfer characteristics [22–24].

#### **3. Speed characteristics**

With the help of the programs presented above, transient characteristics can be obtained for various operating regimes, which can be chosen by the signals applied to the speed prescription inputs and to the disturbing inputs of the load torques. Thus, transient regime characteristics can be obtained for speeds, currents, voltages, fluxes, mechanical torques, regulation errors, and others. These programs allow complex analyzes of the behavior of speed control systems based on fuzzy PI controllers. The fuzzy PI controller can be replaced with a conventional, linear PI controller. In order to demonstrate the good functioning of the programs, the following is an example of an operating regime often encountered in practice for the three-speed regulation structures. The simulated operating regime consists of: starting the machine idle up to the nominal speed, loading it with a nominal mechanical torque, and reversing the load. It was also chosen to exemplify the case when a conventional linear PI speed regulator is used. The characteristics in the two cases - fuzzy and linear - are presented in the same graph, and the same coordinate axes, for example. **Figure 11a**–**c** show the speed characteristics for the DC machine, induction machines, and the permanent magnet synchronous machine, respectively.

It is observed that in the case of fuzzy control better quality control indicators are obtained: zero overshoot, shorter rise time, shorter time for elimination of load torque effect, etc. [18–20]. The fuzzy control structures are global absolute internal stable and external BIBO stable [28]. The fuzzy control structures are robust at parameter identification errors and at the perturbation from the load torque [21].

#### **4. Conclusion**

The chapter presents a library of Matlab/Simulink programs for the control of electric drives. Thus, Simulink schemes are presented for modeling and simulating the fuzzy speed control systems of direct current machines, induction machines with vector control with rotor flux orientation, and synchronous machines with permanent magnets. Matlab/Simulink programs are presented for modeling and

simulating fuzzy PI controllers based on the Mamdani structure. To demonstrate the operation of the programs, the characteristics of the speed obtained in the case of the three adjustment structures are presented. Fuzzy system modeling programs can be developed for various types of membership functions, inference methods, and rule bases.

#### **Conflict of interest**

The author has no conflict of interest.

#### **Appendix**

The parameters of the three motors taken as examples are presented below. The DC motor: *P*<sup>n</sup> = 1 kW, *U*<sup>n</sup> = 220 V, *n*<sup>n</sup> = 3000 rot./min., η = 0,75, *p* = 2, *J* = 0,006 kgm<sup>2</sup> , *M*<sup>n</sup> = 3,2 Nm, Ω<sup>n</sup> = 314 rad/s, *I*<sup>n</sup> = 6A, *I*<sup>M</sup> *=* 10,8 A, *R*<sup>a</sup> = 2,01 Ω, *L*<sup>a</sup> = 0,034 H,*T*<sup>a</sup> = 0,017 ms, *k*<sup>e</sup> = 0,664 Vs, *k*<sup>m</sup> = 0,533 Nm/A, *k*<sup>f</sup> = 8.10<sup>4</sup> Nms, *K*CNA = *K*CAN = 1, *I*lim = *I*M, *U*aM = 240 V.

The induction motor: *R*<sup>s</sup> = 12,4 Ω; *R*<sup>r</sup> = 12,4 Ω; *L*<sup>m</sup> = 0,8 H; *L*s<sup>σ</sup> = 0,06 H; *L*r<sup>σ</sup> = 0,06 H; *p* = 4; *k*<sup>f</sup> = 0,008 Nms; *J* = 0,01 kgm<sup>2</sup> ; *M*Mc = 7 Nm; *M*Mt = 24 Nm; nb = 750 rot/min; *P*N(Mc) = 550 W; *I*sN = 1,77 A; *I*sM = 8 A; *U*sN = 220 V.

The permanent magnet synchronous motor: *P*<sup>N</sup> = 400 W; *I*<sup>N</sup> = 3 A; *I*<sup>M</sup> = 8 A; nm = 4000 rot/min; nb = 3000 rot/min; *M*Mc = 1,3 Nm; *M*Mt = 3,4 Nm; *J* = 0,001 kgm<sup>2</sup> ; *k*<sup>f</sup> = 0,0001 Nms; *R*<sup>s</sup> = 0,6 Ω; *L*<sup>d</sup> = 4 mH; *L*<sup>q</sup> = 5 mH; *p* = 4; Φe0 = 0,072 Wb; *V*cc = 200 V.

#### **Author details**

Constantin Volosencu Department of Automation and Applied Informatics, "Politehnica" University Timisoara, Romania

\*Address all correspondence to: constantin.volosencu@aut.upt.ro

© 2021 The Author(s). Licensee IntechOpen. This chapter is distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/ by/3.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

*Matlab Program Library for Modeling and Simulating Control Systems for Electric Drives… DOI: http://dx.doi.org/10.5772/intechopen.101488*

#### **References**

[1] Sekar A. Fuzzy PI DC motor Speed Control. 2021. Available from: https:// www.mathworks.com/matlabcentral/ fileexchange/74291-fuzzy-pi-dc-motorspeed-control. MATLAB Central File Exchange. The Mathworks, Inc., Natick, MA, USA. [Accessed 2021-01-06]

[2] Malla S. Fuzzy controller based Speed Control of DC Motor. 2021. Available from: https://www.mathworks.com/ matlabcentral/fileexchange/36508-f uzzy-controller-based-speed-control-ofdc-motor. MATLAB Central File Exchange. The Mathworks, Inc., Natick, MA, USA. [Accessed 2021-01-06]

[3] Merah A. Speed control of DC motor using Fuzzy Logic Controller. 2021. Available from: https://www.math works.com/matlabcentral/fileexchange/ 64993-speed-control-of-dc-motorusing-fuzzy-logic-controller. MATLAB Central File Exchange. The Mathworks, Inc., Natick, MA, USA. [Accessed 2021- 01-06]

[4] Elbesealy M. A Fuzzy V/F Control for High Performance Induction Motors Drive. 2021. Available from: https:// www.mathworks.com/matlabcentral/ fileexchange/59454-a-fuzzy-v-fcontrol-for-high-performance-induc tion-motors-drive. MATLAB Central File Exchange. The Mathworks, Inc., Natick, MA, USA

[5] Sang N.T. Fuzzy controller induction motor. 2021. Available from: https:// www.mathworks.com/matlabcentral/ fileexchange/68377-fuzzy-controllerinductin-motor. MATLAB Central File Exchange. The Mathworks, Inc., Natick, MA, USA. [Accessed 2021-01-06]

[6] Zadeh LA. Fuzzy Logic Toolbox User's Guide. The Math Works, Inc., Natick, MA, USA.; 1995-2020.

[7] Sybille G, Dessaint LA. et al. Simscape Electrical Reference

(Specialized Power Systems). Hydro-Québec and The MathWorks, Inc., Natick, MA, USA; 1998–2020

[8] Sybille G, Dessaint LA. et al. Simscape Electrical Reference. The MathWorks, Inc., Natick, MA, USA; 2013–2020

[9] Bose BK. Expert System, Fuzzy logic and neural network applications in power electronics and motion control. Proceedings of the IEEE. 1994;**8**: 1303-1323. DOI: 10.1109/5.301690

[10] Bolognani S, Zigliotto M. Fuzzy logic control of a switched reluctance motor drive. In: Conference Record of the 1993 IEEE Industry Applications Conference Twenty-Eighth IAS Annual Meeting; 2–8 October 1993; Toronto. Ontario, Canada: IEEE; 2005. DOI: 10.1109/IAS.1993.299145

[11] Cerruto E, Consoli A, Raciti A, Testa A. Fuzzy adaptive vector control of induction motor drives. IEEE Trans. on Power Electronics. 1997;**6**:1028-1040. DOI: 10.1109/63.641501

[12] Slemon GR. Electrical machines for variable-frequency drives. Proc. of the IEEE. 1994;**8**:1123-1139. DOI: 10.1109/ 5.301681

[13] Lorenz RD, Lipo TA, Novotny DW. Motion control with induction motors. Proc. of the IEEE. 1994;**8**:1215-1240. DOI: 10.1109/5.301685

[14] Jahnd TM. Motion control with permanent magnet AC mashines. Proc. of the IEEE. 1994;**8**:1241-1252. DOI: 10.1109/5.301686

[15] Holtz J. Pulse width modulation for electronic power conversion. Proc. of the IEEE. 1994;**8**:1194-1214. DOI: 10.1109/5.301684

[16] Mohan N, Robbins WP, Underland TM, Nilsen R, Mo O. Simulation of power electronic and motion control systems - an overview. Proc. of the IEEE. 1994;**8**:1287-1302. DOI: 10.1109/5.301689

[17] Buhler H. Reglage par logique floue. Lausanne: Press Polytechniques et Universitaires Romands; 1994. p. 20

[18] Volosencu C. Fuzzy control of electrical drives, based on fuzzy logic. WSEAS Transactions on Systems and Control. 2008;**9**(3):809-822

[19] Volosencu C. Speed Control of a Permanent Synchronous Motor, Based on a Quasi-Fuzzy Controller, In Proceedings of the 10th European Conference on Power Electronics and Applications, European Power Electronics and Drives Association, 2003, Toulouse, France.

[20] Volosencu C. Some Consideration about Using Fuzzy Logic for Speed Control of Electrical Drives, In The 7-th European Congress on Intelligent Techniques and Soft Computing EUFIT'99, 1999. Aachen, Verlag Mainz, Germany

[21] Volosencu C. Demonstration by Simulation of the Robustness of the Fuzzy Control System of a DC Motor at Errors at the Parameter Identification, In Pemc'98 Conference, 1998, Prague, Czech Technical University, Czech Rep.

[22] Volosencu C. Introductory Chapter: Basic Properties of Fuzzy Relations, In Volosencu C, editor. Fuzzy Logic, IntechOpen, London, UK; 2020. p. 3-10. DOI: 10.5772/intechopen.88172

[23] Volosencu C. Properties of fuzzy systems. WSEAS Transactions on Systems. 2009;**2**(8):210-228

[24] Volosencu C. On Some Properties of Fuzzy Systems, In Proceedings of the 8th WSEAS International Conference on Signal Processing, Robotics and

Automation (ISPRA09), Feb. 21–23, 2009; Cambridge, UK, 2005.

[25] Volosencu C. Tuning Fuzzy PID Controllers, In Rames C. Panda, editor. Theory, Tuning and Application to Frontier Areas, IntechOpen, London, UK.; 2012. 171-190. DOI: 10.5772/32750.

[26] Volosencu C. Pseudo-equivalence of fuzzy PID controllers. WSEAS Transactions on Systems and Control. 2009;**4**(4):163-176

[27] Volosencu C. Pseudo-Equivalence of Fuzzy PI Controller, In Proceedings of the 8th WSEAS International Conference on Signal Processing, Robotics and Automation (ISPRA09), Feb. 21–23; Cambridge, UK, 2009, WSEAS Press, Athens, Greece.

[28] Volosencu C. Stabilization of fuzzy control systems. WSEAS Transactions on Systems and Control. Athens, Greece: WSEAS Press; 2008;**10**(3): 879-896

[29] Leonhard W. Control of Electrical Drives. Berlin: Springer Verlag; 1985

[30] Boldea I, Nasar SA. Vector Control of A.C Drives. Boca Raton, Florida: C. R. C. Press; 1992

### *Edited by Constantin Voloşencu*

The book presents a comprehensive overview of MATLAB and Simulink programming. Chapters discuss MATLAB programming for practical usages in mesosphere– stratosphere–troposphere (MST) radars, geometric segmentation, Bluetooth applications, and control of electric drives. The published examples highlight the capabilities of MATLAB programming in the fields of mathematical modeling, algorithmic development, data acquisition, time simulation, and testing.

Published in London, UK © 2022 IntechOpen © smirkdingo / iStock

MATLAB Applications in Engineering

MATLAB Applications

in Engineering

*Edited by Constantin Voloşencu*