LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Butterworth filter is not filtering data properly

Hello,
 
I am trying to use a low-level Butterworth filter to filter some data.  I am sampling the data at 100 samples per second so I have been using this as the sampling frequency.  I have also initialized the filter so that it will theoretically work continuously.  After playing around with different cut off levels, to no success, I wanted to see if my data was simply passing through the filter correctly... which it isn't.  I have read related postings on "High Pass Filter Settings [NEW]" and I am thinking that my sample rate is not passing correctly to my filter.
 
Does anyone have any idea why this would be the case... or how to fix my problem.  Eventually I would like to differentiate this data...
 
I've included my LabView VI (the filter is in the first while loop).  I am using LabView 7.1 with PC-CARD DAS16/16AO
 
Thanks
 
Jenna
0 Kudos
Message 1 of 9
(6,296 Views)
Jenna,

You are correct that the filter does not know what the sampling rate is. Because you have not told it. The Filter VI you are using takes an array datatype as the X input. The sampling frequency fs is connected to a different input. You have not specified several other parameters of the filter as well. Are the defaults what you want?

Rather than building a waveform and then separating the components for the filter, just wire the Array after multiplying by 36.13732 to the X input. Feed the dt to a 1/x function and then to the fs input of the filter VI.

Keep the Context help window on while you are develoing your programs. That way you can see the names of all the inputs to a VI whne the cursor moves over it. Coercion dots are also a clue that an input is not exactly matched to the datatype you have wired to it: A hint that some information may have been lost.

Lynn
Message 2 of 9
(6,277 Views)

Hi Lynn,

Thanks for your reply, I was manipulating the filter parameters using the properties function of the Butterworth filter (and at times setting them to my desired default).

I think the problem I was having might have more to do with the fact that I am unsure what the frequency of my signal is.  I tried using the Tone Express VI, but I wasn't able to have it update every 0.01 s (so it wasn't very helpful).  Maybe you could answer these questions for me:

1) Is there a way to have the tone VI or another frequency measuring VI read into my spreadsheet file 100 times a second?

2) When I am using a lowpass filter do I have to specify high and low cutoff?  If not, do I specify the high cutoff to "cut off" the high frequency in my lowpass filter?

The context window does help me to realize some things in my VI, but I often find that since I am not an expert at LabView (or programming for that matter) troubleshooting becomes more reliant on trial and error.  Reading threads on this website, along with some posts has been most helpful.

Thanks again

Jenna

0 Kudos
Message 3 of 9
(6,263 Views)
Jenna,

For question 2 here is the section of the detailed help file for the filter:

"sampling freq: fs is the sampling frequency and must be greater than zero. The default is 1.0. If sampling freq: fs is less than or equal to zero, this VI sets Filtered X to an empty array and returns an error.
high cutoff freq: fh is the high cutoff frequency. The VI ignores this parameter when filter type is 0 (Lowpass) or 1 (Highpass). When filter type is 2 (Bandpass) or 3 (Bandstop), high cutoff freq: fh must be greater than low cutoff freq: fl and observe the Nyquist criterion.
low cutoff freq: fl is the low cutoff frequency and must observe the Nyquist criterion. The default is 0.125. If low cutoff freq: fl is less than or equal to zero or greater than half the value of sampling freq: fs, the VI sets Filtered X to an empty array and returns an error. When filter type is 2 (Bandpass) or 3 (Bandstop), low cutoff freq: fl must be less than high cutoff freq: fh.
order specifies the filter order and must be greater than zero. The default is 2. If order is less than or equal to zero, the VI sets Filtered X to an empty array and returns an error.
init/cont controls the initialization of the internal states. The default is FALSE. The first time this VI runs or if init/cont is FALSE, LabVIEW initializes the internal states to zero. If init/cont is TRUE, LabVIEW initializes the internal states to the final states from the previous call to this instance of this VI. To process a large data sequence that consists of smaller blocks, set this input to FALSE for the first block and to TRUE for continuous filtering of all remaining blocks."

