I am trying to filter my force signal using Butterworth low pass filter.enter image description here

so this is the signal, I have to filter (noise frequency is around 33 Hz). So when I use Butterworth filter with following command in MATLAB (with sixth order):


the result I get is enter image description here

So the problem is the filtered signal start from zero mark instead of around 1.5. How can i start the filtered signal from the same value as unfiltered signal has?



1 Answer 1


Filters do have a delay (a lag) since they do not act immediately on your signal. Also all samples before the time 0 are zeros, thus in general you will start from the "zero mark", as you said (just imagine your filter equation with all zeros).

There are ways to make a filter to have a zero lag. It is done by so called zero-phase filtering, also known as forward-backward filtering. The way you do it is by filtering your signal twice - in forward and in backward direction. Obviously this can work only for offline applications. In MATLAB you can do it very easily using the filtfilt function.

Please find below a code corresponding to your case.

fs = 100;
T = 2;
t = 0:1/fs:T;
f = 2;
s = 1.5*cos(2*pi*f*t) + 0.7*sin(2*pi*33*t);

[B,A]=butter(6, 5/fs,'low');
S=filter(B, A, s);
Sff=filtfilt(B, A, s);

plot(t, s)
hold on
plot(t, S)
plot(t, Sff)
grid on
legend({'Original signal', 'Signal filtered using filter', 'Signal filtered using filtfilt'})

That yields what I suspect you want:

enter image description here

  • $\begingroup$ Why do the beginning and the end of the filtfilt-filtered signal look different? $\endgroup$ Commented Jan 10, 2016 at 17:49
  • 4
    $\begingroup$ Using MATLAB's method there will always be some transients at the ends. This type of filtering is generaly about removing filters' delay, and about not having a perfect transients. Initialisation of parameters at the borders is very difficult but generally having 0's is fine (especially for lower orders). If you are looking for something that is closer to being perfect then I suggest to read the Gustafsson Article Determining the initial states in forward-backward filtering. $\endgroup$
    – jojeck
    Commented Jan 10, 2016 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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