% Post Processing for IMU v0.1



[FileName, PathName] = uigetfile('*.txt');
data = importdata([PathName FileName]);
time = data(:,1);       % extract time
accel = data(:,2:4);    % extract accels
gyro = data(:,5:7);     % extract gyros
mag = data(:,8:10);     % extract mag

% Setup scaling factors to convert to engineering units (if needed)

accel_full_scale = 8;       % Valid ranges for LIS331DLH are 2, 4 or 8
                            % Valid ranges from LIS331HH are 6, 12, 24
                  
accel_offset = -16;         % remove any biases. harded coded for now, will be determined and removed onboard in the future
accel_scale = 32768/accel_full_scale;    % 4096 for +/-8g's
gyro_scale = 1;     % leave as rad/sec 
mag_scale = 1;      % pass through raw counts for now


accel = (accel - accel_offset) ./ 4096;

figure
subplot(3,1,1)
plot(time, accel)
title('Accels (Gs)')
xlabel('Time (sec)')
ylabel('Gs')
legend('X','Y','Z')
subplot(3,1,2)
plot(time,gyro)
title('Gyros (rad/sec)')
xlabel('Time (sec)')
ylabel('rad/sec')
legend('X','Y','Z')
subplot(3,1,3)
plot(time, mag)
title('Magnetometer (raw counts)')
xlabel('Time (sec)')
ylabel('Raw Counts')
legend('X','Y','Z')
