# Phase of a Wein Bridge Oscillator (AC Mains Harmonics Analyzer)

• jendrix
Thanks, it is something I have considered although my programming skills are a bit lacking and I think it may be too complex for me unfortunately.You could use an external 16 bit ADC connected to your Arduino instead...https://www.google.com/search?q=Arduino+Uno+and+external+ADC&ie=utf-8&oe=utf-8&client=firefox-b-1And then use an FFT on the digitized data.And then use an FFT on the digitized data.

#### jendrix

Hello, I am working on a project to calculate harmonic distortion on a mains signal. The signal has already been stepped down so it oscillates between 0-5V at 50Hz. I looked into some old THD analyzers and it seemed they would generate a clean signal to mimic the fundamental deduct this from the main signal to leave only distortion and noise.

My plan was to use a Wein Bridge Oscillator design to generate a 50Hz signal, invert this and use a summing junction along with the mains signal to deduct the fundamental. My concern was that the two signals would be out of phase which could create issues when summing them together.

Is there a way of linking the phase of the mains to that generated by the oscillator?

Regards

Are you familiar with phase-locked loops? https://en.wikipedia.org/wiki/Phase-locked_loop

You will also need some method to lock the amplitude of your generated signal to the amplitude of the fundamental of the AC Mains waveform. That may be tricky, depending on noise and harmonics present in the AC Mains signal.

This would probably be easier to do in the digital (DSP) domain. Is there a reason you want to do this with analog circuitry? With that size signal and such a low frequency, you could probably use a 16-bit ADC to digitize the waveform, and then use DSP to analyze the fundamental and harmonics...

jim hardy
jendrix said:
The signal has already been stepped down so it oscillates between 0-5V at 50Hz.
BTW, how wide-band is this step-down transformer? Or are you using a resistor voltage divider to do this? Depending on how you do this, you may be affecting the amplitude of the harmonics before you can measure them.

Also, can you post a diagram of your step-down circuit? If it is using a resistor divider, there may be some AC Mains safety issues that we should address. Thanks.

Hello, I did consider going the DSP route although it is something I haven't worked with much before. I would be using an Arduino Uno which due to limited memory seemed to max out at 128 samples per second when I did some experiments.

As far as the transformer goes, this is for a project so any input signal will be simulated for the time being. I won't be involved with the transformer stage.

Thanks

berkeman said:
And then use an FFT on the digitized data.

Svein said:
And then use an FFT on the digitized data.

Could this be done on an Arduino Uno as almost like a proof of concept? So for example only measure the first few harmonics to prove the method works and could be expanded with better equipment? I remember Fourier transform theory but am new to FFT, would this need a library or can it be implemented from scratch?

Thanks

jendrix said:
Could this be done on an Arduino Uno as almost like a proof of concept?

Especially for a proof of concept, I would use the Arduino to gather the data, and then use my PC for the heavyweight analysis. You can manipulate the raw data many ways, including FFT, in a spreadsheet. I just checked. Excel does have a built in FFT function.

The limiting factor might be if the Arduino can sample fast enough and if there are anti-aliasing analog filters before the ADC. It might be better for proof of concept to connect the external ADC (as @berkeman suggested) directly to the PC, and skip the Arduino. When your proof of concept is finished, you can re-think what you can accomplish with the Arduino.

Actually, for proof of concept, I would ask around for an example file of raw data anti-ailiased and sampled at a high rate. I could play with that data to see what I could accomplish with data analysis. That eliminates the need for me to have any special hardware.

By the way, is this a DIY project? If so, different people have different objectives with their projects. Some like using external hardware like ADC or Arduino, others like playing with the data once logged. Also, if this is a DIY, I can move it to the DIY forum.

Last edited:
berkeman
anorlunda said:
Especially for a proof of concept, I would use the Arduino to gather the data, and then use my PC for the heavyweight analysis. You can manipulate the raw data many ways, including FFT, in a spreadsheet. I just checked. Excel does have a built in FFT function.

The limiting factor might be if the Arduino can sample fast enough and if there are anti-aliasing analog filters before the ADC. It might be better for proof of concept to connect the external ADC (as @berkeman suggested) directly to the PC, and skip the Arduino. When your proof of concept is finished, you can re-think what you can accomplish with the Arduino.

Actually, for proof of concept, I would ask around for an example file of raw data anti-ailiased and sampled at a high rate. I could play with that data to see what I could accomplish with data analysis. That eliminates the need for me to have any special hardware.

