## Phase shift measurement

Forum for discussing PicoScope version 6 (non-automotive version)
jane
Newbie
Posts: 0
Joined: Sat Mar 03, 2012 12:20 pm
Location: Norway

### Phase shift measurement

To find the phase shift between two signals (Ch A and B) I:
a) Add a cycle time measurement to Ch A (or B).
b) Use cursors to measure the time delay between signal A and B.
c) Calculate the phase shift from the information above.

Is it possible to implement a measurement into PicoScope 6 that calculates the phase shift (in deg) between Ch A and B.

BR
JanE

Martyn
Posts: 3583
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

### Re: Phase shift measurement

You can do this reasonably well using Maths Channels and the following equation

acos(integral(A*B)/(sqrt(integral(A*A))*sqrt(integral(B*B))))/Pi*180

although you have to take the value after the phase settles down as the start conditions are unknown and the first part of the trace will be inaccurate.
Martyn
Technical Support Manager

jane
Newbie
Posts: 0
Joined: Sat Mar 03, 2012 12:20 pm
Location: Norway

### Re: Phase shift measurement

One word: Brilliant!
I ran a quick test connecting probe A/B before/after a filter and the phase shift read-outs matched the filter's transfer function very well.

Thank you!

BR,
JanE

Barnett
Newbie
Posts: 0
Joined: Mon Nov 07, 2016 5:20 pm

### Re: Phase shift measurement

Hello,
I am trying to get used to the math functions in 2208B scope. Can you explain the steps in the phase calculation or point me to a paper? It works well. I would like to understand the steps.
acos(integral(A*B)/(sqrt(integral(A*A))*sqrt(integral(B*B))))/Pi*180

lab!fyi
Newbie
Posts: 0
Joined: Mon Dec 12, 2016 6:58 pm
Contact:

### Re: Phase shift measurement

FYI there is newer method around:

"New accurate and fast phase shift calculation formula"
topic31641.html

Example, phase measured on 100MHz sines:

at 50GS/s: 6.387°
at ~1MS/s: 6.372° (250x below "practical" Nyquist)
Thats also absolute difference of 0.00417%

Martyn
Posts: 3583
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

### Re: Phase shift measurement

It is a correlation formula

integral(A*B)/(sqrt(integral(A*A))*sqrt(integral(B*B)))

to check A and B where 1 is positive correlation, 0 no correlation, and -1 negative correlation

before scaling to degrees.

If you also remember that integral is calculating the area under a curve, and by doing A*A you are rectifying the signal you should be able to understand the rest.
Martyn
Technical Support Manager

lab!fyi
Newbie
Posts: 0
Joined: Mon Dec 12, 2016 6:58 pm
Contact:

### Re: Phase shift measurement

Martyn wrote:If you also remember that integral is calculating the area under a curve, and by doing A*A you are rectifying the signal you should be able to understand the rest.
...and there also lies trap for young players. With this method not only duty cycles but also areas under curve must be exactly identical otherwise calculus is off. phase(A;B) measurement is integral method taken between cursors where it is more less settled:
Actual physical offset is 1.23°

Barnett
Newbie
Posts: 0
Joined: Mon Nov 07, 2016 5:20 pm

### Re: Phase shift measurement

Thanks for all who have helped on phase shift measurement.
When I use (acos(integral(A*B)/(sqrt(integral(A*A))*sqrt(integral(B*B))))/Pi*180) I get up to a 30% error.

When I use ((((atan(1/tan(pi*(A/10000)))/pi)+(A/10000))*-((atan(1/tan(pi*(B/10000)))/pi)+(B/10000)))+0.25)/0.002777777 it matches the cursors.

I would still like to understand how the first formula works.
acos(integral(A*B)/(sqrt(integral(A*A))*sqrt(integral(B*B))))/Pi*180
Would you say the formula below is what it is doing?
acos(correlation formula)/Pi*180

Thanks / Charles

lab!fyi
Newbie
Posts: 0
Joined: Mon Dec 12, 2016 6:58 pm
Contact:

### Re: Phase shift measurement

Maybe this helps a little:

https://www.eevblog.com/forum/testgear/ ... msg1106436
It's correlation formula. Will only show phase if the shape is exactly the same (except phase shift). For in-phase signals, it'll measure the similarity between waveforms (if you remove "acos" and scaling). It'll be "1" if the signals are completely the same (ignoring scale) and "0" if they're completely dissimilar. "-1" will mean the same sinal, but inverted. You can use the formula to measure how similar is your waveform to the sine wave (or any other signal you may want to use as an etalon).
Overall to understand the formula you start working "inside out". Something along these lines:

