LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Zero-phase Butterworth filtering function

Solved!
Go to solution

Hi!

 

I know very little about filtering, and need some help finding the right function to use in CVI to accomplish what I want. I have some data that I filter using a low-pass, 4th order Butterworth filter. For this I use the function Bw_LPF(...). This introduces a phase shift which is unwanted. When I googled, I came across a pedagoical explanation (Butterworth filter "regular" and "zero phase" (siemens.com)) that said that it's part of the Butterworth process, but that it can be circumvented if you have access to all data at once (because you can then rely both on future data and past data instead of simply past data to do the filtering), and I do have all data that I want to filter.

 

Is there a function in CVI to do this? Added an example as an attachment (blue is original data, green is Bw-filtered).

Thanks!

0 Kudos
Message 1 of 3
(1,512 Views)

That is an awesome find, and looks like it could be very useful for many people. To answer your question, one of the linked articles goes into more detail. Check section 5.1 on https://community.sw.siemens.com/s/article/introduction-to-filters-fir-versus-iir . It says you reverse the results (Output_Array), and feed it into the filter again. Likely after getting this new response you reverse the order again. The article says you lose some data at the end per figure 16.

0 Kudos
Message 2 of 3
(1,449 Views)
Solution
Accepted by topic author guybrush_threepwood

Thanks for your answer and the article link. I have experimented around some more, and I have found that you can filter using a "general" filter functions instead of using Bw_LPF() directly, and these have more options. For instance, there is one called ZeroPhaseFiltering() which takes "forward" and "reverse coefficients" which are defined by your filter function, order, cutoff frequency and so forth. In my case I used the function called Bw_Coef() to get the coefficients, and then fed them to the ZeroPhaseFiltering function along with the data I wanted to filter.

 

From what I understand, it does exactly what you describe - filter twice. I have noticed two "artefacts" from this method, most of which are mentioned in the article you linked:

  • The filtered frequencies are damped twice as much (if I filter a cutoff-frequency sinus curve with amplitude 1 my resulting amplitude is not 1/sqrt(2), but 1/2).
  • I get artifacts both at the start of my data and at the end. The article only says that you should get artifacts at the end, but at the same time that direct filtering gives a artifact in the beginning and I see no reason why this should disappear when filtering again, so that could be correct.

But anyhow, the phase shift is gone, so I'm pleased!

0 Kudos
Message 3 of 3
(1,439 Views)