text:
\input{../preamble}

\usepackage{wrapfig}

%\newcommand{\bolditem}{\normalfont\origitem\bfseries}

\AtBeginSection[]{
    {
        \setbeamertemplate{footline}{}
        \begin{frame}[noframenumbering]{\insertsubtitle}
            \tableofcontents[currentsection]
        \end{frame}
    }
}
\AtBeginSubsection[]{
    {

        \setbeamertemplate{footline}{}
        \begin{frame}[noframenumbering]{\insertsubtitle}
             \tableofcontents[currentsection, currentsubsection]
        \end{frame}
    }
}

\subtitle{Phase Contrast X-ray}

\begin{document}

\frame[plain,c]{\titlepage} % plain-Option deaktiviert Kopf- und Fusszeile

%subtitle
%toc for this chapter

\section{Motivation}%
\label{sec:motivation}

\begin{frame}{Motivation: Frozen Mouse}
    \begin{center}\includegraphics[width=0.4\linewidth]{images/mouse-abs-updated.eps}\end{center}
    \begin{center}\includegraphics[width=0.4\linewidth]{images/mouse-dpc2-updated.eps}\end{center}
    \begin{center}\includegraphics[width=0.4\linewidth]{images/mouse-dark-field-updated.eps}\end{center}

    \begin{flushright}
        \tiny Sources: Erlangen Centre for Astroparticle Physics (ECAP), Erlangen, Germany
    \end{flushright}
\end{frame}

\begin{frame}{Motivation: A Cancerous  Mastectomy Sample}
    \begin{center}
        \begin{tabular}{lll}
            \includegraphics[width=0.3\linewidth]{images/MastectomyAbsorption.pdf} & \includegraphics[width=0.3\linewidth]{images/MastectomyPhaseContrast.pdf} &
            \includegraphics[width=0.3\linewidth]{images/MastectomyDarkfield.pdf}
        \end{tabular}
    \end{center}
    \vspace{-0.3cm}
    \begin{flushright}
        \tiny Sources: Erlangen Centre for Astroparticle Physics (ECAP), Erlangen, Germany
    \end{flushright}
\end{frame}

\begin{frame}{Contrast mechanisms in phase-contrast X-ray}
    \begin{itemize}
        \item \bluefat{Absorption}
              \begin{itemize}
                  \item based on differences in radiation absorption
                  \item excellent contrast where highly absorbing structures are embedded in relatively weakly absorbing material, i.e. bones and muscles\\[1cm]
              \end{itemize}
        \item \bluefat{Phase contrast}
              \begin{itemize}
                  \item of a light wave light based on differences in phase shifts
                  \item different weakly absorbing materials may exhibit a significant difference in the phase shifts\\[1cm]
              \end{itemize}
        \item \bluefat{Dark field}
              \begin{itemize}
                  \item based on ultra-small angle scattering
                  \item exhibits contrast for structural variations from structures with few micrometers diameters (fibers, grains)
              \end{itemize}
    \end{itemize}
\end{frame}

\section{Physics of Phase-contrast X-ray Imaging }%

%\begin{frame}{Refractive Index of X-rays}

%	\begin{itemize}
%		\item is a complex quantity
% 		\item is commonly written as: $n=1-\delta+i\beta$
% 		\item the real part $\delta$ causes the X-ray phase shift
% 		\item the imaginary part $\beta$ causes X-ray attenuation
% 		\item $\beta$ is usually much smaller than $\delta$
% 	    \item close to one, thus
% 	    \begin{itemize}
% 	    \item X-ray lenses are not available
% 	    \item X-ray phase contrast imaging requires a different acquisition setup than phase contrast microscopy
% 	    \end{itemize}
%\item can be calculated from atomic scattering factor.
%\item The NIST database provides up-to-data information for  atomic scattering factor.

%	\end{itemize}

%\end{frame}

%\begin{frame}{Definition of a Wave}

%  \begin{align*}
%  \begin{split}
%  \psi(\mathbf{r}, t)  &= A(\mathbf{r}) e^{j\phi(\mathbf{r})} e^{j\omega t}\\
%  &=\psi_0 e^{jw(t-r/c)} e^{j(2\pi\delta/\lambda)r}e^{-(2\pi\beta/\lambda)r}
%  \end{split}
%  \end{align*}

% \begin{itemize}
% \item $\lambda$: wavelength
% \item $\psi_0 e^{jw(t-r/c)}$: vacuum propagation
% \item $e^{j(2\pi\delta/\lambda)r}$: $\phi$-shift
% \item $e^{-(2\pi\beta/\lambda)r}$: decay
% \end{itemize}

% \end{frame}

\begin{frame}{Interferences}
    \begin{figure}
        \includegraphics[height=0.8\textheight]{images/interferencesex.eps}
    \end{figure}

    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
\end{frame}

\begin{frame}{Interferences}
    \begin{figure}
        \includegraphics[height=0.8\textheight]{images/interferences3.eps}
    \end{figure}
\end{frame}

\begin{frame}[c]{Interference}
    Stationary interference requirements:
    \vspace{0.3cm}
    \begin{itemize}
        \setlength\itemsep{0.3cm}
        \item Need at least two waves
        \item Waves must have the \bluefat{same frequency}
        \item Waves must be in constant phase difference.
    \end{itemize}
\end{frame}

