From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I store an IIR filter's internal state in a shift register?

I'd like to filter from 1 to 8 signals with NI's "Butterworth Filter (DBL).vi". I'm sampling them continuously, so when I put them in a For Loop and filter more than one (using the filter's "init/cont (init:F)" input, the filter's internal state jumps between the various signals. One workaround is to put 8 of these Butterworth filters in parallel on a single VI's block diagram, but that is clunky. Is there a way to do this in a loop where I'm storing each signal's filtering coefficients in a shift register?

 

0 Kudos
Message 1 of 5
(3,160 Views)

Hello Bmihura, 

 

Thank you for posting on our support forums. I have been investigating your question regarding how to store the 'internal states' of the Butterwork Filter.vi. After looking into the coding of this VI, it appears that from the use of functional global variables and shift registers in the IIR Cascade Filter (DBL).vi, there will be a new instance for each block dropped onto the block diagram. So, if we were to auto-index a For Loop, we will run into this issue of having the 'internal states' crossing and jumping between the signals. 

 

It appears that the only way to correctly implement your request is to perform the work around that you have already suggested; placing a Butterworth Filter.vi for every signal. 

 

Please read this KnowledgeBase article for a more detailed explanation on this. This KB is regarding the Decimate (continuous) VI, but it also applies to the Butterworth Filter as well. 

 

Unfortunately, this is how the implementation needs to be. Due to the architecture of the VIs, we need to ensure that a separate block is placed for each signal to ensure that the instances of the filter are different. 

 

Huntington W
National Instruments
Applications Engineer

***Don't forget to give Kudos and Accepted as Solution where it is deserved***
Message 2 of 5
(3,121 Views)

Would using a Parallel For provide a different instance for each call? It seems like it would since it would be executing them in parallel.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 3 of 5
(3,106 Views)

There are also two VIs which let you explicitly set initial conditions (mening the same as filter state): IIR Filter with I.C..vi and FIR Filter with I.C..vi. You can find them in Signal Processing -> Filters -> Advanced IIR/FIR. You can store the states and coefficients in 2D arrays. Here's general idea how should it work:

filters.png

0 Kudos
Message 4 of 5
(3,090 Views)

The_Hunt,

 

You have stated my question much more eloquently than I did. Now that I have the verbage down pat, I will look into your suggestions. Thanks for getting the wording clear!

 

I am being stubborn and still think that there is some way to do this in a loop, but once I read your link, I may be proven wrong.

0 Kudos
Message 5 of 5
(3,075 Views)