A faster covariance function for 1 or 2 monodimensional vectors
The zip file includes:
- readme.txt this file
- cov_1d.c the mex file
- prova.m an example of use
Instructions:
cov_1d compute 1-dimensional covariance
Copy cov_1d.c in matlab current directory
mex compile this file:
mex cov_1d.c
To call this function:
- cov_1d(a) returns the variance of the vector elements normalizes by (N-1) where N is the number of observations
- cov_1d(a,0) returns the variance of the vector elements normalizes by (N-1) where N is the number of observations
- cov_1d(a,1) returns the variance of the vector elements normalizes by (N) where N is the number of observations
- cov_1d(a,b) a and b are monodimensional vectors with the same size N. It returns E[(a-aa)(b-ba)] where aa=E[a] and ba=E[b] E is the mathematical expectation normalizes by (N-1) where N is the number of observations
- cov_1d(a,b,0) a and b are monodimensional vectors with the same size N. It returns E[(a-aa)(b-ba)] where aa=E[a] and ba=E[b] E is the mathematical expectation normalizes by (N-1) where N is the number of observations
- cov_1d(a,b,1) a and b are monodimensional vectors with the same size N. It returns E[(a-aa)(b-ba)] where aa=E[a] and ba=E[b] E is the mathematical expectationnormalizes by (N) where N is the number of observations
NOTE: a and b must be REAL vectors (i.e. monodimensional)
From these relationships it follows that:
- cov_1d(a,a)=cov_1d(a)=cov_1d(a,a,0)
- cov_1d(a,a,1)=cov_1d(a,1)
- sqrt(std(a)) is the standard deviation of vector a (normalized to N-1)
- sqrt(std(a,1)) is the standard deviation of vector a (normalizaed to N)
cov_1d is faster than matlab cov function and can be also used to compute std of 1-dimensional vector.
Example:
elapsed_time =
2.10900000000000
elapsed_time =
0.75000000000000
Download Now
Popularity: 3% [?]
Related Posts
Comments
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!
Include MATLAB code in your comment by doing the following:
<pre lang="MATLAB">
%insert code here
</pre>

















