\begin{frame}[c]{Young's Double Slit Experiment}
    \begin{itemize}
        \setlength\itemsep{0.2cm}
        \item 1801: Thomas Young first demonstrated interference in light waves from two sources.
        \item Light is incident on a screen with a narrow slit
        \item The light waves emerging from this slit arrive at a second screen that contains two narrow, parallel slits.
    \end{itemize}

    \begin{figure}
        \centering{}
        \includegraphics[width=0.6\textwidth, trim={0  0 3.5cm 0},clip]{images/slit_book.pdf}
    \end{figure}
    \vspace{-0.4cm}
    \begin{flushright}
        \tiny Sources: Medical Imaging Systems: An Introductory Guide~\cite{bopp18}
    \end{flushright}
\end{frame}

\begin{frame}[c]{Young's Double Slit Experiment}
    \begin{figure}
        \centering{}
        \includegraphics[width=\textwidth]{images/slit_book.pdf}
    \end{figure}
    \begin{flushright}
        \tiny Sources: Medical Imaging Systems: An Introductory Guide~\cite{bopp18}
    \end{flushright}
\end{frame}

\begin{frame}[c]{Young's Double Slit Experiment}
    \begin{itemize}
        \setlength\itemsep{0.3cm}
        \item The light from the two slits form a visible pattern on a screen
        \item The pattern consists of a series of bright and dark parallel bands called \textit{fringes}
        \item Constructive interference occurs where a bright fringe occurs
        \item Destructive interference results in a dark fringe
    \end{itemize}
\end{frame}

\begin{frame}{Interference Patterns}
    \vspace{-1cm}
    \begin{columns}[c, onlytextwidth]
        \begin{column}{0.5\textwidth}
            \begin{itemize}
                \item Constructive interference occurs at the center point
                \item The two waves travel the same distance and arrive in phase, i.e. arrive at the same time.
            \end{itemize}
        \end{column}\begin{column}{0.5\textwidth}
            \begin{figure}
                \centering{}
                \includegraphics[height=1\textheight, trim={5cm  0 2cm 0},clip]{images/bright.pdf}
            \end{figure}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}{Interference Patterns}
    \vspace{-1cm}
    \begin{columns}[c, onlytextwidth]
        \begin{column}{0.5\textwidth}
            \begin{itemize}
                \item The upper wave has to travel farther than the lower wave
                \item The upper wave travels one wavelength farther
            \end{itemize}
        \end{column}\begin{column}{0.5\textwidth}
            \begin{figure}
                \centering{}
                \includegraphics[height=1\textheight, trim={2cm  0 2cm 0},clip]{images/bright2.pdf}
            \end{figure}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}{Interference Patterns}
    \vspace{-1cm}
    \begin{columns}[c, onlytextwidth]
        \begin{column}{0.5\textwidth}
            \begin{itemize}
                \item The upper wave travels one-half of a wavelength farther than the lower wave
                \item The trough of the bottom wave overlaps the crest of the upper wave ($180^\circ$ phase shift)
            \end{itemize}
        \end{column}\begin{column}{0.5\textwidth}
            \begin{figure}
                \centering{}
                \includegraphics[height=1\textheight, trim={2cm  0 2cm 0},clip]{images/bright3.pdf}
            \end{figure}
        \end{column}
    \end{columns}
\end{frame}

\begin{frame}{Interference Patterns}
    \vspace{-1cm}
    \begin{columns}[c, onlytextwidth]
        \begin{column}{0.5\textwidth}
            \begin{itemize}
                \item[$d$] Distance between slits S1 and S2
                \item[$\Delta d$] Path difference
            \end{itemize}
        \end{column}\begin{column}{0.5\textwidth}
            \begin{figure}
                \centering{}
                \includegraphics[height=1\textheight, , trim={2cm  0 2cm 0},clip]{images/bright4.pdf}
            \end{figure}
        \end{column}
    \end{columns}

\end{frame}

\begin{frame}[c]{Interference Patterns}
    \begin{itemize}
        \item \bluefat{Bright fringe:} path difference must be either zero or some integral multiple of of the wavelength
              \begin{eqnarray*}
                  \Delta d &=& d\sin\theta_{\text{bright}}= m\lambda
              \end{eqnarray*}
              where the order number is
              \begin{eqnarray*}
                  m &=& 0,\pm 1, \pm 2, \pm 3,\ldots
              \end{eqnarray*}
    \end{itemize}
\end{frame}

\begin{frame}[c]{Interference Patterns}
    \begin{itemize}
        \item \bluefat{Dark fringe:} path difference must be of an odd half wavelength
              \begin{eqnarray*}
                  \Delta d &=& d\sin\theta_{\text{dark}}= \left(m + \dfrac{1}{2}\right)\lambda
              \end{eqnarray*}
              where the order number is
              \begin{eqnarray*}
                  m &=& 0,\pm 1, \pm 2, \pm 3,\ldots
              \end{eqnarray*}
    \end{itemize}
\end{frame}

\begin{frame}{Talbot Effect}
    A near-field diffraction effect that shows periodic revival of a wave function at Talbot distance.

    \centering{\includegraphics[width=.6\linewidth]{images/talbot.eps}} \\
    \begin{tabular}{ll}
        Talbot distance: & $d(n) = n\dfrac{p^2}{8\lambda} \quad n \in \mathbb N$ \\
                         & $n$ = Talbot order                                    \\
                         & $p$ = period of the grating
    \end{tabular}
\end{frame}

\section{Grating Based Interferometer}

\begin{frame}[c]{Interferometers}
    \begin{itemize}
        \setlength\itemsep{0.4cm}
        \item \bluefat{Crystal interferometer:}
              \begin{itemize}
                  \item invented by Bonse \& Hart (1965)
                  \item X-ray beam is split and converged to create interference patterns
              \end{itemize}
        \item \bluefat{Propagation based imaging:}
              \begin{itemize}
                  \item interference pattern is created in the free space propagation
                  \item measure the Laplacian of the phase front
              \end{itemize}
        \item \bluefat{Analyzer based imaging:}
              \begin{itemize}
                  \item parallel beam, produced by a single or a double crystal, is analyzed
                  \item refraction angle is measured with a Bragg analyzer

              \end{itemize}
              \bolditem Grating based imaging
    \end{itemize}
\end{frame}

\begin{frame}{Grating}
    \begin{figure}
        \includegraphics[width=0.45\linewidth]{images/grating.eps}
    \end{figure}
    \begin{itemize}
        \item Optical component with a regular pattern
        \item Used to diffract X-ray beams
    \end{itemize}
\end{frame}

\begin{frame}[c]{Grating Base Interferometer}
    \begin{figure}
        \includegraphics[width=\linewidth]{images/grabase.eps}
    \end{figure}
    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
\end{frame}

\begin{frame}{Grating Base Interferometer}
    \begin{figure}
        \includegraphics[width=\textwidth]{images/grasebase2.pdf}
    \end{figure}
    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
\vspace{-1.5cm}
    This pattern is observed for a specific design energy of the interferometer.
\end{frame}

\begin{frame}{Fringe Shifts}
    \begin{figure}
        \includegraphics[width=0.8\linewidth]{images/frigeshift.pdf}
    \end{figure}
    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
\end{frame}

\begin{frame}[c]{Detector Resolution}
    \begin{figure}
        \includegraphics[width=\linewidth]{images/detector.eps}
    \end{figure}
    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
    Detector pixel presents a single pixel on the detector.
\end{frame}

\begin{frame}[c]{Analyzer Grating G2}
    \bluefat{Problem:}
    \begin{itemize}
        \setlength\itemsep{0.3cm}
        \item Each fringe has a width of few microns\\
              \bluefat{$\Rightarrow$} Detector is not able to resolve each single fringe

    \end{itemize}
    \vspace{0.5cm}

    \bluefat{Solution:}
    \begin{itemize}
        \item Introduction of the \textit{Analyzer Grating G2}
        \item G2 has the same period as the fringes at the design energy
        \item Measured intensities encode different information
              \begin{itemize}
                  \item Absorption
                  \item Phase
                  \item Dark-field
              \end{itemize}
        \item Separation with \textit{phase stepping}
    \end{itemize}
\end{frame}

\begin{frame}{Phase Stepping}
    \vspace{-0.5cm}
    \begin{figure}
        \includegraphics[height=0.92\textheight]{images/phase1.eps}
    \end{figure}
    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
\end{frame}

\begin{frame}{Phase Stepping}
    \vspace{-0.5cm}
    \begin{figure}
        \includegraphics[height=0.92\textheight]{images/phase2.eps}
    \end{figure}
    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
\end{frame}

\begin{frame}{Phase Stepping}
    \vspace{-0.5cm}
    \begin{figure}
        \includegraphics[height=0.92\textheight]{images/phase3.eps}
    \end{figure}
    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
\end{frame}

\begin{frame}{Phase Stepping}
    \vspace{-0.5cm}
    \begin{figure}
        \includegraphics[height=0.92\textheight]{images/phase4.eps}
    \end{figure}
    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
\end{frame}

\begin{frame}{Phase Stepping}
    \vspace{-0.5cm}
    \begin{figure}
        \includegraphics[height=0.92\textheight]{images/phase5.eps}
    \end{figure}
    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
\end{frame}

\begin{frame}{Phase Stepping}
    \vspace{-0.5cm}
    \begin{figure}
        \includegraphics[height=0.92\textheight]{images/phase6.eps}
    \end{figure}
    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
\end{frame}

\begin{frame}{Phase Stepping}
    \vspace{-0.5cm}
    \begin{figure}
        \includegraphics[height=0.92\textheight]{images/phase7.eps}
    \end{figure}
    \begin{flushright}
        \scriptsize Sources: Wilhelm Haas
    \end{flushright}
\end{frame}

\begin{frame}{Incoherent polychromatic X-Ray Source}
    \vspace{-0.5cm}
    \begin{figure}
        \includegraphics[width=0.75\linewidth]{images/inco-updated2.eps}
    \end{figure}
    \begin{itemize}
        \item G0 splits the large source in an array of smaller subsources
        \item each sub-source is small enough to create an interference pattern
    \end{itemize}
\end{frame}

\begin{frame}{Formulas}

    \vspace{-0.5cm}
    \begin{minipage}{0.5\textwidth}
        \begin{figure}
            \includegraphics[width=0.9\linewidth]{images/formula.pdf}
        \end{figure}
    \end{minipage}\begin{minipage}{0.5\textwidth}
        \begin{itemize}
            \setlength\itemsep{-0.2cm}
            \item \textbf{\color{faublue}{Differential phase image}}
                  \begin{eqnarray*}
                      \Delta \phi = \phi_{ff} - \phi_o = \dfrac{\lambda d}{p_2} \dfrac{\partial\Phi}{\partial x}
                  \end{eqnarray*}

            \item  \textbf{\color{faublue}{Attenuation}}
                  \begin{eqnarray*}
                      \mu = - \text{ln} \left( \dfrac{\text{mean} ( I_{o}(x_p))}{\text{mean} ( I_{ff}(x_p))} \right)
                  \end{eqnarray*}

            \item \textbf{\color{faublue}{Visibility (contrast), n=\{off, o\}}}
                  \begin{eqnarray*}
                      V_n = \dfrac{\max(I_n(x_p)) - \min(I_n(x_p))}{\max(I_n(x_p)) + \min(I_n(x_p))}
                  \end{eqnarray*}

            \item \textbf{\color{faublue}{Dark-field}}
                  \begin{eqnarray*}
                      D = \dfrac{V_{ff}}{V_{o}}
                  \end{eqnarray*}
        \end{itemize}
    \end{minipage}
\end{frame}

\section{Summary: X-ray Dark-field Imaging}%
\label{sec:further_reading}

\begin{frame}[c]{X-ray Dark-field Imaging}
    \begin{itemize}
        \large
        \setlength\itemsep{0.3cm}
        \item<1-> Caused by ultra-small angle scattering
        \item<2-> Allows reconstruction of structures at length scales below
              the resolution of conventional X-ray imaging systems.
        \item<3-> Yields the possibility of reconstructing the orientation of fibrous structures
        \item<4-> May become medically useful, i.e. diagnosis of osteoporosis

    \end{itemize}
\end{frame}

\section{Examples}%
\label{sec:examples}

\begin{frame}[c]{Examples -- Frozen mouse}
    \begin{center}
        \begin{tabular}{ll}
            \includegraphics[width=0.3\linewidth]{images/brainrat1.eps} & \includegraphics[width=0.3\linewidth]{images/brainrat2.eps}
        \end{tabular}
    \end{center}

    \begin{center}
        \begin{flushright}
            \scriptsize Sources: Frank Pfeiffer TU M\"uchen
        \end{flushright}
    \end{center}
\end{frame}

\begin{frame}[c]{Examples -- Gummi Bears}
    \begin{center}
        \centering{}
        \includegraphics[width=\textwidth]{images/gummi.png}
    \end{center}

    \begin{center}
        \begin{flushright}
            \scriptsize Courtesy of ECAP Erlangen~\cite{bopp18}
        \end{flushright}
    \end{center}
\end{frame}

\begin{frame}{Examples -- Dark-field: Chicken Wing}
    \begin{center}
        \begin{tabular}{ll}
            absorption:                                             & dark-field:                                             \\
            \includegraphics[width=0.25\linewidth]{images/wing1.eps} & \includegraphics[width=0.25\linewidth]{images/wing2.eps}
        \end{tabular}
    \end{center}
    \begin{center}
        \begin{flushright}
            \scriptsize Sources: Frank Pfeiffer TU München
        \end{flushright}
    \end{center}
\end{frame}
\begin{frame}{Examples -- Dark-field Reconstruction: CFRC sample}
    \begin{center}
        \begin{tabular}{ll}
            Dark-field reconstruction                              & Visualization of CFRC sample:                                          \\
            \includegraphics[height=0.75\textheight]{images/CFRC.pdf} & \includegraphics[height=0.75\textheight]{images/microstructures_cfrc.pdf}
        \end{tabular}
    \end{center}
\end{frame}

\begin{frame}{Examples -- Dark-field Reconstruction: Wooden block}
    \begin{figure}
        \centering
        \includegraphics[width=0.6\linewidth]{images/Wooden.pdf}
        \caption[Visualization of micro-structures of the wooden sample.]{Visualization of micro-structures of representative layer of the wooden sample. \label{images:Wooden3D}}
    \end{figure}
\end{frame}

\begin{frame}{Examples -- Experimental Setup in ECAP}
    \begin{center}
        \begin{tabular}{l}
            Experimental Setup in ECAP \\
            \includegraphics[width=0.5\linewidth]{images/setup.pdf}
        \end{tabular}
    \end{center}
    \begin{flushright}
        \scriptsize Sources: Erlangen Centre for Astroparticle Physics (ECAP), Erlangen, Germany
    \end{flushright}
\end{frame}

\section{Further Questions?}

\begin{frame}[t]{Further Readings}
    \begin{itemize}
        \item \fullcite{bopp18}
    \end{itemize}

\end{frame}

\end{document}


text:
\subsection*{Elementwise Operations
\hspace*{\fill}\hyperlink{VSIPspecHead}{(up)}\hypertarget{ElementwiseOperations}{}} \addcontentsline{toc}{subsection}{Elementwise Operations}
Elementwise operatons are simple operations which are done on each element in a matrix or vector. Most of the time, when more than one \ttbf{view} is input, the \ttbf{view} shapes will need to be the same since the operation is done to identically indexed elements for each input \ttbf{view} and the operation result is placed in an identically indexed element of the output \ttbf{view}. \\
The tables referenced in this section list elementwise operations with a link to the corresponding function page. Although the function pages are alphabetical, the lists here are in the same order (although not necessarily identical) to the order they appear in the C VSIPL specification.
\begin{table}[H]
\hypertarget{vectorAndElementwise}{}
\caption{Vector And Elementwise Operations}
\label{tab:elementwiseChapter}
\begin{center}
\begin{tabular}{|l|}\hline
\hyperlink{elementaryMath}{Elementary Math Functions}\\
\hyperlink{unaryOperations}{Unary Operations}\\
\hyperlink{binaryOperations}{Binary Operations}\\
\hyperlink{ternaryOperations}{Ternary Operations}\\
\hyperlink{logicalOperations}{Logical Operations}\\
\hyperlink{selectionOperations}{Selection Operations}\\
\hyperlink{bitwiseOperators}{Bitwise and Boolean Logical Operators}\\
\hyperlink{elementGenerationOperations}{Element Generation and Copy}\\
\hyperlink{manipulationOperations}{Manipulation Operations}\\
\hline\end{tabular}
\end{center}
%\label{default}
\end{table}%
%%%
      \input{ElementaryMath}
      \input{UnaryOperations}
      \input{BinaryOperations}
      \input{TernaryOperations}
      \input{LogicalOperations}
      \input{SelectionOperations}
      \input{BitwiseOperators}
      \input{ElementGenerationOperations}
      \input{ManipulationOperations}

ext: tex

max_stars_repo_name: rrjudd/jvsip

max_issues_repo_name: rrjudd/jvsip

max_forks_repo_name: rrjudd/jvsip


text:
\chapter*{\prefacename}\label{ch:preface}

Preface text here

% Generate signature list
\signaturelist

max_issues_repo_name: NoobHereo/aau-report-template

max_forks_repo_name: NoobHereo/aau-report-template


text:
\documentclass[11pt,twoside]{article}

\usepackage{paperlighter}

% Recommended, but optional, packages for figures and better typesetting:
\usepackage{microtype}
\usepackage{graphicx}
\graphicspath{ {images/} }

\usepackage{subfigure}
\usepackage{booktabs} % for professional tables

\usepackage{tikz}
\usetikzlibrary{snakes}

\usepackage{wrapfig}

% Attempt to make hyperref and algorithmic work together better:
\newcommand{\theHalgorithm}{\arabic{algorithm}}

% Todonotes is useful during development; simply uncomment the next line
%    and comment out the line below the next line to turn off comments
%\usepackage[disable,textsize=tiny]{todonotes}
\usepackage[textsize=tiny]{todonotes}
\usepackage{wrapfig}

\slimtitle{Speed of Sound Lab Report}
\slimauthor{Tanish Tyagi}

\begin{document}

\lightertitle{Speed of Sound Lab Report}
\lighterauthor{Tanish Tyagi}

\section{Analysis of Standing Waves in Air}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.6\columnwidth]{air_graph_with_fits.png}
    \caption{Graph of Air Column Length vs. Wavelength of Sound Wave}
