Hello!!
I am reading a code for measuring ADC data, and found something strange.
Normally we take multiple readings and then take average of all these readings, but in this code, they have taken squared sums.
The Code is something like this:-
Code C - [expand]
1
2
3
4
5
6
for(i=0;i<LENGTH;i++){
value += ADC_Data[i]*ADC_Data[i];}
value = ADC_Data/LENGTH;
value =sqrt(value);
where LENGTH is length of the ADC_Data array.
I take dummy values and check it in excel to verify the code, the results are almost identical.
But i want to know why this method, why not normal average method is used.
Out of context it is difficult to tell but the most likely reason is the ADC data holds negative values. Squaring them then taking the root ensures all the values are positive.
Its not only for negative values, but main reason is finding the power.
for example if you have 1 V on a 1 ohm resistor you will have 1 W power, if you have 10v on the same resistor you will have 100W power dissipation so plain average will not help you in power calculations.
example if you are having 1V for half the period and 10 V for remaining period your
average voltage is 5.5V
Rms voltage is √( (100 + 1) / 2) = 7.106V
IF you calculate the power with RMS value you will get the right power value.
It gives you output in two offset values you can take any input if you subtract the offset you will get the positive and negative values.
for example
if you have Vref of 3.3 and giving the input signal if you subtract the binary value for 1.29V you will get the array of both ac and dc values. Its all depend on what mechanism actually included in your code and hardware.
if you have Vref of 3.3 and giving the input signal if you subtract the binary value for 1.29V you will get the array of both ac and dc values. Its all depend on what mechanism actually included in your code and hardware.
Can you please provide me an algorithm to measure the AC voltage.
Do we have to measure the ADC Data periodically and then store it in a buffer.
It means there will be a limitation on the lowest and highest frequency measurement.
Please provide me an algorithm, i am confused.
Thanks in Advance.
Then the algorithm is clear and also how to sample the data.
If you need real time values then storing ADC values in memory may be not good. If you need the value once a second it may be a good solution. It depends on your application.
It is depend on your application, there are is alot can be performed by reading AC values, from RMS to FFT.
And also it is depend on your CPU availability ADC resolution ADC frequency (conversion time), the accuracy you need. the scaling you did in the input side.
Then the algorithm is clear and also how to sample the data.
If you need real time values then storing ADC values in memory may be not good. If you need the value once a second it may be a good solution. It depends on your application.
Yeah I read how to calculate RMS and now it is clear that why Square Values are taken and then divided by number of sample and then square root is taken.
It is depend on your application, there are is alot can be performed by reading AC values, from RMS to FFT.
And also it is depend on your CPU availability ADC resolution ADC frequency (conversion time), the accuracy you need. the scaling you did in the input side.