% Linmot Shield Test Analysis for Bx 15 A motor setup.
%  Finds the max and min of the voltage sample data and then computes the
%  field change for each z point.  Calibration is 1V = 1mT
 
z_positions = -140:20:140;

% Get Bx data

Bx = zeros(1, length(z_positions));
sigBx = zeros(1, length(z_positions));

for i=1:length(z_positions)
   
   Vx1 = Load_testplt(i);
   Bx(i) = 10*mean(max(Vx1.Vsamp) - min(Vx1.Vsamp));  % Units are now Gauss.  3mT = 3V, so 1mT/V = 10 G/V
   sigBx(i) =  10*std(max(Vx1.Vsamp) - min(Vx1.Vsamp));
end
figure
plot_bars(z_positions, Bx, sigBx, 'bo');
xlabel('Z (mm)');
ylabel('Bx (G)');
title('Linmot Bx field during upward movement with 15 A motor Power Supply');

Bx_integral_15A = integrate(Bx, 2); % G-cm units when dx is 2
