DSPRelated.com
Forums

expanded matlab code for COV

Started by Unknown February 1, 2006
Hi,

I am currently in the process of expanding upon some matlab functions,
that is, to explicitly write out the code for a function.

I have been trying to write code to give the results of COV in matlab
(I got it for a bit, then mysteriously to me, it stopped working when i
relocated code)...

Anyway, has anyone gone through this process or come across code that
would be of help to me???

Thanks in advance.

marwanboustany@gmail.com wrote:

> Hi, > > I am currently in the process of expanding upon some matlab functions, > that is, to explicitly write out the code for a function. > > I have been trying to write code to give the results of COV in matlab > (I got it for a bit, then mysteriously to me, it stopped working when i > relocated code)... > > Anyway, has anyone gone through this process or come across code that > would be of help to me??? > > Thanks in advance.
Ok, upon analysis... it just seems that the matlab COV is getting the wrong zero mean for the data vectors. matlab does it like this: - zero_mean_sensor_data = sensor_data - ones(n,1) * mean(sensor_data); the 'ones(n,1) * mean(sensor_data)' part does the following: - x = 1 2 3 4 5 6 will give you 2.5000 3.5000 4.5000 2.5000 3.5000 4.5000 that is, the mean of each column is being calculated, whereas, if data is in columns with observations (say sensor data) in rows, it should be the mean of the rows and not the culumns that are being calculated, like the following: zero_mean_sensor_data = sensor_data - mean(sensor_data,2)*ones(1,Num_samples); where from x = 1 2 3 4 5 6 you get -1 0 1 -1 0 1 which is theoretically (I think) what is supposed to be happening... so this is why my cov value was different to matlab's... anybody any suggestions as to why?