Living Things: Breathing pattern

Ryoji Kuwae Neto
7 min readNov 21, 2021

For Portuguese, go to this link.

Stop. Inhale. 1. 2. 3. Exhale. 1. 2. 3. Inhale…

This is something that we've done our entire life and still we haven't mastered it, this is due to countless variables, but one of those we could say that is the fast life we have in big cities. If we don’t actively understand breathing, how could we simulate this for robots?

Let’s take a look into how breathing patterns works and how doctors actually learn in school. If you take a look in the video below, you’ll see a few breathing patterns along with specific situations for each one of those.

Apnea, Eupnea, Tachypnea, Bradypnea, Biot, Cheyne-Stokes, Kussmaul.

Those are some of the names gathered in medicine along the years to describe breathing patterns that we have as humans, but they’re not exactly ready for usage as they do not relate specifically to a current emotion, and more likely to how our body is chemically/hormone related responding.

A peak of adrenaline may increase the speed in your hearbeat, on the other hand obesity or alcoholism, or even metabolic disorders may cause entirely different scenarios.

How to simulate them?

If you look carefully in eupnea example, you’ll see that when exhaling there’s a heartbeat in the end of each cycle.

By that, one could infer that there's some linear behavior between beats per minute (BPM) and breathing cycle.

Breathing Cycle = Some Weight * BPM

How to model the real equation? One could obtain a dataset of breathing pattern and heartbeat, and identify how the amplitude on each signal relates to another.

For the sake of simplicity, let’s keep it that way.

If we consider that each breathing cycle contains solely a heartbeat in the exhale part, we could consider for Eupnea example that the equation could be:

Breathing Cycle = 2 * BPM

However, this would imply that we have a breathing cycle faster than our heartbeat and this isn’t true. Let’s go back to the medical articles and see what they’ve learnt so far?

Heartbeat Resting behavior

A normal resting heart rate for adults ranges from 60 to 100 beats per minute. Generally, a lower heart rate at rest implies more efficient heart function and better cardiovascular fitness. For example, a well-trained athlete might have a normal resting heart rate closer to 40 beats per minute.

Source: https://www.mayoclinic.org/healthy-lifestyle/fitness/expert-answers/heart-rate/faq-20057979

Breathing resting behavior

The “normal” rate depends on your age, but a typical adult takes between 12 and 20 breaths a minute when resting.

Source: https://www.webmd.com/lung/breathing-problems

Those were the two first links that I’ve found about each theme.Since we’re not thinking about medical precision or getting the perfect model for human body itself and we’re trying just to use approximate data to emulate a behavior, I believe this is accurate enough.

So, what we’ve collected is that a healthy adult has a heartbeat between 60–100 beats per minute and a breathing cycle of 12–20 breaths per minute while resting.

At both maximum and minimum ranges, we’d have the following equation, entirely different from the last “expected equation”.

Breathing Cycle = 0.2 * BPM

Wait a minute… We said the word healthy, this implies that the equation has another factor which could increase or decrease breathing capability based on illness. To simplify:

Breathing Cycle = 0.2 * BPM + Some weight * Illness Factor

By that we could, for example, if trying to give life to an autonomous car, measure its heartbeat based on the last 20 seconds of average speed to emulate its heartbeat, and for illness factor we could detect all types of failures that could compromise the speeding behavior, such as tyres that aren’t pressurized enough, electrical problems. We could also add environment conditions such as too hot temperature, too cold, windy, rainy conditions.

Be careful where you implement this concept

All of these options would add a more “living thing” pattern. However, would this be inconvenient? Would you be happy while driving if the seat would go up and down like you’re driving a horse? Perhaps not.

Wouldn’t it be cool to be felt in a smooth way in the front panel of the car? Absolutely.

Does emotions changes breathing?

Huoma et Masaoka says in the article Breathing rhythms and emotions that "Respiration is primarily regulated for metabolic and homeostatic purposes in the brainstem. However, breathing can also change in response to changes in emotions, such as sadness, happiness, anxiety or fear. Final respiratory output is influenced by a complex interaction between the brainstem and higher centres, including the limbic system and cortical structures."

But what is emotion?

Emotion: a natural instinctive state of mind deriving from one’s circumstances, mood, or relationships with others.

Or is it just chemical changes in our brain and due to a release of dopamine/serotonine/adrenaline we’d feel different?

Isn’t an easy thing to answer, and we’ll leave it aside and consider it in a few moments. For now, we’re going to emulate the first equation and later we will talk about emotions and how those would change our breathing pattern.

How does a breathing pattern looks like?

The equation that we considered so far is something like is:

Breathing Cycle = 0.2 * BPM + Some weight * Illness Factor

I’ve applied the concepts that we’re talking about which can be seen in the library Living Things and implemented in an easy way to follow up and see how those patterns would apply to a living thing, which may be a robot itself, an autonomous vehicle or anything you’re creative enough to apply to.

Here we’re considering a python approach and the lib itself is developed for Raspberry Pi as its one of the easiest boards to emulate a physical behavior and serves quite well our purpose.

## Installing the library
pip install git+https://github.com/ryojikn/livingthings

Let’s start by instantiating an object called Breathing

# Create a custom .py file and add those lines
import livingthings as lt
lungs = lt.Breathing()

I’ve called the object lungs to relate to the human body, and in this method there’s a few parameters you could add:

## parameters in lt.Breathing() that can be changed
device: gpiozero.devices.GPIOMeta = None,
bpm: int = 60,
illness_factor: float = 1,
alpha: float = 0.5,
pwm_factor: int = 1000

and this lungs object now has its main class called breath, which we’ll test in the following lines of code. I’ve separated a few examples with a physical led pwm exhibition, but it can always be replaced by a motor and perhaps a physical lung 3d printed for example.

Normal breathing — BPM 60

lungs.breath(bpm=60, dry_run=True)
>> Inhale
>> Inhale for 2.5s
>> Exhale
>> Exhale for 2.5s
>> Breathing stopped manually...

Faster breathing — BPM 150

lungs.breath(bpm=150,
dry_run=True)
>> Inhale
>> Inhale for 1.0s
>> Exhale
>> Exhale for 1.0s
>> Breathing stopped manually...

Slower Breathing — Illness factor added — BPM 150

lungs.breath(bpm=150, illness_factor=0.3,
dry_run=True)
>> Inhale
>> Inhale for 3.33s
>> Exhale
>> Exhale for 3.33s
>> Breathing stopped manually...

Distorted breathing — Inhale stage compromised — BPM 150

lungs.breath(bpm=150, illness_factor=1,
alpha=0.1,
dry_run=True)
>> Inhale
>> Inhale for 0.2s
>> Exhale
>> Exhale for 1.79s
>> Breathing stopped manually...

Distorted breathing — Enhale stage compromised — BPM 150

lungs.breath(bpm=150, illness_factor=1,
alpha=0.9,
dry_run=True)
>> Inhale
>> Inhale for 1.8s
>> Exhale
>> Exhale for 0.2s
>> Breathing stopped manually...

Visualizing

A visualization can also be done with:

Final thoughts

For now we’ve seen how to simulate human breathing behavior and how it potentially has some relation with our heartbeat, as well as other more complex things such as hormone releases in our brain, or even illness factor that could go from damaged lungs all the way to any type of breathing disease.

This is a work in progress and will potentially evolve with more features and other concepts as I group them together.

I hope you’ve liked and please send me a message if you'd like to suggest improvements, I’ll be glad to discuss!

--

--

Ryoji Kuwae Neto

Data Scientist | Machine and Deep learning lifelong student with aspiration to be a Roboticist in the future