diff --git a/ReadMe.md b/ReadMe.md index 4582864..33cb8e2 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -25,19 +25,30 @@ Accelerometer "random walk" | `accelerometer_random_walk` | opening the mat file.\n') load(mat_path); %% Get the calculated sigmas -fprintf('plotting accelerometer.\n') +fprintf('=> plotting accelerometer.\n') [fh1,sigma_a,sigma_ba] = gen_chart(results_ax.tau1,results_ax.sig2,... results_ay.sig2,results_az.sig2,... titlestr,'acceleration','m/s^2',... 'm/s^2sqrt(Hz)','m/s^3sqrt(Hz)'); -fprintf('plotting gyroscope.\n') +fprintf('=> plotting gyroscope.\n') [fh2,sigma_g,sigma_ga] = gen_chart(results_wx.tau1,results_wx.sig2,... results_wy.sig2,results_wz.sig2,... titlestr,'gyroscope','rad/s',... @@ -37,6 +39,7 @@ %% Print out for easy copying +fprintf('=> final results\n'); % Accelerometer fprintf('accelerometer_noise_density = %.8f\n',sigma_a); fprintf('accelerometer_random_walk = %.8f\n',sigma_ba); diff --git a/matlab/functions/gen_chart.m b/matlab/functions/gen_chart.m index 808c55f..557b596 100644 --- a/matlab/functions/gen_chart.m +++ b/matlab/functions/gen_chart.m @@ -6,10 +6,10 @@ % ======================================================================= % Plot the results on a figure fh1 = figure; -loglog(tau, sqrt(sigx)); hold on; -loglog(tau, sqrt(sigy)); hold on; -loglog(tau, sqrt(sigz)); hold on; -loglog(tau, sqrt(sigavg)); hold on; +loglog(tau, sigx); hold on; +loglog(tau, sigy); hold on; +loglog(tau, sigz); hold on; +loglog(tau, sigavg); hold on; grid on; title([titlestr,' ',name]); xlabel('\tau [sec]'); @@ -20,18 +20,18 @@ % Find location of tau=1 by finding where difference is near zero tauref = 1; taudiff = abs(tau-tauref); -tauid1 = find(taudiff == min(taudiff)); +tauid1 = find(taudiff == min(taudiff),1); fprintf('tau = %.2f | tauid1 = %d\n',tau(tauid1),tauid1); % We will fit our "white-noise" line where tau is 1 -%windowsize = 50; +windowsize = 50; %window = tauid1-windowsize:tauid1+windowsize; minid = find(sigavg == min(sigavg)); % find where the min is -window = 1:minid; % go from start to min +window = 1:minid-windowsize; % go from start to min % Get our x and y values x = tau(window); -y = sqrt(sigavg(window)); +y = sigavg(window); nanx = isfinite(y); % Fit to log-log scale (slope of -1/2) @@ -39,7 +39,7 @@ coeffs(1)= -0.5; intcs = log(y(nanx)./x(nanx).^coeffs(1)); coeffs(2) = mean(intcs); -%fprintf('h_fit1 slope = %.4f | y-intercept = %.4f\n',coeffs(1),coeffs(2)); +fprintf('h_fit1 slope = %.4f | y-intercept = %.4f\n',coeffs(1),coeffs(2)); % Convert from logarithmic scale to linear scale and plot h_fit1 = tau.^coeffs(1).*exp(coeffs(2)); @@ -50,18 +50,18 @@ % ======================================================================= % Next we should fit a 1/2 line to the bias side of the allan plot minid = find(sigavg == min(sigavg)); % find where the min is -window = minid:length(tau); % go from min to the end +window = minid+windowsize:length(tau); % go from min to the end % Get our x and y values x = tau(window); -y = sqrt(sigavg(window)); +y = sigavg(window); nanx = isfinite(y); % Calculate the intercept given the slope of +1/2 coeffs(1)= 0.5; intcs = log(y(nanx)./x(nanx).^coeffs(1)); coeffs(2) = mean(intcs); -%fprintf('h_fit2 slope = %.4f | y-intercept = %.4f\n',0.5,mean(intcs)); +fprintf('h_fit2 slope = %.4f | y-intercept = %.4f\n',0.5,mean(intcs)); % Convert from logarithmic scale to linear scale and plot h_fit2 = tau.^coeffs(1).*exp(coeffs(2)); @@ -72,7 +72,7 @@ % Get what our bias should be (should be at a tau of 3) tauref = 3; taudiff = abs(tau-tauref); -tauid2 = find(taudiff == min(taudiff)); +tauid2 = find(taudiff == min(taudiff),1); fprintf('tau = %.2f | tauid2 = %d\n',tau(tauid2),tauid2);