From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

measure frequency of digital random signal

Solved!
Go to solution

Dear all.

 

I want to measure the frequency of the signal. This value will be sent to other device to vibrate the vibrator according to the value.

 

For example, I want to measure this signal:

puls2.png

I have try using tone measurement vi and extract single tone measurement vi, but the result is not right, for example, if I have no pulse on the graph the result is 11,5hz  (it must be 0 hz)

I use NI USB 6210 and DAQ assistant to get data from sensor

 

 

0 Kudos
Message 1 of 14
(6,137 Views)

Hi,

   I suggest you use a loop and a counter to measure the time (# of samples) between the points where your signal crosses zero. Every time it goes above zero, you reset your counter, and wait for it to go below zero. Before you reset the counter, store it in an array. This will convert your signal to a sequence of periods. The best estimate of the instantaneous frequency is just the inverse of any period. If you want to calculate the average frequency, you take N samples, divide by 2 times their sum. Zero frequency can only be guaranteed after an infinite amount of time -- if your signal is random, their could always be one more pulse 😉 But, after converting to a sequence of periods, you can set a limit above which you assume the frequency is zero, for instance 0.5 s, or maybe 0.05 s. Do you have Labview experience? Would you like an example vi that solves this problem?

0 Kudos
Message 2 of 14
(6,115 Views)

Hi GabeG..

 

Thank you for the fast response, yeah I am newbie for labview. I just can using functions in labview.

If there is an example, I am very pleased.

Your approach might be appropriate with my application with very short period, because I need it "real time".

 

regards

limavolt

 

0 Kudos
Message 3 of 14
(6,106 Views)

Hi,

   Attached is a vi which models your signal, and provides a way to measure the average frequency over a window of time. It converts the signal to a sequence of periods. I usually start with this approach because you can save the data in a much more compact form if your sampling rate is high. Obviously over a specified period of time, if there are no zero crossings the frequency is zero, so I was a little incoherent before. The real issue is the latency caused by averaging. Your frequency measurement is most accurate half your window size before the current time, so smaller windows give you more up to date measurements, but also more noisy. If you need the most up to date measurement, then you have to use the time since the last crossing which is the case where the frequency never goes to zero. That's probably not a realistic situation. If you needed less latency, you could use a prediction algorithm.

 

Also, there are a number of signal measuring and processing vi's that LV gives you, for instance pulse measurements that could be used to partially implement this or other approaches, but I normally steer clear of them unless they fit exactly due to having to convert back and forth to the waveform data type.

 

Have fun!

Download All
0 Kudos
Message 4 of 14
(6,094 Views)

Hi GabeG

 

I have to learn much about labview, because when I see your program makes me feel inferior.

I want to ask you how to connected to the sinyal from the DAQ assistant data/from the signal data. I have tried like in the attachment, but it seems not right.

 

Thank you

 

 

 

0 Kudos
Message 5 of 14
(6,064 Views)
Solution
Accepted by topic author limavolt

LOL! Whatever motivates you... I don't see an attachment. I commented the block diagram on the attached vi which might help. What you can do in your DAQ program, is use obtain queue with the name Data. Then take the waveform out of DAQ assistant and use get waveform components to retrieve the actual signal values (-1, and 1). Now use a for loop with auto-indexing on the signal array, and inside use enqueue to place each signal value on the data queue. In the attached filter program, you can either copy the bottom loop into your DAQ program, or delete the top signal generation loop and run them in parallel. The nice thing about queues is they can transport data between different vi's on the same computer as long as the name is the same. If you want to do something with the frequency measurements, then you can use another queue to buffer the data out of the measurement loop.

 

Good luck!

0 Kudos
Message 6 of 14
(6,051 Views)

Hi GabeG

 

Thank you for your explanation, I do like this:

 

freq 2.png

 

But the Freq still 0 eventhough there are some pulses, Have something wrong with my code?

 

0 Kudos
Message 7 of 14
(6,043 Views)

Okay, you're close now. Move the two obtain queue vi's to the left of the while loop. You only need to obtain queue once when your vi starts. Create another while loop above your measurement loop. Move the DAQ assistant, for loop, etc... into the new loop. Now that the obtain queue for the data queue is outside the measurement loop, you can lay down a wire up to your new acquisition loop. In the new loop, remove the constant 10 wired to the N input of the for loop. Use the get waveform components, off the waveform palette to convert the waveform into an array, before it goes into the for loop. The get waveform components works like an unbundle by name. It needs to show Y, which is the array of data embedded in the waveform. Wire this through to the enqueue element vi. It should auto index at the boundary of the for loop. The wire will be thick orange outside, and thin orange inside with a white node at the boundary. If it's not indexing you may have to right click the node and choose enable indexing. This allows labview to determine the N input at runtime. The other option would be to keep the constant 10, assuming your reading 10 samples in DAQ assistant and then disable auto-indexing and use an array index vi inside the loop with the loop counter i wired to the index. You might get it working both ways for the experience if you haven't dealt with indexing arrays much.

 

Good luck.

0 Kudos
Message 8 of 14
(6,029 Views)

Hi GabeG,

 

Sorry to bothering you again,

 

I build the program like this:

 

freq3.png

 

But the result of the frequency still zero. Is it the program that I have made is not right?

 

Thank you

 

0 Kudos
Message 9 of 14
(5,994 Views)

One obvious issue is that your Data queue is created to handle an integer data type and you are enqueuing a floating point data type. If the value of Y[i] is less than +/-0.5 for example the resulting integer will always be zero.  I cannot tell from the image whether the integers are signed or unsigned. Obviously the product of two unsigned integers will never be <0. Change the data type on the queue to be DBL. This probably applies to the Periods queue also but the enqueue is not shown.

 

Why not enqueue the waveform? Then you have the timing data as well.

 

Lynn

0 Kudos
Message 10 of 14
(5,981 Views)