\end{figure}
We can construct $L = m\lambda$ equations from the three subsets of the data, where $L$ = length of the air column and $\lambda$ = wavelength of the sound wave. This gives us the length of the air column in terms of the wavelength of the sound wave. We can manipulate the equation to get $\lambda = \frac{L}{m}$, which gives us the wavelength of the sound wave in terms of the length of the air column. This means that the data tells us the relationship between the length of the air column and the wavelength of the sound wave.

\textbf{Equation Fits for subsets of data:}

Black Line: $L =\frac{5}{4}\lambda$, $\lambda = \frac{4}{5}L$.

Blue Line: $L =\frac{3}{4}\lambda$, $\lambda = \frac{4}{3}L$

Green Line: $L = \frac{1}{4}\lambda$, $\lambda = 4L$

These equations mean that one $\lambda$ is $\frac{4}{5}$, $\frac{4}{3}$, and $4$ times the length of the tube, respectively. Inside the tube, sound waves are being produced that obey the aforementioned relationships. These equations can also help us draw the resonant sound waves in the pipes. Below are the diagrams for all subsets:

% \begin{figure}[H]
% \centering

% \begin{minipage}{\textwidth}
%   \centering
%   \includegraphics[width=.33\columnwidth]{lambda_4.png}
%   \label{fig:test1}
% \end{minipage}

