\chapter{Reference Manual --- VertEgg Version 0.9}

\section{Overview of the Toolbox}

The VertEgg toolbox  presently contain  the following tools,
grouped here according to functionality.

\begin{itemize}
  \item Initialise VertEgg
    \begin{itemize}
      \item \edb{ve\_init}
      \item \edb{ve\_grid(Hcol, dz)}
    \end{itemize}
  \item Make initial egg distribution
    \begin{itemize}
      \item \edb{spawn(M, Z)}
      \item \edb{ve\_rand(M)}
    \end{itemize}
  \item Compute the stationary solution
    \begin{itemize}
      \item \edb{eggsact(M, K, W, Z)}
      \item \edb{srcsact(K, W, P, alpha)}
      \item \edb{sstate(M, K, W)}
    \end{itemize}
  \item Solve the transient problem numerically
    \begin{itemize}
      \item \edb{fluxlim(A0, K, W, nstep, dt, P, alpha)}
      \item \edb{ftcs(A0, K, W, nstep, dt, P, alpha)}
      \item \edb{lwendrof(A0, K, W, nstep, dt, P, alpha)}
      \item \edb{upstream(A0, K, W, nstep, dt, P, alpha)}
    \end{itemize}
  \item Compute terminal egg velocity
    \begin{itemize}
      \item \edb{dens0(S, T)}
      \item \edb{eggvel(drho, d, mu)}
      \item \edb{eggvelst(S, T, d, Se)}
      \item \edb{molvisc(S, T)}
    \end{itemize}
  \item Analyse distributions
    \begin{itemize}
      \item \edb{eggmom(A, p)}
      \item \edb{ve\_drint(A, z1, z2)}
      \item \edb{ve\_int(A)}
      \item \edb{ve\_mean(A)}
      \item \edb{ve\_std(A)}
      \item \edb{ve\_rmsd(A, B)}
    \end{itemize}
\end{itemize}

\section{Description of the Tools}

