LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Lowpass filtering live data yields discontinuities

Solved!
Go to solution

I'm acquiring torque data for a system driven at (different) constant speed(s). There is a physical eccentricity in the bearing/shaft system that manifests itself in the data, though there are some other harmonics that don't seem to correlate to test speeds. For our current discussion, the physical issue causing the noise cannot be solved.

 

I'm using an NI-9239 on cDAQ-9178 chassis, acquiring at 2 kHz and 400 samples per channel (there's 2 channels but only one of interest here). I need to display semi-live data (currently 5 seconds, updating every 200 ms) to the operator, but as the raw data is noisy I want to display filtered data. However, I haven't been able to find a way to do so without discontinuities due to transients at the start of each loop call, with either a Savitsky-Golay or Butterworth (set to continuous after first call). I set up an IIR butterworth filter with (rough) initial conditions, and that did resolve the discontinuities. However, the magnitude is off by a factor of approximately -2. Can anybody point me in the correct direction? Thanks in advance.

 

 

 

 

0 Kudos
Message 1 of 8
(3,301 Views)

Hi Johnny,

 

are you in the same team as Milon?

You are using a very similar algorithm to filter a signal and the very same suggestions apply to yur message too…

 

However, I haven't been able to find a way to do so without discontinuities due to transients at the start of each loop call

Why are there discontinuities at all when you sample those data with a DAQmx task set to continuous operation mode?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(3,277 Views)

Thanks for the reply, Gerd. I'd seen Milon's post in my search results but hadn't realized how recent it was. Not part of his/her team, though.

I'm at a different job today so can't generate images of the data, but in my actual acquisition (or in the attached simplified VI with sample data), there are no discontinuities in acquired data, only with the S-G filter and Butterworth filter.

If you run the attached VI you can see the issue after every 400 samples are read. I thought I could remedy this by wiring the continuous terminal on the filter after the first call but it doesn't work.

Also, in looking at this post of yours, if I similarly wire my actual sampling rate (2 kHz) to the Butterworth filter, the transient response occupies virtually the entire 5s window the operator would like to view.

So, to hopefully be clearer, my question is how I can better set the initial conditions for the IIR filter to get the correct magnitude, or is it possible to better configure the S-G or regular Butterworth filters to avoid the transient effects I'm seeing?

0 Kudos
Message 3 of 8
(3,260 Views)

You are introducing the discontinuities yourself!  You have a set of data, Y, that you introduce into the loop via a Shift Register.  You filter it, then 200 msec later, you filter it again (and again, and again), as though your Signal was a concatenation of your original waveform with itself, over and over.  Unless the end of the waveform was continuous with the beginnning (so that putting two copies in sequence showed no "break" where the first ended and the second began), you are creating the discontinuity you have been observing.

 

Bob Schor

0 Kudos
Message 4 of 8
(3,257 Views)

Thanks for the reply, Bob. My intent was to replicate the producer-consumer loop data flow of my actual VI using 30s of saved data and reading in at an equivalent quantity per loop, with the 200 ms delay to replicate the interface update rate the operator sees. If there's a difference between the actual VI (obviously difficult to say as I can't share it) and this simplified VI, I'm missing something, as my intent was to replicate filtering only the 400 sample subsets of data, not a continuously concatenated form.

0 Kudos
Message 5 of 8
(3,238 Views)
Solution
Accepted by topic author johnnyfear

OK, so I did what I should have done before -- I ran your code, and found both mistakes! 

 

One doesn't matter with the "random" data that I think you are using for your simulation (but would if the data were real).  You generate a very long waveform and then present it to your filter, pulling off 400 points per iteration (to simulate your sampling at 2kHz for 200 msec).  You use Delete from Array, and don't wire the Index input -- well, this has the peculiar property that if unwired, it means the last element!  [As far as I know, this is the only LabVIEW function where an unwired Integer input does not default to 0, but to "Array Size -1".

 

But the Fatal Error was using the Loop Index (instead of a Shift Register) to handle the initialization of the Filter.  Wire up a Shift Register, put a Boolean "True" on the right-edge (output) Shift Register, and wire the input (from outside the While) to False (the default).  Wire that to the Init/Continue input.  You used more complex logic ("i=0") and "got it backwards", but a straight-up "False the first time, true every other time because I wired it that way!!" statement is safer.

 

Bob Schor

Message 6 of 8
(3,229 Views)

Thanks for taking another look, Bob. I missed in the help that delete from array starts at the end, and your method of wiring the initialization of the filter definitely seems more robust. Stupid LabView doing what I tell it to do, not what I meant! Cat Sad

 

I made those changes and got the Butterworth filter working properly.

 

Interestingly enough (to me), in case anyone else finds this, I was able to remove the occasional discontinuity in the Savitzky-Golay filtered data by increasing sampling rate/samples read, allowing increased side point quantity. I also found that if the side point quantity is above ~40% of samples available, error -20008 will appear with S-G filter.

 

Thanks again for the help!

0 Kudos
Message 7 of 8
(3,218 Views)

@johnnyfear wrote:

Stupid LabView doing what I tell it to do, not what I meant! Cat Sad


Yeah, I've been there, too ...

 

BS

0 Kudos
Message 8 of 8
(3,215 Views)