# Sampling a mains signal

#### TormundB

Joined Jan 6, 2018
9
Hello,

I am working on a device that will analyse a mains signal to find instantaneous voltage. I will be working with a stepped down domestic mains signal of 12V at 50Hz. I am working on an anti aliasing filter but can't decide on a cutoff frequency. The aim is to take 30 reading per cycle of the signal so therefore I would need to be sampling at a rate of 1500Hz minimum.

If the main signal is at 50Hz I assume there will be a natural tolerance, I also intent to calculate frequency eventually too. Is it possible with distortion that the mains will go much above 50Hz? Should I look to filter out harmonics too?

Regards

#### AnalogKid

Joined Aug 1, 2013
9,191
Aliasing occurs when the sample rat is *less* than the highest frequency of interest. Your sample rate is 30x the fundamental, which is slightly above the first 29 harmonics. That's a lot, so I don't think you need a filter specifically for fundamental aliasing effects.

Separate from that, you might want one to eliminate high frequency noise. This noise can be above your sample rate and would create some alias artifacts (apparent energy at lower frequencies that isn't actually there). However, this noise amplitude probably is small compared to the mains signal. Still, rolling it off probably is a good thing. But -

The more you filter the input signal, the more you move it toward a pure sine wave shape. If your goal is to measure power line distortion, as in the non-sinusoidal characteristics of the waveform, the less filtering the better. The tradeoff is a multi-pole filter that is as far above the fundamental as possible. I don't know of any way to predict or calculate an optimum cutoff frequency, but someone with power quality monitoring experience might. As a start, an 720 Hz, two-pole, equal component value, Sallen-Key smells nice.

ak

Last edited:

#### MrChips

Joined Oct 2, 2009
23,286
Why are you interested in instantaneous voltage as opposed to peak amplitude or average sine wave amplitude?

Power line cycle frequency is very stable to ±0.01Hz or ± 0.02% at 50Hz.

30 samples per cycle is ample.You can reduce that if desired. With that amount of data you can perform a least squares fit to a sine wave and would be able to extract the frequency, phase, and amplitude.

Generally speaking, if your sampling frequency is fs, your Nyquist limit is fs/2. Hence you can set your cutoff frequency to fs/2.
You do not need to filter in your case.

#### TormundB

Joined Jan 6, 2018
9
Why are you interested in instantaneous voltage as opposed to peak amplitude or average sine wave amplitude?

Power line cycle frequency is very stable to ±0.01Hz or ± 0.02% at 50Hz.

30 samples per cycle is ample.You can reduce that if desired. With that amount of data you can perform a least squares fit to a sine wave and would be able to extract the frequency, phase, and amplitude.

Generally speaking, if your sampling frequency is fs, your Nyquist limit is fs/2. Hence you can set your cutoff frequency to fs/2.
You do not need to filter in your case.
Hello, the device is going to be a phasor measurement unit, similar to this, one of the stipulations is instantaneous voltage.

https://www.digikey.com/en/articles...surement-units-improve-smart-grid-reliability

If you set your cutoff to fs/2 is it possible the components in the stopband could still cause aliasing?

Would this still be considered oversampling at the frequency of interest is 50Hz? As I understand it, I would need to oversample if I planned on using a digital filter to remove additional noise added by the ADC.

Thanks

#### MrChips

Joined Oct 2, 2009
23,286
I think you are confuscating things.

Why do you anticipate noise in the ADC?
Or is it really noise in the signal?

If the noise in the signal is of a periodic nature or of higher order harmonics then yes, frequencies higher that the Nyquist limit will be folded back into the pass band as aliases.

If you are trying to determine signal quality via fourier analysis then you will have to establish your max frequency of interest and then set your sampling rate and anti-aliasing accordingly as I described before.

Edit: Sorry, maybe I didn't state that quite right.
If you attenuate the signal above the Nyquist limit sufficiently, then no, you will not get aliasing. That is the purpose of the anti-aliasing filter.

#### TormundB

Joined Jan 6, 2018
9
I think you are confuscating things.

Why do you anticipate noise in the ADC?
Or is it really noise in the signal?

If the noise in the signal is of a periodic nature or of higher order harmonics then yes, frequencies higher that the Nyquist limit will be folded back into the pass band as aliases.

If you are trying to determine signal quality via fourier analysis then you will have to establish your max frequency of interest and then set your sampling rate and anti-aliasing accordingly as I described before.

Edit: Sorry, maybe I didn't state that quite right.
If you attenuate the signal about the Nyquist limit sufficiently, then no, you will not get aliasing. That is the purpose of the anti-aliasing filter.
Thanks, I was confused about having the cutoff at the Nyquist limit, but your edit explains this now.

As for the ADC, I was under the impression that an ADC could add noise to the signal though I wasn't sure if it was a case of generating noise during analogue to digital conversion or if the component itself generated noise in the circuit too?

Thanks

#### TormundB

Joined Jan 6, 2018
9
Aliasing occurs when the sample rat is *less* than the highest frequency of interest. Your sample rate is 30x the fundamental, which is slightly above the first 29 harmonics. That's a lot, so I don't think you need a filter specifically for fundamental aliasing effects.

Separate from that, you might want one to eliminate high frequency noise. This noise can be above your sample rate and would create some alias artifacts (apparent energy at lower frequencies that isn't actually there). However, this noise amplitude probably is small compared to the mains signal. Still, rolling it off probably is a good thing. But -

The more you filter the input signal, the more you move it toward a pure sine wave shape. If your goal is to measure power line distortion, as in the non-sinusoidal characteristics of the waveform, the less filtering the better. The tradeoff is a multi-pole filter that is as far above the fundamental as possible. I don't know of any way to predict or calculate an optimum cutoff frequency, but someone with power quality monitoring experience might. As a start, an 720 Hz, two-pole, equal component value, Sallen-Key smells nice.

ak
Hi, I have actually been working on a Sallen Key 2nd order design. Are all Sallen Key filters Butterworth? As I had been comparing filter approximations and Butterworth seemed the most suited to my needs as the response in the passband was maximally flat, therefore the signal of interest should remain fairly untouched.

Am I along the right lines?

Thanks

#### crutschow

Joined Mar 14, 2008
27,021
Are all Sallen Key filters Butterworth?
No, they can be designed for other responses, such a elliptical, Bessel, and Chebyshev.

#### TormundB

Joined Jan 6, 2018
9
Aliasing occurs when the sample rat is *less* than the highest frequency of interest. Your sample rate is 30x the fundamental, which is slightly above the first 29 harmonics. That's a lot, so I don't think you need a filter specifically for fundamental aliasing effects.

Separate from that, you might want one to eliminate high frequency noise. This noise can be above your sample rate and would create some alias artifacts (apparent energy at lower frequencies that isn't actually there). However, this noise amplitude probably is small compared to the mains signal. Still, rolling it off probably is a good thing. But -

The more you filter the input signal, the more you move it toward a pure sine wave shape. If your goal is to measure power line distortion, as in the non-sinusoidal characteristics of the waveform, the less filtering the better. The tradeoff is a multi-pole filter that is as far above the fundamental as possible. I don't know of any way to predict or calculate an optimum cutoff frequency, but someone with power quality monitoring experience might. As a start, an 720 Hz, two-pole, equal component value, Sallen-Key smells nice.

ak

Hi, if I were to say sample at 2kHz would this filter be sufficient? I was thinking if I used a 10 bit ADC then the higher frequencies wouldn't be sufficiently attenuated below the maximum quantisation error?

For example I would be using a 10bit ADC and a 12V peak to peak signal which would give a max quantisation error of ~11.7mV.