% \begin{minipage}{\textwidth}
%   \centering
%   \includegraphics[width=.33\columnwidth]{lambda_4_5.png}
%   \label{fig:test2}
% \end{minipage}

% \begin{minipage}{\textwidth}
%   \centering
%   \includegraphics[width=.33\columnwidth]{lambda_3_4.png}
%   \label{fig:test2}
% \end{minipage}

% \end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.5\columnwidth]{lambda_4.png}
    \caption{Sound Waves Diagram for $\lambda = 4L$}

    \includegraphics[width=0.6\columnwidth]{lambda_4_5.png}
    \caption{Sound Waves Diagram for $\lambda = \frac{4}{5}L$}

    \includegraphics[width=0.6\columnwidth]{lambda_3_4.png}
    \caption{Sound Waves Diagram for $\lambda = \frac{4}{3}L$}
\end{figure}

We can see that the each of the waves have with a node at the closed end of the tube and an antinode at the open end. This is due to the boundary conditions of the wave, which are that the wave can vibrate at the open end and not at the closed end. A node is therefore formed at the closed end because the air molecules are not free to vibrate back and forth at the closed end. The opposite occurs at the open end to allow for the formation of an antinode. Since the wave has to start with a node and end with an antinode, it is not possible for any equation fits to be of the form $L = \frac{1}{2}\lambda$. An wave with this equation would have nodes at both ends, which is not possible. A standing wave diagram illustrates this below:

\begin{figure}[H]
    \centering
    \includegraphics[width=0.6\columnwidth]{L_0.5_wavelength.png}
    \caption{Standing Wave with Equation $L = 0.5\lambda$}
\end{figure}

\section{Analysis of Standing Waves in $CO_2$}

To determine the wavelength of the standing waves in $CO_2$, we can turn to our data that says the positions of the two $CO_2$ resonances are $0.12$ and $0.39$m. The positions of these resonances have to be antinodes, and they construct a standing wave that looks like this:

\begin{figure}[H]
    \centering
    \includegraphics[width=0.5\columnwidth]{0.5_wavelength.png}
    \caption{Standing Wave for $CO_2$ Data}
\end{figure}

As you can see, the distance between $0.12$ and $0.39$m is equivalent to $\frac{\lambda}{2}$. Therefore, the wavelength for the standing wave in $CO_2$ is $(0.39 - 0.12) \cdot 2 = 0.54$m. If we revisit the graph in Figure 1, we can see that the resonance positions of 0.39 and 0.12m fall into the pink and blue clusters of data points, respectively. The equation for the pink cluster is $\lambda = \frac{4}{3}L$ and $\lambda = 4L$ for the blue cluster. Using these equations, we can find the $\lambda$ for the standing wave with a resonance at $0.39$ m to be $\frac{4}{3}(0.39)$ = $0.52$m and $4(0.12)$ = $0.48$m for the standing wave with a resonance at $0.12$m. We can now use the wave equation with $f$ = $500$hz to get two wave speeds, $260$ and $240$m/s. We can average these values to get an experimental speed of $CO_2$ value of $250$m/s.

We can use the percent error formula
$\delta = |\frac{V_{true} - V_{observed}}{V_{true}}| \cdot 100$ to compare our experimental value with the accepted value of $260$m/s. The percent error is $\approx 3.8\%$, which is quite small for measurements that are only accurate to 2 significant figures. Additionally, it is easy to be inaccurate with recording the positions of resonances, as the water level is rising rapidly and there is a ever present risk of identifying false positives.

We can also find the speed of sound in $CO_2$ using the established fact that the speed of sound in air is $340$m/s and the kinetic theory of gases. The kinetic energy of $N_2$ and $CO_2$ molecules should be the same by the kinetic theory of gases. The formula for kinetic energy is $\frac{1}{2}(m)(v)^2$. We need to get the mass of $N_2$ and $CO_2$ from amu to kg first.

Mass of $N_2$: $\approx 4.6 \cdot 10^{-26}$ kg

Mass of $CO_2$: $\approx 7.3 \cdot 10^{-26}$ kg

Therefore, the kinetic energy for the $N_2$ molecules is $KE_{N_2} = \frac{1}{2}(4.6 \cdot 10^{-26})(340)^2 \approx 2.7 \cdot 10^{-21}$ J. We can solve for the $v$ in the equation for kinetic energy in $CO_2$ to get $271.22 \approx 270$ m/s.

We can even extend our analysis to weighing molecules. For example, the speed of sound in methane, $CH_4$, is $445$m/s. Using the kinetic theory of gases, we know that the kinetic energy of molecules in $CH_4$ has to be equal to the kinetic energy of molecules in air. We know that $KE_{N_2} \approx 2.7 \cdot 10^{-21}$ J. We can set $\frac{1}{2}(m)(445)^2$ = $KE_{N_2}$, and solve for $m$ to get $m$ = $2.7 \cdot 10^{-26}$kg. We can convert this to amu and get that the molecular mass of methane is $\approx 16$ amu.

\section{Resonance and its Connection to this Lab}

Resonance is the phenomenon that causes a wave to have increased amplitude. This occurs at certain frequencies, or when the incident and reflected wave are in phase, resulting in constructive interference. In this lab, we observed the points of resonance when the length of the air column allowed for the standing wave to have a node at the closed end and antinode at the open end. It was in these scenarios that constructive inference was able to occur. The below figure shows the incident wave (in red), reflected wave (in purple), and the ``net" wave (in green).

% \begin{figure}[H]
%     \centering
%     \includegraphics[width=0.4\columnwidth]{resonance.png}
%     \caption{The Effect of Resonance}
% \end{figure}

\begin{wrapfigure}{l}{0.4\textwidth}
    \centering
    \includegraphics[width=0.4\textwidth]{resonance.png}
    \caption{The Effect of Resonance}
\end{wrapfigure}

As you can see, constructive inference occurs with then incident and reflected wave, resulting in the phenomenon of resonance taking effect and creating a wave with an amplitude twice the amplitude of incident/reflected waves. It is important to note that this only occurs when there is a node at the closed end and an antinode at the open end. If two tuning forks are held over the time at the same time and are in sync with each other, then resonance will amplify the sound wave double as much as the scenario in which there is only one tuning fork.This is because the incident and reflected waves of both tuning forks are once again in phase, resulting in resonance occurring. The figure on the next page shows this idea:

\clearpage

\begin{figure}
    \centering
    \includegraphics[width=0.5\textwidth]{resonance_two_tuning_forks.png}
    \caption{The Effect of Resonance with Two Tuning Forks}
\end{figure}

The amplitude produced by resonance can be generalized to $2N \cdot A_{incident}$, where $N$ is number of tuning forks, and $A_{incident}$ is the amplitude of the incident wave. If the tuning forks are not fully in sync, then only partial constructive interference will occur, and the sound will not be amplified as much by resonance as it would have been if both tuning forks were in sync.

The concept of resonance can also be seen when you blow over the top of a glass bottle and a tone is created. When you blow over the top of a bottle, you produce many different frequencies. Some of the many frequencies produced allows for the incident and reflected wave to be in phase resulting in resonance amplifying the sound wave produced by those frequencies. All the other frequencies that are generated do not change the tone created, as they are not amplified. This is similar to the concept of a velocity selector that we discussed earlier this term. Particles are fired at many different velocities, but only those fired at a certain velocity can travel through the hole. The resonant frequencies can be thought of as the particles being fired at the velocity needed to go through the hole.

\end{document}

max_stars_repo_path: Physics/Speed of Sound Lab Report.tex

max_issues_repo_path: Physics/Speed of Sound Lab Report.tex

max_forks_repo_path: Physics/Speed of Sound Lab Report.tex


