Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Sep 6, 2006


Feedback


Yes No

Related Categories

Products

Development Topic

Related Links - Developer Zone

Related Links - Products and Services

Harmonic Distortion Analysis in LabVIEW 6i

38 ratings | 3.45 out of 5
Print

Overview

One of the new features of LabVIEW 6i is the Waveform Data Type (WDT), which allows for substantially easier manipulation and processing of time-domain signals. Along with the introduction of the WDT, LabVIEW now includes a number of new signal processing and analysis VIs that take signals in the waveform data type as inputs.

Here the new WDT VIs “Harmonic Distortion Analyzer” and “SINAD Analyzer” are discussed and compared to the “Harmonic Analyzer” VI, which was contained in LabVIEW version 5.1 and which takes an array as its signal input.

Introduction

One of the new features of LabVIEW 6i is the Waveform Data Type (WDT), which allows for substantially easier manipulation and processing of time-domain signals. Along with the introduction of the WDT, LabVIEW now includes a number of new signal processing and analysis VIs that take signals in the waveform data type as inputs.

Here the new WDT VIs “Harmonic Distortion Analyzer” and “SINAD Analyzer” are discussed and compared to the “Harmonic Analyzer” VI, which was contained in LabVIEW version 5.1 and which takes an array as its signal input.

Readers are strongly encouraged to refer to the example VI “THD & Harmonic Analyzer.vi” in conjunction with this material. It compares the action of the Harmonic Analyzer VI with that of the two new WDT VIs discussed here. This VI can be found in the Example Programs Document "Harmonic Distortion Analysis Example VIs." A link is below.

Harmonic Distortion Analysis Example VIs
See Also:
Harmonic Distortion Analysis Example VIs

Total Harmonic Distortion


Both the array-based Harmonic Analyzer VI (hereafter referred to as the THD VI, after its icon) and the WDT-based Harmonic Distortion Analyzer (HDA) VI compute the Total Harmonic Distortion (THD) of a signal, which is defined as follows:
(1)

where Hj is the amplitude in the jth harmonic, and F is the amplitude of the fundamental. THD is a measure of the energy contained in the harmonics of a signal, as compared to the energy contained in the fundamental. This operation requires knowing how many significant harmonics the input signal contains. Another common value given is %THD, defined simply as 100 times THD.

New Features of the WDT-based Harmonic Distortion Analyzer VI


First, the HDA VI internally windows the input signal and computes the auto power spectrum, prior to finding the amplitudes of the harmonics and the total harmonic distortion. In contrast, the THD VI requires as input not the time-domain signal, but its auto-power spectrum.

Second, The HDA VI removes the fundamental from the auto-power spectrum of the input signal before looking for the harmonics and before determining the THD. In contrast, the old THD VI did not remove the fundamental before looking for the harmonics. The HDA VI uses a better algorithm and results in more accurate measurements of the THD. In addition, and more importantly, this method of computing the values allows the user to select from a list of signals to be exported. All signals are exported as a cluster of a time waveform (in WDT form) and the associated single-sided magnitude spectrum. The options for export are the input signal, the fundamental signal (1st harmonic only, i.e. a sinusoid in the time domain), the residual signal (everything except the fundamental frequency component), and the harmonics (the fundamental and the harmonics calculated by the VI, but excluding additional harmonics, DC, and noise).

Due to the change in the method of computing the THD and the amplitudes of the harmonics, expect to see some differences in their typical output values if you switch from using arrays and the THD VI to using the waveform data type and the Harmonic Distortion Analyzer VI.

The HDA VI has an optional input cluster called Advanced Search. This contains inputs for specifying an approximate fundamental frequency fapprox and for specifying the size of the interval about fapprox in which to look for the fundamental frequency. These can be useful if you work with very noisy signals.

Aliasing



As in all calculations in the frequency domain, take care that the frequencies of interest do not extend past half the sampling frequency. In the case of the THD VI, any harmonic frequencies past the Nyquist frequency (half of fs) and their corresponding amplitudes are returned as NaN (not a number) in these output arrays.

The Harmonic Distortion Analyzer VI has a Boolean input “stop search at Nyquist.” The default is true (T). In that case, the VI simply does not return any values for frequencies that are above the Nyquist frequency, and truncates the output array accordingly.

Using a Hanning Window


In the Harmonic Distortion Analyzer VI, the input time signal is windowed using a scaled Hanning window. This is done to reduce spectral leakage, and thereby improve the measurement accuracy of the THD and of the amplitudes of the harmonics. The Hanning window is a good general-purpose window for this type of application.

With this in mind, notice that the time domain signal input to the Auto Power Spectrum VI, prior to the action of the THD VI, should first be windowed using a scaled time domain window. Furthermore, expect to see identical or very close results from using the THD VI and the Harmonic Distortion Analyzer VI only if you use a scaled Hanning window.

Frequency Resolution


