# 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?

You should be able to determine differences in lung volume over the span of a few breaths, but since you never get an an absolute measurement, you can't measure the total volume of air in the lungs. The integrated reading will also drift over time as you've noticed. This will happen eventually no matter how good your sensors are.

As for zeroing the sensors. You could look for a point during the breathing cycle where the flow is know to be zero, and zero it then. Another alternative would be to install a valve or similar that allows you to disconnect the sensor for zeroing; or use 2 flow pathways and a flapper valve so you can zero one sensor while the other is in use.

I'm not sure what kind of noise you're seeing out of your sensors, but I've worked with the MPXV5004DP and we were able to get the noise down to 1 count on a 10 bit adc.

• Drew, thanks for your reply. We are indeed using the MPXV5004DP sensors. It drifts like crazy though, see uncorrected volume measurements at github.com/RespiraWorks/VentilatorSoftware/blob/master/… In terms of zeroing sensors, there's really no point when we know flow is 0; the patient could exert inspiratory effort at any point. Thus the need for a more sophisticated zeroing algorithm, though I'm not sure what it needs to look like. Jun 5 '20 at 6:25
• You can create a point by diverting gas through an alternate path.
– Drew
Jun 6 '20 at 0:39