text:
\documentclass[conference]{IEEEtran}
\IEEEoverridecommandlockouts
% The preceding line is only needed to identify funding in the first footnote. If that is unneeded, please comment it out.
\usepackage{cite}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage[table,xcdraw]{xcolor}
\def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em
    T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}}
\begin{document}

\title{ConfigNVPSim: GEM5 Based Configurable NVP Simulator\\
}

\author{\IEEEauthorblockN{Gulsum Gudukbay}
\IEEEauthorblockA{\textit{Computer Science and Engineering} \\
\textit{Pennsylvania State University}\\
gxg5138@psu.edu}
\and
\IEEEauthorblockN{Sethu Jose}
\IEEEauthorblockA{\textit{Computer Science and Engineering} \\
\textit{Pennsylvania State University}\\
sxj487@psu.edu}
\and
\IEEEauthorblockN{Vineetha Govindaraj}
\IEEEauthorblockA{\textit{Computer Science and Engineering} \\
\textit{Pennsylvania State University}\\
vzg99@psu.edu}
}

\maketitle

\begin{abstract}
The demand for feature-rich systems like smartphones and IOT has increased over recent years. These systems could benefit from using non-volatile processors (NVP) by providing an optimal power budget along with increased performance. ConfigNVPSim, a non-volatile simulator on a gem5 platform, provides a solution to realizing a non-volatile simulator. NVP systems ensure forward progress even at intermittent energy levels. ConfigNVP system aims at improving NVPSim \cite{b1} system by adding configurability at all levels. ConfigNVP system implements new power levels to CPU based on the system energy level. Energy management unit in ConfigNVPSim monitors the system energy. The state machine implemented in the energy management unit ensures that the power levels are switched between off, on and power retention states based on preconfigured energy thresholds. This implementation of ConfigNVPSim can be modified in future revisions to add backup and restore mechanisms to different system modules like DRAM and caches.
\end{abstract}
\vspace{5 mm}
\begin{IEEEkeywords}
Non Volatile Processors, GEM5, Energy profiling, State Machine, Energy Harvesting, Computer Architecture, Intermittent Power Supply, Capacitor, Power Failure
\end{IEEEkeywords}

\section{ \textbf{Introduction}}
Non-Volatile Processors(NVPs) are designed to preserve the system state during power deficiencies. NVPs hide data backup and restoration from the executing software to provide an execution mode that will eventually complete the current task. NVPs are a promising solution for energy-harvesting scenarios. The power supply in such systems is unstable and intermittent. Such systems should harvest their energy from solar, thermal or other intermittent power sources. NVPs are highly suited for such systems because of its ability to ensure that even short periods of sufficient power can help to gain forward progress.
\subsection{NVP Architecture Overview}
 Many architectural explorations for NVPs have been previously made. There have been theoretical observations on the plausible architectures like a Non-Volatile Cache / Non-Volatile DRAM etc. But power and cost overhead to realize such a system has proved to be a major drawback. Ma et.al. investigated various designs for nonvolatile processors with different microarchitectures and different input power sources to maximize the forward progress of NVPs \cite{b4}. The focus of their design was to implement different policies for backing up registers in NVPs. As mentioned, high write energy and latency overhead will be induced due to the characteristics of NVMs. Thus, cache design proves to be a significant component is nonvolatile processors as the performance gap between cores and memories increases. The NVPSim developed by Yizi Gu et. al is an efficient solution in implementing NVP simulators. The ConfigNVPSim is based on this implementation. The special focus of this project is on adding configurability to NVPSim implementation by Yizi Gu et. al \cite{b1}. This system considers the delay incurred by non-volatile components of the system and provides an approximate performance estimate.
 \subsection{Simulation Overview}
 Since NVPs have a considerable overhead in terms of its architecture, need for simulating such a system is paramount to understand its efficiency. GEM5 was used in this project the simulation platform to realize the NVP architecture. GEM5 simulator has been used for analyzing the CPU and memory-centric designs, and models for several IPs to collectively study their impact on system-level performance and power. Extra modules are implemented on a GEM5 base system to make the system capable of making forward progress with an intermittent power source. This is achieved using discrete energy input which is fed at a preconfigured constant time interval to the system. Based on this, a system model which can handle such variations in power and analyze the performance was developed. The main logic behind handling the intermittent energy source is the energy management unit. This unit lets the system know when to back up the data and when to restore. Energy management unit interacts with the system CPU to communicate the power level of the input. Based on that, CPU decides on how to process the instructions to avoid any data loss.

\vspace{5 mm}

The goal of this paper is twofold. First is the architectural implementation of NVP on the GEM5 platform. Second, the evaluation of different configurations that can be achieved using the existing architectural implementation.
\vspace{5 mm}

The simulated architecture offers the following features provided by NVPSim \cite{b1}:\newline
1. A simple ARM base system clocked at 100MHz\newline
2. Energy harvester to harvest energy for the system which loads tick level energy values from a file for configurability\newline
3. Power levels for the system which is monitored by the energy management unit. These power levels and their possible transitions are as follows:
\begin{description}
  \item[$\bullet$] POWER\_RET to POWER\_ON
  \item[$\bullet$] POWER\_ON to POWER\_RET
  \item[$\bullet$] POWER\_OFF to POWER\_ON
\end{description}
4. Addition of Energy ports to GEM5's SimObjects to communicate energy consumption levels and state changes between GEM5 modules and the energy management unit.
5. Modifications to GEM5's AtomicSimple CPU module which will switch power states based on the energy messages from the state machine

\section{\textbf{System Configuration}}
In GEM5, a python configuration file is used to build and configure the system that has to be simulated. To configure a nonvolatile system, a single ARM core was used and its main memory as shown in Figure ~\ref{fig:basic_block}. An atomic simple model of the CPU with 100MHz CPU clock and 512MB of addressable memory range was utilized.

\begin{figure}[htbp]
\centerline{\includegraphics[scale=0.85]{simple_config.png}}
\caption{GEM5 base system configuration}
\label{fig:basic_block}
\end{figure}

In order to add the non-volatility to the system, an energy management system which updates and monitors the system's energy storage was added. The basic system configuration of~\ref{fig:basic_block} with energy harvesting module, energy manager and a state machine was augmented as shown in Figure~\ref{fig:nvpsim}. A state machine monitors the current energy level of the system and commands the system to switch between various power levels. The details of these individual modules are explained in the subsequent sections.

\begin{figure}[htbp]
\centerline{\includegraphics[scale=0.4]{nvpsim.png}}
\caption{NVPSim system}
\label{fig:nvpsim}
\end{figure}

\subsection{Energy Harvester}
The concept of an intermittent power source is not inherent to the GEM5 system. To achieve better control over the input power source, input power levels can be generated using tools like Octave or Matlab. These waveforms are passed to GEM5 as an input file. To test different input conditions, the waveforms shown in Figure ~\ref{fig:sine_wave} and Figure ~\ref{fig:real_wave} were used. Figure ~\ref{fig:sine_wave} shows positive half of an ideal sine wave extended with 200 data points of 0s. This sine wave provides a simplistic input to interpret the performance of the system. Figure ~\ref{fig:real_wave} shows a real intermittent power supply. We show that NVPsim works consistently with this real-world input.

\begin{figure}[htbp]
\centerline{\includegraphics[scale=0.4]{sine_wave.jpg}}
\caption{Ideal Sine wave Power Source}
\label{fig:sine_wave}
\end{figure}

\begin{figure}[htbp]
\centerline{\includegraphics[scale=0.4]{real_wave.jpg}}
\caption{Real Intermittent Power Source}
\label{fig:real_wave}
\end{figure}

The python configuration file configures the energy management system with the input power file and energy consumption \textit{energy\_time\_unit} to be used in the system simulation. Upon system initialization, the energy harvester module reads and maintains a copy of the input power in the system. Then it schedules a periodic call to itself every \textit{energy\_time\_unit} interval of time to update the system energy based on the input file. Hence, \textit{energy\_time\_unit} decides at what rate the input power file is read by the energy harvester. Once the energy is read by the harvester, it updates the energy manager which maintains the current energy level of the system \textit{energy\_remained}.

