close all
clear all

filename = '2023.06.18T16.19.13';

load([filename '.mat']);

idx = 1:length(Time_DateNum);
idx = 57500:62500;
figure('Position',[1440 133 1008 1205]);
ah1 = subplot(3,1,1);
plot(Time_DateNum(idx),PC_Voltage(idx));
hold all
ylabel('Battery Voltage (V)');
grid on;
datetick('x');


ah2 = subplot(3,1,2);
plot(Time_DateNum(idx),PC_LoadCurr(idx));
hold all
ylabel('Battery Current (A)');
grid on;
datetick('x');


ah3 = subplot(3,1,3);
plot(Time_DateNum(idx),PC_LoadCurr(idx).*PC_Voltage(idx));
hold all
ylabel('Battery Power (W)');
grid on;
datetick('x');
xlabel('time (hh:mm:ss)');


linkaxes([ah1 ah2 ah3],'x');

idx = find(~isnan(XB_XAccel));
window = 2500;
noverlap = 0;
f = [0.05:.001:2];
fs = 50;  %Hz
[pxx,fxx] = pwelch(XB_XAccel(idx),window,noverlap,f,fs)
[pyy,fyy] = pwelch(XB_YAccel(idx),window,noverlap,f,fs)
[pzz,fzz] = pwelch(1+XB_ZAccel(idx),window,noverlap,f,fs)

figure
semilogx(fxx,pxx)
hold all
semilogx(fyy,pyy)
semilogx(fzz,pzz)
legend('x','y','z');
title("Power Spectral Density of Linear Accelerations in Storm");
xlabel('Hz');
ylabel('g^2/Hz');
grid on;


t_datenum = Time_DateNum(idx);
a_x = XB_XAccel(idx);
a_y = XB_YAccel(idx);
a_z = XB_ZAccel(idx);

save('BuoyLinearAccelerations.mat','t_datenum','a_x','a_y','a_z','fs');

