09-03-2013 01:31 PM - edited 09-03-2013 01:42 PM
I want to apply a low pass butterworth filter in labview based on matlab code i already have.But it seems to be more difficult then it should.This is the code I have in matlab:
----------------------
Wn=low_cutoff*2/20;
[fb fa]=butter(2,Wn,'low');
Data_LPF = filtfilt(fb,fa,intensity);
-----------------------
where low_cutoff and intensity are inputs.
I want to do the same in labview.
Option 1 is to Use a mathscript node and copy the exact code above and get the same results.
This is good, except the problem is right now I am testing both matlab and labview codes with a data file.
so I can adjust the number of data points being read in.
Since the filtfilt() in matlab needs a minimum input length of 3*filter order, I will need to pass it in at least 6 data points(filter order is 2). Right now I can control this, but ultimatley data will be coming in at various lengths, so it will not always be 6, and I get an error.
So my question is how can I do this using the labview vis, because I know they dont have a limit like this on the input length?
I tried using Butterworth coefficients.vi, followed by IRR Filter.vi, but the results are not the same.
even the forward and reverse coefficients(fa and fb) are not the same.
Im not too good with all these filters so if someone could please help!!
And I what the filter to be applied continuously, to all data coming in. That's why I set the init/cont value to TRUE.
In the attached vi, each case shows the various ways I have tried so far but still no luck : (
I tried reading this:
http://forums.ni.com/t5/Signal-Conditioning/IIR-Filter-Someone-please-help-me/td-p/2427108
but what they recommend doesnt seem to work for me...
09-04-2013 11:26 AM
Hey Dev,
Probably a simpler vi to use is the Filter.vi express vi. You can add it to your block diagram by opening the functions palette and going to Signal Processing>>Wfm Conditioning>>Filter.vi. It has the blue border around it.
You can select the order and then sample that many values from your signal source before feeding into the filter.
The other option is you add an input to the mathscript node so that you can pass in how many # of elements you want to filter and the filter order. Right click on the border of the mathscript module and select new input. The name will need to be the same as your variable defined in the script. Make sure to remove any assignments otherwise the value will update to the inscript assignment.