Covariance plays an important role in Signal Analysis:
1. It indicates whether X is positively correlated or negatively correlated with Y. If X is negative, the covariance is positive and the covariance is positive. 2. Covariance shows the correlation degree of X and Y. When the correlation points are scattered in the four quadrants, the correlation degree is very low. When the correlation points are distributed on the average line of X and Y, indicates unrelated. When the correlation point is close to the always-on line, it indicates that the correlation relationship is close. When the correlation point falls to the always-on line, it indicates completely related.
The computer formula for covariance is sxy = (Σ (Xi-x ^) (Yi-y ^)/(n-1), I =, 2 ..., n-1. ^ indicates the average value.
Void Cox (int x [], int y [], int N, double * P)
{
Int I;
Double averx, Avery, sumx = 0, Sumy = 0;
Double sum = 0;
For (I = 0; I <n; I ++)
{
Sumx + = x [I];
Sumy + = Y [I];
}
Averx = sumx/N;
Avery = Sumy/N;
For (I = 0; I <n; I ++)
Sum + = (X [I]-averx) * (Y [I]-Avery );
* P = sum/(n-1 );
}
Void output (INT array [], int N)
{
Int I;
For (I = 0; I <n; I ++)
Printf ("% 4D", array [I]);
}
Void main ()
{
Int X [5] = {1, 2, 3, 4, 5 };
Int y [5] = {5, 4, 3, 2, 1 };
Double Co;
Cox (X, Y, 5, & Co );
Printf ("/NX:/N ");
Output (x, 5 );
Printf ("/NY:/N ");
Output (Y, 5 );
Printf ("/nthe Cox of X and Y is: % lf/N", CO );
}