Example Code

Calculate Frequency of Square Wave in LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

Calculate the frequency of a signal (square wave) in LabVIEW.

 

Description

This example takes a portion of an acquired signal, and implements edge counting in software to determine the frequency of the signal.

Note that this example will count extra transitions with noisy data. Filtering or other modifications may be necessary to ensure accurate counting if noise is present

 

Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Select simulated signal to read frequency of on Front Panel.
  2. Run example to see measured frequency.
 
Additional Information or References

 

VI Snippet.png

 

 

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

 

------------------------------------------------------------------------------------------

Jon F.
Technical Support Engineer
National Instruments

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

Comments
rhettyj92
Member
Member
on

If this works when I get to my lab I think I'll cry! Been trying to get a photointerrupter signal with my myRIO (no DAQmx) for the past 5 days with no luck. It also doesn't help that I've not had any training! I'll let you know how it works out 🙂

popobbb
Member
Member
on

your idea is great, it just work on square signals only.

so i just added a few ideas to make more signals to work with your idea.

averaging noises then scalling down around zero and then making it monobit so sine waves will work too.

here his my addition.

measure freq 1.jpg

 

i cant post the average VI here , so here is a link to a version of it i posted.

Smooth-Average-an-array-of-n-numbers

vinlet
Member
Member
on

Hi,

 

i'm using the VI posted by Jon F. of NI at beginning of this post to calculate the Frequency of a Square Wave,generated in my works with a Signal Simulate,and the result obviously is ok!

 

Now i would like to know:

 

if i add a Noise to the same Square Wave always with Simulate Signal (the SIMULATE is my waveform generator for my studies :)...) how can i do to obtain a correct measurement of the Frequency? How should i modify  the VI posted by Jon F. for  added Noise? Which code should i add to the initial VI?

 

In my tests i'm adding to the Square Wave with the Simulate Signal  UNIFORM WHITE NOISE as type,and small values of Noise Amplitude and Seed Number.

I hope for your help! It would be great to receive some easy code attacched to solve this my problem!

 

Thanks all!