2
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – jaket
    Sep 27 at 15:07
  • $\begingroup$ Of course, I tipically have at least 50 complete cycles $\endgroup$ Sep 27 at 18:44
  • $\begingroup$ 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 $\endgroup$
    – Knut Inge
    Sep 28 at 9:19
0
$\begingroup$

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

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

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.

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

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.

$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$ Sep 28 at 8:51
  • $\begingroup$ 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. $\endgroup$
    – Hilmar
    Sep 28 at 15:14
0
$\begingroup$

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).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.