MORECHEMISTRY.COM::MORE CHEMISTRY ON THE WEB
Home Member Area Links Events Publications Promotions
 
 

Value within range over time

Introduction

In some experiments a signal must be checked as often as possible for safety reasons. And if the signal is too high or too low the process must be stopped. But what if that signal is very noisy? And what if even the average of that signal goes up and down like a wave?
One solution is to check the signal over a longer period of time during which it must stay within limits for at least a given percentage of time. The following picture illustrates the solution:


In the color band orange identifies the duration of a signal within range, red and blue identify a signal above the high limit and below the low limit respectively.

This page presents 2 methods to implement this solution: an analytical method, which is more complicated to program but quite precise, and a method by approximation, which is fairly easy to program but less precise.

Analytical method

Basically this method calculates the time between consecutive measurements during which the signal was within range.

It first checks if the signal changes position in regard to the limits. If applicable it calculates where the signal(line) crosses the (upper or lower) limit(line). In some cases the signal is out of range during this period, so the signal is 'valid' for 0 s. In other cases the signal is in range during this period, so the signal is 'valid' for the entire period s.

All in all there are 9 possible scenarios how the signal may change between consecutive measurements. The following table illustrates all possible 'from' 'to' combinations and what the 'valid' time e.g. the time during which the signal is in range would be:

  FROM
too low in range too high
TO too low 0
until getting too low from getting in range until getting too low
in range from getting in range entire period from getting in range
too high from getting in range until getting too high
until getting too high 0

Table 1 - overview of descriptions of how to calculate valid times for certain transitions

As can be seen on the table there are 8 different descriptions meaning there are 8 different calculations. Fortunately, for all situations where the validity changes, it all comes down to a single formula:

tx=(Ylimit-(Y-(dY/dt)*t))/(dY/dt)

where

tx = sought time of signal crossing limt line
Ylimit = value of either high or low limit line
t = time of current reading
Y = value of current reading
dY = value of current reading minus value of previou reading
dt = time of current reading minus time of previous reading

Since coding this in LabVIEW would require a case structure, with inherently stacked cases, it is tempting to use a Formula Node to add some readability to the code. This can be done with a mix of ordinary LabVIEW code as in version 1 of the download or with all code scripted as in version 2 of the download. Since all code belongs to the same algorithm it can be argued that version 2 is the  better version.

Method by approximation

Basically this method splits the period between two consecutive measurements into sections of equal time and for each section calculates if the mean signal is within range or not. This method requires no comparison of 'from' 'to' combinations and hence no stacked case structure and what's more, it can easily be coded in LabVIEW:

Discussion

The analytical method would be precise if the timing were precise. But timing on Windows PC's is quite poor. The time will only increase in finite steps and the actual time step is about 15 ms (see LabVIEW programming topics - ms resolution timestamp). As a result this method cannot be used more than 66 times per second (1000 ms/15 ms) because then dt becomes 0 and division by 0 as in dY/dt is invalid.

The method by approximation has no division so it can be used as often as possible but that will only occasionaly result in a 'time in range' other than 0 because 'time new'-'time old' would be 0 most of the time.

From the above it can be concluded that the time between two consecutive calculations should be at least last several times 15 ms. However, this time should not be longer than between two consectutive measurements, because then any valid signal could be missed.

Remarks

  • The presented VIs were created with LabVIEW 8.5.1
  • This functionality can be used to accept a signal of which the average is not okay but it can also be used to reject a signal of which the average looks okay

Downloads

 


Bart Boshuizen, 2012/01/05






© copyright 2000-2012, morechemistry.com
design by Bb.