Test and Measurement Forum

New accurate and fast phase shift calculation formula

Forum for discussing PicoScope version 6 (non-automotive version)

New accurate and fast phase shift calculation formula

Postby lab!fyi » Wed Aug 16, 2017 6:10 pm

AFAIK there is no built-in phase shift calculation formula in PS6. To measure phase between two signals one either uses cursors or this formula that has been circulating on forum for a while:

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

Who has used given formula probably noticed it has some shortcomings, especially with small numbers of wfms on screen. For my work with "virtual MSO" had to come up with means to somehow make analog signal discrete using only trigonometry. This gave idea for completely different approach to phase shift calculation, which worked quite well - accuracy to acquisition natural limit and no "settle time":

((((atan(1/tan(pi*(A/10000)))/pi)+(A/10000))*-((atan(1/tan(pi*(B/10000)))/pi)+(B/10000)))+0.25)/0.002777777

accurate_phase_shift_formula.jpg


Input: 40°
newPhase(A;B): 39.86°
Cursors: 37.54°
oldPhase(A;B): 55.84°

Since this work is quite new cannot fully exclude there's room for further improvements. Suggestions are welcome.
Last edited by lab!fyi on Thu Aug 17, 2017 8:32 pm, edited 2 times in total.
lab!fyi
Advanced User
Advanced User
 
Posts: 21
Joined: Mon Dec 12, 2016 6:58 pm

Re: New accurate and fast phase shift calculation formula

Postby lab!fyi » Wed Aug 16, 2017 7:05 pm

Made test with ETS on 25MHz symmetrical squares. New formula 100% matches cursors carefully placed under substantial zoom:

accurate_phase_shift_formula__ETS.jpg


In general for formula to work wfms must have equal duty cycles at zero crossing, duty itself may differ from 50%. Consequently works with pulses of equal length:

accurate_phase_shift_formula__ETS__pulse.jpg
lab!fyi
Advanced User
Advanced User
 
Posts: 21
Joined: Mon Dec 12, 2016 6:58 pm

Re: New accurate and fast phase shift calculation formula

Postby lab!fyi » Thu Aug 17, 2017 8:27 pm

Further investigation has shown that function works on (equal duty) pulses until they overlap. When pulses do not overlap value gets stuck on maximum value just at the moment of "departure".

Input: 100kHz square, duty 1.63%.

Case 1, 5.32° degree phase shift set, pulses overlap:
accurate_phase_shift_formula__pulses_overlap.jpg
Cursors: 5.332°, Function: 5.336° (ok)


Case 2, 6.32° degree phase shift set, pulses do not overlap:
accurate_phase_shift_formula__pulses_do_not_overlap.jpg
Cursors: 6.339°, Function: 5.867° (notok)
lab!fyi
Advanced User
Advanced User
 
Posts: 21
Joined: Mon Dec 12, 2016 6:58 pm

Re: New accurate and fast phase shift calculation formula

Postby lab!fyi » Thu Aug 24, 2017 11:41 am

Since phase shift is essentially converted to PWM value it can be graphed using following formula, making use of built-in duty() function:

duty(((((atan(1/tan(pi*(A/10000)))/pi)+(A/10000))*-((atan(1/tan(pi*(B/10000)))/pi)+(B/10000))) + 0.25))/0.555555555

Example:
PS6__phase_shift_graph.jpg


What can be seen here are two signals: ChA=10kHz and ChB=10.1kHz. This results in 100Hz beat frequency and varying absolute phase difference of 0-180° that is graphed in example. Note that must be little careful with sample count - keep it reasonable otherwise processing artefacts or general sluggish performance may result.
lab!fyi
Advanced User
Advanced User
 
Posts: 21
Joined: Mon Dec 12, 2016 6:58 pm

Re: New accurate and fast phase shift calculation formula

Postby Martyn » Fri Sep 01, 2017 9:11 am

Looks interesting, need to give it a full work out on a variety of signals and conditions.

The power of maths :D
Martyn
Technical Support Manager
Martyn
Site Admin
Site Admin
 
Posts: 2716
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: New accurate and fast phase shift calculation formula

Postby lab!fyi » Wed Sep 06, 2017 7:06 am

Thanks, heres condition of severe undersmapling...

PicoScope_bode_plot.jpg


0-100MHz bode plot with external gen on coax stub filter. 100ms sweep time. Phase data unsigned. Level normalized to 0dBm full bw. Theres some underlying stuff that needs to be explained and developed further, maybe move this to "Projects" section?
lab!fyi
Advanced User
Advanced User
 
Posts: 21
Joined: Mon Dec 12, 2016 6:58 pm


Return to PicoScope 6 for Windows

Who is online

Users browsing this forum: No registered users and 1 guest