Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How do I calculate THD in MATLAB?

Status
Not open for further replies.

powersolda

Newbie level 4
Joined
Jul 26, 2010
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,330
How can I calculate THD (Total Harmonic Distortion) in a MATLAB file?, I have signal out put of the inverter, Please note, I know I can do this in Simulink, I am looking for a way to do this from MATLAB directly.
 

Here is one already started thread
https://www.edaboard.com/threads/57557/
and from your post to the mathworks you seem to be quite eager...

Essentially do the FFT as said in the thread above. Find the power bin, sum all the powers in 2*bin, 3*bin, etc.

If you do not use coherent sampling and if you distortion components are folded around Nyquist, you have to be a bit creative.

Some pseudo code is given here, but you need to adjust for the starting DC point (power_bin+1), etc.

% x is signal
XX = abs(fft(x)).^2;

% assume peak is fundamental
power_bin = min( find(XX==max(XX)));
signal_power = XX(power_bin);
dist_power = sum( [2 3 4 5 6]*power_bin );
THD = dist_power/signal_power; % Or whatever definition you like.

You can also look at the time-domain data and fit a sinusoid to that data. The deviation between measured and fitted sinusoid will be your SNDR (~THD if noise is low).
 
thank you my friend , i want calculate THD of this single
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top