I am not sure I understand question 1. You seem to be sampling at 100 samples/second. You can certainly save all the samples you collect. However, you must have multiple samples to define a frequency. Depending on how precisely you need to measure the frequency, the waveform of the signal, and the signal to noise ratio, you may need a few samples or thousands of samples to get the measurement you want. At low frequencies it is sometimes better to measure period and calculate the frequency.

Lynn
0 Kudos
Message 4 of 9
(6,258 Views)
It was a lot easier to measure the period and calculate the frequency since my signal does have a very low frequency.  Thanks for your help.
 
I know that there are posts on filter delays and how to account for them in the forum (I believe you have written quite a few Lynn).  I'm just wondering if you have any pointers for my application?  I'm afraid that if I start using techniques that involve filtering followed by reverse array filtering to bypass the delay, that my program will waste precious processing time that I need to conserve for future additions to my VI. 
 
Thanks
 
Jenna
0 Kudos
Message 5 of 9
(6,245 Views)
Jenna,

Before I try to comment on filtering approaches, I need to know more about your application. What is your purpose in filtering? Are you trying to eliminate out of band noise or specific interference such as power line frequency? What is the nominal waveshape of your desired signal? What are the frequencies and magnitudes of both the desired and interferring signals? What are you going to do with the filtered data? Display for user monitoring and automated analysis for control may require quite different methods.

I could not open your VI in LV7.1. It caused a crash of LV. It opened OK in LV 8.2, however. I do not have your hardware nor many of the subVIs. I cleaned up the diagram a bit and added some notes (numbered 1 through 6). If you can save some typical data as default values, I will take a look to see what might work for you.

Lynn
0 Kudos
Message 6 of 9
(6,236 Views)

Hi Lynn,

The purpose of my LabView program is to read in a variable sine wave (which represents a swinging leg), measure the torque, position and angles over time and be able to adjust a motor on the fly.  My purpose in filtering is to allow for a smoothly differentiated signal.  If I differentiate without a filter… my signal is a mess.  The nominal waveshape is a sine wave and the frequencies and magnitudes of the signal vary with each trial.   Generally though, the frequency of the signal is 1.5 Hz or less.  The peak to peak amplitude for the analog out channel from an optical encoder (which measures the leg angle) is approximately 70 degrees (1.94V).  It is necessary to have the differentiated and filtered “angular velocity” in sync with the other channels to know the effect of the change in the motor speed at different points in the cycle.  I will be analyzing this data mainly after it has been collected, so the precision on the charts while it is running is not too important.

I’ve tried modifying my VI so that you will be able to see it, but since my signal is continuous “making the current values default” freezes my VI at one point in time... so my simplified VI doesn’t run as the more complete one did.

I have also briefly looked into a Savitzky Golay filter that differentiates and filters simultaneously, but I haven’t had much luck getting it to work.

Any suggestions?

Thanks

Jenna
0 Kudos
Message 7 of 9
(6,206 Views)
Jenna,

The Savitzky Golay filter is considered a good approach to obtaining smooth derivatives.

It is really hard to tell without seeing some of the data. If your frequency is 1.5 Hz, then 1 second of data will cover more than one cycle. That should be enough to get some idea of the noise or roughness of your signal.

What kind of sensor are you using for the signal you want to differentiate? Does the position of the motor need to track the position of the leg (as in a device to maintain a specified torque or load throughout the motion)?

Lynn
0 Kudos
Message 8 of 9
(6,204 Views)

Hi Lynn,

I am using an optical encoder as the sensor that measures the leg angles... so I will need to differentiate that signal to get the angular velocity.  Eventually the motor voltage will be made to change at different points of the swinging leg cycle as well as at different angular velocities of the swinging leg.  So you're right in that we will be controlling the torque throughout the motion. This is why it is important to have very little delay from the filters and a 180 degree phase shift with the differentiated signal.

The Butterworth filter that I used works well with a cutoff at 10 and order of 3 before differentiation, and a cutoff of 3 and order of 3 after the differentiation.

Thanks

Jenna

 

 

0 Kudos
Message 9 of 9
(6,194 Views)