0

The 6 faces method is a very cheap and fast way to calibrate and accelerometer like my MPU6050, here a great description of the method.

I made 6 tests to calibrate the accelerometer based on the g vector.

enter image description here

After that I build up a matrix and in each row is stored the mean of each axis expressed in m/s^2, thanks to this question I automatically calculated the mean for each column in each file. enter image description here

The tests were randomly performed, I tested all the six positions, but I didn't follow any path. So I sorted manually the final matrix, based on the sort of the Y matrix, my reference matrix. The Y elements are fixed.

enter image description here

The matrix manually sorted is the following

enter image description here

Here how I manually sorted the matrix

    meanmatrix=[ax ay az];
    mean1=meanmatrix(1,:);
    mean2=meanmatrix(2,:);
    mean3=meanmatrix(3,:);
    mean4=meanmatrix(4,:);
    mean5=meanmatrix(5,:);
    mean6=meanmatrix(6,:);
    meanmatrix= [mean1; mean3; mean2; mean4;mean6;mean5];

Based on the Y matrix constrain how can sort my matrix without knowing "a priori" which is the test stored in the row?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Andrea Ciufo
  • 359
  • 1
  • 3
  • 19

1 Answers1

1

Assuming that the bias on the accelerometer is not huge, you can look at the rows of your matrix and see with which of the rows in your Y matrix matches.

sorted_meanmatrix = zeros(size(meanmatrix));
for rows = 1:length(Y)
    % Calculates the square of distance and see which row has a nearest distcance 
    [~,index] = min(sum((meanmatrix - Y(rows,:)).^2, 2)); 
    sorted_meanmatrix(rows,:) = meanmatrix(index,:);
end
Laleh
  • 488
  • 4
  • 16
  • Noob question why your code return me "Error using - Matrix dimensions must agree." ? I changed the code this way `(meanmatrix(rows,:) - Y(rows,:)` but it returns a wrong matrix an image [here](http://imgur.com/a/BYxQR) – Andrea Ciufo Jun 12 '17 at 16:57
  • from MATLAB R2016b, you can subtract a row from a matrix. If you are using an older version of matlab you should use "repmat" to make a matrix from Y(rows,:) and then do the subtraction! – Laleh Jun 13 '17 at 07:18
  • Maybe is a noob question but i am not able to implement the solution. I wrote this code, but Matlab returns me an error message on matrix dimension `[~,index] = min(sum(meanmatrix - repmat((Y(rows,:).^2),5,0), 2)); ` – Andrea Ciufo Jun 15 '17 at 13:22
  • If you are not using newer version of matlab, you need this:[~,index] = min(sum((meanmatrix - repmat(Y(rows,:),6,1)).^2, 2)); – Laleh Jun 15 '17 at 13:44
  • or [~,index] = min(sum(bsxfun(@minus, meanmatrix, Y(rows,:)).^2, 2)); – Laleh Jun 15 '17 at 14:28
  • Cool it works! Thanks for your time and patience! <3 – Andrea Ciufo Jun 15 '17 at 14:37