Example Code

Threshold Detector with Hysteresis.vi

Code and Documents



This example VI demonstrates the use of state machine to build a threshold with hysteresis and introduces an example to use it.



This VI detects peaks above a threshold and hysteresis level.  The following example explains the functionality in detail:

community image.PNG

The blue line is the input signal, the red line is the threshold level, and the green line is the hysteresis level.  With this VI, peaks will only be counted at the vertical dotted lines, when the values pass both threshold and hysteresis, but only if the data has not crossed both already.  This way, noisy data jumping around the threshold level does not count multiple peaks.

The VI and an example of its implementation are attached.  NOTE: a 'First Call?.vi' boolean must be input into the subVI in order to allow the peak counter to reset.



  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Open the VI "Threshold-hysteresis Example 2012 NIVerified.vi";
  2. Run the program;


Additional Information or References
VI Block Diagram of "Threshold-hysteresis Example 2012 NIVerified.vi"

Block Diagram.png


 **This document has been updated to meet the current required format for the NI Code Exchange.**

National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.