BTP_END_SEM

21
1 EMBEDDED SYSTEM FOR CONTROL OF AN AC COMPRESSOR BASED ON SLEEP STAGE DETECTION ABHISHEK KUMAR AGRAWAL

Transcript of BTP_END_SEM

1

EMBEDDED SYSTEM FOR CONTROL OF AN AC

COMPRESSOR BASED ON SLEEP STAGE DETECTION

ABHISHEK KUMAR AGRAWAL

2

B.Tech Project

Department of Electrical Engineering

Indian Institute of Technology, Kharagpur

Submitted to

Indian Institute of Technology, Kharagpur

Submitted by

Abhishek Kumar Agrawal

[email protected] | 7699503327

Under the Guidance of

Prof. A. Routray

Professor,

The department of Electrical Engineering

Indian Institute of Technology, Kharagpur

3

CERTIFICATE

This is to certify that the report entitled, “Intelligent control of an Ac

compressor based on sleep stage detection for energy saving” submitted by

Mr. Abhishek Kumar Agrawal to Indian Institute of Technology, Kharagpur,

for 4th year BTP work, is a record of bonafide project work carried out by him

under my supervision and guidance.

__________________

Prof. Aurobinda Routray

Date:

4

ACKNOWLEDGEMENT

I take the opportunity to express my reverence to my supervisor Prof. Aurobinda

Routray for his guidance, inspiration and innovative technical discussion during

the course of this project. His perpetual energy and enthusiasm in research has

motivated us. In addition, he was always accessible and willing to help in this

project.

I would also like to thank Mr. Laxmi Kant Tiwari for his support, who always

found time between his busy research schedules to help me when stuck at any

problem.

I would also like to extend my gratitude to all the professors for their contribution

in my studies and research work. They have been great source of inspiration for

me.

Last but not the least I would like to thank my parents, who taught the value of

hard work by their own example.

Abhishek Kumar Agrawal

11EE35012

Department of Electrical Engineering

IIT Kharagpur

5

Index

Sl. No. Content name Page No.

Certificate by supervisor 3

1 Introduction 6

2 Objective 6-7

3 Algorithm development 7-12

3.1 System Overview 7

3.2 Sampling frequency selection 7-8

3.3 Active noise cancellation 8-9

3.4 Getting breath count 9-12

4 Real time implementation 13-16

4.1 Flow chart for respiratory rate counter

implementation 13-14

4.2 Wireless link for data transfer 15

5 Hardware selection 16

5.1 Development Board 16

5.2 Microphone 16

5.3 Wi-Fi module 16

6 Prototype developed 17-19

7 Image Sources 20

8 References 20

6

1. Introduction:

Now days there is significant increase in number of Ac sleeping rooms and energy demand by

them has been increased in proportion. It seems that this trend will be in future as well and

requirement of energy will be increasing.

Compressor is the heart of any air conditioning system and a major player in total

energy consumption. As a person goes to bed he leaves Ac on and it will be keeping the room

temperature at reference temperature whole night with the help of compressor, which is not

needed. In night a person goes through sleep cycle many times. A sleep cycle consists of NREM

(non-rapid eye movement) sleep stage 1-2-3-4, and REM (rapid eye movement) stage.

Fig1. 1.1 shows an example of 8

hour sleep. In initial stages he is

in deep sleep but in later part he

is dreaming more.

As a person is in stage 2, 3, 4, of NREM sleep, chances of his waking up due to little variation

in room temperature is very less, so compressor can be switched of leaving the room

temperature to fluctuate with variation in surrounding temperature. But if he in stage 1 of

NREM or REM he may wake up due to changed room temperature and its chances are high so

compressor should be switched on in this stage. So, using the information of sleep stages of

person, on and off state of Ac compressor can be controlled intelligently and unnecessary

consumption of energy can be reduced.

2. Objective:

Key of this control is sleep stage detection on which further decision will be made.

There are many methods for detecting sleep stages mainly based on EEG signal, heart rate and

respiratory rate. EEG based sleep stage detection is standard but costly and of contact type.

Heart rate based sleep stage detection is also of contact type and person need to wear some

