I am using a multiplier phase detector like here 1to find the phase difference between two phase shifted sine signals, and I got the value of magnitude but how to find if the signal 2 is leading/laging wrt signal 1? The cosine would give a positive value for both negative and positive angles.

I also thought of checking the first sample point of both signal 1 and signal 2 to see which has greater magnitude and deduce a conclusion based on that. if (signal 1 > signal 2 => sig 2 is lagging and vice versa).

But I am trying to implement this in a stm32 and I am for some reason, not being able to do that. Is there any other robust way?

  • \$\begingroup\$ One method might be to invert one of your inputs and add the samples. The difference represents the phase difference. Basically the sum of two sines 180deg apart is 0. \$\endgroup\$
    – Kartman
    Jul 10 at 14:22
  • \$\begingroup\$ Yes, but i will be using this in a PLL(DDS + PI loop) and in Real time to constantly phase compensate. The phase is shifting towards zero but then it slips towards other direction. \$\endgroup\$
    – Rima
    Jul 10 at 14:26
  • \$\begingroup\$ Normally you’d compare zero crossings and determine which signal is leading or lagging, but nevertheless, what I described will do much the same \$\endgroup\$
    – Kartman
    Jul 10 at 14:31


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.