Calculate the Frequency of a Time Domain Signal in LabWindows™/CVI™

Updated May 10, 2023

Reported In

Software

  • LabWindows/CVI

Issue Details

How can I calculate the frequency of a time domain signal using the Fast Fourier Transform (FFT) in LabWindows™/CVI™?

Solution

To get the frequency of a time domain signal in LabWindows™/CVI™, it is recommended to use the FFTEx function.
 

Additional Information

When using this function, consider the following:

1. Output Datatype: The output of the function is an NIComplexNumber. You will have to calculate the magnitude of the signal at each frequency and then plot it in a graph. Here is an example that shows how to calculate and plot it:



2. Scaling the output: The FFTEx works with raw data and can calculate the FFT without knowing the sample rate or the "dt" of the acquisition. This means the values in the X-axis of the graph do not have a specific unit, so they have to be scaled manually by multiplying by a factor of "df" or "1/dt" according to your acquisition, after calculating the FFT. For example:

Frequency of the signal measured: 10Hz.
Number of Samples = 1000 Samples.
Sample Rate = 20 Samples/s.

Output of the FFT: 500 units. 

To get the frequency of the signal you will have to calculate the following:

1000 [Samp] / 20 [Samp/s] = 50s =dt.
df = 1/50s = 0.02Hz.
500 units * 0.02 = 10Hz.

You can use the following code as a guide to scale the X-axis: