# Angle of complex numbers: how to get continuous plot?

I’m trying to plot the phase of a complex transfer function (as in control engineering) using the angle function.

So essentially, if I have a transfer function g(s), I compute the angle (with rad2deg conversion) of g(j\omega) for a number of different frequencies \omega (j=\sqrt{-1}). Here is what I get:

This looks ugly, and I want to avoid the jumps in the phase (angle) when the phase passes through -180^\circ. I.e., instead of jumping to +180^\circ, I want it to continue to a negative value past -180^\circ.

Question: Is there a simple/efficient/smart way to do this?

Note: This is a somewhat complex transfer function from a system of PDEs, and does not fit into the ControlSystems framework. [Unless ControlSystems allows me to pass on frequency and magnitude and phase instead of the system, and then does it form me.]

I am afraid you need to write the code that does this yourself… I did that in the past, should only be 5 or 10 lines of code, but I don’t have the code available right now…

1 Like

Would the unwrap() function from DSP.jl help?

3 Likes

Yes, unwrap seems to do the trick:

The only “problem” (unavoidable?) is that I had to compute the phase in 10^5 datapoints… If I use fewer, say, 10^4, I get the following…

…which kind of makes sense: it is almost like an “aliasing” effect where the phase falls more than 360^\circ for each datapoint, I guess.

1 Like

Of course, if I “cheat” and limit the ylims range, I can get away with 10^4 data points…

Nice plots for transfer functions from tube-side, shell-side inlets to tube-side, shell-side outlets in a co-current heat exchanger (with fictitious numbers).

In reality, there may not be these “comb filter” effects if I include heat diffusion and heat capacity of heat exchanger walls…

Maybe a polar plot for the angle, with radius as 1/omega will look nice

1 Like

Not quite clear to me what you mean. I compute some complex numbers as a function of omega. Then I compute the magnitude and phase angle of the complex numbers, and plot these as a function of omega (Bode plot).

Another common plot is the Nichols plot, where one plots magnitude as a function of phase angle with omega as parameter.

A third common plot is a Nyquist plot, where the imaginary value is plotted as a function of the real part, again with omega as parameter.

Do you prefer to a Nichols plot, a Nyquist plot, or something else?

What I meant was a polar plot with:

r = 1/ω or 1/log(ω)
θ(r) = angle(ω)


No magnitude involved (which is probably what most are interested in, but appears in the other plot).
Don’t think this plot has a name yet (probably for good reason)