function P = interphase(PB,PA,FB,FBI,FA,FPlen,sr)

%Hop size in seconds
T = 128/sr;

FBI=[FBI FA];

phi = zeros(1,FPlen+1);
P = zeros(1,FPlen);
ftemp=FB(end)+FBI(1);

phi(1) = PB(end)+pi*T*(ftemp);

for n=2:(FPlen+1)
    
    ftemp=ftemp+FBI(n-1)+FBI(n);
    phi(n)=phi(1)+pi*T*ftemp;
    
end
phi=mod(phi,2*pi);

% erphi=PA(1)-phi(end);
% 
%  if erphi<(-pi)
%      p=erphi+2*pi;
%  elseif erphi>pi
%      p=erphi-2*pi;
%  else
%      p=erphi;
%  end
% 
% for n=1:(FPlen+1)
%     P(n)=phi(n)+(n/(FPlen+1))*p;
%     
% end
%     
%     P=P(1:end-1);
%     P=mod(P,2*pi);

P=phi(1:end-1);


end
