Commit bd3099d0023b0610c0faf0d4077f6fd1a9068bf3
1 parent
2ae5099ce4
Exists in
master
add PDH signal
Showing 1 changed file with 38 additions and 18 deletions Inline Diff
tf_cavity/tf_cavity_num.py
#!/usr/bin/python | 1 | 1 | #!/usr/bin/python | |
# -*- coding: utf-8 -*- | 2 | 2 | # -*- coding: utf-8 -*- | |
3 | 3 | |||
'''TF of FP cavity in reflection | 4 | 4 | '''TF of FP cavity in reflection | |
5 | 5 | |||
---------- | 6 | 6 | ---------- | |
X(s) ----- | -tau⋅s | | 7 | 7 | X(s) ----- | -tau⋅s | | |
-------------->|1-R|----->(X)----->|e |------ | 8 | 8 | -------------->|1-R|----->(X)----->|e |------ | |
| ----- ^ ---------- | | 9 | 9 | | ----- ^ ---------- | | |
| | | | 10 | 10 | | | | | |
| | V | 11 | 11 | | | V | |
---- ---- ---- | 12 | 12 | ---- ---- ---- | |
|-R| |-R| |-R| | 13 | 13 | |-R| |-R| |-R| | |
---- ---- ---- | 14 | 14 | ---- ---- ---- | |
| ^ | | 15 | 15 | | ^ | | |
| | ---------- | | 16 | 16 | | | ---------- | | |
Y(s) V ----- | | -tau⋅s | | | 17 | 17 | Y(s) V ----- | | -tau⋅s | | | |
<-----(X)<-----|1-R|<--------------|e |<----- | 18 | 18 | <-----(X)<-----|1-R|<--------------|e |<----- | |
----- ---------- | 19 | 19 | ----- ---------- | |
20 | 20 | |||
''' | 21 | 21 | ''' | |
22 | 22 | |||
'''import matplotlib as mpl | 23 | 23 | '''import matplotlib as mpl | |
mpl.use('pgf') | 24 | 24 | mpl.use('pgf') | |
25 | 25 | |||
def figsize(scale): | 26 | 26 | def figsize(scale): | |
fig_width_pt = 469.755 # Get this from LaTeX using \the\textwidth | 27 | 27 | fig_width_pt = 469.755 # Get this from LaTeX using \the\textwidth | |
inches_per_pt = 1.0/72.27 # Convert pt to inch | 28 | 28 | 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) | 29 | 29 | 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 | 30 | 30 | fig_width = fig_width_pt*inches_per_pt*scale # width in inches | |
fig_height = fig_width*golden_mean # height in inches | 31 | 31 | fig_height = fig_width*golden_mean # height in inches | |
fig_size = [fig_width,fig_height] | 32 | 32 | fig_size = [fig_width,fig_height] | |
return fig_size | 33 | 33 | return fig_size | |
34 | 34 | |||
pgf_with_latex = { # setup matplotlib to use latex for output | 35 | 35 | pgf_with_latex = { # setup matplotlib to use latex for output | |
"pgf.texsystem": "pdflatex", # change this if using xetex or lautex | 36 | 36 | "pgf.texsystem": "pdflatex", # change this if using xetex or lautex | |
"text.usetex": True, # use LaTeX to write all text | 37 | 37 | "text.usetex": True, # use LaTeX to write all text | |
"font.family": "serif", | 38 | 38 | "font.family": "serif", | |
"font.serif": [], # blank entries should cause plots to inherit fonts from the document | 39 | 39 | "font.serif": [], # blank entries should cause plots to inherit fonts from the document | |
"font.sans-serif": [], | 40 | 40 | "font.sans-serif": [], | |
"font.monospace": [], | 41 | 41 | "font.monospace": [], | |
"axes.labelsize": 10, # LaTeX default is 10pt font. | 42 | 42 | "axes.labelsize": 10, # LaTeX default is 10pt font. | |
"text.fontsize": 10, | 43 | 43 | "text.fontsize": 10, | |
"legend.fontsize": 8, # Make the legend/label fonts a little smaller | 44 | 44 | "legend.fontsize": 8, # Make the legend/label fonts a little smaller | |
"xtick.labelsize": 8, | 45 | 45 | "xtick.labelsize": 8, | |
"ytick.labelsize": 8, | 46 | 46 | "ytick.labelsize": 8, | |
"figure.figsize": figsize(0.9), # default fig size of 0.9 textwidth | 47 | 47 | "figure.figsize": figsize(0.9), # default fig size of 0.9 textwidth | |
"pgf.preamble": [ | 48 | 48 | "pgf.preamble": [ | |
r"\usepackage[utf8x]{inputenc}", # use utf8 fonts becasue your computer can handle it :) | 49 | 49 | r"\usepackage[utf8x]{inputenc}", # use utf8 fonts becasue your computer can handle it :) | |
r"\usepackage[T1]{fontenc}", # plots will be generated using this preamble | 50 | 50 | r"\usepackage[T1]{fontenc}", # plots will be generated using this preamble | |
] | 51 | 51 | ] | |
} | 52 | 52 | } | |
mpl.rcParams.update(pgf_with_latex) | 53 | 53 | mpl.rcParams.update(pgf_with_latex) | |
''' | 54 | 54 | ''' | |
from numpy import * | 55 | 55 | from numpy import * | |
import matplotlib.pyplot as plt | 56 | 56 | import matplotlib.pyplot as plt | |
57 | 57 | |||
r = 0.99 | 58 | 58 | r = 0.99998 | |
L = 140e-3 | 59 | 59 | L = 140e-3 | |
c = 299792458 | 60 | 60 | c = 299792458 | |
61 | 61 | |||
tau = L/c | 62 | 62 | tau = L/c | |
fsr = 1/(2*tau) | 63 | 63 | fsr = 1/(2*tau) | |
64 | finesse = pi*r/(1-r**2) | |||
65 | print('Finesse = %f\n FSR = %f\n FSR/Finesse = %f'%(finesse, fsr, fsr/finesse)) | |||
64 | 66 | |||
f0 = (193e12//fsr)*fsr | 65 | 67 | f0 = (193e12//fsr)*fsr | |
f = linspace(f0-0.1*fsr, f0+0.1*fsr, 1e5) | 66 | 68 | f = linspace(f0-0.1*fsr, f0+0.1*fsr, 1e5) | |
67 | 69 | |||
70 | fm = 30e6 | |||
71 | ||||
#TF of cavity in reflection | 68 | 72 | #TF of cavity in reflection | |
def Fr(w): | 69 | 73 | def Fr(w): | |
s = 1j*w | 70 | 74 | s = 1j*w | |
return r*(exp(-2*tau*s)-1)/(1-r**2*exp(-2*tau*s)) | 71 | 75 | return r*(exp(-2*tau*s)-1)/(1-r**2*exp(-2*tau*s)) | |
72 | 76 | |||
G = Fr(2*pi*f) | 73 | 77 | G = Fr(2*pi*f) | |
78 | Glsb = Fr(2*pi*(f-fm)) | |||
79 | Gusb = Fr(2*pi*(f+fm)) | |||
74 | 80 | |||
81 | #plot setup | |||
82 | fig, axarr = plt.subplots(3, 2, sharex='col') | |||
83 | ||||
#plot bode of F(w) | 75 | 84 | #plot bode of F(w) | |
ax1 = plt.subplot(3, 1, 1) | 76 | 85 | axarr[0, 1].set_ylabel('Magnitude') | |
ax1.set_ylabel('Magnitude') | 77 | 86 | #axarr[0, 1].set_xlabel('Frequency (Hz)') | |
ax1.plot(f, abs(G)) | 78 | 87 | axarr[0, 1].plot(f, abs(G)) | |
ax1.grid() | 79 | 88 | axarr[0, 1].grid() | |
89 | axarr[1, 1].set_ylabel('Phase (deg)') | |||
90 | #axarr[1, 1].set_xlabel('Frequency (Hz)') | |||
91 | axarr[1, 1].plot(f, angle(G, deg = True)) | |||
92 | axarr[1, 1].grid() | |||
80 | 93 | |||
ax2 = plt.subplot(3, 1, 2, sharex = ax1) | 81 | 94 | #PDH signal | |
ax2.set_ylabel('Phase (deg)') | 82 | 95 | iG = (G*Gusb.conjugate()-G.conjugate()*Glsb).imag | |
ax2.set_xlabel('omega (rad.s$^{-1}$)') | 83 | 96 | axarr[2, 1].set_ylabel('epsillon normalized') | |
ax2.plot(f, angle(G, deg = True)) | 84 | 97 | axarr[2, 1].set_xlabel('Frequency (Hz)') | |
ax2.grid() | 85 | 98 | axarr[2, 1].xaxis.set_label_coords(0.5, -0.3) | |
99 | axarr[2, 1].plot(f, iG) | |||
100 | axarr[2, 1].grid() | |||
86 | 101 | |||
87 | 102 | |||
#nyquist | 88 | 103 | #nyquist | |
ax3 = plt.subplot(3, 1, 3) | 89 | 104 | axarr[2, 0].set_ylabel('$j\omega$') | |
ax3.set_ylabel('$j\omega$') | 90 | 105 | axarr[2, 0].set_xlabel('$\sigma$') | |
ax3.set_xlabel('$\sigma$') | 91 | 106 | axarr[2, 0].plot(real(G), imag(G)) | |
ax3.plot(real(G), imag(G)) | 92 | 107 | axarr[2, 0].grid() | |
ax3.grid() | 93 | 108 | axarr[2, 0].axis('equal') | |
ax3.axis('equal') | 94 | 109 | axarr[2, 0].set_xlim([-1.1, 1.1]) | |
95 | 110 | |||
111 | #layout | |||
112 | axarr[0, 0].axis('off') | |||
113 | axarr[1, 0].axis('off') | |||
114 | fig.subplots_adjust(wspace=0.5) | |||
115 | plt.tight_layout() | |||
#plt.savefig('fig.pgf') | 96 | 116 | #plt.savefig('fig.pgf') | |
plt.show() | 97 | 117 | plt.show() | |
98 | 118 | |||
'''results | 99 | 119 | '''results | |
100 | 120 | |||
⎛ -2.0⋅ⅈ⋅L⋅ω ⎞ | 101 | 121 | ⎛ -2.0⋅ⅈ⋅L⋅ω ⎞ | |
⎜ ───────────⎟ | 102 | 122 | ⎜ ───────────⎟ | |
⎜ c ⎟ | 103 | 123 | ⎜ c ⎟ | |
r⋅⎝-1 + ℯ ⎠ | 104 | 124 | r⋅⎝-1 + ℯ ⎠ | |
F(w) = ───────────────────── | 105 | 125 | F(w) = ───────────────────── | |
-2.0⋅ⅈ⋅L⋅ω | 106 | 126 | -2.0⋅ⅈ⋅L⋅ω | |
─────────── | 107 | 127 | ─────────── | |
2 c | 108 | 128 | 2 c |