1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Nyquist Diagram from Data

  1. Aug 25, 2014 #1
    1. The problem statement, all variables and given/known data

    I'm trying to make a Nyquist diagram based on experimental data obtained of the gain and phase of a high-pass RC filter which has the transfer function:

    ##\frac{V_{out}}{V_{in}}=\frac{R}{R+1/(j \omega C)}=\frac{1}{1-j\omega_0/\omega}##

    Here are the superimposed experimental and theoretical Bode plots:


    And here is the theoretical Nyquist plot I made by using the equation above with Matlab's nyquist() function:


    So how can I make an experimental Nyquist plot (using the two sets of data obtained on amplitude and phase of the filter)?

    3. The attempt at a solution

    Unfortunately I couldn't get any help with this problem so far and I haven't found anything relevant online.

    So, I have 3 vectors containing the collected data (gain in dB, phase in degrees, frequency in Hertz). How can I plot the Nyquist diagram using the data and NOT the transfer function? :confused:

    Is there a simple way that Matlab can turn my data into a Nyquist plot? Or do I need to do everything manually? If it has to be done manually, then how should I approach this?

    Any explanation, sample code, or perhaps links would be greatly appreciated.

    P. S. I've attached my data just in case.

    Attached Files:

  2. jcsd
  3. Aug 25, 2014 #2
    If your system doesn't have any zeros or poles at the origin, then its Nyquist diagram is just its Bode plot in polar form with its complex conjugate superimposed on top of it, so if you have your gain (in linear magnitude) and phase (in radians) in a couple of vectors, then one half of the Nyquist diagram is simply given by:

    Code (Text):

    z = gain.*exp(j*phase);
    You can complete it using:
    Code (Text):

    You'll have to mentally add the direction, but that should be simple enough.
  4. Aug 25, 2014 #3

    rude man

    User Avatar
    Homework Helper
    Gold Member

    For starters, this is not in the correct form. You need to rewite your transfer function so ω appears in the denominator as a term in ω, not 1/ω. At least, that is the convention. Whether you can proceed the way you did is questionable to me.
  5. Aug 25, 2014 #4
    I assume you're talking about the form that shows break frequencies for use in, for instance, drawing Bode plots using asymptotic approximations. That form isn't necessarily "correct", or even good, for drawing Nyquist diagrams. You can often find a much more convenient polar form of the transfer function for these, i.e. it's not always better to draw Bode plots first and then use them to sketch the Nyquist diagram (Edit: Just to elaborate, straight lines in Bode plots aren't that great when drawing in polar form).

    In any case, the OP's question was about plotting a Nyquist diagram from a data set, not a transfer function.
    Last edited: Aug 25, 2014
  6. Aug 26, 2014 #5
    Thank you for the helpful post Miles. But how would you modify the code if the transfer function contains a zero/pole at the origin?

    For instance I tried your method for an LC resonant circuit (the notch filter) which had a transfer function of:

    ##\frac{V_{out}}{V_{in}} = \frac{R_2}{R_2+z_p}##

    with ##z_p = \frac{R_p}{1+jR_p(\omega C -\frac{1}{\omega L})}##

    It simplifies to ##\therefore \frac{R_2 s}{R_2 s + R_ps + (1/C) - (1/L)}## (s=jω)

    Clearly it has a zero at the origin. In fact here is the diagram I got when I tried using that code (magenta is the experimental, blue is the theoretical):


    I have the same problem with plotting Nyquist diagram of LC bandpass filters. I'm not quite sure why that happens and how to fix it. :confused:

    Attached Files:

  7. Aug 27, 2014 #6
    Actually in the previous plot value of Rp was not correct, when I correct that the two plots almost completely overlap. However in the experimental diagram why do we have these straight lines tangential to the curve?

    Attached Files:

    Last edited: Aug 27, 2014
  8. Aug 27, 2014 #7
    Similarly, I tried to make a Nyquist diagram of a bandpass filter with transfer function:

    ##\frac{R_1}{R_1 + R_s + sL+1/sC}## (R1=83Ω, L=10mH, C=22nF, Rs=20Ω). Once again it has a zero at the origin. This is what I got using experimental data (not the TF):


    (Magenta is the experimental one)

    What is causing the straight line at the center, and how can we get rid of it?

    Attached Files:

  9. Aug 27, 2014 #8
    You don't have to modify it, you just have to remember that the frequency response of the system only gives part of its Nyquist diagram. That fact is more important when you have a zero or pole at the origin, because you then have to change the Nyquist path to "go around" that zero or pole, which either gives an arc around the origin or out at infinity, respectively, in your Nyquist diagram:
    What does the Nyquist plot look like for a system with poles at the origin?

    I'm not exactly sure what you're doing in those plots - mine look very different. Maybe you could post your source code? (use CODE tags).

    They are, however, going to look a bit odd for the data sets you've provided. You only have a couple of data points at the resonance frequency of your filters, which isn't going to make for a great Bode plot or Nyquist diagram. You should have a higher resolution around where the magnitude/phase starts changing rapidly with frequency. 'plot' in MATLAB does linear interpolation between points, so you can get some odd looking graphs if you're not careful.

    On another note, when uploading data sets, it's a good idea to use a standard format, like delimiter-separated values. MATLAB, for instance, can export workspace variables as comma-separated values in an ASCII file using the command 'csvwrite' (not with the greatest accuracy, but still).
  10. Aug 27, 2014 #9
    Here's my source code for the bandpass filter:

    Code (Text):
    gain=10.^((1/20).*[-59.047 -57.164 etc...]);

    % Experimental Nyquist plot

    phase=0.0174532.*[90.029 89.812 etc...];

    plot([z;conj(z(end:-1:1))], 'm', 'LineWidth', 2);

    % Theoretical plot for comparison

    hold on


    s = tf('s');

    sys = R1/(R1+n);
    nyquist(sys, '--')
    For phase and amplitude I just used the data attached to the previous post (the actual data are in degrees and dB respectively so they are multiplied by a conversion factor).

    Yes, I did use separated values when entering the data set. I've attached the experimental Bode plot (gain being on the vertical axis).

    So how is your plot different from mine? :confused: Did you use a different code??

    P.S. The transfer function for this filter was:

    ##T= \frac{R_1}{R_1 + z_s}## where ##z_s=R_s \left[ 1+j(\frac{\omega L}{R_s}) - \frac{1}{\omega R_s C} \right]##

    The series resistance is ##20 \Omega## and ##R_1=82 \Omega##, ##L= 10 mH##, ##C=22 nF##.

    Attached Files:

    • expr.jpg
      File size:
      11.5 KB
    Last edited: Aug 27, 2014
  11. Aug 27, 2014 #10
    You've written MATLAB commands directly into your 'Data.txt' file. When I enter those commands in my MATLAB workspace, I get gain and phase column vectors. In your other files, they're row vectors. This is why I suggested you use, for instance, 'csvwrite' to export data instead.

    Code (Text):
    is meant to work with column vectors (since it just simply appends one column vector in reverse order to another). If you try using it for row vectors, you'll give 'plot' a 2 by something complex matrix, which it will try to plot column-wise.

    For row vectors, you can use this instead:
    Code (Text):
    plot([z conj(z(end:-1:1))])
    This works for both cases:
    Code (Text):

    hold on
    But again, these are still going to look terrible since you have so few data points around the resonance frequencies of your filters.
  12. Aug 28, 2014 #11
    Thanks for the remark, I made the correction to all my plots.

    But are you sure this is because there is not have enough data points around resonance? Because for the previous RC circuits, I had the same amount of data, and yet the experimental Nyquist diagram closely matched the theory!

    Is there any way to somehow smooth out the diagram a little? With the correction this is how the plots look like so far:





    I don't see why there's a double line in the last one...
  13. Aug 28, 2014 #12
    As you can tell from your first diagram, there's only so much fidelity you can get using linear interpolation with so few data points around the resonance frequency. The problem is that the phase changes rapidly (at high magnitude) from something positive to something negative in a few data points, so you get those straight lines darting around and connecting those few points.

    It's not that big of a deal for a notch filter, however, since that phase transition occurs at very low magnitude, so it really doesn't alter the overall shape of the Nyquist locus.

    Compare how rapidly the magnitude/phase changes with frequency for your RC-circuit and your LC-circuits. You don't have the same amount of data around where it matters!

    If you don't want to measure any more data, then it might be an option to just superimpose your data on a Bode plot of a filter with a transfer function of the right form, but where you can adjust the parameters until "it fits". Just try and eyeball it for now - I don't think it's worth getting into system identification just for these simple systems.
  14. Aug 28, 2014 #13
    It's because, for the ideal filter, "one half" of the Nyquist diagram is already an ellipse in the complex plane. When you superimpose its complex conjugate, you do so right on top of the locus that's already there.

    For your data set, that second "go around" isn't going to fit perfectly due to measurement errors and what not, so you get to see the whole shebang.
  15. Aug 29, 2014 #14
    Thank you for the explanation (the system doesn't allow me to thank you twice). It makes a lot more sense now.
  16. Aug 29, 2014 #15
    You're very welcome.

    I should probably have mentioned something in my first post: 'Phase' in the complex plane is synonymous with 'angle'. In your original post, can you see how that Bode plot traces out the upper half of the Nyquist diagram?

    A magnitude and phase pair in the Bode plot gives a point in the complex plane with the same magnitude and phase (angle).
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted