Author Topic: Matlab Zero-Phase Digital Filtering Question  (Read 667 times)

0 Members and 1 Guest are viewing this topic.

Offline joeqsmithTopic starter

  • Super Contributor
  • ***
  • Posts: 11874
  • Country: us
Matlab Zero-Phase Digital Filtering Question
« on: September 22, 2022, 12:41:25 pm »
I am attempting to replicate MatLab's filtfilt function.  I'm curious if we have any MatLab users that may be able to explain the details of how they handle the start-up and ending.

Quote
filtfilt minimizes start-up and ending transients by matching initial conditions. Do not use filtfilt with differentiator and Hilbert FIR filters, because the operation of these filters depends heavily on their phase response.

https://www.mathworks.com/help/signal/ref/filtfilt.html

Online ejeffrey

  • Super Contributor
  • ***
  • Posts: 3896
  • Country: us
Re: Matlab Zero-Phase Digital Filtering Question
« Reply #1 on: September 22, 2022, 02:44:52 pm »
I'm not sure exactly how filtfilt does it but I think you start with the filtic function:
  https://www.mathworks.com/help/signal/ref/filtic.html

Calling filtic with x and y values corresponding to the first value in the data (assuming a low pass filter with DC gain 1) will eliminate the effective discontinuity at the start.  Depending on the order of the base filter you could set an initial value that matches more of the derivatives of the signal.
 

Offline radar_macgyver

  • Frequent Contributor
  • **
  • Posts: 730
  • Country: us
Re: Matlab Zero-Phase Digital Filtering Question
« Reply #2 on: September 22, 2022, 02:59:21 pm »
You can find an implementation in the octave-signal package. The comments to that implementation refer to "Hardware-efficient technique for minimizing startup transients in Direct Form II digital filters" by Likhterov and Kopeika.
 
The following users thanked this post: joeqsmith

Offline joeqsmithTopic starter

  • Super Contributor
  • ***
  • Posts: 11874
  • Country: us
Re: Matlab Zero-Phase Digital Filtering Question
« Reply #3 on: September 22, 2022, 04:00:04 pm »
Quote
For example, the function filtfilt (in MATLAB 2001b) pads the input sequence with its mirrored part, which is three times longer than the filter order.

I don't believe that would be close.

***
I think I miss understood the term mirrored.  I was thinking just the along the vertical axis but I suspect they mean both.   
***
Coding the 2 axis mirror like shown using a window 3X the filter order, its slightly worse than  my previous attempt.   

***
Bug in code.  Very close now.  Plot comparing MatLab filtfilt with using the above.    Basically feeding a series of noise into each filter. 

Thanks for the help.
« Last Edit: September 22, 2022, 11:12:49 pm by joeqsmith »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf