title: identifying phase shift between signals
body: <p>I have generated three identical waves with a phase shift in each. For example:</p>
  
  <pre><code>t = 1:10800; % generate time vector
  fs = 1; % sampling frequency (seconds)
  A = 2; % amplitude
  P = 1000; % period (seconds), the time it takes for the signal to repeat itself
  f1 = 1/P; % number of cycles per second (i.e. how often the signal repeats itself every second).
  y1 = A*sin(2*pi*f1*t); % signal 1
  phi = 10; % phase shift
  y2 = A*sin(2*pi*f1*t + phi); % signal 2
  phi = 15; % phase shift
  y3 = A*sin(2*pi*f1*t + phi); % signal 3
  
  YY = [y1',y2',y3'];
  
  plot(t,YY)
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/n9SZn.png" alt="enter image description here"></p>
  
  <p>I would now like to use a method for detecting this phase shift between the waves. The point of doing this is so that I can eventually apply the method to real data and identify phase shifts between signals. </p>
  
  <p>So far I have been thinking of computing the cross spectra between each wave and the first wave (i.e. without the phase shift):</p>
  
  <pre><code>for i = 1:3;
      [Pxy,Freq] = cpsd(YY(:,1),YY(:,i));
      coP = real(Pxy);
      quadP = imag(Pxy);
      phase(:,i) = atan2(coP,quadP);
  end
  </code></pre>
  
  <p>but I'm not sure if this makes any sense. </p>
  
  <p>Has anyone else done something similar to this? The desired outcome should show a phase shift at 10 and 15 for waves 2 and 3 respectively. </p>
  
  <p>Any advice would be appreciated. </p>