tf_cavity_num.py 3.38 KB
#!/usr/bin/python
# -*- coding: utf-8 -*-

'''TF of FP cavity in reflection

                                   ----------
 X(s)          -----               | -tau⋅s |
-------------->|1-R|----->(X)----->|e       |------
       |       -----       ^       ----------     |
       |                   |                      |
       |                   |                      V
     ----                ----                   ----
     |-R|                |-R|                   |-R|
     ----                ----                   ----
       |                   ^                      |
       |                   |       ----------     |
 Y(s)  V       -----       |       | -tau⋅s |     |
<-----(X)<-----|1-R|<--------------|e       |<-----
               -----               ----------

'''

'''import matplotlib as mpl
mpl.use('pgf')

def figsize(scale):
    fig_width_pt = 469.755                          # Get this from LaTeX using \the\textwidth
    inches_per_pt = 1.0/72.27                       # Convert pt to inch
    golden_mean = (5.0**0.5-1.0)/2.0            # Aesthetic ratio (you could change this)
    fig_width = fig_width_pt*inches_per_pt*scale    # width in inches
    fig_height = fig_width*golden_mean              # height in inches
    fig_size = [fig_width,fig_height]
    return fig_size

pgf_with_latex = {                      # setup matplotlib to use latex for output
    "pgf.texsystem": "pdflatex",        # change this if using xetex or lautex
    "text.usetex": True,                # use LaTeX to write all text
    "font.family": "serif",
    "font.serif": [],                   # blank entries should cause plots to inherit fonts from the document
    "font.sans-serif": [],
    "font.monospace": [],
    "axes.labelsize": 10,               # LaTeX default is 10pt font.
    "text.fontsize": 10,
    "legend.fontsize": 8,               # Make the legend/label fonts a little smaller
    "xtick.labelsize": 8,
    "ytick.labelsize": 8,
    "figure.figsize": figsize(0.9),     # default fig size of 0.9 textwidth
    "pgf.preamble": [
        r"\usepackage[utf8x]{inputenc}",    # use utf8 fonts becasue your computer can handle it :)
        r"\usepackage[T1]{fontenc}",        # plots will be generated using this preamble
        ]
    }
mpl.rcParams.update(pgf_with_latex)
'''
from numpy import *
import matplotlib.pyplot as plt

r = 0.99
L = 140e-3
c = 299792458

tau = L/c
fsr = 1/(2*tau)

f0 = (193e12//fsr)*fsr
f = linspace(f0-0.1*fsr, f0+0.1*fsr, 1e5)

#TF of cavity in reflection
def Fr(w):
    s = 1j*w
    return r*(exp(-2*tau*s)-1)/(1-r**2*exp(-2*tau*s))

G = Fr(2*pi*f)

#plot bode of F(w)
ax1 = plt.subplot(3, 1, 1)
ax1.set_ylabel('Magnitude')
ax1.plot(f, abs(G))
ax1.grid()

ax2 = plt.subplot(3, 1, 2, sharex = ax1)
ax2.set_ylabel('Phase (deg)')
ax2.set_xlabel('omega (rad.s$^{-1}$)')
ax2.plot(f, angle(G, deg = True))
ax2.grid()


#nyquist
ax3 = plt.subplot(3, 1, 3)
ax3.set_ylabel('$j\omega$')
ax3.set_xlabel('$\sigma$')
ax3.plot(real(G), imag(G))
ax3.grid()
ax3.axis('equal')

#plt.savefig('fig.pgf')
plt.show()

'''results

         ⎛      -2.0⋅ⅈ⋅L⋅ω ⎞
         ⎜      ───────────⎟
         ⎜           c     ⎟
       r⋅⎝-1 + ℯ           ⎠
F(w) = ─────────────────────
             -2.0⋅ⅈ⋅L⋅ω
             ───────────
          2       c
       - r ⋅ℯ            + 1

'''