imu_plot.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. function imu_plot(data_name)
  2. load(data_name);
  3. clc
  4. acc(:,1) = m(1,(178:258));
  5. acc(:,2) = m(2,(178:258));
  6. acc(:,3) = m(3,(178:258));
  7. acc = acc * 9.81;
  8. figure('Position', [9 39 900 300], 'NumberTitle', 'off', 'Name', 'Velocity');
  9. hold on;
  10. plot(acc(:,1), 'r');
  11. plot(acc(:,2), 'g');
  12. plot(acc(:,3), 'b');
  13. title('ACC');
  14. xlabel('Time (s)');
  15. ylabel('ACC (m/s)');
  16. legend('X', 'Y', 'Z');
  17. hold off;
  18. % Integrate acceleration to yield velocity
  19. vel = zeros(size(acc));
  20. for t = 2:length(vel)-1
  21. vel(t,:) = vel(t-1,:) + acc(t,:) * 0.01;
  22. end
  23. % Compute integral drift during non-stationary periods
  24. velDrift = zeros(size(vel));
  25. stationaryStart = 1;
  26. stationaryEnd = length(vel);
  27. for i = 1:numel(stationaryEnd)
  28. driftRate = vel(stationaryEnd(i)-1, :) / (stationaryEnd(i) - stationaryStart(i));
  29. enum = 1:(stationaryEnd(i) - stationaryStart(i));
  30. drift = [enum'*driftRate(1) enum'*driftRate(2) enum'*driftRate(3)];
  31. velDrift(stationaryStart(i):stationaryEnd(i)-1, :) = drift;
  32. end
  33. % Remove integral drift
  34. vel = vel - velDrift;
  35. % Plot translational velocity
  36. figure('Position', [9 39 900 300], 'NumberTitle', 'off', 'Name', 'Velocity');
  37. hold on;
  38. plot(vel(:,1), 'r');
  39. plot(vel(:,2), 'g');
  40. plot(vel(:,3), 'b');
  41. title('Velocity');
  42. xlabel('Time (s)');
  43. ylabel('Velocity (m/s)');
  44. legend('X', 'Y', 'Z');
  45. hold off;
  46. % -------------------------------------------------------------------------
  47. % Compute translational position
  48. % Integrate velocity to yield position
  49. pos = zeros(size(vel));
  50. for t = 2:length(pos)
  51. pos(t,:) = pos(t-1,:) + vel(t,:) * 0.01; % integrate velocity to yield position
  52. end
  53. % Plot translational position
  54. figure('Position', [9 39 900 600], 'NumberTitle', 'off', 'Name', 'Position');
  55. hold on;
  56. plot(pos(:,1), 'r');
  57. plot(pos(:,2), 'g');
  58. plot(pos(:,3), 'b');
  59. title('Position');
  60. xlabel('Time (s)');
  61. ylabel('Position (m)');
  62. legend('X', 'Y', 'Z');
  63. hold off;
  64. % plot(vel(:,2), 'g');
  65. % plot(vel(:,3), 'b');
  66. % plot(acc(:,1));
  67. %
  68. % plot(acc(:,2));
  69. % hold on;
  70. % plot(acc(:,3));
  71. % hold on;
  72. % plot3(pos(:,1),pos(:,2),pos(:,3))
  73. % plot(acc(:,1));
  74. % hold on;
  75. % plot(vel(:,1));
  76. % hold on;
  77. % plot(pos(:,1), 'r');
  78. % hold on;
  79. % plot(pos(:,2), 'g');
  80. % hold on;
  81. % plot(pos(:,3), 'b');
  82. % hold on;
  83. % plot(acc(:,2));
  84. % hold on;
  85. % plot(acc(:,3));
  86. % hold on;
  87. % plot(vel);
  88. % hold on;
  89. end