MATLAB Answers

Initial and end artifacts after applying digital filter (filtfilt)

4 views (last 30 days)
I need to filter highly noisy signals (at a sample rate of 2000 Hz).
When applying the code:
order = 2; Fcutoff = 4Hz; Fs = 2000 Hz; x = Non filtered signal as a double vector;
The output filtered signals appear to have (only for some cases) and initial and end artifact, where they tend to deviate upwards or downwards (only at the edges of the filtered signal).
What is the data that is being processed by the filter at the edges?
How can I know how many data points are being used in this process?
Is there a clean way to tackle this problem?

  1 Comment

Mathieu NOE
Mathieu NOE on 23 Oct 2020
these artifacts are sometimes caused by the filtfilt function that do filtering in both direct and reverse time axis (so no phase lag)
try filter instead (this runs the signal only in the causal time direction, but you will get phase alg according to the low pass filter)
i see also that you are focusing on the very low frequency range , while your signal is sampled at 2000 Hz
I woud recommend to decimate your signal (this also apply a low pass filter) so if you have very long data, this will help you speed up your post processing
help decimate
DECIMATE Resample data at a lower rate after lowpass filtering.
Y = DECIMATE(X,R) resamples the sequence in vector X at 1/R times the
original sample rate. The resulting resampled vector Y is R times shorter,
DECIMATE filters the data with an eighth order Chebyshev Type I lowpass
filter with cutoff frequency .8*(Fs/2)/R, before resampling.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 23 Oct 2020
In many situations that is caused by the signal having a significant d-c (constant) offset. There are two general ways to deal with it:
(1.) concatenate a constant value vector equal to the mean of the signal of about 10% of the signal length to each end
(2.) subtract the mean of the signal from the signal, and then filter it, then add the mean value of the original signal to the filtered output
Those have both worked for me in the past when I had similar problems.


Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!