3

Consider the following example Simulink (Download example) system:

enter image description here

Input is a magnitude and an ever increasing angle, which will return two sine, the real and imaginary part as expected:

enter image description here

Calculating the Magntitude from real and imaginary part is no issue. Getting the angle in the domain between -pi and pi neither:

enter image description here

But I'm really struggling in calculating the original angle from the imaginary and real part. Do you have any ideas how to get rid of the discontinuity (yellow line, last picture)?

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113

3 Answers3

2

Daniel's Solution was exact what I was looking for, but in case the DSP System Toolbox is not available, like in case of my project partners, I came up with the following solution:

enter image description here

with

function [y, corr]  = phase_unwrap(zz,z,v)
%#codegen

d = diff([v,z,zz]);
if abs(d(1)) > pi
    y = sign(d(1));
    corr = -3/2*d(2);
else
    y = 0;
    corr = -3/2*d(1);
end

end

The discrete time integrator has the same sampling time as the zero-order-hold and a gain of 2*pi.

The example output is satisfying, but I still need to test it for the real case.

enter image description here

Community
  • 1
  • 1
Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
2

How about this example?

enter image description here

function [ub_ang,ang] = phase_unwrap(re, im, theta)
%#codegen

ang = atan2(im,re);

tmp = [theta ang];

uang = unwrap(tmp);

ub_ang = uang(2);

Scope1 plot is below

enter image description here

Scope plot is below.

enter image description here

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
KKS
  • 1,389
  • 1
  • 14
  • 33
  • 1
    Apart from that you need to swap imaginary and real part in the `atan` calculation and you shouldn't use `real` and `imag` as variable names, as they are in-built functions - it works great! – Robert Seifert Dec 22 '15 at 10:20
  • Tjank you for your comment~ – KKS Dec 22 '15 at 11:38
1

Use the block called unwrap. In case the toolbox is not available, this discrete implementation in simulink could be used:

enter image description here

Daniel
  • 36,610
  • 3
  • 36
  • 69