velAvg=[];
angAvg=[];
velTim=[];
angTim=[];
for i=5:20

Navg3 = 1+2*i;
[Tyy,~] = tfe2(ETMYZ,ITMYZ ,1/sampf, Navg3);
[Txx,F] = tfe2(ETMXZ,ITMYZ,1/sampf, Navg3);

maxfX=Af(find(AETMXZ==max(AETMXZ),1));
indexX=find(F==(0.0602+sign(F-0.0602)*min(abs(F-0.0602))));
phaseX=angle(Txx(indexX))*180/pi;
delta_t_X=phaseX/360/maxfX;

maxfY=Af(find(AETMYZ==max(AETMYZ),1));
indexY=find(F==(0.0602+sign(F-0.0602)*min(abs(F-0.0602))));
phaseY=angle(Tyy(indexY))*180/pi;
delta_t_Y=phaseY/360/maxfY;

angAvg=[angAvg atan(delta_t_Y/delta_t_X)*180/pi];
velAvg=[velAvg 4e3/sqrt((delta_t_X)^2+(delta_t_Y)^2)];

scale=AETMYZ_out(find(AETMYZ_out==max(AETMYZ_out),1))/ABRS(find(ABRS==max(ABRS),1));
% vel=scale*2*pi*maxfX*sin(ang*pi/180);
end
binLength=1000;
for i=5:floor(length(ETMYZ)/binLength)-6

Navg3 = 13;
[Tyy,~] = tfe2(ETMYZ(i*binLength:(i+1)*binLength),ITMYZ(i*binLength:(i+1)*binLength) ,1/sampf, Navg3);
[Txx,F] = tfe2(ETMXZ(i*binLength:(i+1)*binLength),ITMYZ(i*binLength:(i+1)*binLength),1/sampf, Navg3);

maxfX=Af(find(AETMXZ==max(AETMXZ),1));
indexX=find(F==(0.0602+sign(F-0.0602)*min(abs(F-0.0602))));
phaseX=angle(Txx(indexX))*180/pi;
delta_t_X=phaseX/360/maxfX;

maxfY=Af(find(AETMYZ==max(AETMYZ),1));
indexY=find(F==(0.0602+sign(F-0.0602)*min(abs(F-0.0602))));
phaseY=angle(Tyy(indexY))*180/pi;
delta_t_Y=phaseY/360/maxfY;

angTim=[angTim abs(atan(delta_t_Y/delta_t_X)*180/pi)];
velTim=[velTim 4e3/sqrt((delta_t_X)^2+(delta_t_Y)^2)];

scale=AETMYZ_out(find(AETMYZ_out==max(AETMYZ_out),1))/ABRS(find(ABRS==max(ABRS),1));
% vel=scale*2*pi*maxfX*sin(ang*pi/180);
end
figure(11)
plot(angAvg)
ylabel('Angle (degrees)')
xlabel('Averages')
grid on

figure(12)
plot(velAvg)
ylabel('Velocity (m/s)')
xlabel('Averages')
grid on

figure(13)
plot(angTim)
ylabel('Angle (degrees)')
xlabel('Time (binLengths)')
grid on

figure(14)
plot(velTim)
ylabel('Velocity (m/s)')
xlabel('Time (binLengths)')
grid on