acos(integral(A*B)/(sqrt(integral(A*A))*sqrt(integral(B*B))))/Pi*180

=>

A*A
integral(A*A)
sqrt(integral(A*A)
sqrt(integral(A*A))*sqrt(integral(B*B))

A*B
integral(A*B)

etc. After you get a visual picture what each part does on specific signal you can put it together and understand. Brain likes visual ques. So even running seemingly basics on known signal like A*A can help sometimes.

Barnett
Newbie
Posts: 0
Joined: Mon Nov 07, 2016 5:20 pm

### Re: Phase shift measurement

Thanks very much for explaining this. This is similar to the formula for rms [ sqrt(integral((A)^2)/T) ]
It is easy to see this because the T is the amount of time along the X axis of the display. In the correlation formula how is it able to work without a T? Thanks / Barnett

lab!fyi
Newbie
Posts: 0
Joined: Mon Dec 12, 2016 6:58 pm
Contact:

### Re: Phase shift measurement

BTW there is important topic about TRMS, there are some tricks to getting it work correctly should you experiment with graphing:
topic29531.html

Barnett
Newbie
Posts: 0
Joined: Mon Nov 07, 2016 5:20 pm

### Re: Phase shift measurement

Hello, Would you check to see if my math is correct. Almost have it.

phase shift degrees = acos(integral(A*B)/(sqrt(integral(A*A))*sqrt(integral(B*B))))/Pi*180

Correlation formula:
(integral(A*B)/(sqrt(integral(A*A))*sqrt(integral(B*B))))
(integral(A*B)/(A rms*B rms))
this will give a value between -1 and 1 showing how similar the two waves are.
1 would mean the signals are identical.
0 would mean the two are completely dissimilar.
-1 would mean identical signals but opposite polarity.
This is also the power factor cos Θ.

Example:
E & I in a power xfmr to see the phase shift.
V: 115 vac @ 60 Hz
I: 180 ma rms
Phase shift: 44 degrees = 0.768 radians

acos(corr)/Pi*180
0.768/pi=0.2446
0.2446 * 180 = 44 degrees

correlation = (integral(A*B)/(A rms*B rms))
0.719 = (integral(A*B)/(115 *0.180))
0.719 = (integral(A*B)/(20.7))
0.719 = 14.88/20.7

How do you get 14.88 from integral(A*B)

lab!fyi
Newbie
Posts: 0
Joined: Mon Dec 12, 2016 6:58 pm
Contact:

### Re: Phase shift measurement

Must correlate correlable What you are fundamentally doing here is comparing maximum potential output power (watts) to current output. Which is directly tied to phase between voltage and current.

Code: Select all

``````TRMS(A) = sqrt(integral(A^2)/T)
TRMS(B) = sqrt(integral(B^2)/T)
√P(A*B) = sqrt(integral(A*B)/T)*
ABS(P(A*B)) = sqrt(integral(A*B)/T)^2)
P(A*B) = integral(A*B)/T
MAX(P(A*B)) = (sqrt(integral(A^2))*sqrt(integral(B^2)))/T``````
*n/a with negative integral

Maximum possible output:
Attachments

Barnett
Newbie
Posts: 0
Joined: Mon Nov 07, 2016 5:20 pm

### Re: Phase shift measurement

Thanks very much for explaining this. In your code you use T. Where is the T in the equation below?
To calculate an integral you have to have a T don't you.

phase shift degrees = acos(integral(A*B)/(sqrt(integral(A*A))*sqrt(integral(B*B))))/Pi*180

lab!fyi
Newbie
Posts: 0
Joined: Mon Dec 12, 2016 6:58 pm
Contact:

### Re: Phase shift measurement

MAX(P(A*B))

Code: Select all

``integrate (115*sin(x)) * (0.18*sin(x)) * (2/pi); 0 to pi``
https://www.wolframalpha.com/input/?i=i ... );+0+to+pi

P(A*B)

Code: Select all

``integrate (115*sin(x)) * (0.18*sin(x-44pi/180)) * (2/pi); 0 to pi``
https://www.wolframalpha.com/input/?i=i ... );+0+to+pi
Attachments
phase_shifted.gif (2.86 KiB) Viewed 2668 times
phase_sync.gif (2.36 KiB) Viewed 2668 times