Admin Production ni-theme
Current Publication

HarmonicAnalyzer

LabWindows/CVI

HarmonicAnalyzer

Advanced Analysis Library Only

AnalysisLibErrType HarmonicAnalyzer (double autoPowerSpectrum[], ssize_t autoPowerSpectrumSize, ssize_t frameSize, int numberOfHarmonics, int windowType, double samplingRate, double fundamentalFrequency, double harmonicAmplitude[], double harmonicFrequency[], double *percentTHD, double *percentTHDNoise);

Purpose

Finds the amplitude and frequency of the fundamental and harmonic components present in autoPowerSpectrum.

HarmonicAnalyzer also calculates the percent of total harmonic distortion and the total harmonic distortion plus noise.

If the sampling rate is 1,000 Hz and the fundamental frequency is 250 Hz, the number of harmonics is limited by samplingRate/(2 × fundamentalFrequency) = 2. If you set numberOfHarmonics equal to 4, HarmonicAnalyzer sets the third and the fourth element of the harmonicAmplitude and harmonicFrequency array equal to 0.0.

Typically, you should pass the time-domain signal to ScaledWindowEx and then to AutoPowerSpectrum. You then pass the output of AutoPowerSpectrum to HarmonicAnalyzer.

Parameters

Input
Name Type Description
autoPowerSpectrum double [] Single-sided auto power spectrum of the windowed signal.
This array can be the output of a frequency-domain averaging process for improved harmonic estimation. Typically, this array is the output of AutoPowerSpectrum.
autoPowerSpectrumSize ssize_t Number of elements in autoPowerSpectrum.
frameSize ssize_t Number of samples in the time-domain signal array.
frameSize is typically the number of samples in one block of data from a data acquisition operation. If this input is less than or equal to zero, frameSize is set equal to twice the size of the autoPowerSpectrum input array.
numberOfHarmonics int Number of harmonic components to approximate and use in the measurement.
This number includes the fundamental component. For example, if you want to compute the second harmonic distortion in your signal, this number should be equal to two: find the fundamental frequency component (say at f1 Hz) and its second harmonic (at f2 Hz).
windowType int Window type the function applies to the time-domain signal.
NI recommends that you use a window for accurate total harmonic distortion estimation. The following table lists the possible window types.
  • None (0)
  • Hanning (1)
  • Hamming (2)
  • Blackman-Harris (3)
  • Exact Blackman (4)
  • Blackman (5)
  • Flattop (6)
  • Four Term Blackman-Harris (7)
  • Seven Term Blackman-Harris (8)
samplingRate double Input sampling rate in Hertz.
fundamentalFrequency double Estimate of the fundamental frequency.
Output
Name Type Description
harmonicAmplitude double [] Amplitudes of the fundamental components and its harmonics.
These values are always positive and are in units of Vrms if the input autoPowerSpectrum values are given in V2rms.
harmonicFrequency double [] Frequencies of the fundamental component and its harmonics.
These values are in units of Hz if the input sampling rate is given in Hz.
percentTHD double Percent total harmonic distortion present in autoPowerSpectrum.
percentTHDNoise double Percent total harmonic distortion plus noise present in autoPowerSpectrum.

Return Value

Name Type Description
status AnalysisLibErrType A value that specifies the type of error that occurred. Refer to analysis.h for definitions of these constants.

Additional Information

Library: Advanced Analysis Library

Include file: analysis.h

LabWindows/CVI compatibility: LabWindows/CVI 5.0 and later

Example

Refer to analysis\thd.cws for an example of using the HarmonicAnalyzer function.