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.

Measuring Harmonics in AC signal by using ATmega

Status
Not open for further replies.
Hi,

one way is to sample a lot of data (2^n) and perform an FFT.

find the fundamental frequency. calculate it´s amgnitude.

Then find all harmonics (overtones) to the fundamental frequency (upto the upper specified frequency), and add them up.

Now divide (sum of harmonics) / fundamental to get THD.

Klaus
 

what is the fundamental frequency of the signal?
do you intend to sample of block of data and process it or sample continuously doing an FFT in real time
 

The fundamental frequency is 50Hz

- - - Updated - - -

Hi Dear KlausST,

1)one way is to sample a lot of data (2^n) and perform an FFT.

2)find the fundamental frequency. calculate it´s amgnitude.

3) Then find all harmonics (overtones) to the fundamental frequency (upto the upper specified frequency), and add them up.

4)Now divide (sum of harmonics) / fundamental to get THD.


How to implement on microcontroller because it can not take AC value on any port?

Please clarify point 1 and 2?
 

Hi,

If your ucontroller has no ADC, then you need an external one.
Resolution and sampling speed depemd on your needs.

Harmonics up to what frequency are you interested in?
What precision and what resolution do you need?
How stable and accurate is you 50Hz? Please specify.
Do you need the sum of harmonics or every harmonic independently?
How often do you want to calculate?
What do you want to do with the result(s)? Display as decimal number, in dB? Print out? Transmit to a PC? Graphical display?
Save to memory?

To your post:
Please clarify point 1 and 2?
Sampling data means to covert analog values to digital values. You need a very stable sampling frequency depending on your needs (questions above). Perfom an FFT means to process the digital data with software. FFT is the short for fast fourier transform, this is a mathematical calculation to get the frequencis and their amplitudes of an input (analog) signal.

"Find the fundamental frequency" is -at least - partly answered by yourself.
As questioned above it is important to know its variation.
50Hz from mains is fairly stable, but from a small generator engine with varying load it is quite unstable.
50Hz from a DDS is high quality...

Pleas tell us more about your project.

Klaus
 

Hi,

Your questions
1)If your ucontroller has no ADC, then you need an external one.
Resolution and sampling speed depemd on your needs.

2)Harmonics up to what frequency are you interested in?
3)What precision and what resolution do you need?
4)How stable and accurate is you 50Hz? Please specify.
5)Do you need the sum of harmonics or every harmonic independently?
6)How often do you want to calculate?
7)What do you want to do with the result(s)?
8)Display as decimal number, in dB? Print out? Transmit to a PC? Graphical display?
9)Save to memory?

My Answers:
1)uC has ADC of 10-bit.
2)50 to 60Hz.
3)Precision and resolution depend on my ATmega series microcontroller.
4)50Hz is slightly unstable between 49 to 50Hz. But I need for 50Hz for mains.
5)I need Total Harmonic Distortion in %..
6)Its depend on uC.
7)I want to display THD% in inductive loads system.
8)Display in percentage.
9)Yes.

"Find the fundamental frequency" is -at least - partly answered by yourself.
As questioned above it is important to know its variation.
50Hz from mains is fairly stable, but from a small generator engine with varying load it is quite unstable.
50Hz from a DDS is high quality...

10)Pleas tell us more about your project.

My Answer:
10) I am making digital energy analyzer which shows kw,kva,kvar and THD and volts,amp,Hz.
 

Hi,

2)50 to 60Hz.

this is the fundamental.

but you need to know about the max. frequency of the harmonics.

fundamental: 50Hz, harmonics: 100, 150, 200, 250, 300 ... Hz.

In symmetric system i expect mostly/only odd harmonics: 150, 250, 350.. Hz..

Klaus
 
How to measure max.frequency of harmonics?

By this, THD = No.of Harmonics/fundamental frequency.

It is the voltage ratio of harmonics to the fundamental, not the number of harmonics.

So using a high Q Bandpass Filter (unity gain) and a notch filter at the fundamental one can take the ratio to get THD.
 
Hi,

How to measure max.frequency of harmonics?

This is not to measure, but to specify.
There are different rules for mains quality measurements. Some calculate up to the 25th harmonic, others to the 40th harmonic.

If it is ok for you to measure up to the 25th harmonic then this means 50Hz x 25 = 1125 Hz.
According nyquist you then need a sample frequency of 2x 1125 Hz at least. = ÷2250Hz.

I'd choose 100ms sample time with 256 samples = 2560 Hz sample frequency.
Or even better 5120Hz.
With this you get frequencies: (0Hz), 10, 20, 30, 40, 50, 60, 70.....1270Hz (...2550Hz)
Therefore you can use it for 50Hz as well as 60 Hz mains frequency...

Klaus
 
Dear KlausST,

Can I measure harmonics by using formaulas below in microcontroller.

