HEM Data Support: Helpful Hints
Navigation

Emulating Counter-Timer Functions with Waveform Analyzer

Using the Waveform Analyzer module of Snap-Master, you can emulate the basic functionality of Counter-Timer hardware. The functions most often used are event counting, and the measurement of pulse width and frequency.

The basic set of equations for these functions look like the following (assuming your input channel is A0). The output channels of interest are R4, R5, and R6.

# Run Comments Equation Definition Label Units
1 Event detection R0 = A0 > 2 detect bool
2 Rising edge R1 = R0 > z[-1](R0) edge bool
3 Time at last edge R2 = rmax(time * R1) last start time secs
4 Delta t at edge R3 = R2 – z[-1](R2) elapsed time secs
5 COUNT R4 = round (intg(R1) * info[s](R1)) Count events
6 PULSE WIDTH w/ HOLD R5 = if (R3 = 0, z[-1](R5), R3) Pulse Width secs
7 PULSE FREQUENCY R6 = if(R5<>0, 1/R5, 0) Frequency Hz

Line 1 is a critical part of the equation set – it turns an analog signal into a Boolean waveform (with values of 0 or 1) which indicates when the event is true or not. You may substitute any set of logical statements for Line 1, as long as the result (R0) is a waveform which goes from 0 to 1 when the event occurs. For digital inputs, the signal is already a Boolean waveform so this equation is not necessary (or write it as R0 = A0, substituting your input channel for A0).

Line 2 determines each rising edge of R0 by establishing when the current point is greater than the previous point (using the time shift, or z, function). Line 2 also results in a Boolean waveform, in this case having the value 0 for all samples but the specific ones where R0 has changed from 0 to 1.

Line 3 measures the time at the last pulse by multiplying the current frame time by the Boolean waveform with pulse heights of 1. The running maximum function holds the previous value so we can use it later.

Line 4 calculates the difference between the current time and the time at the previous point. When R1 is not on an edge, the difference between these values is 0 because the running max is not increasing. On an edge, there is a difference between the current and previous points because the running max has updated for the current point.

Line 5 takes advantage of the pulses created by Line 2 (which have a height of 1 and a width of 1 sample) to perform a count of the pulses. The integral of the pulses multiplied by the sample rate (the info[s] function) produces a stair-step result where each step is an integer value (the round function preceding the counting cleans up any fractional artifacts from the integration). This equation produces the EVENT COUNTING result.

Line 6 looks for the discontinuities in the time difference of R3 and only updates the result when it has changed. If the difference between the current and previous points is 0, then the previous result value is retained. This equation produces the PULSE WIDTH result, which is updated during each new cycle.

Line 7 simply takes the inverse of the PULSE WIDTH result to measure the FREQUENCY of the pulse width. The if function is used to only calculate the inverse when the PULSE WIDTH is not 0 (which it is at the beginning of the frame until the first cycle is completed).

To see the equations in action, set up the following instrument:

Snap-Master Acquisition Instrument

In the Wave Generator element, this example has set up a succession of square wave stages of differing frequencies each with a duration of 2 seconds (the total frame length is 10 seconds). For information on creating waveform stages, refer to section 5.4 of the Snap-Master User’s Guide.

The original waveform is in the upper left corner, and consists of a 10 Hz, 5 Hz, 1 Hz, 20 Hz, then a 50 Hz square wave. The EVENT COUNT result in the upper right corner follows the frequencies with a steeper slope for higher frequencies, and the PULSE WIDTH measurement in the lower left corner shows the actual pulse width for each stage. In the lower right corner, the FREQUENCY measurement validates the settings for the square waves set up in the Wave Generator element.

(The results for this instrument appeared in real-time using a Pentium-class computer, with the sample rate of the Wave Generator set to 500 Hz. Your performance results may vary based on the type of computer, the element used for the data source, any additional analysis equations being processed, and other factors affecting overall performance of your computer.)