LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

compare signals - measure time till match

Hello,


Im making labview application that will read data (range 0 to 359.99) from microcontroller (and sensor attached to it) and will display it after some processing.

Right now my application reads data via RS232 and in real time displays it on chart, finds current minimum and maximum and displays history of data (as array indicator) and simply displays how long was VI running.

Now im starting to play with signal processing. Since the measurements from sensor are noisy (its magnetic sensor) i want to filter recieved data in labview. I want to compare multiple filters. So far i tried simple first order low pass filter:

output = output + coef*(measurement - output)

What is intresting me is how close and most important how fast will the filtered data get to original data and how it changes while manipulating filter coeficents (like if i set filter coeficent high the output will be less filtered but filter will work fast, but if i lower it too much it will be slow but less noise).

Right now to do that i check when the filtered signal will reach at least 99.8% of original signal and then it just lights up indicator (works only when signal is rising).

 


What i would like to achieve is a more precise indicator that will actually count time. Even if it will be as simple as measuring time from start of VI running till signals match.

ps. I know there are pre made filter function blocks but i dont want to use them. Later when im done with experimenting ill be implementing same filter, signal processing directly in microcontroller so its going to be easier for me if ill be making filters in labview straight from formulas, on my own

 

Thank you in advance for help.

0 Kudos
Message 1 of 7
(3,159 Views)

It looks like you have a good start on what you want, and your code isn't painful to the eyes so congradulations

 

Your loop rate will vary.  You are essentially performing software timing, where you are continually asking for data and getting it over serial.  How long does it take to get 10 data points?  It can't be known.  Windows is a nondeterministic OS and as a result you will have jitter.

 

But that might be fine with you.  What sounds more important than getting a sample every 10ms, is knowing how much time difference there is between samples.  And that you can do in Windows (more or less).

 

My suggestion to you is to log the data like you are, but to also log the time, and the filtered value.  This way you can graph the data in Excel in an XY chart, showing the data at times that may not always be exactly the same time apart.  Use the Write To Spreadsheet.vi under the File I/O palette.  You can wire to it a 1D array of values, which should have your 3 elements in it.  It has an optional input for Appending to an existing file.  Wire a True to that input and you shouldn't have to worry about setting the location for the next write in the file.

0 Kudos
Message 2 of 7
(3,148 Views)

While using a spreadsheet and then doing math on data in there sounds good, it require additional operations after taking measurements.

 

Id rather go into direction of real time measurement. I start my application, i have incoming stream of data with and without filtering and from the start it measures how long it took filtered data to catch up with original data data catches up (filtered is not different from orignal by example 1%) then in real time i make change in data stream (im reading rotary encoder position so i can just turn the know) and program notices change in data and filtered data and starts counting again untill filter catches up.

 

Whole event would start and end when triggers occur.

 

delta = signal *0.01

 

starting trigger for increasing signal value:

filtered< (signal - delta): if its true it means that signal values are increasing and filter is about to start catching up with them by rising, triggers counter

 

ending trigger:

filtered >= (signal - delta)

 

starting trigger for decreasing signal value:

filtered  > (signal + delta): if its true it means that signal values are decreasing and filter is about to start catching up with them by decreasing, triggers counter

 

ending trigger:

filtered <= (signal + delta)

 

 

After either of starting condition is true it triggers counter. I would want to try making it similar how i measure running time. When the condition is true, a current value from "high resolution relative seconds" would be remembered and read only once when the trigger happens. Then during whole counting process, previous value from 'relative seconds' would be substracted from real time value from second 'relative seconds' counter. This way ill be measuring relative time from the moment of start condition turning true. Counting would be terminated by ending condition and last value would stay on display.

If start condition would occur again in single run of VI the previous value indiciating how long it took last time for filtered value to catch up with real value would be erased and replaced by new counting.

 

I want to begin with a simple "stopwatch" instead of triggering by signal, i want to trigger it with switch. So, my VI is running, and when i press switch it starts counting.

 

I tried to do this with a case structure.

counter.png

 

But there is that problem, if button is off/on type (because thats how my start end condition will work like) if its on both 'relative time' counters are running at the same time thus result is 0.

Even if button would be latch when pressed, it will read value from 'relative time' but as soon as condition turns false, the previous value is replaced by 0 (deault value, exit terminal cant be unwired in "false" condition).

0 Kudos
Message 3 of 7
(3,110 Views)

@User002 wrote:

While using a spreadsheet and then doing math on data in there sounds good, it require additional operations after taking measurements.

 

Id rather go into direction of real time measurement. 


Then you probably shouldn't be using Windows.  You can use producer consumer loops where another loop is consuming and producing filtered data in parallel to serial communication.  This will likely get you as close as you want.  

 

If you really need a real-time system, then you really need a real-time system.

0 Kudos
Message 4 of 7
(3,102 Views)

Ok, maybe i shouldnt use "real time" phrase there because thats what i meant. I meant that rather than using write to spreadsheet and then check how fast filter catches up after my VI stopped running i want to do it in the while loop, while the VI is still running.

0 Kudos
Message 5 of 7
(3,095 Views)

@User002 wrote:

Ok, maybe i shouldnt use "real time" phrase there because thats what i meant. I meant that rather than using write to spreadsheet and then check how fast filter catches up after my VI stopped running i want to do it in the while loop, while the VI is still running.


Oh well that's very different and can be done.  Sorry I didn't understand your post.  Yes your code is a good start, but in the false case what you really want, the the value that was there when it was true.  You can keep this old value, by wiring it to a shift register on the inside of that loop.

0 Kudos
Message 6 of 7
(3,090 Views)

Okay I figured I could come up with a quick example instead of just words.  Here is an example VI that will measure the amount of time it takes for a filtered signal to cross a threshold of 5, from when the control signal crosses a threshold of 5.  My filter is a 6 point average and some white noise added.  The important thing to take away is how the time is kept in the shift registered, and updated when the condition is met which in this case is when the value is greater than 5 but it was less than 5 before.

Message 7 of 7
(3,083 Views)