Signal Conditioning

cancel
Showing results for 
Search instead for 
Did you mean: 

IIR Filter - Someone please help me!

Hi all,

 

I thought this was a simple problem to do, but for some reason it's not working for me.

 

I'm taking in some data from an IR sensor and I'm trying to do some filtering on the signal. I want to highpass the signal so that the DC offset of the signal and any low frequency will be attenuated. I've implemented a digital IIR butterworth filter in MATLAB to first verified that it worked and then tried to implement the same thing in LabVIEW. The problem is that the results were not the same. I implemented the IIR filter two ways in LabVIEW with both differing results from MATLAB.

 

Here's what I did in MATLAB:

 

I generated the IIR coefficients for a butterworth highpass filter that's 7th order with a digital cutoff frequency of .1. Then I got the filtered results and plotted it. I've attached the MATLAB figure images.

 

[b a] = butter(7, .1, 'high')

b =

Columns 1 through 4

0.4918 -3.4426 10.3279 -17.2132

Columns 5 through 8

17.2132 -10.3279 3.4426 -0.4918

 

a =

Columns 1 through 4

1.0000 -5.5890 13.5047 -18.2709

Columns 5 through 8

14.9365 -7.3738 2.0344 -0.2419

 

PS1filtered = filtfilt(b,a,PS1);

plot(PS1)

figure(2)

plot(PS1filtered)

 

unfilteredMATLAB.jpgfilteredMATLAB.jpg

 

So in LabVIEW, I thought it would be simple to implement as well. I've attached my VI that I made. In the VI, I used the Butterworth Filter VI and I also used the IIR Filter VI with manually entered forward and reverse coefficient values that I calculated in MATLAB. Please note that I'm only processing the second column of data in my data file. At least one of the graphs in LabVIEW should resemble the result that I got in MATLAB.

 

LabVIEW.JPG

 

LabVIEW2.JPG

 

Can anyone help explain this?

 

Download All
0 Kudos
Message 1 of 2
(7,199 Views)

take a look at the function you used in matlab:

 

Description

y = filtfilt(b,a,x) performs zero-phase digital filtering by processing the input data, x, in both the forward and reverse directions [1]. filtfilt operates along the first nonsingleton dimension of x. The vector b provides the numerator coefficients of the filter and the vector a provides the denominator coefficients. If you use an all-pole filter, enter 1 for b. If you use an all-zero filter (FIR), enter 1 for a. After filtering the data in the forward direction, filtfilt reverses the filtered sequence and runs it back through the filter. The result has the following characteristics:

  • Zero-phase distortion

  • A filter transfer function, which equals the squared magnitude of the original filter transfer function

  • A filter order that is double the order of the filter specified by b and a

filtfilt minimizes start-up and ending transients by matching initial conditions, and you can use it for both real and complex inputs. Do not use filtfilt with differentiator and Hilbert FIR filters, because the operation of these filters depends heavily on their phase response.

 

 

--------------------------------

 

You didn't do the same in LV 😉

 

If you have a continious data stream you can simply apply the LV IIR filter twice and after a initial filter arifact you should get the same data.

If you only want to remove the 'mean' of one datablock, do that (to minimize jumps) and filter twice with inversed data

here a quick mod

IIRmodbd.png

 

and the result:

IIRmod.png

 

 

Have fun

 

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 2 of 2
(7,177 Views)