By the way, is this a DIY project? If so, different people have different objectives with their projects. Some like using external hardware like ADC or Arduino, others like playing with the data once logged. Also, if this is a DIY, I can move it to the DIY forum.

Hello, this is actually for a project, the plan was to incorporate it into a standalone system running from the mains that would send data to a 3rd party. As such I was hoping to run it from the microcontroller.

I looked into how some of the old THD analyzers would work and have come up with a different solution, be interested to hear some thoughts on it. As I need to find the sum of the harmonic content and the fundamental I thought I could use a notch filter. First find the rms of the complete signal then use a notch filter to subtract the fundamental and remeasure. Then I could use

Vh(rms)/(Vt(rms)-Vh(rms))

I could either sample the whole signal using an anti aliasing filter and then incorporate a digital filter or use a hardware filter and measure the input and output. My thinking was that I don't need specific harmonic information just the total.

Thanks

jendrix said:
Hello, this is actually for a project, the plan was to incorporate it into a standalone system running from the mains that would send data to a 3rd party. As such I was hoping to run it from the microcontroller.
What standard are you following for this analysis? The international EN 61000-3-2 standard is what we test to:

https://en.wikipedia.org/wiki/IEC_61000-3-2

It includes analysis up to the 40th harmonic. Can you say what sampling frequency and accuracy you need in order to follow this standard?

The ADC in a NodeMCU ESP8266 can sample ~ 10,000 per second, and provides ~ 10 bit resolution. It can be programmed with the Arduino IDE. And has built in wi-fi, so you can open a socket to a computer, and that computer could email updates (there might be a nicer way to do that).

https://www.amazon.com/dp/B010O1G1ES/?tag=pfamazon01-20 ( ~ $8-$9 US )

https://goo.gl/Wzzm8E ( ali-express ~ $3-$4 US - slow boat from China)

berkeman and anorlunda
berkeman said:
What standard are you following for this analysis? The international EN 61000-3-2 standard is what we test to:

https://en.wikipedia.org/wiki/IEC_61000-3-2

It includes analysis up to the 40th harmonic. Can you say what sampling frequency and accuracy you need in order to follow this standard?

This project isn't working within a set standard as it is a prototype of a home phasor measurement unit. We were told that as it would be designed for domestic use the standard could be a bit lower than those set by the IEEE Std C37.118.1-2011

I was aiming for a 1Hz refresh rate with a +/-1% accuracy although this isn't set in stone.

Thanks

The harmonics are easier to analyse if the fundamental can be attenuated. I made a piggyback mains plug that contains a twin-T notch filter. The output coaxial cable goes to an oscilloscope with FFT analyser. There are voltage clipping diodes on the output to protect the oscilloscope from on/off transients.

The step-down transformer will generate harmonics. It is better to use a potential divider made from a chain of RC parallel elements, all with the same time constant.

Twin-T filter:

This filter can be improved with some feedback:

#### Attachments

• rc_twin_t.gif
2.9 KB · Views: 530
• Bootstrapped-Twin-T-Notch-Filter-Produces-High-Q.jpg
22.6 KB · Views: 528
Baluncore said:
The harmonics are easier to analyse if the fundamental can be attenuated. I made a piggyback mains plug that contains a twin-T notch filter. The output coaxial cable goes to an oscilloscope with FFT analyser. There are voltage clipping diodes on the output to protect the oscilloscope from on/off transients.

The step-down transformer will generate harmonics. It is better to use a potential divider made from a chain of RC parallel elements, all with the same time constant.

Thanks, I like the idea but the device is already mostly built and working off a transformer hence having to come up with a solution with the existing parts. Maybe if I do a version 2 though.

The traditional way of doing THD is to apply the signal to a RC network having a deep null, such as a Wien Bridge or Bridged Tee. The network is carefully tuned to the signal and all that remains is harmonics.

Svein said:
This filter can be improved with some feedback:
The higher Q is not needed in this case as the harmonic attenuation and phase will be predictable. The deep null is important, the Q is not.
The other problem with high Q is that if the fundamental voltage changes, or there is a voltage transient on the supply, the twin-T will ring and keep ringing at the fundamental frequency. With a Q of 100 the ringing will continue for a few seconds.
Avoid op-amps where mains voltages may be present. Reduce the voltage by removing the fundamental rather than attenuating the harmonics also.