# Help for baseline drift removal/correction

I have signal as seen in the picture. It has high frequency noise and drifting baseline. I am able to remove the noise in MATLAB but I am not sure what can I do about the drift.

I would like the signal to have a stable baseline. Any help or hints on how I can do that would be most helpful.

Thanks

• Have you tried detrend yet? – jojek May 28 '15 at 15:44
• Plus, you can detrend with wavelets. – Sektor May 28 '15 at 15:52

Like I already mentioned in the comment, you might find MATLAB's detrend function useful. Generally it is useful for removal of linear (or piecewise linear) trend:

y = detrend(x);


Another solution, that should work in your case, is to use the polynomial fitting. This will remove the non-linear trend (providing you want that). A minimal code example:

% vectors t,x are given (time and the signal)
degree = 5; % to be adjusted
[p, S, mu] = polyfit(t, x, degree);
xp = polyval(p, t, [], mu);
y = x - xp;


Personally I do not recommend any Moving Average filtering, since it is introducing delay and can distort your signal.

• I apologize I am quite new to signal processing. I might have stated my question incorrectly. The data comes from a sensor and i expect it to be stable. As you can see the signal is gradually decreasing, whereas it is supposed to maintain somewhat similar amplitude (i.e. around 4, 4.1 for the signal shown). Using detrend or high pass filtering centers the baseline at 0. I am looking for a method which will center the base line at its proper amplitude. I understand there may not be a straightforward command that will do this. Is there any algorithm that can be used? Thanks – Johnny Page May 29 '15 at 14:17
• Then I would suggest you to check the reasons of that drift nevertheless I have no idea what is the outcome you do expect so I am unable to give you fully working answer. You can do try both methods. – jojek May 29 '15 at 14:19

A drifting baseline to me looks like a displacement from zero by the mean amplitude.

• From a stats point of view, you will want compute the rolling mean and subtract.
• From a signals point of view, this problem is a DC offset, and can be corrected with a high pass filter, with a very low cutoff, that essentially removes this low frequency amplitude modulation. There are a number of prior discussion here, and implementations. If you're in MATLAB, detrend can be useful as already mentioned.