1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <iostream>
#include <cmath>
using namespace std;
#define SIZE1 80
#define SIZE2 62
#define SIZE3 29
double getAverage(short arr[], int size)
{
int i, sum = 0;
double avg;
for (i = 0; i < size; ++i)
{
sum += arr[i];
}
avg = double(sum) / size;
return avg;
}
double getRMS (short arr[], int size)
{
int i;
double sumsq;
double RMS;
sumsq = 0;
for (i = 0; i< size; i++)
{
sumsq += arr[i]*arr[i];
RMS = (1/size)*(sqrt(sumsq));
return RMS;
}
}
int main()
{
short cosine[SIZE1] = {
32767, 32666, 32364, 31862, 31163, 30273, 29196, 27938, 26509, 24916,
23170, 21280, 19260, 17121, 14876, 12539, 10126, 7649, 5126, 2571,
0, -2571, -5126, -7649, -10126, -12539, -14876, -17121, -19260, -21280,
-23170, -24916, -26509, -27938, -29196, -30273, -31163, -31862, -32364, -32666,
-32767, -32666, -32364, -31862, -31163, -30273, -29196, -27938, -26509, -24916,
-23170, -21280, -19260, -17121, -14876, -12539, -10126, -7649, -5126, -2571,
0, 2571, 5126, 7649, 10126, 12539, 14876, 17121, 19260, 21280,
23170, 24916, 26509, 27938, 29196, 30273, 31163, 31862, 32364, 32666
};
short triangle[SIZE2] = {
15500, 14500, 13500, 12500, 11500, 10500, 9500, 8500, 7500, 6500,
5500, 4500, 3500, 2500, 1500, 500, -500, -1500, -2500, -3500,
-4500, -5500, -6500, -7500, -8500, -9500, -10500, -11500, -12500, -13500,
-14500, -15500, -14500, -13500, -12500, -11500, -10500, -9500, -8500, -7500,
-6500, -5500, -4500, -3500, -2500, -1500, -500, 500, 1500, 2500,
3500, 4500, 5500, 6500, 7500, 8500, 9500, 10500, 11500, 12500,
13500, 14500
};
short sawtooth[SIZE3] = {
-24000, -22000, -20000, -18000, -16000, -14000, -12000, -10000, -8000, -6000,
-4000, -2000, 0, 2000, 4000, 6000, 8000, 10000, 12000, 14000,
16000, 18000, 20000, 22000, 24000, 26000, 28000, 30000, 32000
};
cout<<"Average of cosine: "<<getAverage (cosine,SIZE1)<<endl;
cout<<"Average of traingle: "<<getAverage (triangle,SIZE2)<<endl;
cout<< "Average of sawtooth: "<<getAverage(sawtooth,SIZE3)<<endl;
cout<<"RMS of cosine"<<getRMS (cosine,SIZE1) <<endl;
return 0;
}
|