Rules | Recent posts | topic RSS | Search | Register  | Log in

calculate the amplitude of sin signal ??


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> calculate the amplitude of sin signal ??
Author Message
gameelgamal



Joined: 14 Dec 2006
Posts: 89
Location: Egypt


Post28 Apr 2009 15:26   

signal amplitude


Hi

How to calculate the amplitude of sin signal using microcontroller?

What I need is the algorithm which will be implemented in the microcontroller to compute the amplitude (or the RMS value) of the input signal...

thanx...
Back to top
FvM



Joined: 22 Jan 2008
Posts: 5044
Helped: 752
Location: Bochum, Germany


Post29 Apr 2009 8:26   

calculate amplitude


RMS can be calculated independant of the waveform type. It's exactly what it's named: RMS root of mean of squared signal. You may want to calculate an RMS of the AC signal by subtracting the DC value (or mean), the operation is equivalent to finding the standard deviation of a series of samples. You'll find the definition in the statistics section of a mathemical formulas collection.
Back to top
smxx



Joined: 18 Aug 2005
Posts: 188
Helped: 8
Location: iran(ahwaz)


Post29 Apr 2009 10:04   

amplitude of a signal


hi
Analog Divece ® have a special 8pin Ic for this purpose.
And for fully sine wave you can calculate this by two samples.
V1 : sample at t1 time
v2 :sampe at (t1+π/2)
V1=Vm sin(t1)
V2=Vm sin(t1+π/2)
Vm²=V1²+V2²
Vrms= Vm /√2
Back to top
gameelgamal



Joined: 14 Dec 2006
Posts: 89
Location: Egypt


Post29 Apr 2009 12:07   

amplitude of sin


smxx wrote:

And for fully sine wave you can calculate this by two samples.
V1 : sample at t1 time
v2 :sampe at (t1+π/2)
V1=Vm sin(t1)
V2=Vm sin(t1+π/2)
Vm²=V1²+V2²
Vrms= Vm /√2

Ok...
I'm going to implement this algorithm using a microcontroller, But I still find some difficulty. So please tell me if I'm wrong

First , at a random point of the program, I will perform an analog to digital conversion process to compute V1.

Secondly , after a certain time (say 1 ms), I will perform another ADC to compute V2.

Now I can compute V1 using the eqn: V1=Vm sin(t1)
But what is the value of (t1) ?? It should be equal zero, isn't ?

Also what do you mean by (n/2). Is it the delay time between the two conversions (1 ms in my case) or what??

thanx....
Back to top
FvM



Joined: 22 Jan 2008
Posts: 5044
Helped: 752
Location: Bochum, Germany


Post29 Apr 2009 20:35   

sin signal


n/2 must be equal to 1/4 period of the input frequency (90° phase shift), otherwise the nice algorithm doesn't work. Also V1, V2 must be DC-free.
Back to top
gameelgamal



Joined: 14 Dec 2006
Posts: 89
Location: Egypt


Post30 Apr 2009 7:29   

signal amplitude


FvM wrote:
n/2 must be equal to 1/4 period of the input frequency (90° phase shift), otherwise the nice algorithm doesn't work. Also V1, V2 must be DC-free.


So. in case of 50 Hz sin wave , n/2=5 ms. Right?

what do you mean by dc free?? you mean no DC offset added to it??

thanx..
Back to top
shoaibali



Joined: 28 Jun 2007
Posts: 40
Helped: 3


Post30 Apr 2009 12:43   

rms of sine wave with dc offset


Use microcontrollers adc to take n(100 would be fine) samples of the input sginal for one cycle of the sine wave and do the rms calculations for that. You will need to bias the sinusoidal signal if the adc low reference voltage is 0 volts.

For example, for 50Hz sinusoidal signal,
take 100 samples each 20ms/100 = 200us apart
This can be done using a timer and adc in the microcontroller

Regards
Back to top
FvM



Joined: 22 Jan 2008
Posts: 5044
Helped: 752
Location: Bochum, Germany


Post30 Apr 2009 15:01   

how to calculate amplitude of a signal