1) v(t)=A + 1/3Sin(3wt) + 1/5Sin(5wt) + 1/7Sin(7wt).

and

2) V = 4*(Vrms)/n*pi.

Please define more about above.
 

Dear KlausST,

Can I measure harmonics by using formaulas below in microcontroller.

1) v(t)=A + 1/3Sin(3wt) + 1/5Sin(5wt) + 1/7Sin(7wt).

and

2) V = 4*(Vrms)/n*pi.

Please define more about above.

Yeah of course you can do whatever you want but
Before choosing sampling frequency and number of samples you have to consider lot of things.

for example,
I'd choose 100ms sample time with 256 samples = 2560 Hz sample frequency.
If you choose 100ms and 256 samples then you will take 25.6 sec for collecting the signal to calculate for one time.

If you choose a high sampling rate then you will need lot of controller resources to work with.
 

Hi,

If you choose 100ms and 256 samples then you will take 25.6 sec for collecting the signal to calculate for one time.

Maybe it was not clear what i meant:
So nowthe other way round:

With a sampling frequency of 2560 Hz converting 256 sampleas will need 100ms.

The 100ms is the complete sampling time for all the 256 samples.

@IMRAN:

Can I measure harmonics by using formaulas below in microcontroller.

1) v(t)=A + 1/3Sin(3wt) + 1/5Sin(5wt) + 1/7Sin(7wt).

I don´t think it is possible this way. Your formula is the fourier series of a square wave.
If you have a sqaure wave then you don´t need to calculate THD, it is fix.

Klaus
 
Can I measure harmonics by using formaulas below in microcontroller.
1) v(t)=A + 1/3Sin(3wt) + 1/5Sin(5wt) + 1/7Sin(7wt).

I don´t think it is possible this way. Your formula is the fourier series of a square wave.
If you have a sqaure wave then you don´t need to calculate THD, it is fix.

But what is the formula for sine wave?
 

Can I measure harmonics by using formaulas below in microcontroller.
1) v(t)=A + 1/3Sin(3wt) + 1/5Sin(5wt) + 1/7Sin(7wt).
Did you mean without FFT ? It is not possible.

The FFT is to bring the given signal in to the fourier series terms like
Code:
v(t)=X + X1 Sin(wt) + X2 Sin(2wt) + X3 Sin(3wt) + . + . . .
You will get the X, X1, X2, ... from FFT

Here X is the amplitude of DC component X1 is the amplitude of Fundamental sine wave and X2 is the second harmonic and so on.

finding the RMS is easy as you have collected the samples of the AC sine wave so you can easily square them add them and divide by number of samples and take the square root.

If you want to calculate a FFT of a given signal I would suggest you to take sampling for two full cycles of given fundamental frequency. For example if you want to find the harmonics of 50Hz, then find the period
which is 20ms.
so you need samples for 40ms.
If you choose to have 256 samples (select the samples according to your resource availability) 40ms/256 = 156uS
6400Hz sampling rate
then after completing FFT you will directly get the Harmonic components like
Code:
FFT_out[0] = DC comp
FFT_out[1] = Amplitude of 25 Hz component
FFT_out[2] = Amplitude of 50 Hz component
FFT_out[3] = Amplitude of 75 Hz component
FFT_out[2] = Amplitude of 100 Hz component
Some algorithms will return values in complex terms you have to calculate the modulas for getting amplitude
 

Did you mean without FFT ? It is not possible.
That's literally wrong. FFT is fast fourier transform, a specific form of fourier analysis. To determine the harmonics of a signal, any kind of harmonic analysis can be used, not only FFT-

I basically agrees with your description of possible FFT usage. To get the fourier series coefficients with a FFT directly, it's required that the fourier window length corresponds to the fundamental period, or an integer multiple of it. Because FFT window length must be a power of two according to the limitations of the algorithm, you must choose the sample frequency respectively.

With a fixed sample frequency, it's easier to use Goertzel filters for the harmonics of interest. That's a different method of harmonic analysis which is not FFT (but also multiplying the input signal with a complex sine).
 

Hi,

But what is the formula for sine wave?

V(t)= a * sin(wt)

That´s the formula for sine.
But this doesn´t help here.
******
To your problem:

the formula for THD: thd(%) = 100% * sqrt ( a2^2 + a3^2 +a4^2 +a5^2 + .....) / a1
where a1 = the amplitude of the fundamental sine
a2 = the amplitude of 2 x fundamental frequency
a3 = the amplitude of 3 x fundamental frequency
a4 = the amplitude of 4 x fundamental frequency
...

a1, a2, a3, a4 is unknown and has to be measured. for example with an FFT.

********
for a square wave a2, a3, a4 ,a5 ... is known, they have a fixed relation to a1.
Therfore there is no need to measure THD of a sqaure wave, you can calculate it.

******

Klaus
 

    V

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top