Before recording any final measurements, make sure that the frequency resolution and the placement of the frequency bins are consistent with the estimated values of the fundamental frequency and the harmonics. That is, try to avoid spectral leakage as much as possible. One solution for this problem, given that real-world frequencies seldomly take on integer values, might be to first use the Extract Single Tone Information VI to obtain a value for the fundamental frequency, and use this result to appropriately set the sampling rate and the number of samples (i.e. length of time over which the measurement must be made).

Frequency Resolution Example


Suppose sampling frequency fs = 1000 (i.e. the sampling interval is 1 ms), so the Nyquist frequency is then fs/2 = 500 Hz, and the frequency resolution is fs/N = df.

In this case df = 2 Hz, and the frequency bins are centered at the integer multiples of df. That is, the first bin is centered at DC, the next at 2 Hz, the next at 4 Hz, etc. So if you have a well-defined fundamental at 100 Hz, then the fundamental and the harmonics fall at the centers of the frequency bins, and the energy of each of these components is nearly completely contained in a single bin. On the other hand, if the fundamental is at 93 Hz, then the odd harmonics will be on the border between two bins, and their energy will be spread between the two, resulting in some spectral leakage. These are idealized cases; obviously the typical fundamental will not be an integer. The main point to keep in mind is that, given a certain sampling rate, the larger the number of samples, the narrower each bin is, and therefore, the greater the frequency resolution.

For a simple demonstration of this phenomenon, refer to the Spectral Leakage Example VI.

Important Differences


The THD VI outputs the harmonics, including the fundamental, array in Vrms, whereas the Harmonic Distortion Analyzer VI outputs the array of harmonics, including DC and the fundamental, in peak amplitude units, i.e. Volts. That is, the first element of the array returned by the WDT Harmonic Analyzer VI is the DC component. The second is the fundamental, followed by the 2nd harmonic, 3rd harmonic, etc. The array given by the THD VI starts with the fundamental and is in units of Vrms.

The Auto Power Spectrum VI gives its output in units of Vrms^2, where the assumption is that the input time signal is in Volts (peak). However, the Harmonic Distortion Analyzer VI outputs the exported time signal in Volts and outputs the exported signal spectrum in dBVrms. This means that in order to see the same frequency spectrum from both VIs, in the units of dBVrms, you must take 10 * log10 of the output of the Auto Power Spectrum VI.

To make sure that the output values are the most accurate and useful, use the following conventions:
· Output the amplitudes of the harmonic components in Volts, because that is what is typical in the literature. Furthermore, in the Harmonic Distortion Analyzer VI, the array of these values has the DC value as the first element of the array, and this must be in volts.
· Output the spectrum in dBVrms. This convention is also typical of the literature and industry practices.

Notice that the HDA VI outputs the THD as a raw decimal, whereas the THD VI outputs a %THD. Therefore, converting from one to the other requires adjusting by a factor of 100.

Using the SINAD Analyzer VI


The THD VI also computes the quantity THD+Noise (or THD+N), which is defined as
, (2)

where APS stands for Auto Power Spectrum; the quantity inside the square root is the sum of the energies (i.e. squares of the amplitudes) of all the frequency components except the DC component and the fundamental component. By comparing this to formula (1), you can see that by letting the number of harmonics extend to infinity, the equation for THD becomes that for THD+Noise.

Similarly, the SINAD VI computes the SINAD (“Signal in Noise and Distortion”), which is defined as the ratio of the energy of the input signal (without DC) to the energy of the input signal (without DC) minus that of the fundamental, converted to units of dB. That is,
. (3)

This quantity is related to THD+N through a simple relationship:
SINAD = -THD+Noise in dB) = -20 log10 (THD+Noise). (4)

As stated above, the THD VI computes both THD and THD+N. However, when working with signals that are to be acquired and analyzed using the waveform data type format, it is easier to use the Harmonic Distortion Analyzer VI to find the THD and the SINAD Analyzer VI to get the SINAD, and then compute the THD+Noise from that, if you want.

There are several similarities between the SINAD Analyzer VI and the HDA VI:
· The SINAD VI also contains an optional Advanced Search input cluster.
· The same restrictions regarding aliasing and frequency resolution apply.
· Both can export several signals based on the input signal.
· Prior to analysis, the signal is modulated by a scaled Hanning window.

The example in “THD & Harmonic Analyzer.vi” shows subVIs that convert between %THD+N and SINAD, in order to compare the values generated by the THD VI, which operates on arrays, and the SINAD Analyzer VI, which takes an input of the waveform data type.

Final Remark


Please notice that, as with all measurement and analysis of real-world signals, you must take care in the use of these VIs. Often faulty assumptions can result in erroneous measurement values. However, given a basic understanding of THD, THD+N, SINAD, and the operation of these VIs, you can easily convert from the Harmonic Analyzer VI to the new WDT Harmonic Distortion Analyzer and SINAD Analyzer VIs.


Harmonic Distortion Analysis Example VIs
Related Links:
Harmonic Distortion Analysis Example VIs
38 ratings | 3.45 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).