**FIND UPDATES BELOW THE ORIGINAL QUESTION TEXT:
I am trying to lowpass filter electrophysiological data and I see ringing near sharp transients at signal start and end.
I am simply using Matlab's default lowpass filter:
fpass=1000;
f_sampling=20000;
fil_X=lowpass(X,fpass,f_sampling);
Two questions:
- Why do I see the weird ringing effect at signal start and end?
- What strategies can I use for reducing the ringing (both at start/end and at sharp transients) other than reducing the steepness of the filter in the frequency domain? Can some fancy windowing be of help? I tried forcing Matlab to use IIR filter with filtfilt and the ringing stays the same.
Thanks, Anand
UPDATES: Padding the signal at start and then removing the padded portion from the filtered trace gets rid of the ringing at start. Thanks!!
For the other problem, I tried an IIR filter without filtfilt. Ignore the unnecessary double filtering. I do it because lowpass automatically applies filtfilt.
[~,ft_obj]=lowpass(X,fpass,f_sampling,'impulseresponse','iir');
fil_X=filter(ft_obj,X);
As you can see, it gets rid of the pre-transient ringing, while introducing post-transient ringing. The post-transient ringing should not be a big issue. But, there is also a signal delay/distortion that becomes clear at the same time point across different conditions (red line). That can shift the absolute and relative timing of events in the signal.
Is there a way to compensate for that?