how to untilt my graphed data?

Hello guys.
So I had some respiratory flow rate vs. time. I needed to find to graph volume of ventilation vs. time so I took the running integral of the flow rate data. However, taking this running integral results in volume data that is tilted. I need to untilt the data before analyzing it but I was unsure how to do it. The help would be greatly appreciated. I used cumtrapz to integrate the flow rate data.
Also, I attached an image of the graph as it may help.

 Respuesta aceptada

Star Strider
Star Strider el 20 de Abr. de 2015

0 votos

It looks as though you are integrating a constant as well as your data. I don’t have your data so I can only suggest possible approaches.
The easiest approach would be to subtract the mean of ‘flow_data’ from ‘flow_data’ before you do the integration.
A more complicated approach would be to use a highpass or bandpass filter on the integrated data to eliminate the descending baseline.

8 comentarios

cocopuffs
cocopuffs el 20 de Abr. de 2015
Thank you for the response. I tried the easier approach. Although it does alter the data, it does not completely remove the baseline shift. Here is what it looks like after the subtracting the mean:
I wanted to try applying some type of filter to the integrated data, but I am unsure how to do so. Can you explain how to do it?
Star Strider
Star Strider el 20 de Abr. de 2015
The volumes that you integrated are most likely correct. (I suggested subtracting the mean because that can be due to instrumentation error.) Respiratory flow is not constant, and therefore volume would not be constant. (The only situation in which flow and volume are relatively constant is in a patient on a ventilator.) Respiratory flow and volume change with metabolic requirements (driven primarily by carbon dioxide — acid — load and secondarily by oxygen demand). It might be valuable to separate the frequency components in your data, and filters would do that.
If you want to filter them, I would start with the fft of your volume data to determine the frequency components, then use one or more bandpass filters to separate the components in each frequency band. I have described the generic design of digital filters here. For a bandpass filter, you have to supply two frequencies for the bandpass and bandstop arguments, but otherwise the design is the same. (I use bandstop frequencies that are 0.8 the lower bandpass frequency and 1.25 the higher bandpass frequency, with a 1 dB passband ripple and a 10 dB stopband ripple.)
One definitely valid reason to filter them would be to separate the low-frequency components from the higher-frequency components because all are important. I would definitely keep all the data.
cocopuffs
cocopuffs el 20 de Abr. de 2015
Editada: cocopuffs el 20 de Abr. de 2015
I don't have any experience in filtering so most of this is new to me. My volume data is a 12000 element column vector. Taking the fft results in an equally sized vector of complex numbers. Looking at your answer from the provided link helps but also confuses me. My data was sampled at a rate of 1000 samples/second with cut off 10 Hz. I am not sure at all what to do with these values. Simplified steps would be greatly appreciated! Once again, thank you.
Star Strider
Star Strider el 21 de Abr. de 2015
My pleasure.
I didn’t intend to confuse you, but signal processing can be complicated (even though MATLAB now makes it much easier than it was when I was up all night designing filters in graduate school). I assume the 10 Hz cutoff is the hardware antialiasing filter.
The documentation for fft — especially the information between the top two images — is important in understanding how to use it and plot it. (The documentation is much better than any explanation I could write, so I refer you to it.)
Your 1 KHz sampling frequency ‘Fs’ is also important. You have a Nyquist frequency, ‘Fn’ of 500 Hz, and a sampling interval, ‘Ts’ of 0.001 seconds. Those are important in plotting the fft and designing your filter.
I don’t have your data, so I can’t be more specific in suggesting your filter design.
cocopuffs
cocopuffs el 22 de Abr. de 2015
I used the following code to remove the baseline drift:
[b,a] = butter(3,2/(1000/2),'high');
volume_data = filter(b,a,volume);
Not exactly sure why it works, but ill take it! Thank you.
Star Strider
Star Strider el 22 de Abr. de 2015
My pleasure!
You created a third-order high-pass filter with a 2Hz cutoff. It eliminates the frequency components below about 2Hz, most notably the baseline and baseline drift.
Congratulations!
The only change I would suggest is to use filtfilt instead of filter. The filtfilt function is phase-neutral, so there is no phase distortion in the filter output.
cocopuffs
cocopuffs el 22 de Abr. de 2015
Great, awesome help.
Star Strider
Star Strider el 22 de Abr. de 2015
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (1)

Chad Greene
Chad Greene el 20 de Abr. de 2015

0 votos

What about detrend?

1 comentario

cocopuffs
cocopuffs el 20 de Abr. de 2015
Yes I tried it, but results is similar to subtracting the mean.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 20 de Abr. de 2015

Comentada:

el 22 de Abr. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by