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.

enter image description here

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


  • 1
    $\begingroup$ Have you tried detrend yet? $\endgroup$
    – jojek
    May 28 '15 at 15:44
  • $\begingroup$ Plus, you can detrend with wavelets. $\endgroup$
    – 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.

  • $\begingroup$ 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 $\endgroup$ May 29 '15 at 14:17
  • $\begingroup$ 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. $\endgroup$
    – 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.