# 50Hz sine wave precise amplitude measurement

I have a 50Hz sine wave(mains voltage divided to the full-scale voltage of the ADC) sampled at 4kHz with not much noise in it. I want to measure precisely the peak-peak voltage of the sine. My first guess was to find the maximum and minimum values of the sine and average the Vpp from these. My second method was to calculate the FFT and get the amplitude from the 50Hz peak. Unfortunately, these two methods were not precise enough.
My question is: what are the best methods to do this simple calculation?
Edit: my percision should be ~0.1% and these two methods I reached 2% in estimating the Vpp of the sine.

• Scanning for the minimum and maximum sample values will give you the exact peaks to the resolution of your digitized signal. Make sure you scan over at least 1 complete cycle of the frequency. Sep 27 at 15:07
• Of course, I tipically have at least 50 complete cycles Sep 27 at 18:44
• What are your requirements for accuracy, and how does the tested methods fail to meet your requirements? Posting a few plots, script or files will generate more attention Sep 28 at 9:19

If the frequency and amplitude are stable I recommend you use a least-squares fit algorithm.

Basically the equation is $$y = A cos(\omega{t}) + B sin(\omega{t}) +C$$

If the frequency is fixed and known, you simply create the D matrix and solve it. In your case, you're measuring the grid voltage. If the grid is strong or rigid if you will, you can consider the frequency to be fixed. However, if the grid is weak, the frequency could vary and this technique might not be accurate.

$$D = \begin{pmatrix}cos({\omega}t_1) & sin({\omega}t_1) & 1\\\ cos({\omega}t_2) & sin({\omega}t_2) & 1\\\ \vdots & \vdots & \vdots \\\ cos({\omega}t_n) & sin({\omega}t_n) & 1 \end{pmatrix}$$

If the frequency is fixed but unknown you can still use the least-squares technique. However, the matrix will be 4 x n and you might need to iterate several times in order to find the best frequency estimate . See https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.35.3486&rep=rep1&type=pdf

• What is $\mathbf{D}$? Sep 30 at 7:17
• Sorry, I forgot to explain that D is the nx3 matric
– Ben
Sep 30 at 19:03

If you have enough samples for an FFT, instead of an FFT, try a least squares fit for the 3 parameters (frequency, phase, amplitude) of a pure sinusoid to that sample set.

• Tried the least squares fit with the leastsq from the scipy.optimize, but it didnt managed to fit the curve: Sep 28 at 5:58

Here is one option:

1. Run a PLL (phased locked loop) to precisely track the frequency.
2. Determine the amplitude by running a least square error fit between the local oscillator and your signal.

Another option would be running a very narrow band-pass filter followed by an RMS detector.

• The narrow bandpass might not be desirable in terms of the settling time, but OP hasn't specified how time-critical the measurement is supposed to be. Sep 28 at 8:51
• That's a fact of life. The more precise you want the measurement to be, the longer it's going to take. The PLL settling time or the bandwidth of the band pass will allow you to dial this in. Sep 28 at 15:14

First, define "precisely". Precision and accuracy are always a tradeoff with cost. In particular, look at your voltage divider: What are the tolerances of the resistors? 10%? 1%? Is the divider calibrated, and if so, to what precision?

If all of that is good, there are a few things one can do to increase precision even if the ADC is low resolution in the analog path. One can full or half-wave rectify the signal and gain another bit (but then remember that there is a voltage drop over the rectifying diode). Then, if crazy good precision is needed, one can subtract a DC offset to bring the signal into the useable range of the ADC. Again, one needs expensive Op-Amps and calibration.

In the digital path, other posters have already suggested least-square fitting. I would perhaps specifically do it just on a select few samples around the peak. FFT is also a good method, but I would select a sample rate and block size such that the bin is precisely on 50 Hz; computationally faster is a Goertzel Filter (effectively computing a single bin of a DFT, https://en.wikipedia.org/wiki/Goertzel_algorithm).