LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Measuring frequency of a series of pulses from analog input

I'm working on a program that uses a DAQ to read in a series of pulses. I need to somehow measure the frequency of these pulses coming in. I'm not sure if I can use the "Extract Single Tone Information" vi for pulses, as it describes only being able to read it in for sine waves.

The frequency of the pulses will range from 0 to about 120 Hz (I measured this much on an oscillicope). I have a while loop running with a 100 millisecond delay in the loop. I was thinking I could somehow measure the number of peaks in a certain time period (ie: the 100 ms that the loop is running at). I'm not sure how to accomplish this, as I'm relatively new to data aquisition.

If anyone could suggest a g
ood way to measure this frequency (i need to measure it about every 100 ms) I would appreciate it. Thanks.
0 Kudos
Message 1 of 4
(3,594 Views)
One method would be to run your 100 msecs worth of samples throught the "Threshold Peak Detector.vi" and use the resulting indices and count to figure out the frequency. The count output tells you how many threshold crossings you had which should equal the number of pulses. Then, subtract the first element of the indices array from the last and multiply by the "delta t" (take the reciprocal of your sample rate for that channel) to get the time period. Now you know how many pulses (count) per time period. Divide the count minus one by the calculated time period to get the frequency. Remember to subtract one from the count and be careful about choosing your threshold.

I know you want to do that with AI, but the counter / timers are really designed for that sort
of thing. If you have any on your DAQ board, they are itching to take this measurement.

Dan Press
www.primetest.com
Message 2 of 4
(3,594 Views)
You could measure it by counting the number of pulses every 100 msec. However, you will only have an resolution of 10 Hz that way, which probably isn't good enough.

You can greatly increase your accuracy by counting the number of pulses and recording when each one occurs. Subtract the time of the first pulse from the last pulse. Divide the number of pulses minus one by the time interval, and you have the pulse frequency.

If the frequencies are going to be less than 20 Hz, you will need to keep track of when the last pulse occurred in the previous block. Otherwise, it will alternate between 0 and 10 Hz as an output.

You could also use Extract Single Tone like you suggested. It will output the primary frequency of a square wave just as well as a sine wav
e. You would want to set your sample rate so that each block of data you analyze is a power of two. This only works for frequencies above 20 Hz, for the same reason - it requires two pulses in one block to work properly.

Bruce
Bruce Ammons
Ammons Engineering
Message 3 of 4
(3,594 Views)
f=1/t

You must know the time between pulses in order to determine the frequency. This can be derived from the sample speed. However, if you are using analog triggering, then you will have to do something else. I would suggest using external hardware if this is the case.

Please explain your acquisition method, including triggering, etc. If this is simple acquistion (buffered), then you already have everything you need.

If the purpose of your DAQ is SOLELY to measure the frequency, then I would suggest using external hardware to convert the signal to a digital one (if necessary - check NI hardware specs vs. your signal. You may already have a 'digital' signal). Once you have a digital signal, you can select from a number of functions to determine the frequency.


Otherwise, the inverse of (peak detector # of peaks / time (100ms)) is a great method.
0 Kudos
Message 4 of 4
(3,594 Views)