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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
//program to form a header file
#include <iostream>
#include<math.h>
using namespace std;
double getAcorr(double *arr, double *arr1, int size1, int size2); //defination for the autocorrelation using two pointer array of type double
double getCcorr(double *arr, double *arr1, int size1, int size2); //defination for the correlation using two pointer array of type double
double getConv(double *arr, double *arr1, int size1, int size2); //defination for the convolution using two pointer array of type double
double *p;
int main (void)
{
int size1, size2, index,index1, i,j;
double input;
int operation;
double *y, z[100];
double x[]={1,2,3};
double h[]={1,2,1};
int m,n;
//finding length of the given array
m= (sizeof(x)/sizeof(*x));
n= (sizeof(h)/sizeof(*h));
cout << "length of array=" << m << endl;
cout << "length of array=" << n << endl;
//operation to be selected using switch condition
cout <<"enter the operation:\n" << endl;
cin >> operation;
switch (operation)
{
case 1:
*p=getAcorr(x, x, m,n);
for (i=0;i<=m+n-2;i++)
{
cout<< *(p+i) << endl; // ouput to be display as incementing ith integer
}
break;
case 2:
*p=getCcorr(x, h, m,n);
for (i=0;i<=m+n-2;i++)
{
cout<< *(p+i) << endl; // ouput to be display as incementing ith integer
}
break;
default :
*p=getConv(x, h, m,n);
for (i=0;i<=m+n-2;i++)
{
cout<< *(p+i) << endl; // ouput to be display as incementing ith integer
}
}
return 0;
}
// operatin to be carried out in the autocorreletion
double getAcorr(double *arr, double *arr1, int size1, int size2)
{
int i,j;
int m=size1,n=size2;
double h[size2];
double x[size1];
double *y, z[100];
// reversing one the vector before its correletion i.e x[size1]
for(i=0,j=size1-1; i<size1; i++,j--)
{
z[i]=x[j];
cout <<" reverse vector's elements are=\n" << i <<' ' << z[i] << endl;
}
// convolving reversed array with other array i.e z[size1] and h[size2]
for(i=0;i<=m+n-2;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(z[i-j]*x[j]);
*p = *y;
}
cout<< "auto corelation sequences are= " << i << " = " << *p << endl;
}
return *p;
}
//// operatin to be carried out in the crosss correletion
double getCcorr(double *arr, double *arr1, int size1, int size2)
{
int i,j;
int m=size1,n=size2;
double h[size2];
double x[size1];
double *y, z[100];
// reversing one the vector before its correletion i.e x[size1]
for(i=0,j=size1-1; i<size1; i++,j--)
{
z[i]=x[j];
cout <<" reverse vector's elements are=\n" << i <<' ' << z[i] << endl;
}
// convolving reversed array with other array i.e z[size1] and h[size2]
for(i=0;i<=m+n-2;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(z[i-j]*h[j]);
*p = *y;
}
cout<< "cross corelation sequences are= " << i << " = " << *p << endl;
}
return *p;
}
// operatin to be carried out in the convolution
double getConv(double *arr, double *arr1, int size1, int size2)
{
int i,j;
int m=size1,n=size2;
double h[size2];
double x[size1];
double *y, z[100];
for(i=0;i<=m+n-2;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(x[i-j]*h[j]);
*p = *y;
}
cout<< "convolution is= " << i << " = " << *p << endl;
}
return *p;
}
|