# Zeroing a ventilator's volume measurement in the face of drifty sensors

I'm a software engineer working with http://respira.works to build an open-source ventilator for COVID-19. Notably, I'm not a controls person or a hardware person, so please forgive me.

## Background

One of the things a ventilator needs to do is measure the volume of air in the patient's lungs. Our ventilator has two venturi flow sensors, one which measures the flow of air going into the patient, and one which measures flow coming out of the patient. We can then integrate the difference between these two sensors to determine the volume of air in the patient.

In theory, the volume of air in the lungs goes to exactly 0 when the patient finishes exhaling, right before they start their next breath. In practice of course this might not be the case.

Some of the reasons the integral might not go to 0 are related to the patient.

• Not all breaths are exactly the same size, and our zero point is arbitrary. That is, the point that we declared as 0 isn't actually "zero air in the lungs", and if a patient exhales a lot, they could go below 0.
• You can imagine similar situations, like maybe the patient doesn't fully exhale before taking their next breath; this is known as a "stacked breath".

Others are related to the machine itself, and in particular inaccuracies in our flow sensors. Empirically it seems our flow sensors have two kinds of error.

• One kind of sensor error is "white" noise. Scare quotes because I don't know if it's technically white noise, but it randomly jumps around near a particular average. This hasn't been a huge problem; we have ample time to take many samples and average this noise away.

• The other kind of sensor error is zero-point drift. That's what this question is primarily about.

What I mean by zero-point drift is: The venturi's pressure-difference (dp) sensor outputs a particular voltage when there is 0 flow. We are sensitive to this zero value, because ultimately the flow signal is pretty small. This zero-pressure voltage is usually constant, so we can calibrate it away. But sometimes it changes. These changes in zero point can be large, and they happen ~instantaneously. The machine registers this change as a constant flow.

## Description of the problem

OK, that's a lot of background. Here's the problem I am trying to solve.

I want to show a graph of volume in the patient's lungs over time. Ideally, this graph should hit zero in between each patient breath, if the patient is breathing "normally". The graph shouldn't hide clinically-useful information like stacked breaths. And, in the event of zero-point drift, it should recover quickly and without "too much" distortion of the graph.

Mathematically, how should I do this?

## Thoughts so far on a solution

Here's my current thought about how to do this. Let $$v_0, \ldots, v_i$$ be a series of observed volumes (before any correction), all of which "should be" zero. Let $$t_1, \ldots, t_i$$ be the length of time between $$v_{i-1}$$ and $$v_i$$.

We estimate that $$v_i = v_{i-1} + c_i + t_i \delta_i$$ where

• $$c_i$$ is a constant error. Usually $$c_i \approx 0$$.
• $$\delta_i$$ is the error in flow due to zero-point drift (therefore $$t_i \delta_i$$ is the error in volume caused by flow error). Usually $$\delta_i \approx \delta_{i-1}$$.

When I phrase it like this, it seems to me in my naïveté that I have just described a PI controller. So...is that the answer? Or is there something else I should be considering here?