Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] what will be the rms value of a sinewave which have shifted using some offset volt ?

Status
Not open for further replies.

thannara123

Advanced Member level 5
Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,601
Helped
122
Reputation
244
Reaction score
116
Trophy points
1,353
Activity points
10,610
Hello Experts sorry for the silly questions
I want to know the dc value calculation of the following graph ,. i used an approximately 1.75 dc offset volt the for the given sinewave ,Then what will be the total dc rms value ,How to measure it ?

11.jpg
 


First, I want to make sure you understand RMS may use as many ADC samples per cycle as you need for amplitude accuracy as long as it is an integer number of cycles from 1 to n and not include a fraction of a cycle. You may have heard that Shannon's Law requires that you only need 2 samples per cycle to detect the frequency, but this does not measure the true RMS or the Vpp amplitude. It is just a sample to guarantee a sample at that maximum "Shannon frequency". It is important to understand the difference as the consequence of this sampling error as and partial sample of one or many waves or DC will contribute some error then RMS is computed for all samples.

We are discussing your question about adding DC to an AC signal for a single supply ADC and you wanted to measure Vrms. This DC is not noise nor does it reduce resolution, rather it actually optimizes it, so you can maximize signal/noise ratio without limiting errors. We use RMS for a whole cycle as it represents the equivalent to DC such that if you had Vrms * Irms this will get you the true power and this is measured as an average Pavg not P_rms but again that average must be over many cycles such that a fraction of 1 cycle introduces no significant error, or if it is a repetitive wave, exactly taking the average of many sample power readings in one cycle.

To demonstrate these subtle differences, let me show Falstad's simulator again which can store 2k samples or less depending on the size of the window. I can put these digital probes on the sreen to display min,avg, max, rms and pp. If the frequency is changed you may assume it is not synchronous to the ADC and therfore RMS may have some partial cycles included giving a residual error. The next time you use a DSO and capture only a few cycles you may check the RMS result and if it constant for different sweep durations, you may thank the engineer who designed it to detect the zero crossing phase and compute only over an integer number of cycles. Then take note if there is any difference in the AC coupled signal and DC coupled signal that has a DC offset.

If you need to interact with the sliders you may restore any setting with ^z or undo or refresh page. Pls ask if there is something you cannot understand I present a normalized 1Vrms signal and let you see t5he 2.828 Vpp signals along with Vmin, max and adjust the DC offset. Then change the frequency which may be synchronized by accident and adjust it so see the residual error.

Removing the DC bias is the minimum takeaway from this answer for your ADC readings. I suggest to define and tell us what accuracy you prefer (e.g. 0.2%) and how to achieve it with the best practices, then compare your result with commercial DMM's.


My Sim https://tinyurl.com/yloznq98

1702709753597.png
 

    thannara123

    Points: 2
    Helpful Answer Positive Rating
Sir ,
I asked so ,The DC offset reduce ADC reresolution

forunderstanding my problem i am giving an example

my adc resoultion is 4096
my offset dc volt (resistor bias dividing ) is 1.25 volt
my microcontroller maximum input volt is 3.3volt
Since RMS is equivalent to DC average, any DC error in your measurement reduces the accuracy of the RMS result. So it is biased for symmetrical full swing and subtracted for necessity.

A bandgap voltage reference exists around 1.25V.

The ADC Vref uses Vdd for full scale taking advantage of rail to rail Op Amp outputs unlike the asymmetrical saturated full scale output of BJT Op Amps.

But you must scale DC bias to Vdd/2 in order to retain symmetry and resolution.

The full range of 4096:1 equivalent to signed values of +/- 2048:1.

Any difference from this V/2 DC offset and not subtracting the DC from your ADC result is a reduction of resolution and signal to noise ratio.

You ought to plan calibrating your ADC with a full-scale slow triangle wave to ensure it is monotonic, linear and accurate as expected and compute the errors meet your expectations and design specification.

At the risk of being obvious or pedantic, please understand and comment on the following;

=================================================



1. Scale the Input: Scale your input signal so that it is centered around Vdd/2. This could be done with a simple voltage divider or more complex circuitry, depending on your specific application requirements.

2. Sampling: Sample the waveform at a sufficiently high rate to capture the waveform accurately, as previously discussed.

3. Calculate DC Offset: Calculate the DC offset either by averaging a set of samples when you know the signal has no AC component or by employing a digital filter to separate AC and DC components.

