%Copyright (C) 2007-2014  Brian Langenberger
%This work is licensed under the
%Creative Commons Attribution-Share Alike 3.0 United States License.
%To view a copy of this license, visit
%http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
%Creative Commons,
%171 Second Street, Suite 300,
%San Francisco, California, 94105, USA.

\subsection{Encoding a FIXED Subframe}
\label{flac:encode_fixed_subframe}
{\relsize{-1}
  \input{flac/algorithms/encode_fixed_subframe}
}
\begin{figure}[h]
  \includegraphics{flac/figures/fixed.pdf}
\end{figure}

\clearpage

\subsubsection{FIXED Subframe Calculation Example}

Given the subframe samples: \texttt{18, 20, 26, 24, 24, 23, 21, 24, 23, 20}:
\begin{table}[h]
\begin{tabular}{r|r|r|r|r|r}
& o = 0 & o = 1 & o = 2 & o = 3 & o = 4 \\
\hline
$\textsf{residual}_{o~0}$ & \texttt{\color{gray}18} & \texttt{\color{gray}2} & \texttt{\color{gray}4} & \texttt{\color{gray}-12} & \texttt{22} \\
$\textsf{residual}_{o~1}$ & \texttt{\color{gray}20} & \texttt{\color{gray}6} & \texttt{\color{gray}-8} & \texttt{10} & \texttt{-13} \\
$\textsf{residual}_{o~2}$ & \texttt{\color{gray}26} & \texttt{\color{gray}-2} & \texttt{2} & \texttt{-3} & \texttt{3} \\
$\textsf{residual}_{o~3}$ & \texttt{\color{gray}24} & \texttt{0} & \texttt{-1} & \texttt{0} & \texttt{6} \\
$\textsf{residual}_{o~4}$ & \texttt{24} & \texttt{-1} & \texttt{-1} & \texttt{6} & \texttt{-15} \\
$\textsf{residual}_{o~5}$ & \texttt{23} & \texttt{-2} & \texttt{5} & \texttt{-9} & \texttt{11} \\
$\textsf{residual}_{o~6}$ & \texttt{21} & \texttt{3} & \texttt{-4} & \texttt{2} \\
$\textsf{residual}_{o~7}$ & \texttt{24} & \texttt{-1} & \texttt{-2} \\
$\textsf{residual}_{o~8}$ & \texttt{23} & \texttt{-3} \\
$\textsf{residual}_{o~9}$ & \texttt{20} \\
\hline
$\textsf{total error}_{o}$ & \texttt{135} & \texttt{10} & \texttt{15} & \texttt{30} & \texttt{70} \\
\end{tabular}
\end{table}
\par
\noindent
Note how the total number of residuals equals the
total number of samples minus the subframe's order,
to account for the warm-up samples.
Also note that if you remove the first $4 - \textsf{order}$ residuals
and sum the absolute value of the remaining residuals,
the result is the \VAR{total error} value
used when calculating the best FIXED subframe order.
\par
Since $\textsf{total error}_1$'s value of 10 is the smallest,
the best order for this FIXED subframe is 1.

\begin{figure}[h]
  \includegraphics{flac/figures/fixed-enc-example.pdf}
\end{figure}
