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.

C Code to calculate RMS of sine-wave

Status
Not open for further replies.

neuralc

Full Member level 4
Full Member level 4
Joined
Nov 6, 2001
Messages
236
Helped
9
Reputation
18
Reaction score
3
Trophy points
1,298
Activity points
2,202
c code rms

Hi all,

Some one have a C code (for embedded) to calculate the RMS value of the sine-wave readed by an ADC of 8 bits?

ThX


NeuralC
 

Hi neuralc,

It is very simple,

Consider your line frequency = 50.00 Hz

50.00 Hz = 20ms = 20000 us

for example if you grab sinewave sample @ 100us interval time you get 200 samples .

store in some buffer, your ADC is 8 bit so you need buffer of size
signed char adcbuf[200]

ok...

now do following

signed int rawrms ;
int rms ;

for( count = 0 ; count < 200 ; count++ )
{
rawrms += adcbuf[count] * adcbuf[count] ;
}

rms = rawrms / 200 ;
rms = sqrt(rms) ;

after squartrooting

you get actual rms of sinewave.


Regards.

Zastereo
 
OK, Thx,

Like this we get the RMS for one cicle, but what about cicle to cicle, we make the average?


ThX

NeuralC
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top