This is an open access article under the CC BY license: Al-Khwarizmi Engineering Journal Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, December, (2022) P. P. 60- 72 BCI-Based Smart Room Control using EEG Signals Oger Zaya Amanuel * Yarub Alazzawi ** *,**Department of Mechatronics Engineering/ Al-Khwarizmi College of Engineering/ University of Baghdad *Email: Awkar.zia1202a@kecbu.uobaghdad.edu.iq **Email: yaarub.omar@kecbu.uobaghdad.edu.iq (2022 September 26 2022; Accepted uly J 42Received ) https://doi.org/10.22153/kej.2022.09.004 Abstract In this paper, we implement and examine a Simulink model with electroencephalography (EEG) to control many actuators based on brain waves. This will be in great demand since it will be useful for certain individuals who are unable to access some control units that need direct contact with humans. In the beginning, ten volunteers of a wide range of (20- 66) participated in this study, and the statistical measurements were first calculated for all eight channels. Then the number of channels was reduced by half according to the activation of brain regions within the utilized protocol and the processing time also decreased. Consequently, four of the participants (three males and one female) were chosen to examine the Simulink model during different actions. The model contained: input signals, data selection according to the activation regions in the brain, features extraction, classification according to the frequency ranges of each action, and an interface with an embedded system to control the actuators. Keywords: EEG, BCI, FFT. 1. Introduction The brain-computer interface-based systems are being used in a variety of applications, such as motor disabilities' needs, games, and other scientific domains that are related to the brain. Through the BCI, EEG signals have been used to manage external equipment. These systems allow disabled patients to operate a variety of equipment using their brain waves. Also, the brain-computer interface (BCI) is a tool capable of converting a user's brainwave patterns into computer-readable messages. Besides, brain activity may be studied using electroencephalography (EEG) by placing electrodes on the scalp to measure brain activity. It is viable, flexible, portable, and can analyze brain interactions in real-time [1] [2] [3] [4] [5]. EEG measures the brain activity and divides it into rhythms depending on the frequency: Delta- 𝛿 (< 4 Hz), theta-𝜃 (4-8) Hz, alpha-𝛼 (8-13) Hz, beta-𝛽(13-32) Hz, and gamma-𝛾 (> 32) Hz [5] [6]. Many previous studies focused on the classification of brain waves and controlling some devices using the Simulink model. [7] Used BCI with Simulink to classify the signals [8]. Described how to control three servo motors (Robotic arms) based on brain waves [9]. Showed the control of an actuator or computer cursor using the Simulink framework [10]. Explained the analysis and classification of EEG signals using the Simulink model. This study involved a large number of participants with a wide range of ages (20-65) years old, giving more information about the data and obtaining more accurate results. Moreover, the statistical measurements were calculated and enhanced. Besides, it was suggested to reduce the number of channels needed according to the used protocol and the activation of brain lobes’ regions. Consequently, the model was examined by four mailto:Awkar.zia1202a@kecbu.uobaghdad.edu.iq mailto:yaarub.omar@kecbu.uobaghdad.edu.iq https://doi.org/10.22153/kej.2022.09.004 Oger Zaya Amanuel Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, P.P. 60- 72 (2022) 61 participants (28-38) years old, and all attempts were successful. 2. Experimental Work The EEG electrodes were positioned as a 10–20 system [6], as shown in Figure (1), and the ultra- cortex mark IV headset (16 channels), shown in Figure (2), was used for brain wave collection. The collected signals were sent by the cyton board to the computer via USB dongle. Fig. 1. 10-20 system of electrodes placement. Fig. 2. Ultra-cortex mark IV headset with the components. Oger Zaya Amanuel Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, P.P. 60- 72 (2022) 62 The headset includes dry EEG sensors and the PIC-32MX250F128B microcontroller in its design, which provides relatively abundant memory and great processing performance. In addition, the Chip-KITTM bootloader and the most modern Open-BCI firmware are already implemented on the board. As well, the system interacts wirelessly with a computer using an RFDuino radio module and USB dongle via BLE, as shown in figure (3). Finally, each channel is recorded at a 125 or 250 Hz sampling rate [11] [12] [13]. 3. Methodology In this work, 10 people participated in signals collection, (9 males and 1 female) aged (20-65) years old, as shown in Table (1). The participants were recruited from inside and outside Al Khwarizmi College of Engineering at Baghdad University to be volunteers to collect their EEG signals. Moreover, all received proper consent under an approved protocol from Al-Khwarizmi College of Engineering/Mechatronics department. The following protocol, shown in Figure (4), was contained in three sessions as following: (open eyes and relaxed), (closed eyes and relaxed) and then (open eyes with concentration and calculate a simple arithmetic mental). Each session was followed by a few seconds of rest. In addition, the signals were collected without smoothing, a notch filter (50 Hz), and a band pass filter (1-100 Hz). Fig. 4. The protocol of EEG signals collection. Fig. 3. The communication between the cyton boards and computer Oger Zaya Amanuel Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, P.P. 60- 72 (2022) 63 Table 1, The volunteers’ information. First, eight EEG channels were utilized in the signals’ collection for each person. The statistical measurements (mean and standard deviation) were calculated as shown in figure (5), and it was noticed that an overlap occurred between the regions in the close and open classes, as shown in table (2). Then, depending on the used protocol (open and closed eyes), the Alpha and Beta rhythms are activated mainly, which are mostly recognized in frontal and occipital regions, because the alpha waves occur while resting with the eyes closed, and the frequency of the rhythm is (8-13) Hz. It is measured in the rear of the skull (occipital), while beta waves are detected in the front central regions of the scalp [14]. Moreover, when the eyes are opened or mental activity begins, the alpha waves diminish and are replaced by beta waves. Fig. 5. The mean and standard deviation of 8 channels. Table 2, The mean values for all channels Accordingly, only the four channels were utilized in this study (Fp1 and Fp2 for the frontal lobe and O1 and O2 for the occipital lobe) [15] [16]. The statistical measurements were recalculated as shown in figure (6), which indicated that the mean values for the open eyes class (positive) were separated from those for the closed eyes class (negative), as shown in Table (3). participant Gender Age Status 1 Male 20 Healthy 2 Female 28 Healthy 3 Male 29 Healthy 4 Male 37 Healthy 5 Male 35 Healthy 6 Male 46 Healthy 7 Male 41 Healthy 8 Male 43 Healthy 9 Male 60 Healthy 10 Male 65 Healthy Participant Mean Closed eyes class Open eyes class 1. -3.0048e+04 -2.5600e+04 2. -9.9268e+03 2.4977e+03 3. 5.5503e+03 -9.5832e+04 4. -7.4672e+04 8.6425e+04 5. -8.8025e+04 -7.6606e+03 6. -2.5069e+03 -3.0630e+04 7. -5.6147e+04 -6.4567e+04 8. -4.6553e+04 -1.0848e+05 9. -5.0164e+04 -7.1173e+04 10. 2.7355e+04 1.7761e+04 Oger Zaya Amanuel Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, P.P. 60- 72 (2022) 64 Fig. 6. The mean and standard deviation of frontal and occipital channels only. Table 3, The mean values for the frontal and occipital regions’ channels The four channels selected (Fp1, Fp2, O1 and O2) were plotted as shown in figure (7), using EEGLAB (scale 1000). EEGLAB is mostly used for visualizing or plotting the signals and removing the artifacts [17]. Then a band pass filter (7–32) Hz was used for the same channels depending on the frequency ranges of Alpha (8–13) Hz and Beta (14–32) Hz rhythms, as presented in Figure (8). Fig.7. The frontal and occipital channels without filtering. Participant Mean Closed eyes class (O1&O2) channels Open eyes class (Fp1 & Fp2) channels 1. -4.6899e+04 1.2860e+04 2. -1.5007e+05 7.5808e+03 3. -3.8224e+04 7.7577e+03 4. -5.3868e+04 9.3905e+03 5. -5.3995e+04 8.6892e+03 6. -3.3575e+04 9.2576e+03 7. -1.9006e+04 5.8581e+03 8. -3.0794e+04 7.0939e+03 9. -3.5690e+04 8.7793e+03 10. -4.3787e+04 6.1779e+03 Oger Zaya Amanuel Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, P.P. 60- 72 (2022) 65 Fig. 8. The frontal and occipital channels with filtering. 4. Pre-processing First, the collected signals are amplified many times before being transmitted to the computer via the cyton board, bio-sensing daisy board, and USB dongle. Then the notch filter is applied, which is used to remove a specific frequency [16], so the filter was applied for 50 Hz because that hertz is the type of activity in the AC current source of the electrical equipment. As well, a band-pass filter (1- 100) Hz is applied to remove the other unwanted frequencies. Moreover, the data is sampled at 250 Hz on each channel. Finally, some epochs (transient time) are removed from each session to avoid the overlap between the classes. 5. Simulation Model Figure (9) illustrates the steps that were followed, beginning with collecting brain waves using the electrodes that were placed in the headset. Then select the data according to the used protocol, which causes the activation in the frontal and occipital lobes. Therefore, the number of channels is reduced from 8 to 4 (2 for the frontal lobe region and 2 for the occipital lobe region). Consequently, the data was mapped to features during the feature extraction step. After that, the features are classified into classes within the classification. Finally, the classified classes control the actuators (DC motors were used to indicate the room devices) via an embedded system, which receives the conditions and commands based on brain waves. Fig. 9. The block diagram. Oger Zaya Amanuel Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, P.P. 60- 72 (2022) 66 In this work, MATLAB Simulink was used to build a model that was capable of reading raw data, selecting specific channels, extracting features, classifying them, and controlling the actuators using an interface with a microcontroller. In other words, for a new participant, first the collected signals in different actions according to a specific protocol enter the model. Then divide the data into some segments, which are translated into features that are classified into two decisions. The decisions are: if the data belong to the closed-eyes class, then the first motor turns on. Whereas if the data belong to the open eyes class, the second motor turns on, as shown in figure (10). Fig.10. The Simulink model. The blocks used in the simulation model were as follows: The (simin) block was used to enter the collected signals into the Simulink model. The DWT (Discrete-Wavelet-Transform) block was used to separate a signal into smaller bandwidth sub-bands and lower sampling rates [18]. It includes a variety of filters (Haar, Daubechies, Symlets, Coiflets, Biorthogonal, and other types), as well as symmetric and asymmetric tree structures. Moreover, the FFT block was used as a feature extraction block with the periodogram- method. Consequently, a nonparametric approximation of the spectrum is computed, and the output is equal 𝑦 = 𝑎𝑏𝑠 (𝑓𝑓𝑡(𝑢, 𝑛𝑓𝑓𝑡)) … (1) Where 𝑢: Is an input 𝑀 𝑏𝑦 𝑁 In addition, in the classification step, a digital filter design block was used to implement a digital FIR or IIR filter or other digital filters. These filters can classify the signals into many bands according to the frequency range, and as the utilized protocol, there were two classes that are different in the frequency range. First, closed eyes class (alpha rhythm) 7-14 Hz. Second, open eyes with a simple mental (beta rhythm) 14-32 Hz. Finally, the digital pin block and PWM block were used to interface the Simulink with a micro-controller to control the actuators, and if the new data is classified as first class, the 1st motor turns on, while if the data is classified as second class, the 2nd motor turns on, as shown in Figure (11). Oger Zaya Amanuel Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, P.P. 60- 72 (2022) 67 Fig.11. The flow chart of the work 6. Results and Discussion The data was collected from ten participants of different ages (20-66) years old, and the statistical measurements (mean and standard deviation) were calculated for eight and four channels, respectively. Then four participants (three males, one female) aged (28–38) years old were chosen to examine the Simulink model. Their brain waves were translated as features using Fast Fourier Transform (FFT) and classified into sub-bands based on the frequency range using band-pass filters according to the participant’s status. Figure (12), depicts the frequency and power spectrum density (PSD) for the frontal and occipital regions (open eyes with arithmetic and closed eyes with relaxation). In addition, the PSD is one of the most significant digital-processing tools. It assists in understanding how a signal's intensity is dispersed in the frequency domain [19]. Oger Zaya Amanuel Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, P.P. 60- 72 (2022) 68 Fig. 12. Frequency and PSD for Fp1, Fp2, O1, and O2 channels. Figure (13), presents the two actuators which were turning on/off based on the participant’s brain waves. The two actuators were connected to a Microcontroller (Arduino) through a driver, and the microcontroller was interfaced with MATLAB to receive the commands based on the simulation model. Moreover, the attempts to examine the model and turn on/off the actuators based on brain waves were successful. Oger Zaya Amanuel Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, P.P. 60- 72 (2022) 69 Fig. 13. The hardware circuit. 7. Conclusion This study proposed a simulation model to control a smart structure, such as simple actuators, depending on brain waves. Ten volunteers participated in collecting the brain waves using electroencephalography (EEG) and non-invasive BCI. First, the statistical measurements for all channels (eight channels) were calculated, and there was an overlap between the results for the two different classes (closed eyes and open eyes with mental activity). Then, depending on the activation of brain lobes’ regions according to the used protocol, the statistical measurements are recalculated and enhanced. Besides, the number of used channels was reduced to four channels only (two channels for the occipital lobe that is activated when the participant is relaxed and the eyes are closed) and (two channels for the frontal lobe that is activated when the eyes are open or during concentrating on a specific task or beginning a simple mental activity. Accordingly, we built a simulation model that contains the following: input of the collected signals, dividing into sub-bands, mapping the data into the frequency domain using the FFT algorithm and extracting features, classifying the data into different classes by using digital filters according to the frequency ranges for each action, and turning on/off the actuators using an interface between the Simulink model and a microcontroller as an embedded system. Moreover, the model was examined by four participants as follows: they input their collected signals, divide the signals into sub-bands, map the data into the frequency domain and extract features, and classify them into class 1 (relax and closed eyes) or class 2 (open eyes with mental activity). Consequently, the actuators were turned on and off, and all experiments succeeded. The significance of this work on the clinical side will be of importance to those who have disabilities, like older people who cannot open doors and windows, or even move from their spot, and are suffering from the normal activities of normal life. In addition, this work could be modified by using artificial intelligence, such as machine learning algorithms, and be used by different kinds of people, with or without a disorder, like those who are unable to access the control units. Oger Zaya Amanuel Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, P.P. 60- 72 (2022) 70 Table 4, Related work Acknowledgements We would like to express our thanks to the biomedical engineering department at Al- Khwarizmi College of Engineering, especially Dr. Noor Kamal Al-Qazzaz, for their guidance and assistance. 8. References [1] S. Abdulkader, A. Atia and M. Mostafa, "Brain computer interfacing: Applications and challenges," Egyptian Informatics Journal, vol. 16, pp. 213--230, 2015. [2] R. Ramadan, S. Refat, M. Elshahed and R. Ali, Basics of brain computer interface, Springer, 2015, pp. 31--50. [3] R. Ramadan and A. Vasilakos, "Brain computer interface: control signals review," Neurocomputing, vol. 223, pp. 26--44, 2017. [4] F. Lotte, L. Bougrain and M. Clerc, "Electroencephalography (EEG)-based brain-computer interfaces," Wiley Encyclopedia of Electrical and Electronics Engineering, p. 44, 2015. [5] J. Wolpaw, N. Birbaumer, D. McFarland, G. Pfurtscheller and T. Vaughan, "Brain- computer interfaces for communication and control," Clinical neurophysiology, vol. 113, pp. 767--791, 2002. [6] P. Abhang, B. Gawali and S. Mehrotra, "Technological basics of EEG recording and operation of apparatus," Introduction to EEG-and Speech-Based Emotion Recognition, pp. 19--50, 2016. [7] V. Rohith, T. Prajitha and S. Suresh, "EEG Signal Analyzing and Simulation Under Computerized Technological Support," International Journal of Engineering and Technology (UAE), vol. 7, pp. 38--41, 2018. [8] P. Pelayo, H. Murthy and K. George, "Brain- computer interface controlled robotic arm to improve quality of life," in 2018 IEEE International Conference on Healthcare Informatics (ICHI), IEEE, 2018, pp. 398-- 399. [9] M. Y, K. Djouani and K. Anish, "A Matlab/Simulink framework for real time implementation of endogenous brain computer interfaces," in 2017 IEEE AFRICON, IEEE, 2017, pp. 100--105. Study EEG signals collection Subjects Feature extraction classification Controlled applications [7] EEG Database in internet - Wavelet Transform (Mean, Median, STD, Min and Max) Sub-band depending on frequency range - [8] OpenBCI Ultra-Cortex 3 FFT SSVEP (three sets of LEDs to distinguish between the degrees of freedom) Servo motors [9] electrocap kit 5 / (26 ±2.5) years old FFT MARS, ANN Computer cursor [10] - 1 PSD and |𝐹𝐹𝑇|2 Digital filters - This study Ultra-Cortex Mark-IV 10 / (20-66) years old and 4 (3 males and 1 female) / (28-38) years old for examining the model. FFT Filters depending on the frequency of each action DC motors This study involved a larger number of participants with a wide range of ages (20-65) years old, giving more information about the data and obtaining more accurate results. Moreover, the statistical measurements were calculated and enhanced. Besides, it was suggested to reduce the number of channels needed according to the used protocol and the activation of brain lobes’ regions. Oger Zaya Amanuel Al-Khwarizmi Engineering Journal, Vol. 18, No. 4, P.P. 60- 72 (2022) 71 [10] G. Phan, "Analysis and processing EMG signals using Simulink," Turkish Journal of Computer and Mathematics Education (TURCOMAT), vol. 12, pp. 7055--7060, 2021. [11] M. Menteş, S. Özbal and G. Ertaş, "Experiences on 3D Printing of an EEG Headset," in 2021 Medical Technologies Congress (TIPTEKNO), IEEE, 2021, pp. 1-- 4. [12] V. Shivappa, B. Luu, M. Solis and K. George, "Home automation system using brain computer interface paradigm based on auditory selection attention," in 2018 IEEE international instrumentation and measurement technology conference (I2MTC), IEEE, 2018, pp. 1--6. [13] A. Rajavenkatanarayanan, "Human factors analysis and monitoring to enhance human- robot collaboration," Ph.D. Dissertation, University of Texas at Arlington, 2021. [14] J. Moini and P. Piran, Functional and Clinical Neuroanatomy: A Guide for Health Care Professionals, Academic Press, 2020, pp. 177--190. [15] N. Al-Qazzaz, M. Sabir, S. Ali, S. Ahmad and K. Grammer, "Effective EEG Channels for emotion identification over the brain regions using differential evolution algorithm," in 2019 41st Annual International Conference of the IEEE Engineering in Medicine and Biology Society (EMBC), IEEE, 2019, pp. 4703--4706. [16] S. Jaafer, "Hurst Exponent and Tsallis Entropy Markers for Epileptic Detection from Children," Al-Khwarizmi Engineering Journal, vol. 17, p. 34–42, 2021. [17] M. Asogbon, O. Samuel, X. Li, N. Jiang, O. Idowu, Y. Jiang, Y. Geng, A. Al-Timemy and G. Li, "A Robust Multi-Channel EEG Signals Preprocessing Method for Enhanced Upper Extremity Motor Imagery Decoding," in 2020 IEEE International Conference on Mechatronics and Automation (ICMA), 2020, pp. 1929-1934. [18] A. Almahdi, A. Yaseen and A. Dakhil, "EEG Signals Analysis for Epileptic Seizure Detection Using DWT Method with SVM and KNN Classifiers," Iraqi Journal of Science, no. 2, p. 54–62, 2021. [19] S. Valipour, A. Shaligram and G. Kulkarni, "Detection of an alpha rhythm of EEG signal based on EEGLAB," Int J Eng Res Appl, vol. 4, pp. 154--159, 2014. (2022) 60-72، صفحة 4، العدد18مجلة الخوارزمي الهندسية المجلد اوكر زيا عمانوئيل 72 غرفة للتحكم بدماغ للالكهربائية شارات االاستنادا الى ربط البيني بين الدماغ والحاسوب النظام ذكية **يعرب العزاوي *اوكر زيا عمانوئيل د*،** قسم هندسة الميكاترونكس/ كلية الهندسة الخوارزمي/ جامعة بغدا Awkar.zia1202a@kecbu.uobaghdad.edu.iq*البريد االلكتروني: yaarub.omar@kecbu.uobaghdad.edu.iq**البريد االلكتروني: الخالصة ( للتحكم في العديد من المحركات بناًء على موجات الدماغ. EEGمن الربط البيني باستخدام تخطيط كهربية الدماغ ) تنفيذ وفحص نموذجتم بحثال افي هذ مباشر مع يكون مفيدًا لبعض األفراد غير القادرين على الوصول إلى بعض وحدات التحكم التي تحتاج إلى اتصال هذا النوع من الدراسات يعتبر مهم النه ( عاًما، وتم حساب القياسات اإلحصائية أوالً لجميع القنوات الثمانية. ثم تم 66-20) أعمارهم كانت شارك في هذه الدراسة عشرة متطوعيناية البشر. في البد ، تم اختيار أربعة من عد ذلك. وبايضا ، كما انخفض وقت المعالجةالبروتوكول المستخدم وحسبمناطق الدماغ نشاطتقليل عدد القنوات إلى النصف وفقًا ل مختلفة.خالل نشاطات نموذج الالمشاركين )ثالثة ذكور وأنثى واحدة( لفحص والتصنيف وفقًا لنطاقات المناسبة او المواصفات واستخراج الميزاتفي الدماغ نشاطاحتوى النموذج على: إشارات اإلدخال واختيار البيانات وفقًا لمناطق ال .او المحركات نظام مدمج للتحكم في المشغالت التعامل مع مسيطر او ومن ثم التردد لكل إجراء mailto:Awkar.zia1202a@kecbu.uobaghdad.edu.iq mailto:yaarub.omar@kecbu.uobaghdad.edu.iq 8. References