BASIC CODE FOR PHASE CALCULATION by John F. Ehlers
This BASIC code finds the real part of the phasor (the horizontal component) and the imaginary part
of the phasor (the vertical component) by summing the product of the price and the two sinusoids over
one full cycle of the dominant cycle. The arctangent function locates the phase to be in the first or fourth
quadrant. The quadrant ambiguity is removed by adding p to the phase angle is the real part is negative.
A value of p/2 is arbitrarily added to the computed phase so the start of the cycle is referenced to a
sinewave. The computed phase angle is then tested to fall within the range from zero to 2p. The phase
is then converted to degrees from radian measure.