%Normaliza las series de resnueva y las filtra
clear

load N2u; N2u=N2u(1:375);
load u

t=1:375;
w=1/365;
to=ones(size(t));
E=[to;sin(2*pi*w*t);cos(2*pi*w*t)];
E=E';
xd=inv(E'*E)*E';
coef1=xd*N2u;
coef2=xd*u;

aju1=E*coef1;
aju2=E*coef2;

N2us=N2u-aju1;
us=u-aju2;
nn=(N2us-mean(N2us))/std(N2us);
nu=(us-mean(us))/std(us);

plot(t,nn,'r')
hold on
plot(t,nu)

hold on

for i=1:length(nn)-15
    nnf(i)=mean(nn(i:i+15));
        nuf(i)=mean(nu(i:i+15));

end

plot(t(8:end-8), nnf,'r')
hold on
plot(t(8:end-8), nuf)


load resnueva
nbb=resnueva(:,7);
ubb=resnueva(:,1);
nnb=(nbb-mean(nbb))/std(nbb);
nub=(ubb-mean(ubb))/std(ubb);

figure
plot(-nnb,'r')
hold on
plot(-nub)
