# Extract breaths from respiratory signal, i.e. peak detection

I am trying to extract breaths from a respiratory signal, which is essentially peak detection. See the example below for what such a signal looks like. This particular signal looks rather clean, however, lower amplitude noise is very common (both high and low frequencies).

I have tried the ones mentioned here, however, those seem to require that the height of the peak can be described by its y-value. As you can see below, the signal is very prone to baseline wander, and the top of a peak can very well fall below 0.

Any suggestions for a peak detection algorithm?

• Did you try my solution? – Cedron Dawg Mar 16 '18 at 19:28

I have a slick trick which may do what you want.

Do an exponential smoothing in the forward direction, call it F.

Do an exponential smoothing in the backard direction, call it B.

Take the difference of these two D = (B - F) / 2. (Rescaling by half isn't necessary)

This will do two things for you:

1) Smooth out the noise

2) Convert peaks (and troughs) to zero crossings, no matter what their height.

You can find details in my blog article "Exponential Smoothing with a Wrinkle". There is a "ramp up" and "ramp down" zone at the beginning and the end that you should not use. They are fairly short and their length depends on your smoothing factor.

Hope this helps,

Ced

A running standard deviation can be used to create a new vector for the detection. It is essentially an easy way to find the steepest gradient. If normalized, I don't think you will need a bandpass filter.

• Can you please elaborate? – A_A Mar 19 '18 at 15:27
• It would give a cheap way of finding the steepest gradients. A vector that maybe takes 3 points in the signal, takes the std and then moves along the signal creating a new signal. But I think the input signal would need to be normalized before it can work. – Brandon Olmos Mar 20 '18 at 17:02
• I understand, I am not asking for myself but to make the response more useful to the original question. Does STD stand for Standard Deviation? – A_A Mar 20 '18 at 17:08
• Oh, sorry yes. I'll edit the main. – Brandon Olmos Mar 20 '18 at 17:50

I am slightly confused in what you mean with "extract breaths from a respiratory signal". If you just want the noise free signal, bandpass filtering is certainly sufficient when you just use fourier transform first to find frequencies of interest. You will have to utilize more than one peak to reconstruct the signal with all its amplitude variations but they should stil be in a clear frequency range.

Do you have any extra information about the signal(s) (such as noise level, sample rate, etc) that limits your potential approach?

• I want to get the index (i.e. position) of the peak of the breaths, such that I can calculate for example how many breaths there are in a given minute, their mean height, etc. – user33236 Jan 15 '18 at 16:58
• And is your SNR so low that you can't distinguish peaks? Do you have an example signal (with noise) to show what you are working with? In any case, I would suggest frequency filtering and then simply use the findpeak function from matlab. I have myself also solved simliar tasks with that. – David Bondesson Jan 16 '18 at 8:12