IoT Baby Monitor
IoT Baby Monitor
Scholar Commons
Electrical Engineering Senior Theses Engineering Senior Theses
6-10-2017
Kyle Takeuchi
Santa Clara University, [email protected]
Recommended Citation
Liu, Xiaoting and Takeuchi, Kyle, "CMAG: IoT Baby Monitor" (2017). Electrical Engineering Senior Theses. 34.
https://scholarcommons.scu.edu/elec_senior/34
This Thesis is brought to you for free and open access by the Engineering Senior Theses at Scholar Commons. It has been accepted for inclusion in
Electrical Engineering Senior Theses by an authorized administrator of Scholar Commons. For more information, please contact [email protected].
CMAG: IoT Baby Monitor
By
Xiaoting Liu
and
Kyle Takeuchi
Advisors:
Professor Tokunbo Ogunfunmi
and
Mr. Shivakaumar Mathapathi
Submitted to
the Department of Electrical Engineering
of
i
Acknowledgements
The CMAG team would like to thank the following people for helping with the development of
the project over the year:
Professor Ogunfunmi for his guidance as faculty advisor
Mr. Shivakaumar Mathapathi for providing the Artik and technical support
Nick Mikstas for providing much assistance with the MATLAB code
Jitendra Kumar for providing the Twilio code foundation
Santa Clara School of Engineering for funding the project
All friends and family who helped or supported the project along the way
ii
Abstract
Sudden Infant Death Syndrome, also known as SIDS, is the leading cause of mortality in infants
from one month to one year of age. We propose a video-based baby monitoring system with
Internet of Things (IoT) capabilities to help shorten the response time of SIDS cases. Using a
video amplification technique developed at MIT dubbed “Eulerian Magnification” to amplify
subtle movements we can compare pixel color differences in frames for breathing detection in a
recorded video of a baby. In the event that abnormal movement is detected from the baby an
alarm will be generated to notify the parents or guardians.
iii
Table of Contents
Abstract...........................................................................................................................................iii
Table of Contents............................................................................................................................iv
List of Figures…………………………………………………………………………………....vii
List of Tables……………………………………………………………………………………viii
Chapter 1: Introduction
1.1 SIDS Background................................................................................................................1
1.2 Project Need…………….…………………………………………………………….…...1
1.3 Project Objective..................................................................................................................1
1.4 About the Internet of Things……………………………………………………………....2
1.5 Eulerian Magnification Background……………………………………………………....2
iv
Chapter 3: Roadblocks
3.1 Internet Connectivity ........................................................................................................13
3.2 Streaming...........................................................................................................................13
3.3 Running Eulerian on Artik.................................................................................................14
3.4 Using Twilio for SMS........................................................................................................15
References……………………………………………………………………..............................30
v
Appendices
MATLAB.........................................................................................................................................I
Twilio…………………………………………………………………………………….………IV
vi
LIST OF FIGURES
vii
LIST OF TABLES
viii
Chapter 1
Introduction
1
magnification technique in video developed by MIT called Eulerian magnification, discussed
further below. The IoT is utilized to communicate through SMS, or short message services, to
message the parent or guardian as soon as an abnormality is detected.
2
Chapter 2
3
represented by the fifth and sixth sequential images, which are Twilio and a cell phone. Twilio
is used to generate an alarm to a parent’s phone in the event that an emergency situation is
detected from the algorithm.
2.3 Requirements
The requirements for the baby monitoring system can be broken down into two
categories: functional and nonfunctional requirements. Functional requirements regard what the
system does while nonfunctional requirements outlines the manner in which the functional
requirements will be accomplished. Both types of requirements are tabulated below:
4
2.4 Constraints
One of the main constraints dealt with in the project are the limitations of Eulerian
magnification. Since Eulerian magnification was designed by an outside team making specific
changes without understanding the entire overview could risk potentially breaking the algorithm.
Many of the files in Eulerian magnification are connected to one another, so one small change
could trickle down and cause unforeseen problems down the line. The team avoided modifying
the Eulerian code as much as possible to avoid these potential mistakes.
Eulerian magnification also works best on a stable video, which means that it is
imperative to have the camera stabilized while filming is taking place. To ensure camera
stability a bendable stand with a clip on the end was used to hold the camera in place. The stand
was bendable enough to be shaped to the required position but sturdy enough to hold the camera
still when it was attached. If the camera is moved during filming Eulerian magnification may
produce an unstable result and therefore the data from the outputted video may be unable to be
accurately analyzed.
The runtime of MATLAB was one of the final major constraints that needed to be taken
into consideration. While the algorithms the team developed ran rather quickly in contrast
running Eulerian magnification took a rather substantial amount of time. Processing a 30 second
video clip took around a minute and thirty seconds in MATLAB, which is a rather lengthy
amount of time. The runtime of Eulerian magnification was one of the constraints that was not
able to be successfully worked around, but is something that can hopefully be reduced in the
future.
5
phone. In addition to the streamed and amplified video would be available to view at any point,
most likely through the user’s phone.
6
In the end the team decided to work with the Artik board as all of the tests that involved
capturing short videos through the Artik were successful. There was also the prospect of running
Eulerian magnification through the Artik board due to its high processing capabilities. The final
implementation method used for generating an alarm was to send a text message to the user’s
phone. Even though there was still risk of having a user with a muted or dead phone using SMS
was the simplest yet effective way to let someone know that something is wrong.
7
Camera module with a 2.1 mm lens and 24 infrared LEDs. The camera also has a high frame
rate of 30 fps and a 1280x720 resolution in addition to coming attached to a 1m cable.
Originally the team looked for MIPI cameras but chose a USB camera in the end due to a wider
variety of night vision options and compatibility. The camera chosen is a relatively high quality
piece of equipment as the team was initially not sure what the optimum resolution and fps would
be to work at.
2.8.2 PuTTY
PuTTY is a free open source SSH, or secure shell, program written in C and was the
primary method of issuing commands and communicating with the Artik board. By connecting
the Artik board to a computer through USB and launching PuTTY one can log in to the board.
On the first run through PuTTY has to be initialized by inputting the serial communication port
number that is read through the device manager. The speed of the serial link in bits per second
should be set to 115200 with connection type set to serial. After these parameters are saved
PuTTY does not need to be reinitialized on subsequent launches.
2.8.3 MATLAB
MATLAB, an abbreviation of Matrix Laboratory, is a numerical computing environment
that is used by millions of scientists and engineers across the world. MATLAB is a very
powerful tool that comes with a large variety of applications and functions that can be used for a
wide range of purposes, such as graph creation and system simulations. Eulerian magnification
was constructed in MATLAB so access to the program was necessary for the project. MATLAB
8
was also the primary choice for breath detection algorithm development due to how powerful the
numerical analysis is and the existing compatibility with MIT’s code.
2.8.4 Twilio
Twilio is a cloud communication platform as a service that allows developers to send and
receive text messages using a web service application programming interface, or API. Using the
Eclipse IDE, or integrated development, for Java one can use Twilio to generate text messages to
a user’s phone. After creating an account one receives a unique security identifier, or SID, and
authentication token that needs to be used in order to send and receive text messages. A Twilio
trial account also provides one free phone number to send messages from with the user’s desired
input.
2.9 Cost
The total cost for the project is detailed in Table 2.2. The total cost for all materials sums
to $200. As the Artik board was loaned to us for free the effective cost to the team was $50. The
school provides access to MATLAB for free, which reduced the cost of the project as basic
access to MATLAB costs $50 for students and $150 for home users. A free Twilio account was
also used although it could be potentially upgraded for further functionality, such as access to
multiple phone numbers.
Item Cost
Total: $200
9
following table, table 2.2, lays out five of the biggest risks, the probability of occurrence, the
severity of the issue, the impact in the event of occurrence, and a mitigation strategy. The impact
is calculated by multiplying the probability by the severity.
10
Table 2.4: Gantt Chart for Fall Quarter
11
Table 2.5: Gantt Chart for Winter Quarter
12
Chapter 3
Roadblocks
3.2 Streaming
Video streaming would have ideally been used in order to continuously keep track of the
baby. An ffserver.conf file could be modified in order to stream using the Artik, using Artik as a
RTSP, or real time streaming protocol, server. Using a video player program on a computer such
as mplayer it would then be possible to view the video captured from the board. Despite creating
a ffserver.conf file that was exactly the same as the recommended one, launching the ffserver
13
yielded no response in PuTTY.
Since running the ffserver was unsuccessful, python could also be used to implement
streaming in combination with OpenCV and Flask. Flask is a micro web framework that uses a
technique where the server provides a response to a request in chunks. The next chunk in line
replaces the previous chunk to produce an animated effect in a browser. Unfortunately
attempting to stream with python code also yielded no response. Debugging errors with the
Artik and PuTTY is a rather difficult task since the Artik is a relatively new product, shipped in
May of 2016. Due to the shorter lifespan of the product there is much less documentation
available, and if the official documentation does not run as expected then there are not many
other resources to turn to. It is still not known why both attempts to stream using the Artik have
failed.
Even if the streaming had worked as intended there would still be the issue of running
Eulerian magnification on the stream in real time. To work around the issue of not being able to
stream and running Eulerian magnification on a stream a method was devised utilizing a known
working feature of the Artik board. The method devised involved capturing short video
segments through Artik and then running Eulerian magnification on the shorter clips for later
analysis, which was the process used in the final design.
The MATLAB Coder application can be used to convert MATLAB code into C code.
The Coder was intended to be used in order to run Eulerian magnification on the Artik board.
When running the Coder on MATLAB code a compatibility measurement is created on a scale of
one to five. Eulerian magnification is composed of 95 separate MATLAB files and there are
frequent occurrences of calling MATLAB unique functions that had poor compatibility with the
Coder. Poor compatibility can be fixed by altering and reformatting the code contents, but the
team did not want to risk changing files without understanding the bigger effects. After realizing
that too many of the files had poor compatibility conversion ratings and realizing that too much
of the file contents had to be changed the idea of attempting to run Eulerian magnification on the
board was abandoned. To carry on with the project and to test the legitimacy of the idea
Eulerian magnification was run directly through the computer instead.
14
3.4 Using Twilio for SMS
There were a two big initial issues when using Twilio in an attempt to send a text
message using Java and Eclipse. The first issue that arose was that the code failed to generate
any message at all. Since the code was derived based off of given sample code from the Twilio
website the fault probably did not lie in the code itself. The failure to generate a SMS was fixed
by authenticating a phone number into the Twilio console user settings. Ideally other phone
numbers could receive text messages by changing the user’s number within the Java code,
however when testing with different numbers the phones did not receive any sort of message.
The reason the other phones were unable to receive messages is likely due to the limitations of
using a Twilio trial account and having only one phone number assigned to the account.
15
Chapter 4
After Eulerian magnification is run the clip is converted to grayscale using the rgb2gray
16
function to reduce the numerical range of the pixel values, which also reduces the variance of
different recorded scenarios. After converting the video to grayscale and going through multiple
frames 200 was chosen as a threshold value to represent significant change, and anything below
that value could be considered as noise. Using MATLAB a basic filter was designed to ignore
the pixel values below the cutoff value and to calculate the sum of the total count of pixels with
value greater than 200 in each frame.
17
Figure 4.3: Chest Movement Plot Generated from Eulerian Video
To simulate different scenarios the team created 13 different sample videos for analysis.
Some of the videos contained breathing and others were videos containing no movement at all.
The thirteen different videos after Eulerian magnification is plotted in figure 4.4. Even though
many of the videos displayed similar sinusoidal behavior, the magnitudes of each plot vastly
differed, partially due to different lighting conditions. The vast differences in magnitudes makes
it harder to generate an algorithm that will work in multiple scenarios as some of the videos with
no movement, or “noise”, had larger magnitudes than videos with breathing.
18
To better analyze the plots the magnitude of each plot was “normalized” by calculating
the pixel differences between each frame over time. Using this strategy the magnitude of all of
the different videos with breathing were able to be fit within the range of -3000 to 3000, making
them easier to compare to one another. In addition to that, the plots of the videos containing
noise were reduced to a significantly smaller magnitude than the plots of the videos that
contained breathing. This method of normalization allows for videos of different scenarios to be
easier analyzed.
19
4.4 Detecting Abnormalities
It would be easier to detect an abnormal breathing pattern and generate an alarm working
with data in the frequency domain. After obtaining a normalized pixel count plot in time
domain, a fast Fourier transform, X1 = abs(fftshift(fft(ab, fft_len))), was used in MATLAB to
convert the time domain plot into a frequency plot. The resulting plot from the original video is
shown in figure 4.7.
A newborn baby’s maximum breathing rate is 60 breaths per minute, which corresponds
to 1 Hz. Therefore we do not care about frequency values that are much larger than 1 Hz, and so
1.6 Hz was chosen as a cutoff. To eliminate these unnecessary frequencies and to clean up the
plot a low pass filter was added using the B = firpm(100, [0 .09 .1 1], [1 1 0 0]) command in
MATLAB, which is a linear-phase FIR filter using the Parks-McClellan algorithm. Figure 4.8 is
a plot of the low pass filter used and it was designed with small band edges, dropping from 1 at
0.09 to 0 at 0.1. The low pass filter was than applied to the frequency domain plot using the
command filt_out = filter(B, 1, ab). The result is shown in figure 4.9.
20
Figure 4.8: The 100th Order Parks-McClellan Linear-Phase FIR Low Pass Filter
A threshold level was determined by analyzing the magnitudes of the frequency plots
from the thirteen different videos. If the magnitude of the frequency plot exceeded the threshold
level that indicates the respiration rate in the video is normal and the system will keep on
working. If the magnitude falls below the threshold level, that indicates that the respiration rate
from the video is not normal and an alarm should be generated. Based on looking at frequency
plots from videos with breathing and videos of just noise a magnitude threshold of 8000 was
chosen. Figure 4.10 and 4.11 are both plots from videos with breathing, with magnitude
differences due to different light conditions in the videos. Figure 4.12 is significantly smaller
21
and is a plot from a video with no breathing and falls under the chosen threshold level.
Figure 4.10: Large Magnitude Breathing Frequency Plot with Threshold Level
Figure 4.11: Low Magnitude Breathing Frequency Plot with Threshold Level
22
4.5 Using Twilio for Alarm Generation
By utilizing the threshold level a text file is able to be generated from the video indicating
the state of the baby. If the baby is breathing okay then the text file would contain a “1” and if
an emergency is detected then the text file would contain a “0”. With some outside help the
team was able to come up with Java code that would read the contents of the file and utilize
Twilio in order to send a message to a desired phone number. The code was run in the program
Eclipse, which is the most commonly used Java Integrated Development Environment. Upon
running the code a text message would be received to the desired phone number indicating if
normal or abnormal breathing was detected, as shown in figure 4.13. Sending messages when
normal breathing is detected would not be necessary, but was done during testing to see if there
was proper functionality.
23
Chapter 5
5.1 Ethics
Ethics is ultimately one of the main driving forces behind engineering. The goal of
engineering is to use science and math principles in a way that will improve the lives of others.
However, not all engineers will use their mental capabilities in a manner that is good for the race,
which brings upon the importance of having ethical consideration and discussion. Stopping for a
moment to consider the ethical impacts of a product may actually end up changing the way the
product is designed. If one is not sure about the ethical implications of a product there is also the
possibility to have an ethical discussion with fellow engineers. Engineering is not just a one
person field and there are many people around willing to have these types of discussions. Ethical
consideration is important because there is possibility that even the best product can be misused
in the wrong hands.
5.3 Sustainability
Successful businesses and practices are distinguished from unsuccessful ones by their
entrepreneurial skills and the quality of their product. To understand some of the defining
aspects of entrepreneurship and quality and how to ensure them it helps to look at a seemingly
unrelated topic, sustainability. There are three different aspects of sustainability: environmental,
social, and economic, and all three are equally important links between entrepreneurship, quality,
and success. If a product was noticeably environmentally unsustainable, it would likely be
24
boycotted in the market. If a product was socially unsustainable, then consumers would have no
desire to purchase the product as it does not improve upon their daily lives. Likewise, if a
product is not economically sustainable people would not purchase it due to its unaffordability or
the company producing it would go out of business. Sustainability factors are very crucial to the
success of any product or project.
25
5.3.3 Economic Sustainability
The project is perhaps weakest in the economic sustainability department. The Artik 10
board is new and not very cheap, coming in at $150. The purchased camera was around $50, so
the hardware total is around $200. The hardware price is slightly problematic since many
commercial baby monitors can fall anywhere in the range of $15 to $180, so the project comes in
on the more expensive side. The price of hardware also does not include the price of necessary
software subscriptions either, so that is a hidden added cost. With time the cost of the Artik
board will hopefully decrease significantly, bringing down the total cost of the project. Cheaper
alternative hardware components could also be used if cost really becomes that big of an issue.
While the price is quite steep, people will hopefully find it to be worth the cost.
26
The software does not have to be manufactured more once it is completed since it can just
be copied multiple times. However, using the software components is a little more tricky since it
requires basic knowledge of Eclipse and MATLAB. Some of the breathing detection MATLAB
algorithm is designed to loop through the number of captured video clips in an attempt to make
the process easier for the user. The alarm written in Eclipse is also designed to run simply
through the use of the run feature after the breathing algorithm has been run. Ideally in the end
the whole process will be able to be operated off a single unit, but the team was not able to bring
the project that far yet.
27
Chapter 6
28
Additional features could also be added to the baby monitor in order to improve accuracy
and functionality while utilizing more of the features of the Artik board. The main example is
the addition of a microphone to be added in tandem with the video processing to act as additional
monitor on the baby’s condition. A separate alarm could be generated if the baby is making loud
noise or making noise for a long period of time. Another feature that could be worked on is
having an amplified video of the baby streaming in real time, as the team did not prioritize
getting this feature to work.
Finally, the entire system would ideally operate on one contained unit. If it were possible
for the board to run Eulerian magnification, the algorithm for breath detection, and generate an
alarm to the user’s phone then the project could be considered truly complete. Although the
team did not complete all of the originally intended features they have hopefully provided a
strong framework to see the rest of the project to completion.
29
References
[1] "Sudden Unexpected Infant Death and Sudden Infant Death Syndrome." Centers for
Disease Control and Prevention. Centers for Disease Control and Prevention, 17 Apr.
2017. Web. 20 May 2017.
[2] "Fast Facts About SIDS." Eunice Kennedy Shriver National Institute of Child Health and
Human Development. U.S. Department of Health and Human Services, n.d. Web. 20 May
2017.
[3] 28, 2017 Kelvin Claveria | April. "13 Stunning Stats on the Internet of Things." Vision
Critical. N.p., 28 Apr. 2017. Web. 31 May 2017.
[4] Wu, Hao-Yu, Michael Rubinstein, Eugene Shih, John Guttag, Frédo Durand, and William
Freeman. "Eulerian Video Magnification for Revealing Subtle Changes in the
World."ACM Transactions on Graphics 31.4 (2012): 1-8. Web.
30
Appendix A
MATLAB
clearvars;
clc;
for vid_num=1:length(myFiles)
v = VideoReader(eval(sprintf('''vid%d.avi''', vid_num)));
%FFT length.
fft_len = 512;
%Loop through every frame and calculate a sum for each frame.
for ii = 1:fft_len+1
video1 = read(v,ii);
video1bw = rgb2gray(video1);
%frame_val = sum(sum(video1bw));
frame_val = sum(video1bw(:) > 200);
aa(ii) = frame_val;
end
%Loop through and calculate the difference between frames.
for ii = 1:fft_len
video1 = aa(ii);
video2 = aa(ii+1);
ab(ii) = video1 - video2;
end
I
%Calculate x-axis values -15Hz to 15Hz.
dW = vid_rate/fft_len;
W = 1 : 1 : fft_len;
W = W - .5*fft_len;
W = W*dW;
%FFT of difference calculation.
X1 = abs(fftshift(fft(ab, fft_len)));
%Create low pass filter with cutoff of 1.5Hz.
B = firpm(100, [0 .09 .1 1], [1 1 0 0]);
[H,WD]=freqz(B,1,1024,'whole');
figure(1);
plot(aa);
xlabel('num of frames');
ylabel('count of pixels value > 200');
grid on;
hold on;
figure(2);
plot(ab);
xlabel('Num of frames');
ylabel('Normalized pixels count');
grid on;
hold on;
%{
figure();
plot(W, X1);
ylim([0 max(X1)]);
xlabel('Frequncy/Hz');
grid on;
grid minor;
set(gca,'xtick',[-15:1:15]);
II
%ylim([0 80000])
figure();
plot((WD-pi)/pi, abs(fftshift(H)));
title('Low Pass Filter w/ 100th order')
%}
figure(vid_num);
plot(W, X2);
ylim([0 max(X1)]);
xlabel('Frequncy/Hz');
grid on;
grid minor;
set(gca,'xtick',[-15:1:15]);
ylim([0 80000]);
trigger = max(X2);
fp = fopen(sprintf('breath%d.txt', vid_num),'w');
fprintf(fp, '1');
fclose(fp);
else
disp('No Breathing Detected!');
fp = fopen(sprintf('breath%d.txt', vid_num),'w');
fprintf(fp, '0');
fclose(fp);
end
end
III
Appendix B
Twilio
package santaC;
import com.twilio.Twilio;
import com.twilio.rest.api.v2010.account.Message;
import com.twilio.type.PhoneNumber;
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
IV
}catch (Exception e){}
return 0;
}
System.out.println(message.getSid());
}
static void noAlertSMS(){
Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
System.out.println(message.getSid());
}
}