%*****************************************************************
% Decorrelate wind and motion data. Sequentially remove correlation
% between wind and platform acceleration/velocity for each axis. Cross
% correlation coefficients computed as in Edson 2011 GASEX paper.
Cua = cov(detrend(uvw(1,:)),detrend(Plat(1,:)));
muua = Cua(1,2)/Cua(2,2);
uvw(1,:) = uvw(1,:) - muua*detrend(Plat(1,:));
Cuv = cov(detrend(uvw(1,:)),detrend(uvwplat(1,:)));
muuv = Cuv(1,2)/Cuv(2,2);
uvw(1,:) = uvw(1,:) - muuv*detrend(uvwplat(1,:));

Cva = cov(detrend(uvw(2,:)),detrend(Plat(2,:)));
muva = Cva(1,2)/Cva(2,2);
uvw(2,:) = uvw(2,:) - muva*detrend(Plat(2,:));
Cvv = cov(detrend(uvw(2,:)),detrend(uvwplat(2,:)));
muvv = Cvv(1,2)/Cvv(2,2);
uvw(2,:) = uvw(2,:) - muvv*detrend(uvwplat(2,:));

Cwa = cov(detrend(uvw(3,:)),detrend(Plat(3,:)));
muwa = Cwa(1,2)/Cwa(2,2);
uvw(3,:) = uvw(3,:) - muwa*detrend(Plat(3,:));
Cwv = cov(detrend(uvw(3,:)),detrend(uvwplat(3,:)));
muwv = Cwv(1,2)/Cwv(2,2);
uvw(3,:) = uvw(3,:) - muwv*detrend(uvwplat(3,:));
%*****************************************************************

% % Cwa = cov(detrend(uvw(3,:)),detrend(Plat(1,:)));
% % muwa = Cwa(1,2)/Cwa(2,2);
% % uvw(3,:) = uvw(3,:) - muwa*detrend(Plat(1,:));
% % Cwa = cov(detrend(uvw(3,:)),detrend(Plat(2,:)));
% % muwa = Cwa(1,2)/Cwa(2,2);
% % uvw(3,:) = uvw(3,:) - muwa*detrend(Plat(2,:));
% % Cwv = cov(detrend(uvw(3,:)),detrend(uvwplat(1,:)));
% % muwv = Cwv(1,2)/Cwv(2,2);
% % uvw(3,:) = uvw(3,:) - muwv*detrend(uvwplat(1,:));
% % Cwv = cov(detrend(uvw(3,:)),detrend(uvwplat(2,:)));
% % muwv = Cwv(1,2)/Cwv(2,2);
% % uvw(3,:) = uvw(3,:) - muwv*detrend(uvwplat(2,:));
% % Cwv = cov(detrend(uvw(3,:)),detrend(uvw(1,:)));
% % muwv = Cwv(1,2)/Cwv(2,2);
% % uvw(3,:) = uvw(3,:) - muwv*detrend(uvw(1,:));
% % Cwv = cov(detrend(uvw(3,:)),detrend(uvw(2,:)));
% % muwv = Cwv(1,2)/Cwv(2,2);
% % uvw(3,:) = uvw(3,:) - muwv*detrend(uvw(2,:));
% % Try correction on c', q' and t'
% Cwa = cov(detrend(Licor_H2O),detrend(Plat(3,:)));
% muwa = Cwa(1,2)/Cwa(2,2);
% Licor_H2O = Licor_H2O - muwa*detrend(Plat(3,:));
% 
% Cwa = cov(detrend(Licor_CO2),detrend(Plat(3,:)));
% muwa = Cwa(1,2)/Cwa(2,2);
% Licor_CO2 = Licor_CO2 - muwa*detrend(Plat(3,:));
% 
% Cwa = cov(detrend(Tsonic),detrend(Plat(3,:)));
% muwa = Cwa(1,2)/Cwa(2,2);
% Tsonic = Tsonic - muwa*detrend(Plat(3,:));
