close all
clear all

b = 14000;
dir = './Feb17ValidationResults/';
load([dir 'Feb17-ValidationResults_Cd2p5_b' num2str(b) 'Quadratic']);

t = dt:dt:tf;

x = 0;
z = -30;
ux = NaN(1,length(t)); uy = NaN(1,length(t)); uz = NaN(1,length(t));
ux0 = NaN(1,length(t)); uy0 = NaN(1,length(t)); uz0 = NaN(1,length(t));
eta0a = NaN(1,length(t));

for i = 1:length(t)
    [ux(i) uy(i) uz(i)] = vel(wave,x,z,t(i));  
    [ux0(i) uy0(i) uz0(i)] = vel(wave,x,0,t(i)); 
    eta0a(i) = eta(wave,x,t(i));
    i
end

x_particle = cumtrapz(t,ux);
z_particle = cumtrapz(t,uz);


y = get(Plate,'x');
ydot = get(Plate,'xdot');
yddot = get(Plate,'xddot');

plate_surge = y(:,1)-mean(y(:,1));
plate_heave = y(:,3)-mean(y(:,3));
plate_surge_vel = ydot(:,1);
plate_heave_vel = ydot(:,3);


water_relx = plate_surge_vel'-ux;
water_relz = plate_heave_vel'-uz;


x_particle = x_particle-mean(x_particle);
z_particle = z_particle-mean(z_particle);


[f, Pxx_platemotions] = tseries2spectrum(t,x_particle,2);
[f, Pzz_platemotions] = tseries2spectrum(t,z_particle,2);

[f, Pxx_watervelocity] = tseries2spectrum(t,ux,2);
[f, Pzz_platevelocity] = tseries2spectrum(t,uz,2);



[f, water_rel_Pxx] = tseries2spectrum(t,water_relx,4);
[f, water_rel_Pzz] = tseries2spectrum(t,water_relz,4);




figure('Position',[520   146   897   952]);
subplot(3,1,1)
plot(t,eta0a)
xlabel('time (s)')
ylabel('$\eta$ (m)','interpreter','Latex');
title(['x = ' num2str(x) ' m     z = ' num2str(z) ' m']);
subplot(3,1,2)
plot(t,ux,t,uy,t,uz)
legend('ux','uy','uz');
xlabel('time (s)')
ylabel('vel (m/s)');
subplot(3,1,3)
plot(t,ux0,t,uy0,t,uz0)
legend('ux','uy','uz');
xlabel('time (s)')
ylabel('vel at surface (m/s)');


figure('Position',[520   146   897   952]);
plot(t,x_particle,t,z_particle)
legend('x motions','z motions');



figure('Position',[520   146   897   952]);
plot(f,Pxx,f,Pzz)
legend('x motions','z motions');
set(gca,'xlim',[0 .8]);

figure('Position',[520   146   897   952]);
plot(t,[water_relx ; water_relz]);


figure('Position',[520   146   897   952]);
plot(f,water_rel_Pxx,f,water_rel_Pzz)
legend('water x velocity','water z velocity');
set(gca,'xlim',[0 .8]);

figure('Position',[520   146   897   952]);
plot(f,water_rel_Pxx_platevelocity,f,water_rel_Pzz_platevelocity)
legend('relative x velocity','water z velocity');
set(gca,'xlim',[0 .8]);