HarmonicAnalyzer

Advanced Analysis Library Only

AnalysisLibErrType HarmonicAnalyzer (const double autoPowerSpectrum[], int autoPowerSpectrumSize, int 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-precision array 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 integer Number of elements in autoPowerSpectrum.
frameSize integer 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 integer 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 integer 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.

Value Description
0 None
1 Hanning
2 Hamming
3 Blackman-Harris
4 Exact Blackman
5 Blackman
6 Flattop
7 Four Term Blackman-Harris
8 Seven Term Blackman-Harris
samplingRate double Input sampling rate in Hertz.
fundamentalFrequency double Estimate of the fundamental frequency.
Output
Name Type Description
harmonicAmplitude double-precision array 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-precision array 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 (passed by reference) Percent total harmonic distortion present in autoPowerSpectrum.
percentTHDNoise double (passed by reference) 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.