{\parindent=0pt

\thead{dens0}{Sigma-T of sea water at zero pressure}

\begin{tdesc}
\item[Usage] \edb{sigma = dens0(S, T)}
\item[Input]
  \begin{vartab}
    \edb{S}  \> : \> Salinity     \>   [psu]   \\
    \edb{T}  \> : \> Temperature  \>   [\degC]
  \end{vartab}
  \edb{S} and \edb{T} may be arrays of the same shape.
\item[Output]
  \begin{vartab}
    \edb{sigma} \> : \> Sigma-T value \>  [\kgpcum]
  \end{vartab}
  \edb{sigma} is an array of the same shape as \edb{S} and \edb{T}.
\item[Description] \mbox{}\\
  \edb{dens0} computes the $\sigma_T$ value (density - 1000)
  of sea water at zero pressure.
  The density is computed by the international equation
  of state for sea water, UNESCO, 1980.
\end{tdesc}

\thead{eggmom}{Moment of egg distribution}

\begin{tdesc}
\item[Usage] \edb{M = eggmom(A, p)}
\item[Input]
  \begin{vartab}
  \edb{A}   \> : \> Egg distribution \>  [eggs/m$^3$] \\
  \edb{p}   \> : \> Order of moment
  \end{vartab}
  \edb{A} must be a matrix where the columns live on egg-points,
  but a row-vector at egg-points is also accepted,
  \edb{size(A) = (Ncell x n)} or \edb{(1 x Ncell)}
\item[Output]
  \begin{vartab}
  \edb{M}  \>  : \> The \edb{p}-th moment of \edb{A} \> [eggs m$^{p-2}$]
  \end{vartab}
  If \edb{A} is a matrix of size \edb{(Ncell x n)}, \edb{M} becomes a
  row-vector of length n containing the moments of
  the columns of \edb{A}. \edb{p} must not be negative.
\item[Description]\mbox{}\\
  Computes the \edb{p}-th moment of the egg-distribution \edb{A},
  \begin{displaymath}
      M = \int^0_{-H} z^p a(z) dz
  \end{displaymath}
   where $a(z)$ is the piecewise constant function
   $a(z) = \edb{A(i)}$ for $\edb{ZF(i+1)} < z < \edb{ZF(i)}$.
   If \edb{A} is a matrix, the moments of the columns are
   calculated.
\end{tdesc}

\thead{eggsact}{Exact stationary solution, const. coeff.}

\begin{tdesc}
\item[Usage] \edb{A = eggsact(M, K, W, Z)}
\item[Input]
  \begin{vartab}
  \edb{M}   \> : \> Vertical integrated concentration \>  [eggs/m$^2$] \\
  \edb{K}   \> : \> Eddy diffusivity     \> [\sqmps] \\
  \edb{W}   \> : \> Terminal velocity   \>  [\mps] \\
  \edb{Z} (opt) \> : \> Vertical coordinate  \> [\m]
  \end{vartab}
  \edb{M}, \edb{K}, \edb{W} are scalars. \edb{Z} can be arbitrary array.
  IF \edb{Z} is omitted, \edb{ZE} is used as vertical coordinates.
\item[Output]
  \begin{vartab}
  \edb{A}     \>  : \> Concentration at depth \edb{Z} \> [eggs/m$^3$]
  \end{vartab}
  If \edb{Z} is present, \edb{size(A) = size(Z)},
  otherwise, \edb{size(A) = size(ZE)}.
\item[Description]
   Computes the exact stationary solution of the
   convection diffusion equation with constant
   eddy diffusivity \edb{K} and velocity \edb{W}.
   If \edb{Z} is present, returns array of pointwise values.
   If \edb{Z} is not present, returns exact cell averages.
\end{tdesc}

\thead{eggvel}{Terminal egg velocity}

\begin{tdesc}
\item[Usage] \edb{[W, Re] = eggvel(drho, d, mu)}
\item[Input]
   \begin{vartab}
   \edb{drho}  \> : \> Buoyancy of egg  \> [\kgpcum] \\
   \edb{d}     \> : \> Diameter of egg  \> [\m] \\
   \edb{mu} (opt) \> :
         \> Dynamic molecular viscosity \>   [kgm$^{-1}$s$^{-1}$]
   \end{vartab}
   \edb{drho}, \edb{d} and \edb{mu} can be matrices (of the same shape).
   \edb{mu} can be also be a scalar or omitted.
   The sign of \edb{drho} is positive if the egg is ascending,
   \edb{drho} = Density of water - density of egg. With only two arguments,
   a default value 0.0016 is used for \edb{mu}.
\item[Output]
  \begin{vartab}
  \edb{W}   \> : \> Terminal velocity  \> [\mps] \\
  \edb{Re} (opt) \> : \> Reynolds number
  \end{vartab}
\item[Description]
  Computes the terminal velocity of a small sphere in sea water
  by the formulas in Stokes' or Dallavalles formula.
\end{tdesc}

\thead{eggvelst}{Egg velocity from salinity and temperature}

\begin{tdesc}
\item[Usage] \edb{[W, Re] = eggvelst(S, T, d, Se)}
\item[Input]
  \begin{vartab}
  \edb{S}  \>  : \> Salinity of the environment \> [psu]   \\
  \edb{T}  \>  : \> Temperature                 \> [\degC] \\
  \edb{d}  \>  : \> Egg diameter                \> [m]     \\
  \edb{Se} \>  : \> Egg salinity                \> [psu]
  \end{vartab}
  All arguments can be arrays of the same shape.
  Alternatively \edb{d} and/or \edb{Se} may be scalars.
\item[Output]
  \begin{vartab}
  \edb{W}    \> : \> Terminal velocity  \> [\mps] \\
  \edb{Re} (opt) \> : \> Reynolds number
  \end{vartab}
\item[Description]\mbox{}\\
  Computes the terminal egg velocity given the hydrography
  of the environment and the salinity \edb{Se} where the egg is
  neutral buoyant.
\end{tdesc}

\thead{fluxlim}{Numerical integration of transport equation}

\begin{tdesc}
\item[Usage] \edb{A = fluxlim(A0, K, W, nstep, dt, P, alpha)}
\item[Input]
  \begin{vartab}
  \edb{A0}  \> : \> Start concentration \>  [eggs/m$^3$] \\
  \edb{K}   \> : \> Eddy diffusivity    \>  [\sqmps]  \\
  \edb{W}   \> : \> Terminal velocity   \>  [\mps]  \\
  \edb{nstep}  \> : \> Number of integration steps \\
  \edb{dt}     \> : \> Time step           \>  [s] \\
  \edb{P}     (opt) \> : \> Spawning term       \>  [eggs/m$^3$/s] \\
  \edb{alpha} (opt) \> : \> Loss coefficient \> [1/s]
  \end{vartab}
  \edb{A0} lives at the egg-points, \edb{size(A0) = (Ncell x 1)}.
  \edb{K} and \edb{W} live at the flux-points, \edb{size = (Ncell+1 x1)}.
  If \edb{P} and \edb{alpha} are present, they also live at the egg-points.
  If \edb{P} and \edb{alpha} are missing, the source term is ignored.
\item[Output]
  \begin{vartab}
  \edb{A} \>  : \> Result concentration \> [eggs/m$^3$]
  \end{vartab}
  \edb{A} lives at egg-points in the same way as \edb{A0}
\item[Description]\mbox{}\\
  Integrates the convection-diffusion equation by the
  flux-limited method. Starting with the concentration
  in \edb{A0} nstep integration steps  are performed.
  The result is saved in \edb{A}.
\end{tdesc}

\thead{ftcs}{Numerical integration of transport equation}

\begin{tdesc}
\item[Usage] \edb{A = ftcs(A0, K, W, nstep, dt, P, alpha)}
\item[Input]
  \begin{vartab}
  \edb{A0}  \> : \> Start concentration \>  [eggs/m$^3$] \\
  \edb{K}   \> : \> Eddy diffusivity    \>  [\sqmps]  \\
  \edb{W}   \> : \> Terminal velocity   \>  [\mps]  \\
  \edb{nstep}  \> : \> Number of integration steps \\
  \edb{dt}     \> : \> Time step           \>  [s] \\
  \edb{P}     (opt) \> : \> Spawning term       \>  [eggs/m$^3$/s] \\
  \edb{alpha} (opt) \> : \> Loss coefficient \> [1/s]
  \end{vartab}
  \edb{A0} lives at the egg-points, \edb{size(A0) = (Ncell x 1)}.
  \edb{K} and \edb{W} live at the flux-points, \edb{size = (Ncell+1 x1)}.
  If \edb{P} and \edb{alpha} are present, they also live at the egg-points.
  If \edb{P} and \edb{alpha} are missing, the source term is ignored.
\item[Output]
  \begin{vartab}
  \edb{A} \>  : \> Result concentration \> [eggs/m$^3$]
  \end{vartab}
  \edb{A} lives at egg-points in the same way as \edb{A0}
\item[Description]\mbox{}\\
  Integrates the convection-diffusion equation by the
  forward time central space (FTCS)  method. Starting
  with the concentration in \edb{A0} nstep integration steps
  are performed. The result is saved in \edb{A}.
\end{tdesc}

\thead{lwendrof}{Numerical integration of transport equation}

\begin{tdesc}
\item[Usage] \edb{A = lwendrof(A0, K, W, nstep, dt, P, alpha)}
\item[Input]
  \begin{vartab}
  \edb{A0}  \> : \> Start concentration \>  [eggs/m$^3$] \\
  \edb{K}   \> : \> Eddy diffusivity    \>  [\sqmps]  \\
  \edb{W}   \> : \> Terminal velocity   \>  [\mps]  \\
  \edb{nstep}  \> : \> Number of integration steps \\
  \edb{dt}     \> : \> Time step           \>  [s] \\
  \edb{P}     (opt) \> : \> Spawning term       \>  [eggs/m$^3$/s] \\
  \edb{alpha} (opt) \> : \> Loss coefficient \> [1/s]
  \end{vartab}
  \edb{A0} lives at the egg-points, \edb{size(A0) = (Ncell x 1)}.
  \edb{K} and \edb{W} live at the flux-points, \edb{size = (Ncell+1 x1)}.
  If \edb{P} and \edb{alpha} are present, they also live at the egg-points.
  If \edb{P} and \edb{alpha} are missing, the source term is ignored.
\item[Output]
  \begin{vartab}
  \edb{A} \>  : \> Result concentration \> [eggs/m$^3$]
  \end{vartab}
  \edb{A} lives at egg-points in the same way as \edb{A0}
\item[Description]\mbox{}\\
  Integrates the convection-diffusion equation by the
  Lax-Wendroff method. Starting with the concentration
  in \edb{A0} nstep integration steps are performed. The
  result is saved in \edb{A}.
\end{tdesc}

\thead{molvisc}{Dynamical molecular viscosity of sea water}

\begin{tdesc}
\item[Usage] \edb{mu = molvisc(S, T)}
\item[Input]
  \begin{vartab}
    \edb{S}     \> : \> Salinity     \>   [psu]   \\
    \edb{T}     \> : \> Temperature  \>   [\degC]
  \end{vartab}
  \edb{S} and \edb{T} may be arrays of the same shape.
\item[Output]
  \begin{vartab}
    \edb{mu} \> : \> Dynamic molecular viscosity \>  [kgm$^{-1}$s$^{-1}$]
  \end{vartab}
  \edb{mu} is an array of the same shape as \edb{S} and \edb{T}.
\item[Description] \mbox{}\\
  Computes the dynamic molecular viscosity by formula~\eqref{eq:molvisc}.
\end{tdesc}

\thead{spawn}{Make concentrated egg distribution}

\begin{tdesc}
\item[Usage] \edb{A = spawn(M, Z)}
\item[Input]
  \begin{vartab}
  \edb{M} \> : \> Vertical integrated concentration \>  [eggs/m$^2$] \\
  \edb{Z} \> : \> Spawning depth              \>       [m]
  \end{vartab}
  \edb{M} and \edb{Z} are scalars.
\item[Output]
  \begin{vartab}
  \edb{A}  \> : \> Egg distribution     \>        [eggs/m$^3$]
  \end{vartab}
  \edb{A} is a column vector, living at the egg points.
\item[Description]\mbox{}\\
  Returns a vertical egg distribution \edb{A} with vertical
  integral \edb{M}, concentrated as much as possible around
  depth = \edb{Z}.
  If $\edb{ZE(Ncell)} < \edb{Z} < \edb{ZE(1)}$, then \edb{Z = ve\_mean(A)}.
\end{tdesc}

\thead{srcsact}{Stationary solution, const. coeff., source term}

\begin{tdesc}
\item[Usage] \edb{A = srcsact(K, W, P, alpha, Z)}
\item[Input]
  \begin{vartab}
    \edb{K} \> : \> Eddy diffusivity  \>  [\sqmps] \\
    \edb{W} \> : \> Terminal velocity \>  [\mps] \\
    \edb{P} \> : \> Egg production    \>  [eggs/m$^3$/s] \\
    \edb{alpha} \> : \> Egg loss rate  \>       [1/s] \\
    \edb{Z} (opt) \> : \> Vertical coordinate \>  [m]
  \end{vartab}
  \edb{K}, \edb{W}, \edb{P} and \edb{alpha} are scalars. \edb{Z} can
  be an arbitrary array.
  If \edb{Z} is ommitted, \edb{ZE} is used as vertical coordinate.
\item[Output]
  \begin{vartab}
    \edb{A} \> : \>  Concentration at depth \edb{Z}.  \>   [eggs/m$^3$]
  \end{vartab}
  If \edb{Z} is present, \edb{size(Y) = size(Z)},
  otherwise, \edb{size(Y) = size(ZE)}.
\item[Description]\mbox{}\\
   Computes the exact stationary solution of the
   convection diffusion equation with constant
   eddy diffusivity \edb{K}, velocity \edb{W}, egg production \edb{P}
   and loss rate \edb{alpha}.
   If \edb{Z} is present, returns array of pointwise values.
   If \edb{Z} is not present, returns exact cell averages.
\end{tdesc}

\thead{sstate}{Steady state solution}

\begin{tdesc}
\item[Usage] \edb{A = sstate(M, K, W)}
\item[Input]
  \begin{vartab}
  \edb{M} \>  : \> Vertical integrated concentration \> [eggs/m$^2$] \\
  \edb{K} \>  : \> Eddy diffusivity \> [\sqmps] \\
  \edb{W} \>  : \> Egg velocity   \>  [\mps]
  \end{vartab}
  \edb{M} is scalar, \edb{K} and \edb{W} are column vectors of
  length \edb{Ncell+1}, \edb{K} and \edb{W} live at the flux-points.
\item[Output]
  \begin{vartab}
  \edb{A}    \>  : \> Stationary solution \> [eggs/m$^3$]
  \end{vartab}
  \edb{A} lives at the egg points, \edb{size = (Ncell x 1)}.
\item[Description]\mbox{}\\
  Computes the steady state solution of the convection-
  diffusion equation without source term, with eddy diffusivity
  \edb{K} and egg
  velocity \edb{W} variable in the water column.
  The solution is computed by viewing \edb{K} and \edb{W}
  as piecewise constant on the grid cells.
\end{tdesc}

\thead{upstream}{Numerical integration of transport equation}

\begin{tdesc}
\item[Usage] \edb{A = upstream(A0, K, W, nstep, dt, P, alpha)}
\item[Input]
  \begin{vartab}
  \edb{A0}  \> : \> Start concentration \>  [eggs/m$^3$] \\
  \edb{K}   \> : \> Eddy diffusivity    \>  [\sqmps]  \\
  \edb{W}   \> : \> Terminal velocity   \>  [\mps]  \\
  \edb{nstep}  \> : \> Number of integration steps \\
  \edb{dt}     \> : \> Time step           \>  [s] \\
  \edb{P}     (opt) \> : \> Spawning term       \>  [eggs/m$^3$/s] \\
  \edb{alpha} (opt) \> : \> Loss coefficient \> [1/s]
  \end{vartab}
  \edb{A0} lives at the egg-points, \edb{size(A0) = (Ncell x 1)}.
  \edb{K} and \edb{W} live at the flux-points, \edb{size = (Ncell+1 x1)}.
  If \edb{P} and \edb{alpha} are present, they also live at the egg-points.
  If \edb{P} and \edb{alpha} are missing, the source term is ignored.
\item[Output]
  \begin{vartab}
  \edb{A} \>  : \> Result concentration \> [eggs/m$^3$]
  \end{vartab}
  \edb{A} lives at egg-points in the same way as \edb{A0}
\item[Description]\mbox{}\\
  Integrates the convection-diffusion equation by the
  upstream method. Starting with the concentration \edb{A0},
  nstep integration steps are performed. The result is
  saved in \edb{A}.
\end{tdesc}

\thead{ve\_drint}{Integrate over a depth range}

\begin{tdesc}
\item[Usage]  \edb{int = ve\_drint(A, z1, z2)}
\item[Input]
   \begin{vartab}
   \edb{A}  \> : \>  Egg distribution \> [eggs/m$^3$] \\
   \edb{z1} \> : \>  First integration limit \>  [\m] \\
   \edb{z2} \> : \> Second integration limit \> [\m]
   \end{vartab}
   \edb{A} must be a matrix where the columns are
   egg distributions. But a row-vector can also
   be accepted, \edb{size(A) = (Ncell x n)} or \edb{(1 x Ncell)}.
\item[Output]
   \begin{vartab}
   \edb{int} \> : \> Integral of A over depth range \> [eggs/m$^2$]
   \end{vartab}
   If \edb{A} is a matrix of size \edb{(Ncell x m)}, \edb{int} becomes
   a row-vector of length \edb{m} containing the integrals
   of the columns of A.
\item[Description]\mbox{}\\
    Computes the vertical integral
    \begin{displaymath}
      \edb{int} = \int_\edb{z1}^\edb{z2} a(z) dz
    \end{displaymath}
    where $a(z)$ is the piecewice constant function
    $a(z) = \edb{A(i)}$ for $\edb{ZF(i+1)} < z < \edb{ZF(i)}$.
    If \edb{A} is a matrix, the integral is computed for each column
\end{tdesc}

\thead{ve\_grid}{Set up vertical grid}

\begin{tdesc}
\item[Usage]  \edb{ve\_grid(H, dz0)}
\item[Input]
  \begin{vartab}
  \edb{H}        \>  : \> Depth of water column  \> [m] \\
  \edb{dz0}      \>  : \> Grid size              \> [m]
  \end{vartab}
\item[Output]
  None
\item[Description]\mbox{}\\
  Sets up the vertical grid used in VertEgg, given the depth
  \edb{H} of the water column and the grid size \edb{dz0}.
  (Re)defines all global variables.
  The global variables are declared by \edb{ve\_init}.
\end{tdesc}

\thead{ve\_init}{Initialize VertEgg}

\begin{tdesc}
\item[Usage] \edb{ve\_init}
\item[Input] none
\item[Output] none
\item[Description]\mbox{}\\
  Script for initializing VertEgg.
  Declares the global variables, so they become
  available in the workspace.
  The actual values are set by \edb{ve\_grid}.
\end{tdesc}

\thead{ve\_int}{Vertical integral of egg distribution}

\begin{tdesc}
\item[Usage] \edb{M = ve\_int(A)}
\item[Input]
  \begin{vartab}
  \edb{A} \>  : \> Egg distribution  \>  [eggs/m$^3$]
  \end{vartab}
  \edb{A} must be a matrix where the columns live on egg-points,
  but a row-vector at egg-points is also accepted,
  \edb{size(A) = (Ncell x n)} or \edb{(1 x Ncell)}
\item[Output]
  \begin{vartab}
  \edb{M}    \>  : \> The vertical integral \>  [eggs/m$^2$]
  \end{vartab}
  If \edb{A} is a matrix of size \edb{(Ncell x n)}, \edb{M} is a
  row-vector of length \edb{n}.
\item[Description]\mbox{}\\
  Computes the vertical integral of an egg distribution.
  \edb{ve\_int} is a vector function.
\end{tdesc}

\thead{ve\_mean}{Mean depth of an egg distribution}

\begin{tdesc}
\item[Usage] \edb{mu = ve\_mean(A)}
\item[Input]
  \begin{vartab}
  \edb{A}  \> :\>  Egg distribution   \>  [eggs/m$^3$]
  \end{vartab}
  \edb{A} must be a matrix where the columns live on egg-points,
  but a row-vector at egg-points is also accepted,
  \edb{size(A) = (Ncell x n)} or \edb{(1 x Ncell)}
\item[Output]
  \begin{vartab}
  \edb{mu}   \> : \> The center of gravity \>  [m]
  \end{vartab}
  If \edb{A} is a matrix of size \edb{(Ncell x n)}, \edb{mu} is a
  row-vector of length \edb{n}.
\item[Description]\mbox{}\\
  Computes the mean (or center of gravity) of the egg
  egg distribution \edb{A},
  \edb{ve\_mean} is a vector function.
\end{tdesc}

\thead{ve\_rand}{Make random egg distribution}

\begin{tdesc}
\item[Usage] \edb{Y = ve\_rand(M)}
\item[Input]
  \begin{vartab}
  \edb{M}    \>  : \> Vertical integrated concentration \> [eggs/m$^2$]
  \end{vartab}
  \edb{M} is a scalar
\item[Output]
  \begin{vartab}
  \edb{Y}    \>  : \>  Random egg distribution \> [eggs/m$^3$]
  \end{vartab}
  \edb{Y} is vector of size \edb{[Ncell 1]}

\item[Description]\mbox{}\\
  A uniform distribution is used to generate random
  values between 0 and 1. The values are scaled
  to make \edb{ve\_int(Y) = M}.
\end{tdesc}

\thead{ve\_rmsd}{Root mean square deviation}

\begin{tdesc}
\item[Usage] \edb{R = ve\_rmsd(X, Y)}
\item[Input]
  \begin{vartab}
  \edb{X} \> : \> Egg concentration  \>  [eggs/m$^3$] \\
  \edb{Y} \> : \> Egg concentration  \>  [eggs/m$^3$]
  \end{vartab}
  \edb{X} and \edb{Y} may be matrixes of the same size
  with \edb{Ncell} rows. \edb{X} and/or \edb{Y} may also be
  vectors of length \edb{Ncell}.
\item[Output]
  \begin{vartab}
  \edb{R} \>  : \> Root mean square deviation \> [eggs/m$^3$]
  \end{vartab}
  \edb{R} is a row vector with length =
  \edb{max(columns(X), columns(Y))}.
\item[Description]\mbox{}\\
  Computes the root mean square deviation \edb{R}
  between the columns of \edb{X} and \edb{Y}. If one
  argument is a vector, it is compared to
  all columns of the other argument.
  If \edb{X} and \edb{Y} are matrices
  \begin{displaymath}
    \edb{R(j)} =
    \sqrt{\frac{1}{\edb{Ncell}} \sum_\edb{i} (\edb{X(i,j)}-\edb{Y(i,j)})^2} .
  \end{displaymath}
  If \edb{Y} is a vector
  \begin{displaymath}
    \edb{R(j)} =
    \sqrt{\frac{1}{\edb{Ncell}} \sum_\edb{i} (\edb{X(i,j)}-\edb{Y(i)})^2} .
  \end{displaymath}
\end{tdesc}

\thead{ve\_std}{Standard deviation of egg distribution}

\begin{tdesc}
\item[Usage] \edb{s = ve\_std(A)}
\item[Input]
  \begin{vartab}
  \edb{A}    \> : \> Egg distribution  \>  [eggs/m$^3$]
  \end{vartab}
  \edb{A} must be a matrix where the columns live on egg-points,
  but a row-vector at egg-points is also accepted,
  size(A) = (Ncell x n) or (1 x Ncell)
\item[Output]
  \begin{vartab}
  \edb{s}   \>  : \> The standard deviation  \> [m]
  \end{vartab}
  If \edb{A} is a matrix of size (Ncell x n), s is a
  row-vector of length n.
\item[Description]\mbox{}\\
  Computes the standard deviation of an egg
  distribution \edb{A},
  \edb{ve\_std} is a vector function.
\end{tdesc}

} % \parindent=0pt


