# Example Programs

cancel
Showing results for
Did you mean:

## Calculate Frequency of Signal Displayed on Waveform Graph

• ,
• ### Software-LabVIEW

Overview

This function will output the frequency of a signal displayed on a waveform graph.  If the user is zoomed into a specific portion of the signal, the function will only take into account the visible portion of the signal.

Description

The function looks at all zero crossings in the visible region of the waveform graph.  It calculates the average distance between zero crossings (rising and falling) to obtain the average semi-period of the signal.  It then multiplies this number by two (average period) and inverts to obtain the frequency of the signal.

Requirements

LabVIEW 7.1 (or compatible)

Steps to Implement or Execute Code

The attached VI is meant to be used as a subVI. A sample use case is pictured below.

Example Use Case:

In the above use case, we acquire a finite amount of data into a waveform graph.  The loop in the end allows the Meas Freq of Visible Waveform sub-vi to continuously compute frequency based on the region of the graph that we are zoomed in on:

To obtain a reference to a waveform graph, simply right-click on the Waveform Graph icon (from the block diagram) then select Create >> Reference.  The waveform graph should have accurate timestamp information (waveform input) for the function to be able to calculate frequency.  The sub-VI will only work on a single waveform (an Array of Waveforms will cause an error within the sub VI).

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

John Passiak
Member

I have been tasked with creating a frequency counter in LabVIEW. I have created a VI that looks like the one described and I have inserted your VI as a sub-VI. The only problem I am having is getting the waveform graph (your sub-vi) to create a reference. In your tutorial, you say to simply right click and in the "Create" area, reference should be there. For some reason, it is not there for me. Only indicator, constant, and control are there, and they are all not selectable. Any help would be appreciated. Thanks!

Trusted Enthusiast

Right-click on the waveform graph indicator from within your main VI--that should give you the option to create a reference (unless that's what you're doing already, then I'm not sure why you wouldn't have that option).  You would then pass this reference into the subVI.

John Passiak
Member

Thanks for the help John! I am now able to get a reference. I was clicking on your sub-VI icon instead of the waveform graph indicator. However, even with that reference, I am having issues. When I try to connect the reference to the sub-VI, it says there is a wire class conflict. I've gone back and remade the entire VI, but I still get the same error. I am currently using LabVIEW 8.6. As a side note, my waveform graph doesn't actually look like a graph. It has a box that has t0, dt, and a table that shows Y. Any ideas about that? Thanks for all the help!

Member

I actually have a new problem. I figured out the reference problem, but now when I run the VI, there is no frequency output. It seems like something in the sub-VI is just looping indefinitely and will not produce a result to pass through it. Any thoughts?

Member