\documentclass{article}
\usepackage{listings} % Include the listings-package

\begin{document}

\section{Appendix: Scripts for Data Processing}

In this appendix, we document the scripts used in Chapter~\ref{bit_compression} for the evaluation of the compressors and the generation of the test binary files for this purpose. We also include here the scripts for the simulation and data post-processing for the evaluation of the NCDs (~\ref{eq:NCD}).

\subsection{Appendix: Compressor Tests}

For the first test of the compressors, we use the Matlab script, \emph{real\_compressor\_test\_vary\_length.m} (Pr.~\ref{sc:real_compressor_test_vary_length}), to generate binary strings of various lengths and write them in ascii format into files. These files, converted to binary using the Python script \emph{batch\_convert\_2\_bin.py} (Pr.~\ref{sc:batch_convert_2_bin}) are later compressed using \emph{compressor\_test.py} (Pr.~\ref{sc:compressor_test}). The returned compressed and original file length are used to calculate $Q$ (Eq.~\ref{eq:compression_overhead}).

For the second test, to replicate the situation found in the actual data processing, we generated strings where every two bits are random and every pairwise consecutive bits have probability $p$ of being correlated. These strings are later processed with the same procedure as with the previous test.

\lstset{language=Matlab}

\lstinputlisting[language=Matlab, frame=single, label=sc:real_compressor_test_vary_length]{real_compressor_test_vary_length.m}
\lstinputlisting[language=Matlab, frame=single, label=sc:real_compressor_test_vary_correlation]{real_compressor_test_vary_correlation.m}
% \lstinputlisting[language=Python, frame=single, label=sc:batch_convert_2_bin]{batch_convert_2_bin.py}
\lstinputlisting[language=Python, frame=single, label=sc:bit_compression_analysis]{bit_compression_analysis.py}
\lstinputlisting[language=Python, frame=single, label=sc:compressor_test]{compressor_test.py}
\lstinputlisting[language=Python, frame=single, label=sc:convert_2_bin]{convert_2_bin.py}

\subsection{Appendix: Simulation and Data Post-Processing}

The set of script shown here are used to simulate and do the data post-processing for ejaculation of the inequality. The script Pr.~\ref{sc:ideal_case_generation} is used to generate the expected binary outcome corresponding for the case of a maximally entangled state. The generated data is processed using Pr.~\ref{sc:bit_compression_data_processing_step_3}. The resulting files is converted using Pr.~\ref{batch_convert_2_bin.py} and evaluated with Pr.~\ref{sc:angle_dep_analysis_bin}.

For the measured data, it needs to be process further by Pr.~\ref{sc:bit_compression_data_processing_step_1} and Pr.~\ref{sc:bit_compression_data_processing_step_2}.

\lstset{language=Python}
\lstinputlisting[language=Matlab, frame=single, label=sc:bit_compression_data_processing_step_1]{bit_compression_data_processing_step_1.m}
\lstinputlisting[language=Matlab, frame=single, label=sc:bit_compression_data_processing_step_2]{bit_compression_data_processing_step_2.m}
\lstinputlisting[language=Matlab, frame=single, label=sc:bit_compression_data_processing_step_3]{bit_compression_data_processing_step_3.m}
\lstinputlisting[language=Matlab, frame=single, label=sc:ideal_case_generation]{ideal_case_generation.m}
\lstinputlisting[language=Python, frame=single, label=sc:angle_dep_analysis_bin]{angle_dep_analysis_bin.py}

\end{document} 