\subsubsection{Energy Manager}
Energy Manager receives energy messages from energy harvester as well as the other SimObjects which consumes energy in the system. Energy harvester updates energy manager with an increase in the system energy. Other SimObjects like AtomicSimpleCPU which are consumers of energy sends messages to energy manager informing the amount of energy consumed by that individual module. Based on the source of these messages, the energy manager updates the system energy. Energy manager confirms that the system energy is restricted to \textit{upper\_bound} and the \textit{lower\_bound} set in the python configuration file. Once the \textit{energy\_remained} has been successfully updated by the energy manager, it invokes the state machine module which dictates how the power level of the system should be updated.

\subsection{State Machine}
The state machine used by the system is simple with three states - STATE\_POWER\_OFF, STATE\_POWER\_RETENTION, and STATE\_POWER\_ON. The state machine state is initialized to STATE\_POWER\_OFF upon initialization. Based on the energy level information received from the energy manager module, state machine updates the states to these modules. The thresholds used by the state machine to update the system is configurable through the python configuration file. When the system energy exceeds threshold \textit{thres\_ret\_to\_1}, the state machine switches the state to STATE\_POWER\_ON. The system remains in the STATE\_POWER\_ON state until the system energy falls below  \textit{thres\_1\_to\_ret}. At this point, the state machine switches to STATE\_POWER\_RETENTION. It can remain in this state until the system energy remains above \textit{thres\_ret\_to\_off}. Once system energy falls below this threshold, the state machine switches back to the STATE\_POWER\_OFF state.

The state machine uses messages to inform SimObjects regarding the state changes. The state change messages are broadcasted to all SimObjects so that they can change their power levels and functionality based on the current system energy level. When STATE\_POWER\_ON is entered, state machine sends the message POWER\_ON to all SimObjects. It sends the message POWER\_RET and POWER\_OFF when it enters the states STATE\_POWER\_RETENTION and STATE\_POWER\_OFF respectively. To implement the messaging system, the SimObject definitions were augmented with an energy port for sending and receiving these messages.

In this implementation, only the AtomicCPU was modified to receive the energy messages broadcasted by the state machine. Moreover, AtomicCPU is the only module in ConfigNVPSim system which can consume power. Extension of energy consumption to other modules like DRAM and cache has to be updated in the subsequent release versions of ConfigNVPSim.

\subsection{AtomicCPU}
AtomicCPU receives the energy messages from the state machine through the energy port. GEM5 keeps the CPU running by scheduling and executing ticks at CPU clock periods. CPU ticks can be controlled to stop or to pause the CPU execution. This strategy is adopted in the NVP system to implement non-volatility.
When the AtomicCPU receives a state change message to POWER\_OFF, the CPU enters the POWER\_OFF state by de-scheduling the previously scheduled tick. This ensures that the CPU doesn't run anymore and that it is powered off. When state machine switches the CPU state to POWER\_RET state, the CPU ticks are rescheduled to the subsequent tick period which prevents the CPU execution. The tick rescheduling continues until the next state change. When the POWER\_ON state is entered, the rescheduled and turned off tick is restored and CPU starts execution.
When the state change is from POWER\_RET to POWER\_ON, the system remembers the previous state and tick is restored from the last backed up tick.

\section{\textbf{Experimentation}}
ConfigNVPSim's performance with an ideal sine input was evaluated in order to examine the state changes. Two parameters were variable: state change thresholds and energy consumptions in each state. Four experiments were done: the first one was with threshold settings 1 and consumption settings 1, the second one was threshold settings 2 and consumption settings 1, the third one was threshold settings 1 and consumption settings 2 and the last one was ConfigNVPSim's response to real power input that was fed into the base Gem5 implementation. To visually observe the state changes and energy remained in each state change,  the input power, energy remained and the state was plotted in one graph for each experiment. Tables \ref{table:cpuconsumption} and \ref{table:cputhresh} show threshold settings and consumption configurations.
To test the performance of ConfigNVPSim, a program called nvp\_hello.c was executed. The functionality of this program includes a loop that increments a counter from 0 to 99 and prints its value. The aim of this program is to confirm that the CPU only executes programs in POWER\_ON state.
\begin{table}[]
\medskip
\begin{center}
\begin{tabular}{|l|l|l|l|}
\hline
\rowcolor[HTML]{D9D9D9}
Configuration & POWER\_ON & POWER\_RET & POWER\_OFF \\ \hline
1             & 0         & 0.3        & 1.3        \\ \hline
2             & 0         & 1.5        & 6.5        \\ \hline
\end{tabular}
\end{center}
\medskip
\caption{CPU Energy Consumption Configurations}
\label{table:cpuconsumption}
\end{table}

\begin{table}[]
\medskip
\begin{center}
\begin{tabular}{|l|l|l|l|}
\hline
\rowcolor[HTML]{D9D9D9}
Configuration & POWER\_ON & POWER\_RET & POWER\_OFF \\ \hline
1             & 40        & 80         & 500        \\ \hline
2             & 200       & 400        & 1000       \\ \hline
\end{tabular}
\end{center}
\medskip
\caption{CPU State Threshold Configurations}
\label{table:cputhresh}
\end{table}

\section{\textbf{Results}}
\subsection{Threshold and Power Consumption Analysis}
Figure ~\ref{sine3} shows the state changes in ConfigNVPSim with threshold settings 1 and power consumption settings 1. With these settings and the positive half of the sine wave as input, it can be seen that the state changes to POWER\_RET once the system energy is depleted. Once the system energy builds back, the CPU starts executing the code. The system goes through multiple iterations of switches between POWER\_RET and POWER\_ON before the input wave dies out and the system falls back to POWER\_OFF.

\begin{figure}[htbp]
\centerline{\includegraphics[scale=0.3]{sine3.png}}
\caption{Performance with sine input (threshold settings 1 and consumption settings 1)}
\label{sine3}
\end{figure}

Figure ~\ref{sinediffthresh3} shows the state changes in ConfigNVPSim with threshold settings 2 and consumption settings 1. As shown in ~\ref{table:cputhresh}, Threshold settings 2 sets the thresholds at higher energy level than Threshold settings 1. This difference is reflected in the reduction in the number of state changes between POWER\_RET and POWER\_ON.

\begin{figure}[htbp]
\centerline{\includegraphics[scale=0.3]{sinediffthresh3.png}}
\caption{Performance with sine input (threshold settings 2 and consumption settings 1)}
\label{sinediffthresh3}
\end{figure}

Figure ~\ref{sinediffcons3} shows the state changes with threshold settings 1 and consumption settings 2. With this setting, the power consumption in POWER\_RET and POWER\_ON is higher which results in a steeper ramp down slop and a higher number of switches between POWER\_RET and POWER\_ON.

\begin{figure}[htbp]
\centerline{\includegraphics[scale=0.3]{sinediffcons3.png}}
\caption{Performance with sine input (threshold settings 1 and consumption settings 2)}
\label{sinediffcons3}
\end{figure}

Figure ~\ref{fig:real} shows the response of the NVP system to a real-world intermittent energy signal. The random variations in the input signal bring unpredictability to the time duration required to complete the CPU task. This makes the non-volatile system ideal for non-critical or optional tasks rather than time-critical tasks.

