I'm building a circuit similar as below. The input signal is a current which will be converted to voltage using a burden resistor. The inverted output sine wave will go into an ADC to calculate the RMS value. The signal can be 50/60Hz and it will have a DC offset. I would like to capture the RMS in one cycle so I need to take enough samples. I'm thinking of sampling at 2 kHz. As the signal has a DC offset, can I implement the formula below as explained in https://masteringelectronicsdesign.com/how-to-derive-the-rms-value-of-a-sine-wave-with-a-dc-offset/ ? Also, would I need to invert back the signal from the output of the amplifier?

enter image description here

enter image description here

  • 1
    \$\begingroup\$ Key question here is how accurate does the result have to bei? \$\endgroup\$ – NoiseEngineer Aug 17 '20 at 4:18
  • 1
    \$\begingroup\$ I think it would be a good idea for you to explain a bit more about what you will use the result for. In other words, why are you computing the RMS voltage? Technically, there is one correct way to calculate RMS, and that is by going through the steps of squaring the voltage, then calculating the mean, then taking the square root. It doesn't matter what the input voltage is. You always calculate it the same way. But if you want to subtract out the contribution of the DC offset, then you will have to do something different. \$\endgroup\$ – mkeith Aug 17 '20 at 4:26
  • 2
    \$\begingroup\$ OK, well the RMS current is the root of the mean of the square of the currents. So, first, subtract the offset, then convert your ADC reading to the true instantaneous current. Save up a batch of samples in an array. Sqaure each sample. Average the squared values. Take the square root of the average. This is your RMS current. Technically, to be accurate, you should sample over an integral number of cycles of the waveform. You might still get decent results if you just sample at 1kHz for 1 second. The ADC will not be your limiting factor on accuracy. The burden resistor and Xformer ratio will. \$\endgroup\$ – mkeith Aug 17 '20 at 5:46
  • 1
    \$\begingroup\$ If you know the frequency is 60 Hz, or 50 Hz, you could build that assumption into your system to achieve more accurate results. For example, if you sample for 100ms, that will be 5 periods for 50 Hz and 6 periods for 60 Hz. In both cases an integral number of periods. Same applies for 200, 300, 400 etc ms. \$\endgroup\$ – mkeith Aug 17 '20 at 5:53
  • 1
    \$\begingroup\$ Because of the squaring operation, you will get the same result for RMS regardless of whether it has been inverted. So no need to worry about that part of it. RMS doesn't care if the waveform is inverted. \$\endgroup\$ – mkeith Aug 17 '20 at 6:30

We know that the RMS of a signal is calculated with the following:

$$ \mathrm{ x_{rms}=\sqrt{\frac{1}{T}\int_0^T x^2(t)dt} } $$

Since the integral is the sum of infinitesimal values, it turns into a Sigma function for discrete signals:

$$ \mathrm{ x_{rms}=\sqrt{\frac{1}{N}\sum_{i=0}^N x_i^2} } $$

Here's a pseudo-code for you:

sum = 0;
for (each adc_value in samples_for_one_period)
    x = adc_value - adc_val_2v5;
    y = x * x;
    sum = sum + y;

rms = sqrt (sum / num_samples);

NOTE: Even though the result does not change when used with an inverting amplifier, I'd use a non-inverting amplifier:


simulate this circuit – Schematic created using CircuitLab

$$ \mathrm{ A_v=1+\frac{RG1}{RG2} \\ \\ V_o = 2.5V + A_v\cdot V_i } $$


$$V_{rms}=\sqrt{\frac{1}{N}\sum_{i=0}^N v_i^2 -V_{offset}^2}$$



Let we write this in simple form, for further explanition:


if d>0 then
   // error imaginary result or
   c = 0; //the closest result
   c=sqrt(-d);  // negative value of rms for monitoring the too large offset setting

Above way is used in electric power metering IC, like ADE7878A. You doA define the offset and you subtract it before executing square root. Perhaps the best way is to make a digital highpass filter before squaring and subtracting measured samples.

Note that this technique is to eliminate the small DC offset of the input stage, it is not meant like your application where you have a biased signal. If you want to precise measure, you should use a differential ADC or any ADC that has the ability to measure also the negative voltage.


enter image description here

enter image description here


Your Answer

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