%% R2_Billingsley_mag
%
% Data de-spun by Max Roberts, Dartmouth
% Script by Bruce Fritz, UNH
%
% Data contained in .mat file includes
% B_IGRF.B_[east, north, down]    [Gauss]
% B_despun.B_[east, north, down]  [Gauss]
% B_spinning.B_[x,y,z]            [Gauss]
% position
% time

load 20170120-RENU2_mag_data.mat

%% Smooth data, take difference

np = 10;

Bn_smooth = fastsmooth(B_despun.B_north, np, 1, 0);
Be_smooth = fastsmooth(B_despun.B_east, np, 1, 0);
Bd_smooth = fastsmooth(B_despun.B_down, np, 1, 0);

Bn_plot = (B_despun.B_north - Bn_smooth)./1e4./1e-9;
Be_plot = (B_despun.B_east - Be_smooth)./1e4./1e-9;
Bd_plot = (B_despun.B_down - Bd_smooth)./1e4./1e-9;

%% Plot
fig = figure(1);
set(fig,'units','normalized','position',[0.6 0.1 0.4 0.8]);
tstart = 400;
tstop  = 649;

subplot(3,1,1)
plot(time,Bn_plot)
title('Despun IGRF Frame - North')
xlabel('Time (s)'); xlim([tstart tstop])
ylabel('\DeltaB (nT)'); ylim([-30 30])

subplot(3,1,2)
plot(time,Be_plot)
title('Despun IGRF Frame - East')
xlabel('Time (s)'); xlim([tstart tstop])
ylabel('\DeltaB (nT)'); ylim([-30 30])

subplot(3,1,3)
plot(time,Bd_plot)
title('Despun IGRF Frame - Down')
xlabel('Time (s)'); xlim([tstart tstop])
ylabel('\DeltaB (nT)'); ylim([-30 30])


