Skip to content
Snippets Groups Projects
Commit 1b2313a4 authored by Matt Rich's avatar Matt Rich
Browse files

Added a .gitignore file. So far it ignores autosave matlab files. Added...

Added a .gitignore file. So far it ignores autosave matlab files. Added several functions and scripts to start analyzing the IMU data and characterizing the noise. They are rough starts at this point.
parent 9e5f1e26
No related branches found
No related tags found
No related merge requests found
*.asv
\ No newline at end of file
close all; clear all; clc;
filename = 'imu.csv';
data = load_IMU_data_from_csv( filename ) ;
t = data.t;
ax = data.ax;
ay = data.ay;
az = data.az;
gx = data.gx;
gy = data.gy;
gz = data.gz;
% analyze the noise (deviation from mean) on each axis and compare the
% emperical distribution to one generated from a quantized Gaussian
% distrubtuion with the same variance.
quantized_accel_noise_gauss_anal( ax , 'x-axis')
quantized_accel_noise_gauss_anal( ay , 'y-axis')
quantized_accel_noise_gauss_anal( az , 'z-axis')
\ No newline at end of file
function data = load_IMU_data_from_csv( filename )
% load_IMU_data_from_csv load data from csv file into workspace
%
%SYNTAX
% data = load_IMU_data_from_csv( filename )
%
%DESCRIPTION
% ...to be written...
%
%
%Inputs:
% filename - string specifying the file
%
%Options:
% none
%
%Outputs:
% data - IMU data loaded into a structure (specify more later)
%
%EXAMPLES
%
%NOTES
% This function currently assumes the csv format that was used as of the
% date: 11/15/2016 (m/d/y)
%
%AUTHORS
% Matt Rich - m87rich@iastate.edu
%
%DEVELOPERS
%
%
%DEVELOPMENT NOTES
%
% dates are in m-d-y format
%
% Initial bare bones function.
% - Matt Rich 11-15-2016
%
delimiter = ',';
formatSpec = '%f%f%f%f%f%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN, 'ReturnOnError', false);
fclose(fileID);
data.t = dataArray{:, 1};
data.ax = dataArray{:, 2};
data.ay = dataArray{:, 3};
data.az = dataArray{:, 4};
data.gx = dataArray{:, 5};
data.gy = dataArray{:, 6};
data.gz = dataArray{:, 7};
end
% function microcart_imu_analysis_1
close all; clc;
filename = 'imu.csv';
delimiter = ',';
formatSpec = '%f%f%f%f%f%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN, 'ReturnOnError', false);
fclose(fileID);
t = dataArray{:, 1};
ax = dataArray{:, 2};
ay = dataArray{:, 3};
az = dataArray{:, 4};
gx = dataArray{:, 5};
gy = dataArray{:, 6};
gz = dataArray{:, 7};
clearvars filename delimiter formatSpec fileID dataArray ans;
% magnitude of acceleration in gs
a = ( ax.^2 + ay.^2 + az.^2 ).^0.5 ;
% magnitude of deviation from ideal
ea1 = 1 - a ;
% magnitude of deviation from mean
ea2 = a - mean(a) ;
% RMS error
ea1rms = sqrt(1/length(ea1)*(ea1')*ea1) ;
ea2rms = sqrt(1/length(ea2)*(ea2')*ea2) ;
subplot(3,1,1);
plot(t, a , t , ones(length(t),1)); axis([min(t),max(t),min([a;1])-0.01,max([a;1])+0.01]); grid;
xlabel('Time (s)'); ylabel('Acceleration (gs)');
legend('Measured','Ideal');
subplot(3,1,2);
plot(t, ea1 ); axis([min(t),max(t),min(ea1)-0.01,max(ea1)+0.01]); grid;
xlabel('Time (s)'); ylabel('Error From Ideal (gs)');
subplot(3,1,3);
plot(t, ea2 ); axis([min(t),max(t),min(ea2)-0.01,max(ea2)+0.01]); grid;
xlabel('Time (s)'); ylabel('Error From Mean (gs)');
%
figure;
X = fft(ea2);
N = length(ea2);
fs = 1/(t(2)-t(1));
F = ([-N/2:N/2-1]/N)*fs; %frequency axis for plotting FFTs
% subplot(2,1,1);
plot(F,fftshift(abs(X))); grid;
xlabel('frequency (Hz)');
ylabel(['|FFT(x)|']);
% subplot(2,1,2);
% plot(F,20*log10(fftshift(abs(X)))); grid;
% xlabel('frequency (Hz)');
% ylabel('|FFT(x)| dB');
suptitle('x = Error From Mean (gs)');
eax = ax - mean(ax);
vx = var(ax);
sigmax = sqrt(vx);
figure;
bins = unique(eax) ;
dbins = bins(2)-bins(1); % the quantization levels consistent
bins_right = bins + dbins/2;
bins_left = bins - dbins/2;
cgauss_right = normcdf(bins_right,0,sigmax);
cgauss_left = normcdf(bins_left,0,sigmax);
empf = length(eax)*(cgauss_right-cgauss_left);
stairs(bins_left,empf,'r','LineWidth',1) ;
xlabel('Error From Mean (gs)');
ylabel('Occurences');
grid;
hold on;
h = hist(eax,bins);
stem(bins,h);
legend(['Quantized Gaussian Noise: N(0,',num2str(vx),')'],'Emperical Distribution')
quantized_accel_noise_gauss_anal( ax )
% end
function varargout = quantized_accel_noise_gauss_anal( a , axis )
% quantized_accel_noise_gauss_anal analysis for quantized acelerometer data
%
%SYNTAX
% quantized_accel_noise_gauss_anal( a , axis )
%
%DESCRIPTION
% ...to be written...
%
%
%Inputs:
% a - vector of a single axis accelerometer reading
% axis - string specifying the axis label
%
%Options:
% none
%
%Outputs:
% none
%
%EXAMPLES
%
%NOTES
% This function is only really meaningful for a static (not moving) test.
%
%AUTHORS
% Matt Rich - m87rich@iastate.edu
%
%DEVELOPERS
%
%
%DEVELOPMENT NOTES
%
% dates are in m-d-y format
%
% Initial bare bones function.
% - Matt Rich 11-15-2016
%
mu = mean(a);
v = var(a);
sigma = sqrt(v);
ea = a - mu;
mue = mean(ea); %calculate the mean of the error from mean
figure;
bins = unique(ea) ;
dbins = bins(2)-bins(1); % assuming the quantization levels consistent
bins_right = bins + dbins/2;
bins_left = bins - dbins/2;
cgauss_right = normcdf(bins_right,mue,sigma);
cgauss_left = normcdf(bins_left,mue,sigma);
emp_dist = length(ea)*(cgauss_right-cgauss_left);
stairs(bins_left,emp_dist,'r','LineWidth',1) ;
xlabel('Error From Mean (gs)');
ylabel('Occurences');
grid;
hold on;
h = hist(ea,bins);
stem(bins,h);
legend(['Quantized Gaussian Noise: N(',num2str(mue),',',num2str(v),')'],'Emperical Distribution');
title(['Accelerometer deviation from mean on ',axis]);
end
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment