Wrong results from THD calculation in MATLAB

Viewed 471

I have measured signals (grid voltages and currents at 50Hz) of which I want to calculate the THD in MATLAB. However, using thd(signalVector, samplingFrequency, numberOfHarmonics) gives completely wrong results. See the attached screenshot: The measured signal is on the left, the middle plot shows the FFT, on the right there is a closeup view of the FFT. As you can see, the THD is calculated to be too high at 86%:

measured signal and calculated fft

Looking at the thd() itself, it obviously mismatches the FFT:

result from thd

I used both fft() and thd() like in the MATLAB examples. For FFT I use:

NFFT = 2^nextpow2(L);
Y = fft(signal_vector,NFFT)/(samples_vector);
f = sampling_frequency/2*linspace(0,1,NFFT/2+1);
y_fft = 2*abs(Y(1:NFFT/2+1));
plot(f,y_fft)

For THD up to the 40. harmonic I simply use:

thd(signal_vector,sampling_frequency,40)

where sampling frequency is 40kHz.

I guess I am doing something essentially wrong. Where is the flaw? Do you need additional information? Any help is appreciated (I hope this is the right place for my question)

EDIT: Using a THD function from the Matlab File Exchange I get a THD of 1.78%, but I do not know if this is correct, but seems realistic.

0 Answers
Related