% Sweep CARM  (common arm length) in DRFPMI and generate plots.
%
% [xPos, sigDC, fDC] = sweepCARM(Nsweep)
% see sweepDC for information about the parameters
%
% This displays some DC signals, and some demod signals, during
% a CARM sweep.  The phase of the REFL_I1 signal is set to maximize
% its response to this sweep.

function [xPos, sigDC, fDC] = sweepCARM(Nsweep)

  % prepare some variables
  sweepSetup

  % adding this to sweepSetup causes matlab to crash, so do it here
  nDC = [nREFL(1) nAS(1) nPOX(1) nPOY(1) nTRX(1) nTRY(1)];

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % CARM sweep
  pos = zeros(opt.Noptic, 1);
  pos(nEX) = 3e-11;
  pos(nEY) = 3e-11;
  
  [xPos, sigDC, fDC] = sweepDC(opt, -pos, pos, Nsweep);

  subplot(2, 1, 1)
  semilogy(xPos(nEX, :), sigDC(nDC, :))
  legend(prbNames(nDC))
  title('CARM sweep: DC signals')
  grid on

  subplot(2, 1, 2)
  plot(xPos(nEX, :), sigDC(nREFL(2:end), :))
  legend(prbNames(nREFL(2:end)))
  title('CARM sweep: REFL demod signals')
  grid on