As said, you can calculate the AC voltage RMS without knowing the DC offset before (by using a standard deviation calculation method):
Code:
uRMS = √(1/n*∑u² - (1/n*∑u)²)
Back to top
gameelgamal



Joined: 14 Dec 2006
Posts: 89
Location: Egypt


Post01 May 2009 12:25   

calculating rms value of sine wave with dc offset


shoaibali wrote:
Use microcontrollers adc to take n(100 would be fine) samples of the input sginal for one cycle of the sine wave and do the rms calculations for that. You will need to bias the sinusoidal signal if the adc low reference voltage is 0 volts.

For example, for 50Hz sinusoidal signal,
take 100 samples each 20ms/100 = 200us apart
This can be done using a timer and adc in the microcontroller

Regards


Should the 100 samples be in the one cycle, or it can be tooken over more than one cycle
Back to top
trekkytekky



Joined: 04 Apr 2009
Posts: 77
Helped: 6
Location: Perth


Post02 May 2009 12:41   

signal + amplitude


If you always know it will be a sinusoidal signal, then you also have the option of implementing a peak detector for maximum and minimum, the amplitude will be (max-min)/2 and multiplying by a constant 1/√2 for RMS

ie:
Amplitude = (max-min)/2
RMS = Amplitude/√2

Just another option.
Back to top
shoaibali



Joined: 28 Jun 2007
Posts: 40
Helped: 3


Post05 May 2009 14:04   

calculate amplitude discrete sine


gameelgamal wrote:
shoaibali wrote:
Use microcontrollers adc to take n(100 would be fine) samples of the input sginal for one cycle of the sine wave and do the rms calculations for that. You will need to bias the sinusoidal signal if the adc low reference voltage is 0 volts.

For example, for 50Hz sinusoidal signal,
take 100 samples each 20ms/100 = 200us apart
This can be done using a timer and adc in the microcontroller

Regards


Should the 100 samples be in the one cycle, or it can be tooken over more than one cycle


The samples have to be in one cycle as you will be doing calculations over one cycle
Back to top
Jack// ani



Joined: 02 Dec 2004
Posts: 484
Helped: 24


Post05 May 2009 17:08   

how to calculate sine of an amplitude


Wrote a little code on CCS PIC, nothing fancy standard deviation with 30 samples at work as discussed by FvM.

Have run out of 16F877A, so couldn't burnt and tested it. Any comments, mistakes, improvements are always appreciated...

Code:
#include <16F877A.h>
#device ADC=10
#include <math.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

void main()
{

   int16 value, samples[29]; //Value is a 10bit data sample
   int i;
   float volts;
   setup_port_a(ALL_ANALOG); // All the 8 channels are analog
   setup_adc(ADC_CLOCK_INTERNAL); // Internal ADC Clock
   set_adc_channel(0); // RA0/AN0(Pin2) is analog input channel

   while(1)
   {
      for(i=0;i<=29;i++)
      {
      samples[i]=read_adc();
      delay_us(666);
      }

      for(i=0;i<=29;i++)
      {
      samples[i]=samples[i]*samples[i]; // Sqaure
      value=samples[i]+value; // Sum total
      }
     
      value = value/30; // Mean of 30 samples
      value = sqrt(value); // Square root

      volts=(float)value*0.0048828125; // 1024 discrete levels, 5/1024 = 0.0048828125
      printf("Voltage is : %3.3f\n",volts);// Print upto 3 decimal places
      delay_ms(500);
   }
}
Back to top
shoaibali



Joined: 28 Jun 2007
Posts: 40
Helped: 3


Post06 May 2009 11:12   

amplitude signal


Jack// ani wrote:
Wrote a little code on CCS PIC, nothing fancy standard deviation with 30 samples at work as discussed by FvM.

Have run out of 16F877A, so couldn't burnt and tested it. Any comments, mistakes, improvements are always appreciated...

#include <16F877A.h>
#device ADC=10
#include <math.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

void main()
{

int16 value, samples[29]; //Value is a 10bit data sample
int i;
float volts;
setup_port_a(ALL_ANALOG); // All the 8 channels are analog
setup_adc(ADC_CLOCK_INTERNAL); // Internal ADC Clock
set_adc_channel(0); // RA0/AN0(Pin2) is analog input channel

while(1)
{
for(i=0;i<=29;i++)
{
samples[i]=read_adc();
delay_us(666);
}

//SQUARE OF SAMPLES
for(i=0;i<=29;i++)
{
samples[i]=samples[i]*samples[i]; // Sqaure
value=samples[i]+value; // Sum total
}

value = value/30; // Mean of 30 samples
value = sqrt(value); // Square root

volts=(float)value*0.0048828125; // 1024 discrete levels, 5/1024 = 0.0048828125
printf("Voltage is : %3.3f\n",volts);// Print upto 3 decimal places
delay_ms(500);
}
}



I would like to add a few things
1- I suggest initialize "vaue" variable to 0
2- Do following to get rid of dc level in the signal(for example if the signal has been biased)
a. DC_Average = sumOfSample/NoOfSamples
b. For each sample samples[i] = PositiveValueOf(samples[i] - DC_Average)
c. Do the rest as in //SQUARE OF SAMPLES

Regards
Back to top
Jack// ani



Joined: 02 Dec 2004
Posts: 484
Helped: 24


Post06 May 2009 14:11   

sin vrms


Hi shoaibali, Yeah the value=0 should be initialized to avoid any previous junk value.

Regarding DC_Average, its not necessary as samples will be taken over a complete cycle, so DC Average will be zero.
Back to top
shoaibali



Joined: 28 Jun 2007
Posts: 40
Helped: 3


Post06 May 2009 17:16   

rms of sine with dc offset


Jack// ani wrote:
Hi shoaibali, Yeah the value=0 should be initialized to avoid any previous junk value.

Regarding DC_Average, its not necessary as samples will be taken over a complete cycle, so DC Average will be zero.


Hi Jack
I was pointing to DC_Average in case the signal is biased to a dc level which most likey it will be if it is going to be sampled by mcu with positive reference only
Back to top
smxx



Joined: 18 Aug 2005
Posts: 188
Helped: 8
Location: iran(ahwaz)


Post12 May 2009 4:57   

sin find amplitude


HI gameelgamal
π/2 eq. 90 deg time shift .π is Pi coefficient (3.14)
I mean you nead two sample with 90deg shift time .
[/img]



Sorry, but you need login in to view this attachment

Back to top
FvM



Joined: 22 Jan 2008
Posts: 5044
Helped: 752
Location: Bochum, Germany


Post12 May 2009 6:21   

calculating rms of sinusoidal signal


