% compute signals from DC fields
%
% vSig = sigDC(opt, pos)
% pos - positions of each optic (Nopt x 1)
% vSig - signals for each probe (Nprb x 1)
%
% Example:
% opt = optFP;
% pos = [0; 0; 1e-11; 0; 0];
% vSig = sigDC(opt, pos)

function vSig = sigDC(opt, pos)

  % === Get Field Source Info
  [vSrc, vFrf] = getFieldSource(opt);
  
  % ==== Sizes of Things
  Nprb = opt.Nprobe;				% number of probes
  Nfld = opt.Nfield;				% number of fields
  Nrf  = length(vFrf);				% number of RF components

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % ==== Signals
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  rslt = compute(opt, pos, []);
  vDC = rslt.vDC;
  vSig = zeros(Nprb, 1);
  
  % loop over probes
  for nPrb = 1:Nprb
    prb = opt.probe(nPrb);
    
    nFld = prb.nField;
    phi = exp(pi * i * prb.phase / 180);
    
    % look for RF frequency matches
    for mRF = 1:Nrf
      for pRF = mRF:Nrf
        if abs(vFrf(pRF) - vFrf(mRF) - prb.freq) < 1e-3
          % add this RF beat to the signal
          vSig(nPrb) = vSig(nPrb) + ...
              real(conj(vDC(nFld, pRF)) .* vDC(nFld, mRF) * phi);
        end
      end
    end
  end
