find the phase difference between two singnals

matlab code

% phase lag of sine and cosine function
% https://www.mathworks.com/help/signal/ug/cross-correlation-of-phase-lagged-sine-wave.html
rng default

t = 0:99;
x = cos(2*pi*1/12*t);  % 12 samples in one periods
y = sin(2*pi*1/12*t);
[xc,lags] = xcorr(y,x,24,'coeff');  % '24' equal to 2 periods 

stem(lags(25:end),xc(25:end),'filled')

hold on
plot (t,x)
%plot (t,y)
plot([2.5 2.55],[-1 1])

ax = gca;
ax.XTick = 0:2.5:20;