user190055
user190055

Reputation: 1

How to expand atan2 to plus/minus 3pi

I want to estimate the phase of harmonic distorted tones when having input tones with random initial phase within [-pi;pi]. I used atan2, build-in function of Matlab, however the phase jump at -pi or pi makes my calculation of phase difference having trouble.

The problem is as follow: there is a nonlinear system, and I want to estimate system's response (amplitude and phase responses). I insert many tones as x[n] = Acos(2pifn*t+b), where fn is frequency, b is the initial random phase within [-pi;pi], and it changes with various tones. If a tone has initial phase b, then 2nd order harmonic distortion (HD) has phase of c=2b, and 3rd HD has phase of d=3b. The phase differences of the HD2 and HD3 could be c/2-b and d/3-b, respectively. Because of the memory effect of the system, the phase differences are no longer zero.

Issues: if the phase of input signal is large, e.g., 70 degree, then HD3 phase is 210 degree, when the phase angle >180, atan2 operation makes a jump to -180 and the HD3 phase become -150 degree instead of 210. Theoretically, cosd(210) = cosd(-150). However, what I want to find is the phase difference. That why, (-150/3-70) leads to a wrong results (it should be 0 if there is no memory effect). Similar situation for the case if input signal has large negative phase and for both HD2 and HD3. The major cause is antan2 limitation of [-pi;pi], and I want to expand to [-3pi;3pi].

Please help.

Thank you very much. Regards

Upvotes: 0

Views: 165

Answers (1)

bg2b
bg2b

Reputation: 1979

The function you want is unwrap, e.g.,

>>> angles=[-0.7*pi -0.9*pi 0.9*pi 0.7*pi]
angles =
  -2.1991e+00  -2.8274e+00   2.8274e+00   2.1991e+00
>>> unwrap(angles)/pi
ans =
  -7.0000e-01  -9.0000e-01  -1.1000e+00  -1.3000e+00

Upvotes: 1

Related Questions