4. Remove DC Offset: For each sample point, subtract the calculated DC offset to center the AC waveform around zero, which will facilitate an accurate RMS calculation.

5. Square, Average, Square Root: Proceed with squaring each sample, averaging these squared values, and then taking the square root to obtain the RMS value, just as before, but with the DC offset removed.

When coding this, you can add a step to account for the DC offset calculation:

Code:
// ... (rest of the setup code)
// Calculate and remove DC offset and calculate RMS
float calculateAdjustedRMS(int* samples, int num_samples) {
float sum = 0;
float offset = 0;
// Calculate DC offset
for (int i = 0; i < num_samples; i++) {
offset += samples[i];
}
offset /= num_samples;
// Adjust samples and calculate RMS
for (int i = 0; i < num_samples; i++) {
float adjustedSample = (float)samples[i] - offset; // Adjust for DC offset
sum += adjustedSample * adjustedSample;
}
float mean = sum / num_samples;
return sqrt(mean);
}
// ... (rest of the code to get samples)
float rms_value = calculateAdjustedRMS(adc_values, NUM_SAMPLES);



Some ADC configurations support differential inputs or otherwise accounting for the expected mid-scale offset.
 
Last edited:

    thannara123

    Points: 2
    Helpful Answer Positive Rating
@D.A.(Tony)Stewart
Sir
Thanks
I much tried to understand what did you mentioned.
As per the discussion I learned a lot of ,I concluded that I require that as follows

I have a sinewave signal Having 50 Hz which is shifted by an offset DC of 1.25 volt
When there is no AC (sinewave ) the ADC get an DC volt of 1.25 that is equivalent to 1550 (ADC value).
Actually I require the RMS value of the Sinewave
But the Sinewave value should read from the zero referance level ie 1.25 DC that is the Ground level of the Sinewave Signal (I understood so).

The sinewave of 50Hz One Half cycle is 10 millisecond I plan to take 200 samples per Half cycle .
Before saving the 200 samples I want to know the Zerocrossing ,to understand that , the coming half cycle is positive or Negative ?
After detecting the zerocrossing the ADC values (200 samples ) need to save or adding to get avarage value ( I just think so dont know correct way ) to an array .
Taking these array values for calculation as said in previous post I will get the rms value

is it good practice to detect the Zerocrossing of the wave as follows

if (adcValue >= 1400 && adcValue <= 1600)
{ // Zero crossing detected
}


I taked 30 samples at debug mode image is attached , can i impliment the above logic to detect the Zerocrossing ?

1.jpg
 
Last edited:

Hi,
The sinewave of 50Hz One Half cycle is 10 millisecond I plan to take 200 samples per Half cycle .
Before saving the 200 samples I want to know the Zerocrossing ,to understand that , the coming half cycle is positive or Negative ?

if your both frequencies are quite accurate, then there is no need to know zero crossing.
I usually do a full wave, so process 400 samples. (according your sampling rate)

Klaus
 

Hi,


if your both frequencies are quite accurate, then there is no need to know zero crossing.
I usually do a full wave, so process 400 samples. (according your sampling rate)

Klaus
Sir
Any way I require the zero crossing flag for the synchronisation in the main code / program .
Sir did you mean the both Half cycles ,
if so , then the total output would be zero ?
 

Hi,

Sir did you mean the both Half cycles ,
if so , then the total output would be zero ?
The RMS for any signal is always > zero.

But the question is: HOW do you want to calculate RMS value? For me speaking: there is only one method:
R - M - S.
for each sample:
* subtract the offset (I´d use a high pass filter)
* (S) square the value
* (M) add all 400 squared values up and calculate average (by dividing by 400)
* (R) take the square root.

All other methods work only with clean undistorted sine. .. or may be adjusted to a known waveform .. and it´s mandatory to keep this waveform. Otherwise the result will be wrong.

Klaus
 
Some methods :



If you use a M0 ARM low end part, many have onchip single cycle 32 bit multiplier that can be used.

Also there are HW solutions, in this case ARM M3 SOC chip, that can do sqrt in 114 cycles, 32 bits.

1702924337312.png


Regards, Dana.
 
What are your parameter goals , expectations for accuracy , preferred uC ?

Your zero-crossing method software adds 5% to 10% error
--- Updated ---

This can be done in hardware or software.
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top