\begin{figure}[htbp]
\centerline{\includegraphics[scale=0.3]{orig3.png}}
\caption{ConfigNVPSim's response to real power input}
\label{fig:real}
\end{figure}

\subsection{Execution Comparison}
Comparing the execution pattern between GEM5 base system and the ConfigNVP system provides meaningful insight into the unique execution strategy adopted in non-volatile systems. In order to do this, nvp\_hello.c benchmark program was run on both GEM5 base system and ConfigNVPSim.

\begin{figure}[htbp]
\centerline{\includegraphics[scale=0.2]{gem5_fw_count.png}}
\caption{FW Counter increase pattern in GEM5 system}
\label{fig:gem5_fw_count}
\end{figure}

Figure ~\ref{fig:gem5_fw_count} shows the pattern of count value increase in GEM5 base system. It can be inferred that the count value increases almost linearly as the processor is always in POWER\_ON state in the GEM5 system.

\begin{figure}[htbp]
\centerline{\includegraphics[scale=0.2]{nvpsim_fw_count.png}}
\caption{FW Counter increase pattern in ConfigNVP system}
\label{fig:nvpsim_fw_count}
\end{figure}
Figure ~\ref{fig:nvpsim_fw_count} shows the pattern of the count value increase in ConfigNVPSim. It is evident that the value increase is not linear and it is dependent on the intermittent nature of the input power. To plot Figure ~\ref{fig:nvpsim_fw_count}, the positive half of the ideal sine wave in ~\ref{fig:sine_wave} was used. Since the power was not sustainable, the ARM core incremented the counter only till 34 at which point the power saved in the energy management unit was depleted.

\section*{\textbf{Conclusion}}
By presenting the idea of ConfigNVPSim, the goals of implementing NVP on the GEM5 platform in terms of architecture and the evaluation of various configurations that can be created utilizing the currently existing architectural implementation were proposed. In this work, an NVP system that can maintain forward progress at intermittent energy level was created. The energy harvesting unit, a state machine that controls the instantaneous energy storage of the system and lastly an AtomicCPU unit that schedules the ticks and controls the CPU's power states were the heart of ConfigNVPSim because they were the main modifications done to the existing base GEM5 implementation to meet the proposed goals. Four experiments were done to evaluate the performance of ConfigNVPSim using different energy consumption and CPU state threshold settings.
Even though non-volatility was successfully implemented on top of the base implementation of GEM5 in terms of energy harvesting module and a state machine that controls the CPU states, the specific module for the backup of data was not implemented in this project, so that can be implemented along with different backup strategies in future work. Since the demand for feature-rich mobile systems like smartphones and tablets has increased, NVP in such a system would provide an optimal power budget paired with increased performance. So as future work, a non-volatile simulator on an android platform would provide a promising solution to realize NVP based mobile systems. Lastly, a capacitance leakage model was not implemented in the energy management unit and should be implemented as future work, to make the simulations closer to real life situations.

\section*{\textbf{Acknowledgment}}

This work is a derivative of the NVPSim work done by Yizi Gu et. al. We especially thank all the prior contributors of NVPSim and Gem5. We thank Prof. Jack Sampson and Prof. Mahmut Kandemir for their valuable guidance. We also thank Prof. Asheesh Kolli for his help and support.

\begin{thebibliography}{00}
\bibitem{b1}Yizi Gu, Y. Liu, Y. Wang, H. Li, and H. Yang, "NVPsim: A simulator for architecture explorations of nonvolatile processors," 2016 21st Asia and South Pacific Design Automation Conference (ASP-DAC), Macau, 2016, pp. 147-152.
\bibitem{b2}Nathan Binkert, Bradford Beckmann, Gabriel Black, Steven K. Reinhardt, Ali Saidi, Arkaprava Basu, Joel Hestness, Derek R. Hower, Tushar Krishna, Somayeh Sardashti, Rathijit Sen, Korey Sewell, Muhammad Shoaib, Nilay Vaish, Mark D. Hill, and David A. Wood. 2011. The gem5 simulator. SIGARCH Comput. Archit. News 39, 2 (August 2011), 1-7. DOI=http://dx.doi.org/10.1145/2024716.2024718
\bibitem{b3} Jason Lowe-Power, Learning Gem 5, Retrieved from http://learning.gem5.org/
\bibitem{b4}Kaisheng Ma, Yang Zheng, Shuangchen Li, Karthik Swaminathan, Xueqing Li,
Yongpan Liu, Jack Sampson, Yuan Xie and Vijaykrishnan Narayanan "Architecture Exploration for Ambient Energy
Harvesting Nonvolatile Processors" 2015 IEEE 21st International Symposium on High-Performance Computer Architecture.
\end{thebibliography}
\vspace{12pt}

\end{document}

max_stars_repo_name: sethujose/NVPsim

max_issues_repo_name: sethujose/NVPsim

max_forks_repo_name: sethujose/NVPsim


text:
\subsection{Choosing the functions}

As mentioned in the introduction, the goal is to make functional programming in Go easier.
To achieve this, the first task is to implement some helper functions for slices, similar to those that exist
for lists in Haskell. To decide on which functions will be implemented, popular
Haskell repositories on GitHub have been analysed. The popularity of repositories
was decided to be based on their number of stars. Out of all Haskell projects
on GitHub, the most popular are\autocite{github-popular-haskell}:

\begin{itemize}
    \item Shellcheck (koalaman/shellcheck\autocite{github-shellcheck}): A static analysis tool for shell scripts
    \item Pandoc (jgm/pandoc\autocite{github-pandoc}): A universal markup converter
    \item Postgrest (PostgREST/postgrest\autocite{github-postgrest}): REST API for any Postgres database
    \item Semantic (github/semantic\autocite{github-semantic}): Parsing, analyzing, and comparing source code across many languages
    \item Purescript (purescript/purescript\autocite{github-purescript}): A strongly-typed language that compiles to JavaScript
    \item Compiler (elm/compiler\autocite{github-elmcompiler}): Compiler for Elm, a functional language for reliable web apps
    \item Haxl (facebook/haxl\autocite{github-haxl}): A Haskell library that simplifies access to remote data, such as databases or web-based services
\end{itemize}

In these repositories, the number of occurrences of popular list functions has
been counted. The analysis does not differentiate between different `kinds' of
functions. For example, `fold' includes all occurrences of \mintinline{haskell}|foldr|,
\mintinline{haskell}|foldl| and \mintinline{haskell}|foldl'|; `map' also includes
occurrences of \mintinline{haskell}|fmap|.
Further, the analysis has not been done with any kind of AST-parsing.
Rather, a simple `grep' has been used to find matches. This means that it is
likely to contain some mismatches, for example in code comments. All in all,
this analysis should only be an indicator of what functions are used most.

Running the analysis on the 7 repositories listed above, searching for a number
of pre-selected list functions, indicates that the most used functions are `:'
(cons), `map' and `fold', as shown in table~\ref{tab:occurrences-list-funcs}.

\begin{table}[htb]
\centering
\begin{tabular}{ll}
\toprule
`:' (cons) & 2912 \\
\midrule
map, fmap & 1873 \\
\midrule
foldr, foldl, foldl' & 303 \\
\midrule
filter & 262 \\
\midrule
reverse & 154 \\
\midrule
take & 108 \\
\midrule
drop & 81 \\
\midrule
maximum & 45 \\
\midrule
sum & 44 \\
\midrule
zip & 38 \\
\midrule
product & 15 \\
\midrule
minimum & 10 \\
\end{tabular}
\caption[Occurrences of list functions]{Occurrences of list functions\footnotemark}
\label{tab:occurrences-list-funcs}
\end{table}

\footnotetext{See Appendix~\ref{appendix:function-occurrences} for how these results have been achieved}

Based on this information, it has been decided to implement the map, cons, fold
and filter functions into the Go compiler.

\subsection{Map}

The most used function in Haskell is map. The table~\ref{tab:occurrences-list-funcs}
counts roughly 1250 occurrences of map, although around 600 of those are from `fmap'.
fmap is part of the Functor type class\footnote{type classes
    in Haskell are similar to interfaces in imperative and object-oriented
languages}, which is described as `a type that can be mapped over'\autocite{functor-wiki}.
In general, a common analogy of the Functor type class is a box. A functor is like a box
where a value can be put into and taken out again. fmap processes and transforms the item
in that box. For lists, this process means iterating over and processing every item within that list.
For the `Maybe' type it means `unpacking' the concrete value and processing it, or if there is
no concrete value, returning `Nothing' instead.

The map function is exactly like fmap but only works on lists:

\begin{quote}
    \[map\] returns a list constructed by applying a function (the first argument) to all
    items in a list passed as the second argument\autocite{haskell-map}.
\end{quote}

Some usage examples of map can be seen at~\ref{code:haskell-map}.

\begin{listing}
    \begin{haskellcode}
Prelude> :t map
map :: (a -> b) -> [a] -> [b]
Prelude> :t fmap
fmap :: Functor f => (a -> b) -> f a -> f b
Prelude> map (*3) [1,2,3]
[3,6,9]
Prelude> fmap (*3) [1,2,3]
[3,6,9]
Prelude> map (++ " world") ["hello","goodbye"]
["hello world","goodbye world"]
Prelude> map show [1,2,3]
["1","2","3"]
    \end{haskellcode}
    \caption{Example usage for map and fmap}\label{code:haskell-map}
\end{listing}
Due to missing polymorphism, map cannot be implemented easily in Go. While
a specific definition of map would be
\begin{gocode}
func map(f func(int) string, []int) []string
\end{gocode}
this definition would only hold true for the specific type combination \mintinline{go}|int|
and \mintinline{go}|string|. A more generic definition, similar to append,
would be:
\begin{gocode}
func map(f func(Type1) Type2, []Type1) []Type2
\end{gocode}
For this to work, the function has to be implemented as a built-in into the compiler.

As there is already a `map' token in the Go compiler (for the map data type),
the function will be called `fmap'. However, compared to Haskell's `fmap',
Go's `fmap' only works on slices. This is due
to the absence of an `functor'-like concept. Again, due to the absence of polymorphism,
this cannot realistically built into the language in this context.

Nonetheless, to avoid possible naming confusions, the `map' function in Go will
be called `fmap'.

In Go, the usage of `fmap' should result in making the program~\ref{code:fmap-usage-go}
behave as shown\footnote{Printf's first argument, the
verb `\%\#v', can be used to print the type (`\#') and the value (`v') of a
variable\autocite{fmt-godoc}.}.

\begin{listing}
\begin{gocode}
package main

import (
  "fmt"
  "strconv"
)

func main() {
  fmt.Printf("%#v", fmap(strconv.Itoa, []int{1, 2, 3})) // []string{"1", "2", "3"}
}
\end{gocode}
\caption{Example usage of map in Go}\label{code:fmap-usage-go}
\end{listing}
\subsection{Cons}

The name cons has been introduced by LISP, where it describes a record structure
containing two components called the `car' (the `\textbf{c}ontents of the \textbf{a}ddress \textbf{r}egister')
and the `cdr' (`\textbf{c}ontent of \textbf{d}ecrement \textbf{r}egister').
Lists are built upon cons cells, where the `car' stores the element and `cdr' a
pointer to the next cell - the next element of the list.
This is why in Lisp, \mintinline{lisp}|(cons 1 (cons 2 (cons 3 (cons 4 nil))))| is equal to
\mintinline{lisp}|(list 1 2 3 4)|. This list is also visualised in picture~\ref{fig:cons}.

\begin{figure}[h!]
  \includegraphics[width=\linewidth]{../img/cons.png}
  \caption{Cons cells forming a list\autocite{cons-image-source}}
  \label{fig:cons}
\end{figure}

The cons operator thus prepends an element to a list, effectively allocating a
variable that contains the newly added element and a pointer to the `old' list.
As a result, prepending to a list is computationally cheap, needing one allocation
and one update.

In Haskell, the `name' of the cons function is the `:' operator.
In Go, names for identifiers (which includes function names) underlie a simple
rule:
\begin{quote}
    An identifier is a sequence of one or more letters and digits. The first
    character in an identifier must be a letter.\autocite{spec-identifiers}
\end{quote}

This rule forbids a function to be named `:'. Instead, the function could be
named `cons'. However, Go already has a function to add to the end of a slice,
`append'. Thus, adding to the beginning of a slice will be named `prepend'.
Using prepend should be very similar to append. The behaviour of `prepend'
should be equal to using `append' with a slight workaround\footnote{This workaround
	is to create a slice containing the prepended element, and expanding the
destination slice with `...', as \mintinline{go}|append| is a variadic function}:

\begin{listing}
    \begin{gocode}
package main

import (
  "fmt"
  "strconv"
)

func main() {
	fmt.Printf("%#v", append([]int{0}, []int{1,2,3}...)// []int{0, 1, 2, 3}
	fmt.Printf("%#v", prepend(0, []int{1, 2, 3})) // []int{0, 1, 2, 3}
}
\end{gocode}
    \caption{Example usage of prepend in go}\label{code:prepend-go}
\end{listing}
\subsection{Fold}\label{sec:fold}

Fold, sometimes also named `reduce' or `aggregate', is another higher-order function
that is very commonly used in functional programming.

\begin{quote}
	fold refers to a family of higher-order functions that
	analyze a recursive data structure and through use of a given
	combining operation, recombine the results of recursively processing its
	constituent parts, building up a return value.\autocite{fold-wiki}
\end{quote}

In other words, fold processes a list one by one and executes a `combining operation'
on every element, for example summing up a list of integers.

The family of fold functions in Haskell consist of three different implementations of
that definition: foldr, foldl and foldl'.
The difference between foldr and foldl is hinted at their function headers:
\begin{listing}
    \begin{haskellcode}
Prelude Data.List> :t foldl
foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
Prelude Data.List> :t foldr
foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
    \end{haskellcode}
    \caption{Function headers of the fold functions}
\end{listing}
The argument with type `b' is passed as the first argument to the foldl
function, and as the second argument to foldr. As can be seen in the illustrations
of foldl and foldr in~\ref{fig:fold}, the evaluation order of the two functions
differ.

\begin{figure}[h!]
    \centering
    \includegraphics[scale=0.5]{../img/foldl.png}
    \includegraphics[scale=0.5]{../img/foldr.png}
    \caption{Folds illustrated\autocite{fold-wiki}}
    \label{fig:fold}
\end{figure}

This is most obvious when using an example where the function is not associative:

\begin{listing}
    \begin{haskellcode}
foldl (-) 0 [1..7]
((((((0 - 1) - 2) - 3) - 4) - 5) - 6) - 7 = -28
foldr (-) 0 [1..7]
1 - (2 - (3 - (4 - (5 - (6 - (7 - 0)))))) = 4
    \end{haskellcode}
    \caption{foldr and foldl execution order}\label{code:foldr-example}
\end{listing}
In foldl, the accumulator (`0') is added to the left end of the list (prepended),
while with foldr, the accumulator is added to the right end.
For associative functions (e.g. `+') this does not make a difference, it does
however for non-associative functions, as can be seen in the example~\ref{code:foldr-example}.

The difference between foldl and foldl' is more subtle:
\begin{quote}
    foldl and foldl' are the same except for their strictness properties, so if both
    return a result, it must be the same.\autocite{fold-types}
\end{quote}

The strictness property is only relevant if the function is lazy in its first argument.
If this is the case, behavioural differences can be seen because foldl builds up a so
called `execution path' (nesting the called functions), while foldl' executes these
functions while traversing it already. An example of this is illustrated in
Appendix~\ref{appendix:foldl-strictness}.

To keep things simpler, Go will only have its versions of foldl and foldr, which
will both be strict --- the Haskell counterparts would thus be foldr and foldl'.\footnote{
If the behaviour from the normal foldl function is required, a workaround can
be applied in the Go version. See Appendix~\ref{appendix:foldl-go}}
The usage of these fold-functions is equal to the Haskell versions, where foldl's
arguments are switched in order.

\begin{listing}
\begin{gocode}
package main

import "fmt"

func main() {
  sub := func(x, y int) int { return x - y }
  fmt.Printf("%v\n", foldr(sub, 100, []int{10, 20, 30})) // -80
  fmt.Printf("%v\n", foldl(sub, 100, []int{10, 20, 30})) // 40
}
\end{gocode}
    \caption{Example usage of foldr and foldl in go}\label{code:fold-go}
\end{listing}
\subsection{Filter}

The filter function is the conceptually simplest higher-order function.
It takes a list and filters out all elements that are not matching
a given predicate.
This predicate usually is a function that takes said element and returns
a boolean if it should be kept or filtered.

A simple example:

\begin{listing}
    \begin{gocode}
package main

import "fmt"

func main() {
  smallerThan5 := func(x int) bool {
    return x < 5
  }

  fmt.Println(filter(smallerThan5, []int{1, 8, 5, 4, 7, 3})) // [1, 4, 3]
}
\end{gocode}
    \caption{Example usage of filter in Go}\label{code:filter-go}
\end{listing}

max_stars_repo_name: tommyknows/bachelor-thesis

max_issues_repo_name: tommyknows/bachelor-thesis

max_forks_repo_name: tommyknows/bachelor-thesis


text: \chapter{index}{IRIS Toolbox Reference Manual}{Contents/index}

max_stars_repo_name: OGResearch/IRIS-Toolbox-For-Octave

max_issues_repo_name: OGResearch/IRIS-Toolbox-For-Octave

max_forks_repo_name: OGResearch/IRIS-Toolbox-For-Octave