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.

calculate the amplitude of sin signal ??

Status
Not open for further replies.

gameelgamal

Member level 5
Joined
Dec 14, 2006
Messages
85
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Egypt
Activity points
1,888
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...
 

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.
 
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
 
amplitude of sin

smxx said:
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....
 

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.
 
signal amplitude

FvM said:
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..
 

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
 
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)²)
 

calculating rms value of sine wave with dc offset

shoaibali said:
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
 

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.
 

calculate amplitude discrete sine

gameelgamal said:
shoaibali said:
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
 

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);
   }
}
 

amplitude signal

Jack// ani said:
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=read_adc();
delay_us(666);
}

//SQUARE OF SAMPLES
for(i=0;i<=29;i++)
{
samples=samples*samples; // Sqaure
value=samples+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 = PositiveValueOf(samples - DC_Average)
c. Do the rest as in //SQUARE OF SAMPLES

Regards
 

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.
 

rms of sine with dc offset

Jack// ani said:
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
 

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]
 

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.
 
  • Like
Reactions: smxx

    smxx

    Points: 2
    Helpful Answer Positive Rating
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.
 

calculate amplitude of the signal from adc output

and by Fourier Transform we have all factors,but it's need more samples
 

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
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top