Example Code

Total Harmonic Distortion (THD)

Code and Documents

Attachment

Overview

A 1 kHz tone is generated, and its harmonic spectrum is shown for various types of distortion, with the Total Harmonic Distortion (THD) in % relative to the fundamental tones level.

Description

This example demonstrates the use of Signal Processing functions to introduce distortion and perform analysis on the resulting signal. A simulated sine wave of 1 kHz is used as the base signal, with various distortion options. The frequency power spectrum and harmonic levels on the distorted signal are then displayed along with the Total Harmonic Distortion. 

Hardware and Software Requirements

Software

  • LabVIEW NXG 1.0 (or compatible)

Steps to Implement or Execute Code

The code can be run as-is since all processing is done on a simulated signal.

1. Run the VI.
2. Try changing the Amplitude (V RMS) and notice the observe in the graphs.
3. Try changing the Distortion Type and observe the change in the graphs.
4. Try changing the Relative distortion (%) and observe the change in the graphs.
5. Click the Stop button to stop the VI.

Additional Information or References

Charlie J.
National Instruments

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

Comments
Kidureji
Member
Member
on

I'm acquiring a voltage signal using NI DAQ assist(NI ELVIS 2 board). My sampling rate is 250000. The fundamental frequency is 50Hz. My concern is: I want to find the THD of successive 8 cycles and average it. How to do it in NI LabVIEW and Mathscript modules? The cycle should begin from the first zero crossing(Thereby I can get a complete sin wave). 

 

I'm a beginner. So plz help me to do this

Contributors