special devices. In case of respiratory rate based methods thermistor is widely used to get

respiratory rate but it is also of wearable type. Microphone based respiratory rate counter can

be used as noncontact type with proper placement and highly sensitive microphone but problem

with highly sensitive microphone is that it will capture surrounding noise as well.

7

In our case microphone based technique has been used with active noise cancellation technique

to minimize the effect of surrounding noise. In nutshell our goal is to develop a respiratory

rate counter based sleep stage detector and establish a wireless link for data transfer.

3. Algorithm Development:

3.1. System Overview:

3.2. Sampling frequency selection:

Initially signal has been recorded using MATLAB ‘audiorecord’ function at 20 KHz.

Then its frequency analysis has been performed and it’s found that recording at 2 KHz

will be good enough and it’s also suits for real time implementation. Further all signal

has been recorded at 20 KHz, using ‘audiorecord’ function as well as using ADC.

Fig. 3.2.1

Fig2. 3.1.1

8

Fig. 3.2.2

Fig. 3.2.1 shows the breath signal and Fig. 3.2.2 shows its frequency transformation.

1024 point fft has been found using MATLAB ‘fft’ command.

3.3. Active noise cancellation:

Active noise cancellation technique uses the information about noise by other

microphone to remove noise from signal. It uses LMS based estimation algorithm to

update the weight so that mean square error can be minimized.

Fig3. 3.3.1

Fig. 3.3.1 shows the schematic for active noise cancellation technique. Signal s(k) is

breath+ noise recorded by signal microphone and n(k) is the noise recorded by reference

microphone. A 2nd order LMS based adaptive filter outputs signal y(k) which should be

ideally equal to noise content in s(k). Difference of s(k) and y(k) is error signal e(k)

which is final output and should be nearly same as original breath signal. Depending

upon e(k) further update of weight W(k) will be done.

9

Equations are

x(k) = [n(k-1),n(k)]

y(k)= W(k)’×x(k)

e(k)=d(k)-y(k)

W(k+1)=W(k)+2𝜇 ×e×x(k)

Fig. 3.3.2

Fig. 3.3.2 shows the result of LMS based active noise cancellation algorithm. Top signal

is breath + noise signal s(k), middle one is noise signal n(k) and bottom one is final

output e(k) of the system.

3.4. Getting breath count:

Now we have to get breath count from output of previous block i.e. from estimated

signal. It can be seen that there is sufficient increase in energy whenever breath occur.

So, window based method has been used to get breath count. Window size is

0.05×sampling frequency i.e. 100 for 2 KHz sampling. Signal is divided in to window

and absolute sum of each window has been found.

Fig. 3.4.1 shows the absolute sum of windowed data. It can be easily found that number

of envelope is equal to number of breath in Fig. 3.3.2. Result of windowed absolute

sum can be further smoothened using a low pass filter. For getting cutoff frequency of

filter frequency analysis of windowed absolute sum has been done using 1024 point fft,

result is shown in Fig. 3.4.2.

10

Looking at Fig. 3.4.2 it can be found that contribution of frequencies above 0.2𝜋 is very

small. So by using a low pass filter of cutoff near 0.2𝜋 , high fluctuation from windowed

absolute sum can be removed. An IIR Butterworth filter has been designed using

impulse invariance method.

Fig. 3.4.1

Fig. 3.4.2

11

Filter specification

𝜔p = 0.15𝜋, 𝜔s=0.25𝜋, amax=0.9, amin=0.1

required order of filter = 6, 𝜔c=0.1918𝜋

Transfer function of designed filter

0.01747

H(z) = -----------------------------------------------------------------------------------------------------

1 - 3.651 z-1 + 5.856 z-2 - 5.201 z-3 + 2.678 z-4 - 0.7538 z-5 + 0.09028 z-6

Pole-Zero plot of designed filter:-

Fig. 3.4.3

12

Phase- magnitude plot of designed filter:

Fig. 3.4.4

Fig 3.4.3 shows the pole-zero position and Fig 3.4.4 shows the magnitude and phase

plot of the designed filter.

This filter has been used to smoothen windowed absolute sum and result is shown in

The Fig 3.4.5

Fig. 3.4.5

Now by counting number of peaks above a threshold i.e. by getting the number of most

dominant peaks respiratory rate can be estimated.

13

4. Real time implementation:

4.1. Flow chart of the respiratory rate counter implementation:

Fig. 4.2.1

N= Number of times external switch has been pressed.

Sampling frequency = 2 KHz

Window size = 100

For 1 minute data number of windows = 1200

Start

Configure system clock, ADC, GPIO,

NVIC and Timer.

Enable interrupt generation using timer

after each 0.5ms

Configure ADCs in single conversion

mode

Enable interrupt generation on one pin of

GPIO by external switch

N%2

Stop the

respiratory rate

counter and

keep waiting for

N=1

Call respiratory rate counter function, get the

Breathe count for last minute

Display number of respiration

in last minute to 7 segment

display

1

0

14

Respiratory rate counter program:

No

Yes

Start Local count = 0;

Count = 0;

Accumulator = 0;

Windowed abs sum [] =0

Timer

interrupt

?

Collect both ADC’s data, clear timer interrupt and again start ADCs.

Call LMS algorithm to get estimated value of signal from above two data.

Add estimated value to Accumulator, and increase local count by 1. Check if

local count =100. If yes set local count =0, update count index data of

windowed abs sum by accumulator, increase count by 1 and reset

accumulator to 0.

Is

Count

=1200

Call LPF function to smoothen windowed

abs sum data

Call dominant peak counter to get

respiratory rate

Return data of number of

respiration in last minute to

caller program

No

Yes

Yes

END

15

4.2. Wireless link for data transfer:

Two Wi-Fi module has been used for transferring data for controlling on and off state

of AC compressor and viewing the data on a mobile application for entire sleep period

Module on AC side is configured as access point and broadcast SSID. A hard coded

SSID and PASSWORD is set and known to user. It has been also configured as server,

whereas module on human side connects to this access point and act as client.

Algorithm outputs sleep stage data after each minute and transmitted to Wi-Fi module

through UART, further module establish a connection with server and transmit this

data. Now, depending upon value of sleep stage a high-low control signal has been

generated and new data has been also written to a file. When user wants to view sleep

data and he press READ button in Application a connection will be made, read

command will be sent and server return that file in which sleep data was written and

delete it’s content. Now, on the mobile app a new activity opens showing the plot of

sleep data transferred.

16

5. Hardware selection:

5.1. Development Board:

ST microelectronics ARM cortex M4 based STM32F4 Discovery board has been

chosen for implementation and testing.

Fig4. 5.1

5.2. Microphone:

Analog Devices ADMP401 analog microphone has been used for this.

5.3. Wi-Fi module:

Esp8266 version 1 Wi-Fi module has been used

Fig5. 5.2

Operating Voltage 3V

Output offset 0.8V

Sensitivity 0.01V/Pa

Output Resistance 2.2KΩ

Fig6. 5.3

Wireless SoC running at 80MHz

Wi-Fi 2.4 GHz,

TCP-IP protocol stack

Low power 32 bit MCU

Standby power consumption <1mW

17

6. Developed Prototyped:

Fig. 6.1

Extension to be connected with Development board for interfacing microphone, Wi-Fi module,

switch. 7 segment display is used for debugging.

Fig. 6.2

To be connected on AC side for generating control signal and hosting server for data transfer.

18

Fig. 6.3

Main Activity for configuring server address, connecting, reading and deleting stored data

Fig. 6.4

Activity which render the received data on a plot. Above plot is just simulation and is not

actual sleep data. .

19

Fig 6.

20

7. Image sources:

Fig 1.1 - www.nwbotanicals.org

Fig 3.3.1 - www.iro.umontreal.ca

Fig 5.1 - galeria.tech-blog.pl/

Fig 5.2 - www.sparkfun.com

Fig 5.3 - www.espduino.com

8. References:

1. www.iro.umontreal.ca/~mignotte/IFT3205/APPLETS/AdaptiveSignalProcessing

/AdaptiveSignalProcessing.html

2. www:github.com/nodemcu

3. STM32F4 reference manual

21

END