I am trying to lowpass filter electrophysiological data and I see ringing near sharp transients at signal start and end.

Ringing at start: enter image description here

Ringing at sharp transients: enter image description here

I am simply using Matlab's default lowpass filter:


Two questions:

  1. Why do I see the weird ringing effect at signal start and end?
  2. 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.


Here is what I get: enter image description here

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?


1 Answer 1

  1. You are using a linear phase filter. These are non causal and hence you get pre-ringing at your transients. Use a minimum phase or IIR filter. Do NOT use filtfilt, since that makes an IIR filter linear phase again and you end up with the same problem
  2. The artifact at the beginning is the step response of the filter. The filter needs access to "past" samples and since it doesn't know what these are, it assumes they are 0. In your case, you have a DC jump and it looks like they are more like -0.05. There multiple work-arounds. In your case it's probable the easiest to pre-pend the signal with a few hundred constant samples that are the average of the first few hundred sample of your signal, filter the whole thing and cut the pre-pended section off again.
  • $\begingroup$ Not sure about point 1, I think your IIR filter will either ring or not. It will not depend whether you use filtfilt or filter. $\endgroup$
    – Ben
    Commented Oct 21, 2020 at 20:50
  • 1
    $\begingroup$ @Ben is right -- a causal filter that rings will still ring -- it'll just confine its ringing to after a step. $\endgroup$
    – TimWescott
    Commented Oct 21, 2020 at 21:41
  • $\begingroup$ Thank you for the answers and comments! I am going to try out some of the suggestions and post the results here! $\endgroup$ Commented Oct 21, 2020 at 23:28
  • $\begingroup$ @Ben, : off course all non-trivial filters will ring. I was specifically refering to "pre-ringing" which is only caused by non-causal filter and in many applications much more of a problem than post ringing. $\endgroup$
    – Hilmar
    Commented Oct 22, 2020 at 12:34
  • $\begingroup$ @Hilmar Thanks a ton for your response!! I have added the results of your suggestion along with further questions. Please take a look and let me know if you have further suggestions! $\endgroup$ Commented Oct 22, 2020 at 20:45

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.