%filtro
addpath /Francia/Velocidades
addpath /Francia/Candela
addpath /Francia/Estadisticas

load Y1n
load N1n
load N2n
load Y3n
load A2n
load resnueva
u=resnueva(:,1);
load /Francia/Velocidades/uvmoy
u=uvmoy(4,1:377)';u=completo_series1(u,5);
u=u(2:end-1);
v=uvmoy(4,378:end)';v=completo_series1(v,5);
v=v(2:end-1);
load A1v
load A1u
for i=1:length(A1v)-10
    A1vm(i)=mean(A1v(i:i+10));
        A1um(i)=mean(A1u(i:i+10));

end
%A1fil=[A1um(1:end-15)',A1vm(1:end-15)'] ;
A1fil=[A1um',A1vm'] ;
load N3v
load N3u
for i=1:length(N3v)-10
    N3vm(i)=mean(N3v(i:i+10));
        N3um(i)=mean(N3u(i:i+10));

end
N3fil=[N3um',N3vm'] ;

load S3v
load S3u
for i=1:length(S3v)-10
    S3vm(i)=mean(S3v(i:i+10));
        S3um(i)=mean(S3u(i:i+10));

end
S3fil=[S3um',S3vm'] ;

load N4v
load N4u
for i=1:length(N4v)-10
    N4vm(i)=mean(N4v(i:i+10));
        N4um(i)=mean(N4u(i:i+10));

end
N4fil=[N4um',N4vm'] ;


load S4v
load S4u
for i=1:length(S4v)-10
    S4vm(i)=mean(S4v(i:i+10));
        S4um(i)=mean(S4u(i:i+10));

end
S4fil=[S4um',S4vm'] ;


for i=1:length(v)-10
    vm(i)=mean(v(i:i+10));
    um(i)=mean(u(i:i+10));
end
adcpfil=[um',vm'];

Y3=Y3n(1:338);
load A2u
load A2v
for i=1:length(A2v)-10
    A2um(i)=mean(A2u(i:i+10));
    A2vm(i)=mean(A2v(i:i+10));
end
A2fil=[A2um',A2vm'];


load N1u
load N1v
load N2u
load N2v
load S1u
load S1v
load Y2u
load Y2v
load Y3u
load Y3v
load A4u
load A4v
for i=1:length(N1v)-10
    N1um(i)=mean(N1u(i:i+10));
    N1vm(i)=mean(N1v(i:i+10));
    N2um(i)=mean(N2u(i:i+10));
    N2vm(i)=mean(N2v(i:i+10));
    S1um(i)=mean(S1u(i:i+10));
    S1vm(i)=mean(S1v(i:i+10));
    Y2um(i)=mean(Y2u(i:i+10));
    Y2vm(i)=mean(Y2v(i:i+10));
    Y3um(i)=mean(Y3u(i:i+10));
    Y3vm(i)=mean(Y3v(i:i+10));
    A4um(i)=mean(A4u(i:i+10));
    A4vm(i)=mean(A4v(i:i+10));
       
end
N1fil=[N1um',N1vm'];
N2fil=[N2um',N2vm'];
S1fil=[S1um',S1vm'];
Y2fil=[Y2um',Y2vm'];
Y3fil=[Y3um',Y3vm'];
A4fil=[A4um',A4vm'];


load Y1u
load Y1v

for i=1:length(Y1u)-10
    Y1mu(i)=mean(Y1u(i:i+10));
    Y1mv(i)=mean(Y1v(i:i+10));
end
Y1fil=[Y1mu',Y1mv'];
load A4n
for i=1:length(N1n)-15
    N1nf(i)=mean(N1n(i:i+15));
    N2nf(i)=mean(N2n(i:i+15));
    Y3nf(i)=mean(Y3n(i:i+15));
    A4nf(i)=mean(A4n(i:i+15));
end
for i=1:length(A2n)-15
    A2nf(i)=mean(A2n(i:i+15));
end
load Y1n
for i=1:length(Y1n)-15
    Y1nf(i)=mean(Y1n(i:i+15));
end

load tt
tt1=tt;
tt=tt(8:end-8);
x=tt1(1):30:tt1(end);
a=datestr(x,12);

subplot(2,1,1)
%title('r=-0.66')
plot(tt,N1nf)
hold on
plot(tt1,N1n)
hold on
plot(tt,N2nf,'r')
hold on
plot(tt1,N2n,'r')
hold on
plot(tt1(121:end),Y1n,'g')
hold on
plot(tt(121:end),Y1nf,'g')
set(gca,'xlim',[min(tt1)-3 max(tt1)+3],'ylim',[-20 30],'xtick',x,'xticklabel',[])
ylabel('\delta u cm/s','fontsize',12)
%xlabel('r=-0.8')
subplot(2,1,2)
plot(tt(1:length(A2nf)),A2nf)
hold on
plot(tt1(1:length(A2n)),A2n)

hold on
plot(tt,Y3nf,'r')
hold on
plot(tt1,Y3n,'r')
set(gca,'xlim',[min(tt1)-3 max(tt1)+3],'ylim',[-20 20],'xtick',x,'xticklabel',a,'fontsize',11)
ylabel('\delta u cm/s','fontsize',12)


figure
%plot(tt,N1fil(:,1),'c')
%hold on
plot(tt,N2fil(:,1),'linewidth',2)
hold on
plot(tt,Y2fil(:,1),'k','linewidth',2)
hold on
plot(tt,Y3fil(:,1),'c','linewidth',2)
ylabel('U (cm/s)', 'fontsize',14)
set(gca,'xlim',[min(tt)-3 max(tt)+3],'xtick',x,'xticklabel',a,'fontsize',12)

ta=tt(1:length(A2nf));
[P,S,MU]=polyfit(ta,A2nf',3);
ya=polyval(P,ta,[],MU);
[P,S,MU]=polyfit(tt,Y3nf',3);
yy=polyval(P,tt,[],MU);

figure
plot(tt,Y3nf)
hold on
plot(tt,yy)
hold on
plot(ta,A2nf,'r')
hold on
plot(ta,ya,'r')

y3sin=Y3nf'-yy;
a2sin=A2nf'-ya;

figure
plot(y3sin)
hold on
plot(a2sin,'r')