% Create an Optickle Fabry-Perot
%
% opt = optFP

function opt = optFP

  % geometrical parameters
  Ri = 14e3;			% radius of curvature of input mirror
  Re = 7e3;			% radius of curvature of end mirror
  lCav = 4e3;			% length of cavity

  % mechanical parameters
  wI = 2 * pi * 0.8;		% resonance frequency of input mirror (rad/s)
  mI = 5;			% mass of input mirror (kg)
  wE = 2 * pi * 0.7;		% resonance frequency of end mirror (rad/s)
  mE = 10;			% mass of end mirror (kg)
  
  % input parameters
  Pin = 1;			% input power (W)
  fMod = 24485446;		% modulation frequency (24.5 MHz)
  gMod = 0.2;			% modulation depth
  Nmod = 1;			% modulation order
  
  % create an empty Optickle model
  opt = Optickle;

  % add a field source
  nMod = (-Nmod:Nmod)';
  vMod = [nMod * fMod, sqrt(Pin) * bessel(nMod, gMod)];
  [opt, nSrc] = addSource(opt, 'Source', vMod);

  % add an AM modulator
  [opt, nAM] = addModulator(opt, 'AM', 0);

  % add mirrors
  % [opt, sn] = addMirror(opt, name, aio, Chr, Thr, Lhr [, Rar, Lmd, Nmd])
  [opt, nIX] = addMirror(opt, 'IX', 0, 1 / Ri, 0.03, 50e-6);
  [opt, nEX] = addMirror(opt, 'EX', 0, 1 / Re, 100e-6, 50e-6);

  opt = setMechTF(opt, nIX, zpk([], -wI * [0.1 + 1i, 0.1 - 1i], 1 / mI));
  opt = setMechTF(opt, nEX, zpk([], -wE * [0.1 + 1i, 0.1 - 1i], 1 / mE));

  % add detectors
  [opt, nREFL] = addSink(opt, 'REFL');
  [opt, nTRNS] = addSink(opt, 'TRNS');

  % add links
  opt = addLink(opt, nSrc, 'out', nAM, 'in', 0);
  opt = addLink(opt, nAM, 'out', nIX, 'bk', 10);
  opt = addLink(opt, nIX, 'fr', nEX, 'fr', lCav);
  opt = addLink(opt, nEX, 'fr', nIX, 'fr', lCav);
  opt = addLink(opt, nIX, 'bk', nREFL, 'in', 5);
  opt = addLink(opt, nEX, 'bk', nTRNS, 'in', 5);

  opt = addLink(opt, nTRNS, 'out', nEX, 'bk', 5);

  % add probes
  opt = addProbeAt(opt, 'REFL_DC', nREFL, 'in', 0, 0);		% DC
  opt = addProbeAt(opt, 'REFL_AC', nREFL, 'in', fMod, 0);	% 1f demod
  opt = addProbeAt(opt, 'REFL_AC', nREFL, 'in', fMod, 90);	% 1f demod
  opt = addProbeAt(opt, 'TRNS_DC', nTRNS, 'in', 0, 0);		% DC
