THD calculation using MATLAB


by EE86
Tags: calculation, matlab
EE86
EE86 is offline
#1
Oct26-13, 10:23 AM
P: 1
Hello,

I'm a novice in using MATLAB. I want to calculate THD value from my experimental data using MATLAB. I have 10,001 data points, sampling frequency is 100kHz and fundamental frequency is 50 Hz (I'm not in USA). Below is my code. Could you please check that my code is correct or not ?


>> data = importdata('sample_1.xlsx');
% 10,001 data points, sampling rate = 100kHz

>> spect = fft(data)/10001;
% frequency of each element = 0, 10, 20, 30,...Hz (100kHz/10,001 data)

>> harmonic = abs(spect(11:5:201));
% here, fundamental = 50 Hz so, frequency 100, 150, 200,....,2000 Hz correspond to 11th, 16th, 21st,....,201st element of spect
% now, harmonic has 39 elements

>> harmonic_sqr = harmonic.^2;
% square each element

>> THD = sqrt(sum(harmonic_sqr(1:39)))/abs(spect(6))*100
% 50 Hz corresponds to 6th element of spect
Phys.Org News Partner Engineering news on Phys.org
A smart prosthetic knee with in-vivo diagnoses
Old tires become material for new and improved roads
Students take clot-buster for a spin
the_emi_guy
the_emi_guy is offline
#2
Oct26-13, 12:17 PM
P: 580
Greetings,

I would create xls files with known THD to test the algorithm.

Pure 50Hz and pure 50Hz plus a single harmonic would only take a minute to write and give you a quick sanity check.

You could spend a little more time and create an xls that added predetermined power at each harmonic, and even have the amount of THD as a parameter so that you could verify the dynamic range.


Register to reply

Related Discussions
How to display all calculation results in Matlab Math & Science Software 4
Calculation American style option in MATLAB? General Engineering 0
Drag Calculation from Matlab General Physics 0
Drag Calculation from Matlab General Math 0
Matlab; Jacobian array calculation question Math & Science Software 0