Skip to content

Instantly share code, notes, and snippets.

@Sup3rGeo
Last active October 5, 2018 15:32
Show Gist options
  • Save Sup3rGeo/17d0eb2b0f4d60c1ebd24695ac692b5d to your computer and use it in GitHub Desktop.
Save Sup3rGeo/17d0eb2b0f4d60c1ebd24695ac692b5d to your computer and use it in GitHub Desktop.
Plot a discrete z-grid with frequency and damping
'''
Author: Victor Maryama
Adapted from
https://tex.stackexchange.com/questions/373314/how-to-draw-this-z-grid-graph-of-constant-damping-factors-and-natural-frequencie?noredirect=1&lq=1
'''
from numpy import pi, linspace
from scipy import sqrt, exp, cos, sin
import matplotlib.pyplot as plt
def zgrid():
for zeta in linspace(0, 0.9,10):
factor = zeta/sqrt(1-zeta**2)
x = linspace(0, sqrt(1-zeta**2),200)
ang = pi*x
mag = exp(-pi*factor*x)
xret = mag*cos(ang)
yret = mag*sin(ang)
plt.plot(xret,yret, 'k:', lw=1)
xret = mag*cos(-ang)
yret = mag*sin(-ang)
plt.plot(xret,yret,'k:', lw=1)
an_i = int(len(xret)/2.5)
an_x = xret[an_i]
an_y = yret[an_i]
plt.annotate(str(zeta), xy=(an_x, an_y), xytext=(an_x, an_y), size=7)
for a in linspace(0,1,10):
x = linspace(-pi/2,pi/2,200)
ang = pi*a*sin(x)
mag = exp(-pi*a*cos(x))
xret = mag*cos(ang)
yret = mag*sin(ang)
plt.plot(xret,yret,'k:', lw=1)
an_i = -1 #int(len(xret)/2.5)
an_x = xret[an_i]
an_y = yret[an_i]
num = '{:1.1f}'.format(a)
plt.annotate("$\\frac{"+num+"\pi}{T}$", xy=(an_x, an_y), xytext=(an_x, an_y), size=8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment