# Why Butterworth filter always starts my signal from from zero mark (amplitude)?

I am trying to filter my force signal using Butterworth low pass filter. 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):

[B,A]=butter(6,5/100,'low');
forceS=filter(B,A,forceS);


the result I get is 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?

Thanks

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.

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: • Why do the beginning and the end of the filtfilt-filtered signal look different? – Olli Niemitalo Jan 10 '16 at 17:49
• Compared to what? – jojek Jan 10 '16 at 18:31
• each other----- – Olli Niemitalo Jan 10 '16 at 18:33
• 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. – jojek Jan 10 '16 at 18:50