Working on enhanced breathing algorithm

Posted on Oct 2, 2017 | 0 comments

This is article covers an ongoing work on enhanced breathing algorithm for the MonBaby smart movement baby monitor. It utilizes a research framework pipeline, which is in essence a simplified MonBaby app.

  • The MonBaby smart button with latest MonBaby firmware
  • The test android app based on monbaby_sdk:¬†https://github.com/varturas/monbaby_sdk
  • The python server running in a virtual environment with plugins to test different algorithm implementations

The MonBaby firmware sends XYZ accelerometer signals with sequence numbers to an Android app. Android app streams the accelerometer data stream via TCP socket to a server listening on an open IP port. An IP port is configured via the app UI.

Once data is consumed it could processed via the algorithm in near real time or saved to disc for further processing.

Here is an example of collected raw data visualized on jupyter python notebook. The data was recorded on a adult subject belly breathing:

  • initial normal (about 0.2Hz) breathing
  • followed by 20 second interruption in breathing, where subject was holding breath
  • followed by another breathing interval, where subject was catching the breath
  • followed by placement of the MonBaby button on a static surface
  • finally by an interval where the MonBaby is at rest

bokeh_plot

Here is the same data passed through IR lowpass filter:

bokeh_plot (1)

One can clearly see with the naked eye oscillation intervals of breathing and no breathing.

Here is an output of one of the test algorithms. Algorithm consist of an actual breathing rate detection and a classifier that uses output of breath rate detection to differentiate breathing from no-breathing.

The breathing rate detection finds leading frequency in the signal. For example, this is the graph of a filtered raw signal and a a candidate for a signal frequency.

raw_vs_signal

Breathing rate is calculated within the data interval of 15 seconds by choosing the frequency that fits the data best. This is done via FFT: D=fft(d), where d is filtered signal, then finding reverse frequency component in time-domain x=ifft(D(freq)) and finding most optimal solution to quadratic expansion of the signal y=c0+c1*x+c2*x*x. The most optimal solution can be solved via least-square method with minimal normalized standard error, NMSE = (y-d)^2/d^2.

Classifier is a second stage of the algorithm that finds best fitting parameters of the model based on the output of the breathing rate detection algorithm. The plot below is the output of the classifier that uses a function of coefficients of quadratic expansion, c0,c1 and c2 to determine goodness of fit. Black points are breathing frequency output that has passed through classifier and have been identified as breathing.

bokeh_plot (2)

One can see that generally the classifier and the algorithm output have a good correlation with the actual signal and noise, but not lined up ideally. This is work in progress and subject to improvement.

In comparison, the plot below is based on the classifier that uses NMSE, rather than coefficients.

rate_plot_nmse

The plot shows similar results but with greater variance of the rate value.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>