# How to detect offset that changes along time in a signal?

I have an issue that has to do with detrending a signal. First, it seems my signals behaves a little unusual (for me, I think). Some signals starts with a quite large offset, then it seems to disapears (or maybe not, it may hide in the signal) once the action of the system (human body) begins. So I want to see or observe how the offset behaves along time. I don't know if the polyfit function is adequate for it. I want to take a number N of samples of a section, then calculate with polyfit of first order, then plot it at an specified interval of time (regarding to the plotting, I can handle it).

My objective is when I know how behaves the offset, I can decide which part of the signal I have to detrend. As you can see the image below, there are many of comments that gives you better understanding. The three signals comes from an accelerometer. You can see the yellow line that mesure the gravity. The other two signals are supposed to mesure 0 m/s^2. The wanted slope is related to the red line, the bottom line. Another thing, the transitory behavior of the red line where I calculate the polynomial is usual, so the real issue is the offset (straight line) hided in the signal (if there is one).

That goal comes from the fact that in all three signals (x-axis, y-axis, and z-axis) all of them share to a greater or lesser degree the acceleration of gravity. That's good, but in the y, and x-axis, there are at the beginning some kind of offset that corrupt my signals. If I decide to eliminate the offsets, I will also be eliminating the shared gravity. That's is the question, I do not want to remove gravity.

PD: I use MATLAB

• I don't get your objective yet. How do you obtain the wanted slope, and what does it represent? Jun 7, 2020 at 9:29
• Let's just focus on the red line at the bottom that represents axis-y. And I want to observe how the dynamic offset behaves along the signal. At the end the signal is no longer corrupted, in other words, it returns to its normal measurement state. In the normal measurement state there is a small offfset of gravity, that is usual.But what is unusual is a unwanted offset which is added to the signal, as at the beginning of the signal. So I want to get behavior of the signal on frequencies close to zero. (I think I've got it,I upload now another picture).... continue below Jun 7, 2020 at 10:56
• After that,I want to build fitting linear function in each section which differs from the others (different slopes). I think what you showed me in the other post, the method of least absolute deviations may work well. I'm working on it. What do you think about it? Jun 7, 2020 at 10:56
• OK, I did not notice that the second image was the same signal at a larger scale. Between 6 s and 15 s, maybe its goes back the same level, but with noise, and then another drop between 16 s and 18 s. Is that meaningful? Jun 7, 2020 at 11:02
• Yes, these two drops are meaningful, Therefore, I need to get those differents slopes in order to detrend part by part the original signal. I think that there is 4 slopes that represents the dynimic offset. Two of them is above of the two drops. See the third image. Jun 7, 2020 at 11:12