Gaussian Modelling of the Cubicles (from Matlab to PIC)

Problem: Given a six-sided die, fitted with accelerometers, we want to estimate which side is up by just looking at the accelerometer data.

Solution: We model each side by a multivariate Gaussian, and perform Maximum Likelihood (ML) estimation.

Concrete: Within the die, two dual-axis accelerometers are fitted, so we'll have 4 values, two of which should behave approximately the same. See the cubicles website for more information. The input vectors, Gaussians, and mean vectors are therefore four-dimensional.

[1: Gaussian Modelling]   [2: Maximum Likelihood Estimation]   [3: generating the PICC-code]   [4: visualization]    [5: adding gestures]

 

1. Gaussian Modelling

We start with visualizing the values from a single sensor:

>> S = [12 14 13 15 11 12 12 12 11 13 12 12 31 33 32 31 32 32 31 31 32 33 32 34];
>> plot(S)
 

The timeseries plot here shows that there's clearly two different kinds of readings here (1-12 and 12-24), and we might know that these relate to two different positions (the sensor pointing upward or downward), for example. These are two states of the sensor, or two classes that we want the system to identify.

One way to model these two classes is by creating Gaussians for each class. To do this, we need to know the mean value per class, and the variance, as the formula for a Gaussian is:

>> m1 = mean(S(1:12));
>> m2 = mean(S(13:24));
>> v1 = cov(S(1:12));
>> v2 = cov(S(13:24));

These value are:

>> disp([m1 m2 v1 v2]);
12.4167 32.0000 1.3561 0.9091

And plotting the two Gaussians gives:

>> G1 = GAUSS(m1, v1, [1:50]');
>> G2 = GAUSS(m2, v2, [1:50]');
>> plot([G1 G2]);

We can use the two Gaussians now to classify every new sensor value that comes in, in either of the two classes, by choosing the one that gives the highest value. The value 30 will for instance give 1.0630e-050 for the first, and 0.0464 for the second, so we can classify it as belonging to the second class, even though that value never occurred in the initial dataset S:  

>> g1 = GAUSS(m1, v1, 30);
>> g2 = GAUSS(m2, v2, 30);
>> disp([g1]);
1.0630e-050
>> disp([g2]);
0.0464

When we have multiple sensors, all that needs changing is the Gaussian formula:

where d is the dimension (number of sensors), cov is the covariance matrix, and mean is the mean vector.

 

Document created by Kristof Van Laerhoven, March 2003.