\documentclass[aps,showpacs,12pt,onecolumn,prd,superscriptaddress,nofootinbib]{revtex4}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{latexsym}
\usepackage{graphicx}
\usepackage{bm}
\usepackage{color}
\usepackage{enumerate}
\usepackage{ulem}

\newcommand{\be}{\begin{equation}}
\newcommand{\ee}{\end{equation}}
\newcommand\ud{{\mathrm{d}}}
\newcommand\uD{{\mathrm{D}}}
\newcommand\calO{{\mathcal{O}}}
\newcommand\bfx{\mathbf{x}}
\newcommand{\ov}[1]{\overline{#1}}
\newcommand{\ph}[1]{\phantom{#1}}
\newcommand{\cte}{\mathrm{cte}}
\newcommand{\nn}{\nonumber}
\newcommand{\hatk}{\hat{k}}
\newcommand{\Hz}{\,\mathrm{Hz}}
\newcommand{\sinc}{\,\mathrm{sinc}}
\newcommand{\Msol}{M_{\odot}}
\newcommand{\bsub}{\begin{subequations}}
\newcommand{\esub}{\end{subequations}}
\newcommand\betaL{{\beta_{L}}}
\newcommand\lambdaL{{\lambda_{L}}}
\newcommand\varphiL{{\varphi_{L}}}
\newcommand\psiL{{\psi_{L}}}
\newcommand\C{{\cos(4\psi)}}
\newcommand\mc{{\mathcal{M}}}

\newcommand{\jgb}[1]{{\color{DarkGreen} #1}}

\begin{document}

\title{Astrometry Inference Note}

\author{John G. Baker}
\affiliation{Gravitational Astrophysics Laboratory, NASA Goddard Space Flight Center, 8800 Greenbelt Rd., Greenbelt, MD 20771, USA}

\date{\today}

\begin{abstract}

This is back of the envelope note on estimating incited GW direction by temporally extended GW observation from a moving platform.

\end{abstract}

\pacs{
04.80.Nn, % Gravitational wave detectors and experiments
95.30.Sf, % relativity and gravitation
95.55.Ym, % Gravitational radiation detectors
}

\maketitle

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Introduction}

The basic idea is that we want to treat a 'synthetic aperature', but with measurements separated by space \emph{and time}. We need to compare the phases at two different spatial observation points to estimate a wavefront incidence angle. Befor doing so, however we need to first realize a time-transfer of the signals to a common time.  The time-transfer depends on the model of the signal and our measured knowledge of it at each time-separated observation.

For now we consider just two epochs of observation non-overlapping in time, but spatially separated because of the motion of the observatory. For this analysis we neglect any direct information about position from within each observation epoch (eg because of the attenna pattern, or finite instrument size) to focus only on the information gained by the instrument's motion.

\section{Minimally evolving source}

For an nearly monochromatic GW source, the signal model is nearly trivial, we will assume that the signal is monochromatic.
(An uncertain frequency drift would seem to break this analysis, as degenerate with the linearly computed phase difference
here, but observing over multiple orbits would break that degeneracy.)

For each epoch $\alpha$ of observation we assume some definition for an epoch-specific reference position $x^i_\alpha$ e.g.
the mean location of the observatory during that epoch and a similar epoch observation time $t_\alpha$.  Through the
observation we can estimate the incident wavefront phase $\varphi\alpha(t_\alpha)$
at that epoch's spacetime reference point.
We can compare the wavefront phases, by projecting them to some common reference time $t_0$ which we are free to select.
For a nearly monochromatic wavefront we estimate reference time phase from observation:
$$
\varphi_\alpha(t_0)\approx\varphi_\alpha(t_\alpha)+\omega_\alpha(t_\alpha)(t_0-t_\alpha) + \mathcal{O}\left(\frac{t_0-t_\alpha}{T_c}\right)
$$
where $\omega_\alpha$ is the signal frequency and $T_c$ is the intrinsic coherence time of the signal.
We won't have perfect knowledge of the epoch's phase and frequency. These will depend on how precisely these can be
inferred during the observation epoch, which in turn will also depend on the epoch SNR $\rho_\alpha$.

We estimate the error in the phase at reference time as
$$
\left(\delta\varphi_\alpha(t_0)\right)^2\approx\left(\delta\varphi_\alpha(t_\alpha)\right)^2+\left(\delta\omega_\alpha(t_0-t_\alpha)\right)^2.
$$
We approximate that the GW phase information content is uniformly distributed according to SNR within the signal so that we can approximate $\delta\varphi_\alpha(t_\alpha)\approx\bar{\delta\varphi}/(\rho_\alpha)$.  (For a chirping signal it might also be appropriate to make this proportional to $1/\omega_\alpha$.)

The estimate for error in the GW frequency estimate builds on that from the phase.  Suppose we split each epoch into two halves, then estimate
$$
\omega_\alpha(t_\alpha)\approx\frac{\varphi_{\alpha R}-\varphi_{\alpha L}}{T_\alpha/2}
$$
where $T_\alpha$ is the duration of the epoch. Again, if there is significant chirp during the epoch, more consideration is needed.  Then, again assuming equal distribution of phase info with $\rho$, and uniform accumulation of $\rho^2$ with time we estimate
$$
\left(\delta\omega_\alpha(t_\alpha)\right)^2\approx\frac{\left(\bar{\delta\varphi}\right)^2}{T_\alpha/2}\left(\frac{1}{\rho^2_{\alpha R}}+\frac{1}{\rho^2_{\alpha L}}\right).
$$
For the non-chirping example, the RHS is optimized when left and right SNRs are each equal to $\rho_\alpha/\sqrt2$.
$$
\delta\omega_\alpha(t_\alpha)\approx\sqrt{\frac{8}{\rho^2_\alpha T_\alpha}}\bar{\delta\varphi}
$$

Now can complete the estimate for the error in the phase at reference time as estimated by the epoch of observation
$$
\left(\delta\varphi_\alpha(t_0)\right)^2\approx\left(\frac{\delta\varphi}{\rho_\alpha}\right)^2\left(1 + 8\frac{\left(t_0-t_\alpha\right)^2 }{T_\alpha}\right).
$$

Now let us construct the angle estimate by comparing the reference phase measurments at epochs $a$ and $b$ between which the constellation has moved by $D=x_b-x_a$. We estimate the triangulation error by
$$
\left(\delta\theta\right)^2 \approx \frac{\lambda^2\left(\varphi_b(t_0)\right)^2+\left(\varphi_b(t_0)\right)^2}{D^2}
$$
where $\lambda$ is the GW wavelength.
Note that we have somewhat conservatively added all error terms in quadrature here. It is likely, though, there may be a common-mode phase errors particularly in the first (explicit phase error) term for each epoch.  Degneracy with intrinsic parameters, for instance, could be common mode.  The analysis assumes such error are not included here.  This likely reduces sensitivity to degeneracy.  In the end, we find that the frequency error terms dominate, where we only more subtle common-mode errors would enter.
If we assume that each epoch's squared SNR is propotional to its duration, then $\rho^2_\alpha=\rho^2(T_\alpha/T)$ where $\rho$ and $T$ are the SNR and duration of the full observation. We thus have
$$
\delta\theta\approx\frac{\lambda\bar{\delta\varphi}}{D}\left(\frac{T}{T_a}+\frac{T}{T-T_a} + 8\frac{\left(t_0-T_a/2\right)^2}{T^2_a} +8\frac{\left(t_0-(T+T_a)/2\right)^2}{(T-T_a)^2}\right)
$$
where we have assumed the epochs are consecutive with epoch $a$ beginning at $t=0$ so $b$ begins at $t=T_a$ and ends at $t=T$. Optimizing, we find minimum error at $T_a=t_0=T/2$, meaning that the minumum error construction is where there are equal durations (and equal SNR) for the two epochs and the phase is compared at the temporal midpoint.  Then,
$$
\bar{\delta\theta}\approx20\frac{\lambda\bar{\delta\varphi}}{D}.
$$
At this optimum, $4/5$ of the estimated comes from the frequency term.

Lastly, a good rough estimate for a good-quality observation is $\bar{\delta\varphi}\approx 1/\rho$, so
$$
\bar{\delta\theta}\approx20\frac{\lambda}{\rho D}.
$$
The factor or 20 is not something we had before.

\end{document}


\section{Equation of State}
CASTRO is written in a modular fashion so that the EOS and network
burning routines can be supplied by the user.   However, for the
examples presented later we use several EOS and network routines
that come with the CASTRO distribution.

EOS routines that come with CASTRO are (listed by directory name):
\begin{itemize}
\item {\bf GammaLawEOS} directory represents a gamma law gas.
\item {\bf HelmEOS} directory contains a general, publicly available
stellar equation of state based on the Helmholtz free energy,
with contributions from ions, radiation, and electron degeneracy, as
described in (Timmes and Arnett 1999, Times and Swesty 2000, and Fryxell et al. 2000).
\item {\bf LattimerSwestyEOS} directory contains a modified version of the
LS EOS available at http://www.astro.sunysb.edu/dswesty.  Full
documentation is available through that web site.  We use this EOS
in the 1D core collapse supernova example in a later section.
\end{itemize}

Each EOS directory contains two subroutines by which it interfaces to
the rest of the CASTRO code.  The first,
\[
{\bf \rm EosGivenRTX}(e^\outp, p^\outp, \rho^\inp, T^\inp, X^\inp, n_{\rm spec}, Y^\inp, n_{\rm aux})
\]
is a direct interface to the EOS, in which density, species and auxiliary variables,
and temperature are specified, and the necessary thermodynamical variables such as
internal energy, pressure, gamma, and sound speed are returned.

The second routine,
\[
{\bf \rm EosGivenReX}(\Gamma^\outp, p^\outp, c^\outp, T^\outp, \rho^\inp, e^\inp, X^\inp, n_{\rm spec}, Y^\inp, n_{\rm aux})
\]
uses a Newton iteration to find the temperature given
the internal energy, density, and species and auxiliary variables.
\section{Burning Network}
Burning network routines that come with CASTRO are (listed by directory name):
\begin{itemize}
\item {\bf networks/null} directory describes a non-reacting white dwarf,
with only hydrogen, helium and carbon12.   There are
no auxiliary variables, and no reactions are allowed.
\item {\bf networks/collapse} directory describes a pre-supernova neutron
star with hydrogen, helium, oxygen and iron, There is one auxiliary
variable, Ye, the electron fraction.  Again no reactions are
allowed.
\item {\bf networks/ignition} directory contains a single-step
$^{12}\mathrm{C}(^{12}\mathrm{C},\gamma)^{24}\mathrm{Mg}$ reaction.
The carbon mass fraction equation appears as
\begin{equation}
\frac{D X(^{12}\mathrm{C})}{Dt} = - \frac{1}{12} \rho X(^{12}\mathrm{C})^2
    f_\mathrm{Coul} \left [N_A \left <\sigma v \right > \right]\enskip,
\end{equation}
where $N_A \left <\sigma v\right>$ is evaluated using the reaction
rate from (Caughlan and Fowler 1988).  The Coulomb screening factor,
$f_\mathrm{Coul}$, is evaluated using the general routine from the
Kepler stellar evolution code (Weaver 1978), which implements
the work of (Graboske 1973) for weak screening and the work of
(Alastuey 1978 and Itoh 1979) for strong screening.
\end{itemize}

There are two primary files within each network directory. The first,
{\tt castro\_burner.f90}, contains the burner routine,
which takes $\rho^\inp, e^\inp, X_k^\inp$, and $\Delta t$ as inputs.
It is possible for the internal energy, $e$, which is computed from $\Ub$, to be
negative due to roundoff error.  CASTRO has an option to protect against using a
negative value of $e$ by recomputing $e = e(\rho,T_{\rm small},X_k)$ using the
equation of state, where $T_{\rm small}$ is a user-defined temperature floor.  In the
event that $e$ is still negative, we abort the program.  CASTRO also has an option to
skip the reactions if the density is below a user-defined density floor.

Next, the burner computes $T = T(\rho^\inp,e^\inp,X_k^\inp)$ using the equation of state.
The burner returns $X_k^\outp$ and $e^\outp$ by solving over a time interval of $\Delta t/2$,
\begin{eqnarray}
\frac{\partial X_k}{\partial t} &=& \omegadot_k.\\
\end{eqnarray}
In particular, to evolve the species, we solve the system:
\begin{eqnarray}
\frac{dX_k}{dt} &=& \omegadot_k(\rho,X_k,T)\enskip, \label{eq:VODE1C} \\
\frac{dT}{dt} &=&\frac{1}{c_p} \left ( -\sum_k \xi_k  \omegadot_k  \right )\enskip. \label{eq:tempreactC}
\end{eqnarray}
\MarginPar{Need to include temperature evolution equation somewhere}
using the stiff ordinary differential equation integration methods provided by
the VODE package.  The absolute error tolerances are set to
$10^{-12}$ for the species, and a relative tolerance of $10^{-5}$ is used for
the temperature.  The integration yields the new values of the mass fractions,
$X_k^\outp$.  Equation (\ref{eq:tempreactC}) is derived from equation (???) by
assuming that the pressure is constant during the burn state.  In evolving these
equations, we need to evaluate $c_p$ and $\xi_k$.  In theory, this means
evaluating the equation of state for each right-hand side evaluation that
VODE requires.  In practice, we freeze $c_p$ and $\xi_k$ at the start of
the integration time step and compute them using $\rho^\inp, X_k^\inp,$ and $T^\inp$
as inputs to the equation of state.  Note that the density remains unchanged during
the burning.  At the end of the routine, we compute
$T^\outp = T(\rho^\outp,e^{\outp},X_k^\outp)$.

The second file, ``{\tt network.f90}'', supply the
number of species and auxiliary variables, names of each species and
auxiliary variable, as well as other initializing data, such as
aion, zion and the binding energy.

It is straightforward to implement additional EOS and network routines; all that is required
is to create an appropriate interface to the CASTRO calls, which is easily done given
the prototypes supplied with the CASTRO distribution.


\documentclass[10pt,journal]{IEEEtran}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage[square, comma, sort&compress, numbers]{natbib}

\begin{document}
\bibliographystyle{IEEEtran}

\title{ {Joint Synchronization and Channel Estimation of ACO-OFDM Systems with Simplified Transceiver}
%\thanks{Manuscript received November 24, 2016.}
\thanks{
Manuscript received October 11, 2017; revised December 27, 2017; accepted January 7, 2018. Date of publication January XX, 2018; date of current version May 19, 2016. This work was supported by Central South University under Post-graduation Innovation Fund project (2016zzts228) and Mittal Innovation Fund project. It is also supported by Research Foundation of Education Bureau of Hunan Province [Project No. 17B238].
}
\thanks{
Xuewen Qian is with Laboratoire des Signaux et Syst��mes (L2S), CentraleSup\'elec-CNRS-Universit\'e Paris-Sud, Universit\'e Paris-Saclay, 3, rue Joliot Curie, 91192, Gif-sur-Yvette, France (e-mail: xuew.qian@gmail.com).
Honggui~Deng is with the Department of Physics and Electronics, Central South University (e-mail: denghonggui@163.com).
Hailang He is with Department of Information Engineering, Shaoyang University, Shaoyang, Hunan, China (e-mail:7887302@qq.com).
}
\thanks{
Color versions of one or more of the figures in this letter are available online at http://ieeexplore.ieee.org.
}
\thanks{
Digital Object Identifier XX.
}
}

\author{Xuewen Qian,
        %Marco Di Renzo,~\IEEEmembership{Senior Member,~IEEE}
        Honggui Deng, ~\IEEEmembership{Member,~IEEE}
        and~ Hailang He }
%\author{Xuewen~Qian,

 %       }

\maketitle
\begin{abstract}
To facilitate the development of asymmetrically clipped optical OFDM (ACO-OFDM) systems, a joint synchronization and channel estimation scheme is proposed. The preamble used in the scheme is based on zero correlation code pair (ZCC pair) and has impulse-like correlation relationship. This property can let the results of synchronization process be the coarsely estimated channel time response, thus simplifies channel frequency response generation. Also, a transceiver with low complexity is proposed. The proposed transceiver needs only half the amount of multiplications compared to conventional transceiver. Simulation results reveal that the proposed scheme achieves better performance both in synchronization and channel estimation than existing schemes.
\end{abstract}

\begin{IEEEkeywords}
Synchronization, channel estimation, ACO-OFDM, low complexity transceiver.
\end{IEEEkeywords}

\section{Introduction}
Visual light communication (VLC) technology\cite{Chi2015,Qian2016Synchronisation} is a promising technique providing light and ensuring data transmission at the same time. Besides, the light emitting diode (LED) \cite{tsonev20143,ferreira2016high} as one of the most popular light sources can promote the widespread utilization of VLC systems. However, multi-path distortion caused by the glass reflections can heavily reduce the communication qualities. Thus, orthogonal frequency division multiplexing (OFDM) technique is introduced to combat the multi-path effect.

Due to intensity modulation and direct detection in most VLC systems, many OFDM-based VLC systems resort to the direct current bias optical OFDM (DCO-OFDM) modulation, asymmetrically clipped optical OFDM (ACO-OFDM) and other schemes to generate positive signals. However, as revealed in \cite{Dissanayake2013Comparison}, it is better to choose ACO-OFDM scheme when constellations like quadrature amplitude modulation (QAM) and 16QAM are exploited since ACO-OFDM scheme has higher optical power efficiency especially for some scenarios such as Internet of Things (IoT) systems.

In IoT systems, low complexity is essential to the ACO-OFDM system implementation. For lower power consumption and higher data rates, ACO-OFDM schemes are integrated to develop other modulation techniques, such as asymmetrically clipped DC-biased optical OFDM (ADO-OFDM), hybrid ACO-OFDM (HACO-OFDM) and layered ACO-OFDM (LACO-OFDM)\cite{yang2016novel,Wang2017Optical}. Therefore, ACO-OFDM scheme with low complexity is important and must be researched.

It is well known that OFDM systems are sensitive to synchronization errors and are heavily affected by the complex channels. Many researches focus on making use of the preamble symbols to synchronize signals and estimate channel frequency response at the same time. Like systems in radio communication systems, the channel state information (CSI) is estimated via preamble symbols in time domain and the channel frequency response can be calculated using CSI.

In \cite{Tian2008}, Tian et. al. proposed a synchronization scheme based on the symmetric symbols. However, this scheme has low estimation precision and the high side-lobes. Ranjha et. al \cite{Ranjha2015} proposed a new timing metric with synchronization performance enhancement but the scheme still has high side-lobes. Thus, the results of synchronization process of Tian's and Ranjha's schemes cannot be exploited for channel estimation. For channel estimation, a common scheme is least square (LS) estimation scheme \cite{wu2016channel}.
The synchronization and channel estimation scheme cannot be combined as a whole for the mentioned schemes.
Aspired by \cite{Qian2017}, modified zero correlation code (ZCC) pair symbols designed based on Physical layer for dynamic spectrum access and cognitive radio (PHYDYAS) \cite{Bellanger2010} filter have impulse-like aperiodic correlation results and are used to estimate CSI to perform channel estimation in DCO-OFDM systems. %This kind of technique can also be applied to ACO-OFDM channel estimation and synchronization.

In this letter, the ACO-OFDM system is firstly investigated and a new transceiver is proposed to reduce the calculation complexity. After that a joint synchronization and channel estimation scheme based on ZCC pair is proposed for ACO-OFDM system.
The rest is organized as follows. In Section II, the system model is presented, including the channel model, ACO-OFDM-based VLC system and the new transceiver. Then, the joint synchronization and channel estimation scheme is proposed in Section III. In Section IV, performance and simulation results are analysed. In the end, the conclusion is drawn in Section V.

\section{System Model}

	\subsection{VLC Channel Model}
		A realistic VLC channel is determined by many factors. As simulated in \cite{Uysal2015Lifi}, in manufacturing cell environment, the maximum path delay may exceed 80ns which is bigger than that of home environment.
%the maximum path delay in home environment is about 60ns and there is often one line of sight (LOS) response while the not line of sight (NLOS) responses are extremely small. However in manufacturing cell environment, the maximum path delay may exceed 80ns.
There are more strong responses as many light traces.

		The VLC channel can be modeled as
        \begin{equation}\label{channel_model}
          h(\tau)=\sum_{l=0}^{L-1}g(l)\delta(\tau-\tau_l),
        \end{equation}
        where $g(l)$ and $\tau_l$ denote the gain and delay of the l-th transmission path, $\delta(\tau)$ denotes the Dirac function and $L$ represents the number of path.
        The $h(\tau)$ can be made discrete at a sampling speed.
        For simplicity, we assume that $\tau_l$ is an integer.
        Since VLC systems can only transfer intensity signals, $g(l)\geq0$.

    \subsection{ACO-OFDM-based VLC system}
		Considering an ACO-OFDM system with N sub-carriers, the signal after IFFT is
		\begin{equation}\label{equ:ACO_OFDM_base}
          x(n)=\frac{1}{\sqrt{N}}\sum_{i=0}^{N-1}X_{i}e^{j2\pi\frac{ni}{N}},-N_{CP}\leq n \leq N-1,
        \end{equation}
        where $n$ denotes the index of signal in time domain and $X_{i}$ denotes the modulated data on the k-th sub-carrier. The $N_{CP}$ represents CP length.
        To make $x(n)$ be real, $X_{i}$ must follow the Hermite symmetry property which is
		\begin{equation}\label{equ:Hermite_symmetry}
          X=[X_0,X_1,\ldots,X_{N/2-1},X(N/2),X_{N/2-1}^{*},\ldots,X_{1}^{*}].
        \end{equation}
		In ACO-OFDM systems, only the odd sub-carriers are used and the even sub-carriers are set to zero so that $ x(n)=-x(n+N/2) $ when $
0\leq n\leq N/2-1 $. In this way, $ x(n) $ can be clipped at zero to be $ x_c(n) $ without information loss. Then, the cyclic prefix (CP) is introduced to overcome the multipath channel.

		The effect of multipath channel is
        \begin{equation}\label{equ:multipath_effect}
          y(n)=\sum_{l=0}^{L-1}h(l)x_c(n-\tau_l)+w(n),
        \end{equation}
        where $h(l)$ represents the VLC channel time domain response and $w(n)$ denotes the total noise which is modeled as white Gaussian noise\cite{Narmanlioglu2015}.

        In frequency domain, (\ref{equ:multipath_effect}) can be expressed as
        \begin{equation}\label{equ:multipath_effect_frequency}
          Y(m)=H(m)X_c(m)+\eta(m),
        \end{equation}
        where $Y(m)$, $H(m)$, $X_c(m)$ and $\eta(m)$ denote the FFT transform results of $y(n)$, $h(\tau)$, $x_c(n)$ and $w(n)$, respectively. Normally, $X_c(2m+1) = X(2m+1)/2 $ when $0\leq m\leq N-1$ \cite{Wang2017Optical}.
        If the $X_c(2m+1)$ is known in advance, $H(2m+1)$ can be acquired via LS method
        \begin{equation}\label{equ:LS}
          \widehat{H}(2m+1) = Y(2m+1) / X_c(2m+1), 0\leq m\leq N-1.
        \end{equation}
        %since only the used sub-channels are useful.

	\subsection{Simplified Transmitter and Receiver}
		Since the original signals are clipped at zero, the direct FFT results of $ x_c(n) $ are not the same as that of $ x(n) $, but the odd sub-carriers are not distorted. %Only the odd sub-carriers are necessary.

		If we denote $ C $ as the first half of $ x(n) $, then $ x=[C;-C] $. If we denote $ A $ and $ B $ as the first half and second half of $ x_c(n) $, then $ C = A - B $. Thus, when $ C $ is generated via IFFT of $ N/2 $ length, $ x(n) $ can be obtained without using IFFT of $ N $ length which reduces the calculation complexity.

		For $ 0\leq n \leq N/2-1 $, $ C $ can be generated via
		\begin{eqnarray}\label{equ:sim_transmitter}
			x(n) &=& \sum_{i=0}^{N/2-1} X_{2i+1}e^{j\frac{2\pi}{N}n(2i+1)} \nonumber\\
				 &=& \sum_{k=0}^{N/2-1} X_{k} e^{j\frac{2\pi}{N/2}nk}e^{j\frac{2\pi}{N}n} \nonumber\\
				 &=& IFFT(X)_{N/2}e^{j\frac{2\pi}{N}n},
		\end{eqnarray}
		where $ IFFT(\cdot)_{N/2} $	represents the IFFT process of $ N/2 $ length.	There are $ N/2 log_2(N/2) + N/2 = N/2 log_2(N) $ multiplications used in generation of $ C $ which is just  half the calculations of conventional method $( N log_2(N) )$.

		For the receiver, the results of the FFT process must be multiplied with 2 due to the signal clipping \cite{Wang2017Optical}. Since only the odd sub-carriers are necessary, thus the received data on the $ 2i+1 $ sub-carrier can be obtained as
        %\begin{small}
		\begin{eqnarray}\label{equ:sim_receiver}
            %\begin{split}
			 %&X_{2i+1}& \nonumber\\
            X_{2i+1}&=& \frac{2}{N}\sum_{n=0}^{N-1} y(n) e^{-j\frac{2\pi}{N}n(2i+1)}\nonumber\\
			&=& \frac{2}{N}\sum_{n=0}^{N/2-1} y(n) e^{-j\frac{2\pi}{N}n(2i+1)}  \nonumber\\
			&&+ \frac{2}{N}\sum_{n=0}^{N/2-1} y(n+N/2) e^{-j\frac{2\pi}{N}(n+N/2)(2i+1)} \nonumber\\
			&=& \frac{2}{N}\sum_{n=0}^{N/2-1} y(n) e^{-j\frac{2\pi}{N}n(2i+1)}  \nonumber\\
			&&- \frac{2}{N}\sum_{n=0}^{N/2-1} y(n+N/2) e^{-j\frac{2\pi}{N}n(2i+1)} \nonumber\\
			&=& \frac{2}{N}\sum_{n=0}^{N/2-1} ( y(n)-y(n+N/2) ) e^{-j\frac{2\pi}{N}n(2i+1)}  \nonumber\\
					 %&=& \sum_{n=0}^{N/2-1} ( y(n)-y(n+N/2) ) e^{-j\frac{2\pi}{N}n} e^{-j\frac{2\pi}{N/2}ni} \nonumber\\
			&=& FFT( ( y(n)-y(n+N/2) ) e^{-j\frac{2\pi}{N}n} )_{N/2},
            %\end{split}
		\end{eqnarray}
        %\end{small}
		where $ FFT(\cdot)_{N/2} $	represents the FFT process of $ N/2 $ length. Just as the proposed transmitter, the computational complexity of proposed receiver is half that of conventional receiver.

		%\begin{figure}[htb]
		%	\centering \includegraphics[width=8cm]{asymmetric_property_ACO_OFDM.eps}
		%	\caption{The symmetric property of symbols after the multipath channels} \label{fig:symmetric_property_illustration}
		%\end{figure}

\section{Synchronization and Channel Estimation Scheme with Low Complexity Transceiver}
	In \cite{Qian2016Synchronisation}, zero-correlation-code (ZCC) pair is proposed to synchronize signal in DCO-OFDM-based VLC systems. In \cite{Qian2017}, modified ZCC pair generated via PHYDYAS filters can be used to obtain the gains and delays of the multi-path channels.
%There is no frequency offset in VLC systems due to the intensity modulation and demodulation property. This makes synchronization and channel estimation process easier than systems in radio communications.
Unlike DCO-OFDM systems, the transmitted signals of ACO-OFDM systems from the data generated after IFFT process are clipped at zero. It is hard to exploit ZCC pair sequences in ACO-OFDM systems directly. To reserve the impulse-like correlation property of ZCC pair sequences, the received signals must be investigated.

	The following is to show that $ y(n)-y(n+N/2) $ contains $ C $.
	%If $C$ is generated to be ZCC pair sequence,
	We denote the $A^{'}$ and $A^{''}$ as the parts of the delayed $A$ and denote  $B^{'}$ and $B^{''}$ as the parts of the delayed $B$ and delayed CP.
	By investigating the effect of multi-path channels,
	\begin{figure}[htb]
        \captionsetup{belowskip=-5pt}
		\centering \includegraphics[width=5cm]{effect_of_channel_ACO_OFDM.eps}
		\caption{The illustration for the effect of multipath channels on symbols} \label{fig:effect_of_channel_ACO_OFDM}
	\end{figure}
	Since $C^{'}=A^{'}-B^{'}$ and $C^{''}=A^{''}-B^{''}$, the results of $y(n)-y(n+N/2)$ are shown in Fig.\ref{fig:effect_of_channel_ACO_OFDM}.

	If $C$ and $D$ are set to be the ZCC pair sequence and the pair sequence, the aperiodic correlation between $C$ and $D$ is impulse-like.
	%Since there is no frequency offset in VLC systems,
	%As shown in \cite{Qian2017}, the
	Because $ \sum_{n=0}^{N/2-1}C(n+k)D^*(n)=N/2 \delta(k) $, the CSI can be estimated via
	%\begin{small}
	\begin{align}\label{equ:gain_acquire}
        %\begin{split}
          %\bar{h}(k)&\nonumber\\
          \bar{h}(k)=&\frac{2}{N}\sum_{n=0}^{N/2-1}(y(n+k)-y(n+k+N/2))D^*(n)\nonumber\\
          =&\frac{2}{N}\sum_{n=0}^{N/2-1}\sum_{l=0}^{L-1}(h(l)(x(n+k-l)-x(n+k-l+N/2))\nonumber\\
          &+w(n+k-l)-w(n+k-l+N/2))D^*(n)\nonumber\\
          =&\frac{2}{N}\sum_{l=0}^{L-1}h(l)\sum_{n=0}^{N/2-1}C(n+k-l)D^*(n)+\tilde{w}(k)\nonumber\\
          =&\sum_{l=0}^{L-1}h(l)\delta(k-l)+\tilde{w}(k).
        %\end{split}
    \end{align}
	%\end{small}
    %where $\tilde{w}(k)$ denotes the noise.

    The next step is to design the required preamble sequence for synchronization and channel estimation. %According to (\ref{equ:sim_transmitter}), all the sub-carriers are needed to generate $ C $. to some extent.

	The detailed steps to generate $ C $ are listed as:

    Step1: Define $S$ as a vector of $N/16+1$ length consisting of $1$ and $-1$:
        $S=[1, \cdots 1, \cdots -1, \ldots -1]^T$.

    Step2: $S$ is multiplied by a matrix $diag([1,j,-1,j^3,\ldots j^{N/16-1},j^{N/16}])$ to be $S_{a}$. This is also called offset quadrature amplitude modulation process.

    Step3: Define $S_b$ as a vector with Hermite property via

        $S_b=[S_{a}(0),S_{a}(1),\cdots S_{a}(N/16),S_{a}^*(N/16-1),\cdots S_{a}^*(1)]^T$.

	Step4: Inverse Fourier transform the $S_b$ to be $S_c$.

    Step5: Finally, we get the required sequence $C$ via $C=[ S_c; S_c; S_c; S_c]\cdot g$. The $g$ is given in \cite{Bellanger2010}.

    According to the relationship of ZCC pair sequences, $D$ is the same as $C$ generated based on PHYDYAS filter. Thus, the preamble in the proposed scheme is designed according to $C$ and the timing offset estimation metric is expressed as
    \begin{eqnarray}\label{equ:synchronization}
          M(k)=\frac{2}{N}\sum_{n=0}^{N/2-1}(y(n+k)-y(n+N/2+k))C^*(n).
    \end{eqnarray}
    Then the timing instant is calculated as
    \begin{equation}\label{equ:d}
            \hat k=\arg\max\limits_{k}(\|M(k)\|),
    \end{equation}
    where $\arg\max\limits_{k}(\|M(k)\|)$ means returning the timing instant $\hat k$ when the absolute value of $M(k)$ is the biggest. It performs an one-dimensional search to find $\hat k$.

    Since the $ h $ is positive, the negative values in $ \bar{h} $ (obtained from (\ref{equ:synchronization}) ) are set to zero to be $ h^{'} $. After the CSI is acquired, the channel frequency response can be calculated via
    \begin{equation}\label{equ:Channel_Fre}
          H(k)=\sum_{l=0}^{L-1}h^{'}e^{-j2\pi\frac{\tau_l k}{N}},0\leq k \leq N-1.
    \end{equation}
    Also, only the odd sub-carriers are transmitting data. Therefore the simplified channel frequency response is expressed as
    \begin{equation}\label{equ:Channel_Fre_sim}
          H(2k+1)=\sum_{l=0}^{L-1}(h^{'}e^{-j2\pi\frac{\tau_l}{N}})e^{-j2\pi\frac{\tau_l k}{N/2}},0\leq k\leq N/2-1.
    \end{equation}
    The calculation complexity of (\ref{equ:Channel_Fre_sim}) is just half of (\ref{equ:Channel_Fre}).

    The received data in frequency domain can be equalized as
    \begin{equation}\label{equ:equalizer}
       X^{'}(2k+1)=\dfrac{2Y(2k+1)}{H(2k+1)},0\leq k\leq N/2-1.
    \end{equation}

    The whole simplified ACO-OFDM system is depict in Fig.\ref{fig:sim_ACO_OFDM_system}.
    \begin{figure}[!htb]
        \captionsetup{belowskip=-5pt}
    	\centering \includegraphics[width=9cm,height=3cm]{ACO_OFDM_system.eps}
		\caption{The illustration for the simplified ACO-OFDM system} \label{fig:sim_ACO_OFDM_system}
    \end{figure}
    The IFFT and FFT process in the system are of $ N/2 $ length. After the generation of $ C $, the positive and negative of $ C $ are used to compose ACO-OFDM symbols and the CP is added before transmitted by optical transmitters. The received signals are firstly subtracted. Then results are used to calculate the right timing point via (\ref{equ:synchronization}). When the right timing point is obtained, the needed channel frequency response is calculated via (\ref{equ:Channel_Fre_sim}) after the negative part of synchronization results are set to zero. In the end, data are equalized according to (\ref{equ:equalizer}).

\section{Simulation and Analysis}
	The simulation channel is the indoor manufacturing cell channel given by \cite{Uysal2015Lifi}. Some other simulation parameters are listed in the Table. \ref{Tab:paramters}.

    \begin{table} [htb]
        \caption{The parameters of simulation}
        \captionsetup{belowskip=-10pt}
         \centering\begin{tabular}{|l|c|}
                    \hline
                    Parameters & Value\\
                    \hline
                    Number of subcarriers & 512 \\
                    \hline
                    CP length & 64\\
                    \hline
                    Frame length & 16 OFDM symbols\\
                    \hline
                    Bandwidth & 500MHz \\
                    \hline
                    Constellation order & 16QAM \\
                    %Maximum time delay $\tau_{max}$ & 50  \\
                    %Number of paths L & [$0.1\tau_{max}$,$0.9\tau_{max}$] \\
                    %Pilot distribution & Scattered \\
                    \hline
                    Simulation trial number & 100000 \\
                    \hline
                    Room area W$\times$H$\times$L & 2$\times$4$\times$3$m^3$\\
                    \hline
                    Receiving node(PD)area & 1$cm^2$ \\
                    \hline
                    Conversion efficient of photoelectricity & $0.5A/W$ \\
                    \hline
                    Receiver field of view(FOV) & $60^{\circ}$ \\
                    \hline
                    \end{tabular}
         \label{Tab:paramters}
    \end{table}

	\begin{figure}[!htb]
        %\setlength{\abovecaptionskip}{-0.1cm}
        \captionsetup{belowskip=-10pt}
    	\centering \includegraphics[width=6cm]{synchronization_mse.eps}
		\caption{The MSE performance comparison of synchronization schemes} \label{fig:synchronization_mse}
    \end{figure}
    Fig.\ref{fig:synchronization_mse} shows the normalized MSE value of timing offset estimation with respect to the IFFT length. The MSE values of the three schemes decrease with enlarging the SNR value. The Tian's scheme achieves the worst performance compared with the Ranjha's and proposed schemes. When SNR value is large, the estimation error is just one third of that of Ranjha's scheme. If the SNR is below 16 dB, the Ranjha's scheme has better performance but the performance difference is small.
    %As to the calculation complexity, the Tian's scheme needs $ N/2-2 $ multiplications at each discrete sample time, while Bilal's \cite{Ranjha2015} and proposed schemes both need
    In \cite{chow2013adaptive}, the OFDM-based VLC systems using common LEDs are tested and the suggested SNR values are over 18dB.
    Thus, the proposed scheme is good enough.

    \begin{figure}[!htb]
        %\setlength{\abovecaptionskip}{-0.1cm}
        \setlength{\abovecaptionskip}{10pt}
        \captionsetup{belowskip=-10pt}
    	\centering \includegraphics[width=6cm]{channel_estimation_HMSE.eps}
		\caption{The channel frequency estimation performance comparison of LS and proposed scheme}
        \label{fig:channel_estimation_HMSE}
    \end{figure}
    Fig.\ref{fig:channel_estimation_HMSE} presents a comparison of channel frequency response estimation performance. The channel frequency estimation MSE value of LS scheme decreases with enlarging SNR with steady slope, while the MSE value of proposed scheme drops gradually to a level but is much lower than that of LS scheme. The proposed scheme has better channel estimation performance than LS scheme.

    %In terms of the calculation complexity, for the proposed algorithm, most calculation can be done via the system FFT module. Only $ N/2 $ multiplications are needed for the simplified channel frequency response.
    %The proposed algorithm is easier than conventional

    \begin{figure}[!htb]
        \setlength{\abovecaptionskip}{10pt}
        \captionsetup{belowskip=-10pt}
    	\centering \includegraphics[width=6cm]{channel_estimation_BER.eps}
		\caption{The BER performance comparison of LS and proposed scheme} \label{fig:channel_estimation_BER}
    \end{figure}

	Fig.\ref{fig:channel_estimation_BER} shows BER performances of the LS scheme, proposed scheme and the ideal performance with prior knowledge of CSI. The proposed scheme has BER performance similar to the ideal performance and is better than LS scheme.

	%Overall, the proposed joint synchronization and channel estimation scheme has better performance than other schemes.

\section{Conclusion}
In this letter, a joint synchronization and channel estimation scheme is proposed for ACO-OFDM systems. A simplified transceiver is proposed which only needs half the calculations compared with conventional transceiver. Simulations have revealed that the proposed scheme has better timing MSE performance than Tian's and Ranjha's schemes in synchronization task and has better channel frequency response MSE performance and BER performance than LS channel estimation scheme.

\scriptsize{\bibliography{mybibtex}}
\end{document}


\documentclass{scrartcl}
\usepackage{threeparttable}

\usepackage{relsize}
\usepackage{xspace}

\usepackage{listings}
\lstset{language=MATLAB,numbers=left,frame=lines}
\lstnewenvironment{snippet}{\lstset{numbers=none,frame=none}}{}

\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{graphicx}

\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\tikzstyle{decision} = [diamond, draw, fill=blue!20,
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
    text width=7em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em]

\newcommand{\RR}{\mathbb{R}}
\newcommand{\trace}{\textrm{tr}}
\renewcommand{\SS}{\mathbb{S}}

\newcommand{\find}{\textrm{find}}
\newcommand{\minimize}{\textrm{minimize}}
\newcommand{\maximize}{\textrm{maximize}}
\newcommand{\subjto}{\textrm{subj. to}}

\newcommand{\li}[1]{\lstinline{#1}}
\newcommand{\spotless}{SPOT{\relsize{-2}LESS}\xspace}
\newcommand{\msspoly}{\lstinline{ msspoly}\xspace}
\newcommand{\spotprog}{\lstinline{spotprog}\xspace}
\newcommand{\spotsdpsol}{\lstinline{spotsdpsol}\xspace}
\newcommand{\spotsosprog}{\lstinline{spotsosprog}\xspace}

%\newcommand{\matlab}{MATLAB$^\textregistered$}
\title{\spotless \\ Polynomial and Conic Optimization}
\author{ Mark M. Tobenkin, Frank Permenter, Alexandre Megretski}
\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
\spotless is a software toolbox for MATLAB for posting conic \cite{cone} and sum-of-squares (SOS) optimization problems \cite{sos}.
The basic functionality provided:
\begin{enumerate}
\item A simple, reasonably fast approximate symbolic algebra package.
\item A modeling tool for posing and pre-/post-processing conic optimization problems.
\item A modeling tool for posing SOS problems.
\end{enumerate}
Several alternative tools exist for addressing these problems, notably  CVX \cite{cvx} and Yalmip \cite{yalmip}.  We recommend these packages as more user-friendly modeling environments -- the emphasis of \spotless is on providing an {\it extensible} tool for {\it  building other libraries}.

\section{Quick Start}
This section provides an explanation of the basic capabilities of \spotless, and provides simple examples of solving conic and SOS programs and inspecting the solutions.

\subsection{Basic \spotless Work-Flow}
The basic work-flow in \spotless is as described by Figure~\ref{fig:basic}.

\begin{figure}
  \centering
\begin{tikzpicture}[node distance = 2.222222cm, auto]
    % Place nodes
    \node [block] (prog) {Create \\Program};
    \node [block,below of=prog] (new) {Create \\ Variables\\(\lstinline{prog.new...})};
    \node [block,below of=new] (with) {Add \\Constraints\\ (\lstinline{prog.with...})};
    \node [block,below of=with] (solve) {Solve \\ (\lstinline{prog.minimize})};
    \node [block,below of=solve] (feas) {Check Feasibility and Accuracy};
    \node [block,below of=feas] (solution) {Extract Solution};

    \path[line] (prog) -- (new);
    \path[line] (new) -- (with);
    \path[line] (solve) -- (feas);
    \draw[->] (feas) -- node[pos=0.5]{If Feasible}(solution);
    \draw [->]  (with.east)  -- ++(10mm,0) |- node [black, near end, yshift=0.75em] {} (new.east);
    \path[line] (with) -- (solve);
  \end{tikzpicture}
\caption{Basic \spotless workflow.\label{fig:basic}}
\end{figure}

Let's walk through the following example to provide some more detail.
The input to the program is a pair of positive integers $(n,m)$ a matrix $A \in \RR^{n \times m}$ and a vector $b \in \RR^{n}$. The program is defined by:
\begin{flalign*}
  \mathop{\minimize}_{x\in\RR^m} \quad & \sum_{i=1}^m |x_i|\\
  \subjto \quad & Ax = b.
\end{flalign*}
\begin{lstlisting}
prog = spotprog;
[prog,x] = prog.newFree(m);
prog = prog.withEqs(A*x - b);

[prog,a] = prog.newPos(m);
prog = prog.withPos(a - x);
prog = prog.withPos(a - (-x));

obj = sum(a);

sol = prog.minimize(obj);

if sol.solutionQuality < 0
    error('Solution is of very low quality.');
elseif sol.solutionQuality < 1
    warning('Low solution quality.');
end
if sol.primalInfeasible || sol.dualInfeasible
    error('Infeasibility detected.');
end

xopt = double(sol.eval(x));
\end{lstlisting}

\subsubsection{Create a program} First, one constructs a program object as in
\begin{lstlisting}[firstnumber=1,frame=none]
  prog = spotprog;
\end{lstlisting}
for conic programming. For SOS programming one instead uses
\begin{lstlisting}[numbers=none,frame=none]
  prog = spotsosprog;
\end{lstlisting}
\subsubsection{Create Variables}
  Next, one constructs new decision variables, e.g.
\begin{lstlisting}[frame=none,firstnumber=2]
[prog,x] = prog.newFree(m);
\end{lstlisting}
updates \lstinline{prog} to have \li{m} new free (unconstrained) variables, stored in the vector \li{x}.
A similar syntax modifies the program to have \li{m} non-negative variables:
as in
\begin{lstlisting}[frame=none,firstnumber=5]
[prog,a] = prog.newPos(m);
\end{lstlisting}
stored in the vector \li{a}.  The types supported by \spotprog are  listed in Table~\ref{tab:spotprog_types}.
\subsubsection{Add Constraints}
  Equality constraints are defined by expressions which must be equal to zero, i.e.
\begin{lstlisting}[frame=none,firstnumber=3]
prog = prog.withEqs(A*x - b);
\end{lstlisting}
ensures $Ax = b$.  Additional ``conic'' constraints can be added, e.g.
\begin{lstlisting}[frame=none,firstnumber=6]
prog = prog.withPos(a - x);
\end{lstlisting}
  requires \lstinline{a(i)} $\geq$ \lstinline{x(i)} for $i \in \{1,\ldots,m\}$.
  Similar function calls, (i.e. \lstinline{prog.withType()}) are used to impose other kinds of constraints.
\subsubsection{Solve The Program}
The next step is to identify an objective, and solve the program:
\begin{lstlisting}[frame=none,firstnumber=11]
sol = prog.minimize(obj);
\end{lstlisting}
here \li{obj} is an affine expression in decision parameters and \li{sol} is a solution object.
Calling \li{prog.minimize} without a first argument, or with zero as the first argument solves a feasibility problem.  See Section~\ref{sec:sol} for more details about specifying a solver and adding pre-/post-processing options.
\subsubsection{Examine Feasibility and Accuracy}
Ideally, a ``solution'' to a conic programming problem should consist of one of:
\begin{enumerate}
  \item[(i)] A pair of primal and dual feasible points which are optimal.
  \item[(ii)] A primal improving direction (proving dual infeasibility).
  \item[(iii)] A dual improving direction (proving primal infeasibility).
\end{enumerate}
Solution {\it quality} in \spotless refers to a numerical measure of confidence that the solver has obtained such a solution.
Both poorly posed problems and numerical errors can lead to a low quality solution.
Section~\ref{sec:bad} contains some examples of programs for which no solution in the above sense exists.

Once a solver has been called, one must examine the quality of the returned solution. Note that {\bf the interpretation of solution quality is application dependent!}  Please see Section~\ref{sec:sol} for information about customizing solution quality reporting for your application.
Negative solution quality is supposed to indicate a useless solution, as tested by
\begin{lstlisting}[frame=none,firstnumber=13]
if sol.solutionQuality < 0
\end{lstlisting}
whereas solution quality less than \li{1} is supposed to be circumspect.

If the soluton quality is high, one can still have an {\it infeasible} program, as test by
\begin{lstlisting}[frame=none,firstnumber=18]
if sol.primalInfeasible || sol.dualInfeasible
\end{lstlisting}
Primal infeasibility generally implies that no choice of decision variables satisfies the given constraints.  Dual infeasibility often means that the optimal cost is unbounded below.  A more thorough account is given in Section~\ref{sec:feas}.
\subsubsection{Extract Solution}
To extract a solution, one first uses \li{sol.eval} to substitute optimal decision parameters into any algebraic expression, e.g.
\begin{lstlisting}[frame=none,firstnumber=18]
xopt = double(sol.eval(x));
\end{lstlisting}
Here, \li{double} is then used to transform the resulting expression from \spotless's internal symbolic algebra library into a numerical vector.
\subsection{Basic Types}

\begin{table}
  \centering
  \begin{threeparttable}[b]
  \caption{Constraint Types for \spotprog\label{tab:spotprog_types}}
  \begin{tabular}{|l|lll|}
    \hline
    Type& Abbrev. & Vector Space & Constraint\\
    \hline
    Free & \lstinline!Free! & $ x \in \RR^n$ & \\
    Positive & \lstinline!Pos! & $x\in\RR^n$ & $x_i \geq 0$\\
    Lorentz & \lstinline!Lor! & $x \in\RR^{n\times m}$ & $x_{1j}^2 \geq \sum_{i=2}^n |x_{ij}|^2$, \quad $\forall j$\\
    Rotated Lorentz & \lstinline!RLor! & $x\in\RR^{n\times m}$ & $x_{1j} \geq 0, \quad x_{1j}x_{2j} \geq \sum_{i=3}^n |x_{ij}|^2$\quad $\forall j$\\
    Positive Semidefinite & \lstinline!PSD! & See below.\tnote{1}
&\\
\hline
\end{tabular}
\begin{tablenotes}
\item [1]  The positive semidefinite cone refers to matrices $X \in \RR^{n\times n}$ such that $v^T X v \geq 0$
      for all $v \in \RR^n$.  Two representations are used in \spotless:  a single PSD variable can be represented by an $n\times n$ \msspoly and  a set of $N$ PSD variables can be represented as ${n+1 \choose 2}\times N$ \msspoly.  When $N=1$ this transformation from one representation to the other is given by \lstinline{mss_v2s} (read: vector-to-symmetric) and \lstinline{mss_s2v} (read: symmetric-to-vector):
  \[
  \lstinline{mss_s2v(X)} = \begin{bmatrix} X_{11} \\ X_{12} \\ X_{22} \\ X_{13} \\ \vdots\end{bmatrix}
\qquad   \lstinline{mss_v2s(x)} = \begin{bmatrix}
    x_1 & x_2 & x_4 & \ldots \\
    x_2 & x_3 & x_5 & \ldots \\
    x_5 & x_3 & x_6 & \ldots \\
    \vdots & \vdots & \vdots & \ddots
  \end{bmatrix},
  \]
  where $X \in \RR^{n\times n}$ and $x \in \RR^{n+1 \choose 2}$.
  {\bf N.B.}: Generally:
  \[
 \trace(\lstinline[mathescape]!X*S!) \not \equiv \lstinline{mss_s2v}(X)'*\lstinline{mss_s2v}(S).
 \]
\end{tablenotes}
\end{threeparttable}
\end{table}

% \end{tabular}

\subsection{Conic Programming Examples}
\subsubsection{$\ell_\infty$ Fitting Example}
Given an positive integers $N$ and $d$ find $x \in \RR^{n}$ to solve:
\begin{flalign*}
  \minimize \quad & \max_{i \in \{-N,\ldots,N\}} \left \{\left |\sum_{i=0}^d x_{i+1} \left(\frac{i}{N}\right)^d - \left |\frac{i}{N}\right|\right| \right \}, \\
  \subjto \quad & x \in \RR^{d+1}.
\end{flalign*}
\lstinputlisting[title=examples/linf\_fitting.m]{examples/linf_fitting.m}
This program fits a degree 5 polynomial in $t$ to the function $|t|$ over $[-1,1]$.  Line 9 constructs a new program.  Lines 11 and 12 introduce the indeterminate t and constructs the vector \lstinline{basis = [ 1 ; t ; ... ; t^d]}.  A vector of $d+1$ coefficients are created on Line 13, and on Line 14 used to construct a function \lstinline{f = coeff(1) + coeff(2)t + ...}.  The function \lstinline{msubs} is used on line 16 to evaluate \lstinline{f} at each \lstinline{t = tt(i)} (returning a row).  Finally Lines 19 and 20 require the free variable \lstinline{obj} to satisfy \lstinline{obj} $\geq$ \lstinline{err(i)} and \lstinline{-err(i)}  respectively for each $i$.  The program is solved (Line 22), and the optimal coefficients are substituted into \lstinline{f} and stored in \lstinline{fopt} on Line 24.

\subsubsection{SDP Projection Example}
Given $A = A' \in \RR^{n\times n}$, solve:
\begin{flalign*}
  \minimize \quad & \|A-X\|_F \\
  \subjto \quad & X \in \SS_{n,+}.
\end{flalign*}
\lstinputlisting[title=examples/sdp\_projection.m]{examples/sdp_projection.m}

The optimization problem begins at line 6 by constructing a new program.  Line 7 constructs a new $n\times n$ PSD decision variable,\lstinline{P}, and line 8 a 1-by-1 free variable, \lstinline{obj}.  Line 10 constraints \lstinline{obj} to be greater than the $2$-norm of $P-A$ when regarded of as a vector using a Lorentz cone constraint (see Section \ref{sec:cones}).  A solution is then generated to the problem of minimizing \lstinline{obj} with the default solver on Line 12.  Finally, Line 14 substitutes the optimizing variables into the expression for \lstinline{P}, and then transforms that expression in a MATLAB double array stored in \lstinline{Popt}.

\subsubsection{SDP Control Design Example}
Given a matrix pair $(A,B) \in \RR^{n\times n} \times \RR^{n \times m}$ representing a stabilizable discrete time LTI system
\[
x[t+1] = A x[t] + B u[t],
\]
find matrix $K \in \RR^{m \times n}$ such that $A+BK$ is exponentially stable.
For $\rho \in (0,1)$ solve
\begin{flalign*}
  \find \quad & (S,L) \in \SS_{n,+} \times \RR^{m\times n} \\
  \subjto \quad &
\begin{bmatrix} (1-\rho)S   & AS+BL\\
  SA'+L'B' &   S
  \end{bmatrix} \in \SS_{2n,+}.
\end{flalign*}
and take $K = LS^{-1}$.
\lstinputlisting[title=examples/sdp\_lti\_control.m]{examples/sdp_lti_control.m}

\subsection{SOS Programming Examples}
\subsubsection{Upper Bound Polynomial On Sphere}
\begin{lstlisting}
% Construct a random polynomial.
n = 2;
d = 4;
x = msspoly('x',n);
basis = monomials(x,0:d);
p = randn(length(basis))'*basis;

g = 1 - x'*x;

prog = spotsosprog;
prog = prog.withIndeterminate(x);
[prog,r] = prog.newFree(1);

[prog,f] = prog.newFreePoly(x,monomials(x,0:d-2));
prog = prog.withSOS(r-p-f*g);

sol = prog.minimize(r);

sol.eval(r);
\end{lstlisting}
\subsubsection{Van der Pol ROA}
\subsubsection{Simple Pendulum ROA}

\section{Basic Classes}
\subsection{\msspoly: Simple Approximate Symbolic Algebra}
\subsection{\spotprog: Representation of Optimization Problems}
\subsection{\spotsdpsol: Representation of Optimization Solutions}
\subsection{\spotsosprog: Representation of SOS Problems}
\section{Function Guide}
\end{document}