Processing Respiratory Patterns from Oxygen Saturation

In this post I will be discussing how to obtain your respiratory rate by analyzing frequencies produced by a heart rate measurement. WIth a little help from MatLab I was able to successfully add this component to my overall major project (obtaining vitals from a cell phone). This part ended up being one of the more complicated mechanisms to explain as it relies heavily on previous work I have done and many abstract concepts. As a prerequisite, I will be making use of the PPG created in one of my earlier posts: Obtaining Heart Rate from Smart Phone Camera

If you would like to obtain the papers I have used for this build, please reach out to me and I will be happy to share!

Proposed Model

The following was assumed to create the model described below:

  1. Respiration affects the waveform of the PPG.
  2. Any signal that can be represented as a variable that varies in time has a corresponding frequency spectrum.

Similar to my previous post, this model will involve a cellphone that will record and flash a light through your finger that will illuminate the flow of blood through it. However, for this analysis, we will be analyzing the peaks within a lower frequency range, as supported by many scientific papers.

Just to revisit, we will use the following model below:

  1. First, an iPhone will be used to record a video of short duration, with the finger placed over the lens of the mobile camera.
  2. During this recording, the flash will turned ON, so that adequate amount of light can reach the finger for proper measurement.
  3. At this point, this video will be transferred on to Matlab on my computer and I will run the developed script to obtain the respiratory rate measurement.

Results

The following is the resulting Respiratory Rate from a 10 second video of a person’s finger while illuminated with flash, and transferred over to Matlab:


A video that was the length of 10 seconds gave us several peaks to work with. However, taking a snapshot view for one instance, were able to identify two peaks (Hz) that helped determine the rounded numbers below:

[0.281  0.993]

Based on the analysis below, we can determine this to be 17 breaths per minute and 60 beats per minute for this particular Power Spectral Density analysis.

For a more expanded view we can look at the total data set numbers:

Peaks in the Heart Rate ranges:

[0.995   0.995  0.995  0.995  0.978  0.978  0.961]

Peaks in the Respiratory Rate ranges:

[0.276  0.276  0.276  0.276  0.293  0.293  0.310]

This overall PPG data sample results with the mean heart rate being 59.097 beats per minute and accompanying respiratory rate of 17.142 breaths per minute.

As you can see, we can learn a lot about a person based on this information.


Technical Overview 

The overall script that was developed can be broken down into several components that build off the last post: Photoplethysmogram (PPG), Band-Pass Filtering, Fast Fourier Transformation (FFT), and Power Spectral Density (PSD).

Photoplethysmography (PPG)

Understanding a PPG and its functions is the foundation of this project.  In general, a PPG aims to measure the volumetric change of the heart by measuring the light transmission or reflection of light. For starters, when the heart contracts, blood pressure within the left ventricle increases. This forces a pulse of blood into the arteries which may cause them to swell slightly before returning to their previous state. Thus, to measure this change, you can shine an LED light source on your finger or earlobe and the increased pulse pressure will cause a measurable difference in the amount of light reflected back. You would want to choose a place like your fingertips or earlobes as it has artiersis that are close to the skin.

The above information is essentially gathered and translated into signals through a PPG. The amplitude of these signals are proportional to pulse pressure, thus the higher the peak the stronger your pulse is. Using algorithms you can identify the peaks which will allow you to calculate the amount of time that occurs between peaks ultimately giving you a measurement of heart rate. Now if you have read my other post, you will know that this is precisely the mechanism I use to estimate heart rates, and mimics exactly what a pulse oximeter does.

Filtering

Just as it was important in finding the heart rate, filtering is important to help obtain respiratory rate information as well. As a refresher, a band-pass filter can be used to ultimately mitigate frequencies outside the interest band for later processing. To be able to truly analyze our the PPG signal from the cellphone camera, we need to resample the time series at uniform levels. This was done in the code of my first post in this series (mentioned above) to analyze it for heart rate data. However for an easier time determining respiratory information, scientific papers also support the use of a a smooth filter (ex. third-order Butterworth high-pass filter). One specific paper references using a filter with a cutoff frequency of 0.2 Hz and a low-pass filter with a cutoff frequency of 0.8 Hz to extract respiration-related components from PPG and to remove the DC offset component. Thus, analyzing the peaks in these areas can give you insight into the respiratory data. These cutoff frequencies were determined considering a normal range of RR (12 to 30 breaths per minute). This would be done to remove all the extra noise and ensure that the extracted respiratory signals were not contaminated with cardiac frequency content.

Fast Fourier Transformation (FFT) & Power Spectral Density (PSD)

To be able to analyze those frequencies in the desired ranges we first have to obtain them from the signal, just like we did for heart rate. Let me re-introduce to you the concept of a Fast Fourier Transform (FFT). It is an algorithm that samples a signal over a period of time (or space) and divides it into its frequency components. Fast Fourier Transforms are widely used for many applications in engineering, science, and mathematics. Essentially we will be using the FFT to estimate the power spectral density. The power spectrum of a time series describes the distribution of power into frequency components composing that signal. According to Fourier analysis, any physical signal can be decomposed into a number of discrete frequencies, or a spectrum of frequencies over a continuous range.

So putting it together now, we obtain band filtered PPG data using a cell phone video light and algorithms described in my other post. Next transformed using FFT to analyze the power spectral density. This type of frequency analysis of PPG signal can show several peaks. This can be easily analyzed using a plot of magnitude and frequency (x = magnitude, y = frequency).  Let’s say we have 2 peaks, the first at around 0.25 to 0.35 Hz and second at around 1 to 1.5 Hz. A FFT at 1Hz relates to 60 BPM and FFT at 0.25 Hz relates to 15 respiratory cycles per minute.

Script Notes

In the below script, fs is short for fps which stands for frames per second. The gain referenced below is the FFT (fft command in MatLab) which occurs earlier in the code. A butterworth filter (butter command in Matlab) was also done up top this script as well. Lastly worth mentioning is that I used a Hanning window to bring edges to zero. In this way, no artificial high frequencies appear when the signal is treated as periodic by the FF. The rest of the script below allows me to properly scale the output of fft for even-length inputs, for normalized frequency and hertz, and for one- and two-sided PSD estimates.

Conclusion

This build involved a lot of research and testing before being comfortable to release it. However, just like the other ones, I had a good time building this out. I also have been able to adapt this functionality for other ideas and projects that are on my Github. 

About This Demonstration

Please click below to see the full script.