I tried to help someone over at
Pico forum with some math stuff that ended up with creating excessive test environment
Thought share it here also maybe useful to someone. Subject is taking apart this formula:
acos(integral(A*B)/(sqrt(integral(A^2))*sqrt(integral(B^2))))/Pi*180Which does give phase shift between two signals with matching wfm shape. On closer inspection it turned out to be based on calculation of
power.
Interesting quote from wiki:
As described above, the term average power refers to the average value of the instantaneous power waveform over time. As this is typically derived from the root mean square (RMS) of the sine wave voltage,[6] it is often referred to as "RMS power" or "watts RMS", but this is incorrect: it is not the RMS value of the power waveform (which would be a larger, but meaningless, number).[7][8][9][10] (The erroneous term "watts RMS" is actually used in CE regulations.[11])
Screenshot of test setup,
saved env attached:
Input signal:
115V AC RMS
180mA AC RMSCurrent lagging by
45°On the
left screen screen measurements are taken by built-in measurements except phase which is my own formula:
((((atan(1/tan(pi*(A/10000)))/pi)+(A/10000))*-((atan(1/tan(pi*(B/10000)))/pi)+(B/10000)))+0.25)/0.002777777...which converts phase to PWM that will give better reading than discussed formula when averaged (incl. on subsampled signals).
On the
middle screen:
TRMS(A) = sqrt(integral(A^2)/T)
TRMS(B) = sqrt(integral(B^2)/T)
P(A*B) = integral(A*B)/T
MAX(P(A*B))) = sqrt(integral(A^2))*sqrt(integral(B^2)))/T
oldPhase(A,B) = acos(integral(A*B)/(sqrt(integral(A^2))*sqrt(integral(B^2))))/Pi*180On the
right screen some inner components are visualized and formulas written on screenshot.
Now inner workings of formula are exposed and can see it is based on dividing current instantaneous power with maximum possible instantaneous power (zero phase shift) and converting reading to degrees at each sample point.
For reference, since example is
with sines then sanity check:
115*0.18*cos(45*Pi/180)=14.64W
115*0.18=20.7W
acos(14.64/20.7)/Pi*180=45°Edit, sanity check 2 with WolframAlpha:
integrate (115*sin(x)) * (0.18*sin(x-45pi/180)) * (2/pi); 0 to piintegrate (115*sin(x)) * (0.18*sin(x)) * (2/pi); 0 to piSuch hands-on visualizations with physical setups involved have helped myself also a lot to get back on track with math I mostly ignored in school (largely due to math teacher nice (.)(.) of course).