Unfortunately, the diagram (that can be imagined showing a sine waveform) has a phase shift near to pi rather than pi/2. It should be noticed, that the two samples method, you're referring to, is based on three prerequisitions:
1. The waveform is a sine (as illustrated by your diagram, this isn't obvious)
2. The samples have eaxctly pi/2 respectively 90° phase shift (see above)
3. The measured signal is DC-free. The above discussion is mostly about measurements with a DC offset.
Back to top
smxx



Joined: 18 Aug 2005
Posts: 188
Helped: 8
Location: iran(ahwaz)


Post12 May 2009 9:21   

how to calculate amplitude


Thank you FvM
in my 1st post I notify to fully sin wave
in last my post I mistake in showing Π/2 off sin wave only.
for sin wave with DC offset we can use as below by 3 sample (for fully sin wave with DC offset). for noisy sin wave we need more sample for digital filtering.
Be Happy and don't Worry.



Sorry, but you need login in to view this attachment



Last edited by smxx on 12 May 2009 9:24; edited 1 time in total
Back to top
smxx



Joined: 18 Aug 2005
Posts: 188
Helped: 8
Location: iran(ahwaz)


Post13 May 2009 5:25   

calculate amplitude of the signal from adc output


and by Fourier Transform we have all factors,but it's need more samples
Back to top
Google
AdSense
Google Adsense




Post13 May 2009 5:25   

Ads







Sorry, but you need login in to view this attachment

Back to top
awaili



Joined: 18 Apr 2009
Posts: 7


Post15 May 2009 19:39   

frequency of sine signal


sorry , but i'm looking for matlab code that can be used to calculate the amplitude and the frequency of sin signal...
if any one has any idea about it code you help me to write this code .....plz

thanks
Back to top
Jack// ani



Joined: 02 Dec 2004
Posts: 484
Helped: 24


Post15 May 2009 21:08   

how we can calcaulate the parameters of signals


awaili wrote:
sorry , but i'm looking for matlab code that can be used to calculate the amplitude and the frequency of sin signal...
if any one has any idea about it code you help me to write this code .....plz

thanks


Go though all the above posts, its carrying enough information to make those calculations. You've to do your homework though...
Back to top
Petre Petrov



Joined: 05 Aug 2009
Posts: 51
Helped: 5
Location: Sofia


Post06 Aug 2009 8:49   

rms dc offset calculate


gameelgamal “calculate the amplitude of sin signal ??”

Hello!
You could use one ADC to calculate all the parameters on the sinusoidal signal (SS) with or without displacement (DC offset).
You must take 4 samples per cycle of the SS (not necessarily at equal intervals, but you must know the intervals).
You should make a system with four equations using the formula below:

A = Am*sin(2*pi*Fss*t + phase) + DC

If you need parameters which are not in the formula above, you could apply the standard formulas in mathematics concerning sinusoidal signal.
I hope that is easy and useful for you.
BR
Back to top
Prabakaran



Joined: 22 Jan 2007
Posts: 160
Helped: 5
Location: Chennai(India)


Post19 Aug 2009 16:02   

calculate offset sinusoidal


Jack// ani wrote:
Wrote a little code on CCS PIC, nothing fancy standard deviation with 30 samples at work as discussed by FvM.

Have run out of 16F877A, so couldn't burnt and tested it. Any comments, mistakes, improvements are always appreciated...

#include <16F877A.h>
#device ADC=10
#include <math.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

void main()
{

int16 value, samples[29]; //Value is a 10bit data sample
int i;
float volts;
setup_port_a(ALL_ANALOG); // All the 8 channels are analog
setup_adc(ADC_CLOCK_INTERNAL); // Internal ADC Clock
set_adc_channel(0); // RA0/AN0(Pin2) is analog input channel

while(1)
{
for(i=0;i<=29;i++)
{
samples[i]=read_adc();
delay_us(666);
}

//SQUARE OF SAMPLES
for(i=0;i<=29;i++)
{
samples[i]=samples[i]*samples[i]; // Sqaure
value=samples[i]+value; // Sum total
}

value = value/30; // Mean of 30 samples
value = sqrt(value); // Square root

volts=(float)value*0.0048828125; // 1024 discrete levels, 5/1024 = 0.0048828125
printf("Voltage is : %3.3f\n",volts);// Print upto 3 decimal places
delay_ms(500);
}
}



I would like to add a few things
1- I suggest initialize "vaue" variable to 0
2- Do following to get rid of dc level in the signal(for example if the signal has been biased)
a. DC_Average = sumOfSample/NoOfSamples
b. For each sample samples[i] = PositiveValueOf(samples[i] - DC_Average)
c. Do the rest as in //SQUARE OF SAMPLES


Dear All

The above information is usefull to me . Can i have more details about the point(b)

Please say me in details what i should with DC Average and what would be the value.

Please say me in detail

And if i have a variable Frequency how could i sample the amplitude.

Waiting for u reply
Regards
Prabakaran
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> calculate the amplitude of sin signal ??
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
calculate amplitude of sin signal?? (2)
How does the Hspice calculate the DFT of a signal ? (4)
how to calculate the frequency of a signal ... (3)
How to calculate the track length of a signal? (4)
How can I calculate the period of this signal? (23)
prove of sin(a+b)= sin(a).cos(b) + sin(b).cos(a) (9)
Shift 1v amplitude of clock signal to 2.5v? (1)
about relation between amplitude of input signal and SNR (3)
How can I derive the sin of a angle (5)
What's the typical amplitude of the crystal oscillator? (3)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS