Value within range over timeIntroductionIn 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?
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 methodBasically 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:
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
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 approximationBasically 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:
DiscussionThe 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
Downloads
Bart Boshuizen, 2012/01/05
|
|||||||||||||||||||||||||||||||||||||||||