## Average Power of sinusoidal signal using Fixe Point Programming Technique in Code Composer Studio V5
/* programme for calculating average power of a sin waves whose amplitude
* is A = 0.9 (scaling factor)
* x[n] = A* sin(2*PI*f0*t)
* x[n] = A* sin ((2*PI*f0*nTs))
* x[n] = A *sin ((2*PI*n)/(fs/f0))
* f0 is 1000; and sampling frequency fs is 32000
* fs/f0 = 32
*
* for four cycle no of samples are 32*4 = 128;
*
* avg power = 1/N [Summation(n=0 to n=N-1){x^2(n)}]; N is no of samples
*/
#include <stdio.h>
#include <math.h>
#define Q15 (unsigned int)32768
#define FS_BY_F0 32
#define PI (float)3.1416
#define SIZE 128
float amp=0.9;
int x[SIZE];
long prod,sum=0;
float avg;
void main()
{
int i;
for (i=0;i<SIZE;i++)
x[i] = (int)(Q15 * amp * sin ((2*PI*i)/FS_BY_F0));
for (i=0;i<SIZE;i++)
{
prod = (long)x[i] * (long)x[i]; //SSI0F30;
prod = prod <<1; //SI0F31
prod = prod >>7; //SI7F24
sum = sum + prod; //SI7F24
}
printf ("before dividing sum is %ld\n",sum);
sum = sum >>7; // dividing by 128 for calculating avg power
// now sum is nearly equal to 1. and just above result is in SI7F24 formate
// converting result in SI0F31 formate
sum = sum <<7;
avg = (float)sum/((unsigned long)Q15<<16);
printf ("average power is %f\n",avg);
}
/*End of Programme*/
**************************************************************
Click on
Project -> build all
then click on debug
for graph display click on Tool ->Graph->single time
select Acquisition buffer 128
DSP Data type 16 bit signed integer
Start Address: x
Then finally Click on OK
A Sinusoidal graph with four cycle will display.