\section{Multi-armed Bandits}
Reinforcement learning involves evaluative feedback rather than instructive feedback. We get told whether our actions are good ones or not, rather than what the single best action to take is. This is a key distinction between reinforcement learning and supervised learning.

\subsection{A $k$-armed Bandit Problem}
In the $k$-armed bandit problem there are $k$ possible actions, each of which yields a numerical reward drawn from a stationary probability distribution for that action. We want to maximise the expected total reward, taking an action at each \emph{time step}. Some notation:

\begin{itemize}
    \item Index timesteps by $t$
    \item Action $A_t$
    \item Corresponding reward $R_t$
    \item \emph{Value} of action $a$ is $q_*(a) = \mathbb{E}[R_t | A_t = a]$
    \item Estimate of value of action $a$ at $t$ is denoted $Q_t(a)$
\end{itemize}

We therefore want to choose $\{a_1, \dots, a_T\}$ to maximise $\sum_{t = 1}^T q_*(a_t)$.\\
\mbox{}\\
At each timestep, the actions with the highest estimated reward are called the \emph{greedy} actions. If we take this action, we say that we are \emph{exploiting} our understanding of the values of actions. The other actions are known as \emph{non-greedy} actions, sometimes we might want to take one of these to improve our estimate of their value. This is called \emph{exploration}. The balance between exploration and exploitation is a key concept in reinforcement learning.

\subsection{Action-value Methods}
We may like to form estimates of the values of possible actions and then choose actions according to these estimates. Methods such as this are known as \emph{action-value methods}. There are, of course, many ways of generating the estimates $Q_t(a)$. \\
\mbox{}\\
An $\varepsilon$-greedy method is one in which with probability $\varepsilon$ we take a random draw from all of the actions (choosing each action with equal probability), providing some exploration.

\setcounter{subsection}{4}
\subsection{Tracking a Non-stationary Problem}
If we decide to implement the sample average method, then at each iteration that we choose the given action we update our estimate by
\begin{equation}
    Q_{n+1} = Q_n + \frac1n [R_n - Q_n]
\end{equation}
Note that this has the (soon to be familiar) form
\begin{equation}
    \mathrm{NewEstimate} \gets \mathrm{OldEstimate} + \mathrm{StepSize}\times[\mathrm{Target} - \mathrm{OldEstimate}].
\end{equation}
\mbox{}\\
If the problem was non-stationary, we might like to use a time weighted exponential average for our estimates (\emph{exponential recency-weighted average}). This corresponds to a constant step-size $\alpha \in (0, 1]$ (you can check).
\begin{equation}
    Q_{n+1} = Q_n + \alpha [R_n - Q_n].
\end{equation}
\mbox{}\\
We might like to vary the step-size parameter. Write $\alpha_n(a)$ for the step-size after the $n^{\mathsf{th}}$ reward from action $a$. Of course, not all choices of $\alpha_n(a)$ will give convergent estimates of the values of $a$. To converge with probability 1 we must have
\begin{equation}
    \sum_n \alpha_n(a) = \infty \quad\quad \mathsf{and} \quad\quad  \sum_n \alpha_n(a)^2 < \infty.
\end{equation}
Meaning that the coefficients must be large enough to recover from initial fluctuations, but not so large that they don't converge in the long run. Although these conditions are used in theoretical work, they are seldom used in empirical work or applications. (Most reinforcement learning problems have non-stationary rewards, in which case convergence is undesirable.)

\subsection{Optimistic Initial Values}
The exponential recency weighted method is biased by the initial value one gives. If we like, we may set initial value estimates artificially high to encourage exploration in the short run -- this is called \emph{optimistic initial values}. This is a useful trick for stationary problems, but does not apply so well to non-stationary problems as the added exploration is only temporary.

\subsection{Upper-Confidence Bound Action Selection}
We might like to discriminate between potential explorative actions. Note that $\varepsilon$-greedy does not do this. We define the \emph{upper-confidence bound} action at $t$ as follows
\begin{equation}
    A_t \doteq \argmax_{a}\left[ \, Q_t(a)+ c \sqrt{\frac{\mathrm{ln}(t)}{N_t(a)}} \, \right]
\end{equation}
where $Q_t(a)$ is the value estimate for the action $a$ at time $t$, $c > 0$ is a parameter that controls the degree of exploration and $N_t(a)$ is the number of times that $a$ has been selected by time $t$. If $N_t(a) = 0$ then we consider $a$ a maximal action.\\

This approach favours actions with a higher estimated rewards but also favours actions with uncertain estimates (more precisely, actions that have been chosen few times).

\subsection{Gradient Bandit Algorithms}
Suppose that we choose actions probabilistically based on a preference for each action, $H_t(a)$. Let the action at $t$ be denoted by $A_t$. We then define the probability of choosing action $a$ via the softmax
\begin{equation}
    \pi_t(a) \doteq \P{}(A_t = a) = \frac{e^{H_t(a)}}{\sum_i e^{H_t(i)}}.
\end{equation}
We then iteratively perform updates according to
\begin{equation}
    H_{t+1}(a) = H_t(a) + (R_t - \bar{R}_t)(\mathds{1}_{A_t = a} - \pi_t(a)),
\end{equation}
where $\bar{R}_t$ is the mean of previous rewards. The box in the notes shows that this is an instance of stochastic gradient ascent since the expected value of the update is equal to the update when doing gradient ascent on the (total) expected reward.


\chapter{Audio Frequency Scaling methods}\label{ch:scaling_methods}
\section{Introduction}
The human hearing system can detect
acoustic vibrations and translate
those vibrations into sounds.
The detectable range of frequencies by the human ear
is referred to as audio or sonic. This range
spans over approximately \(20kHz\),
starting at \(20Hz\) to about \(20kHz\)
\cite{hearthres}.

As a result of aging, the hearing system's dynamic range
as to the detectable bandwidth decreases,
and by middle-age are set at about
\(20Hz \div 14KHz\)\cite{Wiley2008ChangesIH}.
As such, the maximum hearable frequency
declines with age.

The human ear's ability to distinguish
between two different frequencies
is not symmetric.
For example, the spectral distance between two
different frequencies in one distinct region does
not equal the spectral distance
between two additional frequencies in other regions.
Due to that asymmetry, the conventional linear
spectral mapping is impractical for
speech analysis applications.
Thus, a different spectral mapping
based on a different scaling system
that mimics the human hearing as possible
is applied instead as an alternative.

\section{Mel-Scaling}
The Mel-scaling method
is a suggested solution to mapping
standard audio frequencies to perceived frequencies.
The basic idea that lies underneath it is that for
different pitches we assign varying bandwidth,
such that they are equal in distance
from each other, as rated by listeners.
The reference point has been chosen to be
\(1000 Hz = 1000 Mels\).

Mel-scale was first described in \cite{Volkmann} by Stevens and Volkmann,
where the authors presented different curves for Mel-scaling.

Two common tables were composed
according to the Mel-scaling curves. One table by
Beranek in 1949 \cite{beranek1988acoustical}
and the second by Umesh et al. in 1999 \cite{UmeshMel}.

The most popular equation that models the Mel-scale
is given by \cite{o1987speech} and is typically referenced as
the "Logarithm based Mel scale":
\begin{equation}\label{eq:mel_1}
    Mel = \ln \left( 1 + \frac{f}{700} \right) \cdot \frac{1000}{\ln(1+\frac{1000}{700})}
\end{equation}

Equation\;[\ref{eq:mel_1}] can be simplified as follows:
\begin{align}
    Mel & = 1127 \ln \left( 1 + \frac{f}{700} \right) \nonumber \\
    Mel & = 2595 \log_{10}\left( 1 + \frac{f}{700} \right)
\end{align}

Then, the reverse equation, converting Mels back to Hz,
can be written as:

\begin{align}
    f[Hz] & = 700 \left( 10^{\frac{Mel}{2595}} -1  \right)
\end{align}

% \subsection{Logarithm based Mel scale}
% The most popular equation that models the Mel-scale
% is given by \cite{o1987speech}:
% \begin{equation}
%     Mel = \ln \left( 1 + \frac{f}{700} \right) \cdot \frac{1000}{\ln(1+\frac{1000}{700})}
% \end{equation}
% This can be simplified as follows:
% \begin{align}
%     Mel & = 1127 \ln \left( 1 + \frac{f}{700} \right) \nonumber \\
%     Mel & = 2595 \log_{10}\left( 1 + \frac{f}{700} \right)
% \end{align}
% Then, the reverse equation, converting Mels back to Hz,
% can be written as:
% \begin{align}
%     f[Hz] & = 700 \left( 10^{\frac{Mel}{2595}} -1  \right)
% \end{align}
% These modeling equations became de-facto the default way to
% map audio frequencies to Mels.

\subsection{Mel scale approximations}
Computing a logarithm for hardware devices,
whether it is the natural logarithm or any other base,
is not very straightforward.
For example, this kind of computation might require special
techniques or long LUTs (look-up tables),
which are extraordinarily resource hungry.

Instead, other approximations that do not involve
trigonometric or logarithms, but only
simple arithmetic structures can be applied.
By doing so, we benefit from low resource
utilization while maintaining high accuracy.

Multiple approximation methods were studied in \cite{fitmelscale}.
Two approximations are the most prominent for target HW devices.
\begin{align}
    \label{eq:melapproxa} Mel & = a + b \cdot f \\
    Mel & = \frac{f}{a \cdot f + b} \label{eq:melapproxb}
\end{align}

Where \(a\), \(b\) in Equation \ref{eq:melapproxa} are defined as follows:
\begin{align}
    a & = \begin{cases}
        127.7   &,\;f \leq 1000 \\
        1322    &,\;f > 1000
    \end{cases} \nonumber \\
    b & = \begin{cases}
        0.9     &,\;f \leq 1000 \\
        0.19    &,\;f > 1000
    \end{cases}
\end{align}

while in Equation \ref{eq:melapproxb} \(a\), \(b\) are:
\begin{align}
    a & = \begin{cases}
        0.000244   &,\;f \leq 1000 \\
        0.0004    &,\;f > 1000
    \end{cases} \nonumber \\
    b & = \begin{cases}
        0.741   &,\;f \leq 1000 \\
        0.603   &,\;f > 1000
    \end{cases}
\end{align}

\begin{figure}[H]
    \centering
    \includegraphics[width=\linewidth]{Scaling/images/mel_methods_comp}
    \caption{Mel scale comparisons with Beranek \& Umesh tables}\label{fig:mel_methods_comp}
\end{figure}

Figure \ref{fig:mel_methods_comp} has comparisons of three different
Mel-scale implementations with Beranek \& Umesh tables.
The first column, Log Based Mel, represents
O'Shaugnessy's famous log-based Mel modeling.
The Mel option \#1, and Mel option \#2 columns
follow the suggested approximations
given in Equations \ref{eq:melapproxa}
and \ref{eq:melapproxb}, respectively.

From the last row of graphs, we can deduce that the approximation
in Equation \ref{eq:melapproxb}
is the closest along with the range of audio frequencies
to the tables provided by Beranek \& Umesh.
On the other hand, the more simplified approximation
in Equation\ref{eq:melapproxa} seems
to yield the highest errors.

\begin{figure}[H]
    \centering
    \includegraphics[width=\linewidth]{Scaling/images/mel_lut}
    \caption{LUT based Mel FPGA implementation results}\label{fig:mel_lut}
\end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[width=\linewidth]{Scaling/images/mel_approx_no_opt}
    \caption{Mel approx. \#1 FPGA implementation results}\label{fig:mel_approx_no_opt}
\end{figure}

Figures \ref{fig:mel_lut}, \ref{fig:mel_approx_no_opt}
present the results of FPGA implementations
of O'Shaugnessy's log-based Mel and Mel approximation \#1.
Nonetheless, high precision quantization settings were chosen
for the Mel approximation, U32.22,
the shifting error received is higher compared
to the conventional Log Mel scaling implementation.
Although this error shift is compensated
just by selecting the approximation method,
the straightforward approach
turned out to be the non-optimized solution
in terms of HW resources and power consumption,
which utilized four times higher wattage on top of \(25 \div 30 \%\)
additional resources.

Instead, two optimization workarounds were tested.
The first is the multiplication of the \(a, b\) coefficients
in \ref{eq:melapproxb} by 1000.
The second optimization is reorganizing the equation
and storing the result in a sufficient precision
for the fractional part but lower resolution for the integer part.
These optimizations lead to a reduction in the
required number of bits for the fractional part.
As a result, both the frequency shifting error
and the overall resource utilization are greatly improved.

Yet, the split in frequency bands results in two multiplied sets
of coefficients for each band calculation.
Therefore, choosing a more generalized set
of coefficients for the entire audio band can help
in the reduction of redundant LUTs and other combinational logic,
such as selectors and multi-bus multiplexer cells.

Selection of \(a=0.24,\;b=0.741\), showed better results
as can be seen in Figure \ref{fig:mel_approx_logic_opt_generic}.
The accuracy estimation for the non-generic implementation
is shown in Figure\;\ref{fig:mel_approx_logic_opt}.

\begin{figure}[H]
    \centering
    \includegraphics[width=\linewidth]{Scaling/images/mel_approx_logic_opt}
    \caption{Mel approx. \#1 \underline{optimized} FPGA implementation results}\label{fig:mel_approx_logic_opt}
\end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[width=\linewidth]{Scaling/images/mel_approx_logic_opt_generic}
    \caption{Mel approx. \#1 \underline{optimized, generic} FPGA implementation results}\label{fig:mel_approx_logic_opt_generic}
\end{figure}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    % \centering
    \hspace*{-1.8cm}
    \arrayrulecolor{mtblborder}
\begin{tabular}{ !{\color{mtblborder}\vrule}l!{\color{mtblborder}\vrule}rcccc| }
    \hline

    \hline
    \rowcolor{mtblcaption} \color{white}\bf{Algorithm}
    & \color{white}\bf{Latency \([ns]\)}
    & \color{white}\bf{Quant.}
    & \color{white}\bf{Max Err. \([\Delta Hz]\)}
    & \color{white}\bf{Mean Err.}
    & \color{white}\bf{Std Err.} \\
    \hline

    \hline
    \rowcolor{mtbl} Log LUT Mel   & \(14\) (3 C.C) & U16/4 & 1.146 & 0.268 & 0.106 \\
    \hline

    \hline
    \rowcolor{wtbl} Mel \#1   & \(9\) (2 C.C) &  U32/22  & 1.338 & -0.873 & -0.359 \\
    \hline

    \hline
    \rowcolor{mtbl} Mel \#1 Opt      & \(9\) (2 C.C) &  U16/4  & 0.190 & -0.053 & 0.065 \\
    \hline

    \hline
    \rowcolor{wtbl} Mel \#1 Generic     & \(9\) (2 C.C) &  U16/4  & \color{gtblcaption}0.174 & \color{gtblcaption}-0.035 & \color{gtblcaption}0.061 \\
    \hline

    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{Mel-Approx, log-based Mel performance comparison}
\label{tbl:mel_scale_performance}
\end{table}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    \centering
    \arrayrulecolor{ytblborder}
\begin{tabular}{ !{\color{ytblborder}\vrule}l!{\color{ytblborder}\vrule}rrrrr| }
    \hline

    \hline
    \rowcolor{ytblcaption} \color{white}\bf{Algorithm}
    & \color{white}\bf{FF}
    & \color{white}\bf{LUT}
    & \color{white}\bf{DSP}
    & \color{white}\bf{LUTRAM}
    & \color{white}\bf{BRAM} \\
    % & \color{white}\bf{ORM}
    % & \color{white}\bf{Clean} \\
    \hline

    \hline
    \rowcolor{ytbl} Log LUT Mel   & 82(0.04\%) & 276(0.23\%) & 1(<1\%) & 10(0.02\%) & 1.5(1.04\%)  \\
    \hline

    \hline
    \rowcolor{wtbl} Mel \#1     & 47(0.02\%) & 530(0.45\%) & 1(<1\%) & 0(0\%)  & 0(0\%)    \\
    \hline

    \hline
    \rowcolor{ytbl} Mel \#1 Opt      & 47(0.02\%) & 271(0.23\%) & 1(<1\%) & 0(0\%)  & 0(0\%)    \\
    \hline

    \hline
    \rowcolor{wtbl} Mel \#1 Generic     & \color{gtblcaption}47(0.02\%) & \color{gtblcaption}269(0.19\%) & \color{gtblcaption}1(<1\%) & \color{gtblcaption}0(0\%)  & \color{gtblcaption}0(0\%)    \\
    \hline

    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{Mel scaling methods resource utilization table}
\label{tbl:mel_resource_util}
\end{table}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    \centering
    \arrayrulecolor{gtblborder}
\begin{tabular}{ |l|cccc| }
    \hline

    \hline
    \rowcolor{gtblcaption} \color{white}\bf{Parameter}
    & \color{white}\bf{Log LUT Mel}
    & \color{white}\bf{Mel \#1}
    & \color{white}\bf{Mel \#1 Opt}
    & \color{white}\bf{Mel \#1 Generic} \\
    \hline\hline
    \rowcolor{wtbl}\multicolumn{5}{|c|}{\bf{Dynamic Power [W]}}\\
    \hline
    \rowcolor{gtbl} Signals                 & 4.947 & 5.221 & 3.011 & 2.916  \\
    \hline

    \hline
    \rowcolor{wtbl} Logic                   & 6.50 & 6.792 & 3.751 & 3.070  \\
    \hline

    \hline
    \rowcolor{gtbl} DSP                     & 0.014 & 0.013 & 0.014  & 0.014 \\
    \hline

    \hline
    \rowcolor{wtbl} I/O                     & 18.236 & 26.263 & 7.207  & 6.378 \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{dynmic}}\) & \textbf{29.697} & \textbf{38.290} & \textbf{13.983}  & \textbf{\colorbox{Goldenrod!70}{\color{MidnightBlue}12.379}} \\
    \hline

    % \hline
    % \rowcolor{gtbl} Bark Scale      & 56(0.02\%) & 218(\%) & 1(<1\%)   \\
    % % \cline{2-8}
    % % \multirow{-2}{*}{\cellcolor{ytbl}\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\
    \hline\hline
    \rowcolor{wtbl}\multicolumn{5}{|c|}{\bf{Static Power [W]}}   \\
    \hline

    \hline
    \rowcolor{gtbl} PL Static               & 2.364 & 2.466 & 0.499  & 0.499 \\
    \hline

    \hline
    \rowcolor{wtbl} PS Static               & 0.068 & 0.071 & 0.020 & 0.018  \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{static}}\) & \textbf{2.432} & \textbf{2.537} & \textbf{0.519} & \textbf{\colorbox{Goldenrod!70}{\color{MidnightBlue}0.517}}  \\
    \hline

    \hline\hline
    \rowcolor{wtbl}\multicolumn{5}{|c|}{\bf{Total Power [W]}}   \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{total}}\)  & \textbf{32.13} & \textbf{40.827} & \textbf{14.502} & \textbf{\colorbox{Goldenrod!70}{\color{MidnightBlue}12.896}}  \\
    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{Mel-Approx, log-based Mel, Bark Scale Power consumption}
\label{tbl:mel_scale_pwr_tbl}
\end{table}

The LUT implementation makes use of a \(log_{2}\) look-up table.
However, an additional step is
needed for the natural logarithm or other log bases.
Since the logarithm bases are constant,
the LUT result is divided by the \(log_{2}\) of the base,
whether it be the natural base or base ten.
This logarithm bases
convention is described in Equation\;\ref{eq:log_base_conv}.
\begin{align}\label{eq:log_base_conv}
    \log_{b}(a)  & = \frac{\log_{x}(a)}{\log_{x}(b)}
\end{align}

Table\;\ref{tbl:mel_scale_performance} summarizes
the performance comparison between the different Mel scaling
implementation approaches.

The HW setup is for the PYNQ-Z1 development board.
Hence, the results are unique to that specific
HW device and probably change for other
FPGA devices and development boards.

Latencies were simulated with Xilinx Vivado Suit
for an operating clock frequency of \(225MHz\).
In this operating condition, no timing violations were reported.

Tables\;\ref{tbl:mel_resource_util} and \ref{tbl:mel_scale_pwr_tbl}
show the synthesis and implementation results
plus the power estimation reports.
These reports were taken from the Xilinx Vivado Suit application.

\section{Bark-Scaling}
Another scaling method is the Bark scale which is based on
the same principle of retaining the same perceptual distances.
The Bark scale is divided into critical
bands corresponding to the critical hearing bands.
Each band has a bandwidth similar
to the psychoacoustic band of the corresponding
``filter'' in the human hearing system
and is ranked with a unique number.

\subsection{Bark Critical Bands}
Like the Mel scale, several equations were proposed to model best
the Bark scale and its critical bands.

The first method was introduced in \cite{1908630}.
A proposed approximation to the Bark scaling is described in
\cite{TraunmullerScale}; this paper also introduces the
correction of the band boundaries to ensure more
correctness with the original Bark scaling.

Four different equations were proposed to model
the Bark scale.

The first by Zwicker is well described in\cite{1908630} and
is given by the following equation:
\begin{align}% Zwicker Eq
    Bark & = \tan^{-1}\left\{ 0.00073f \right\} + 3.5 \tan^{-1}\left\{
            \left( \frac{f}{7500} \right)^{2}
        \right\}
\end{align}

Another proposed equation by Traunmuller \cite{TraunmullerScale} is:
\begin{align}\label{eq:traunmuller_no_fix}% Traunmuller Eq + Correction
    Bark & = \frac{26.81f}{1960 + f} - 0.53
\end{align}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.75\linewidth]{Experiments/images/Traunmuller_nofix}
    \caption{Traunmuller no fix}\label{fig:Traunmuller_nofix}
\end{figure}

Denoting Traunmuller's original
Bark scale given in Equation \ref{eq:traunmuller_no_fix} as \(Bark'\),
the fixed form for Traunmuller's Bark equation is:
\begin{align}
    Bark & = \begin{cases}
        0.3 + 0.85\cdot \left( Bark' \right)
        &,\;Bark' < 2 \\
        Bark' + 0.22\cdot \left( Bark' - 20.1 \right)
        &,\;Bark' > 20.1
    \end{cases}
\end{align}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.75\linewidth]{Experiments/images/Traunmuller_fix}
    \caption{Traunmuller fix}\label{fig:Traunmuller_fix}
\end{figure}

The fourth possible modeling equation is proposed by
Schroeder in \cite{SchroederScale} and is as follows:
% Schroeder Eq
\begin{align}
    Bark & = 7\ln \left( \frac{f}{650} + \sqrt{1 + \frac{f^{2}}{422500} }  \right)
\end{align}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.75\linewidth]{Experiments/images/bark_comparison}
    \caption{Bark comparisons}\label{fig:bark_comparison}
\end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.75\linewidth]{Experiments/images/bark_comparison2}
    \caption{Bark comparison}\label{fig:wer_23}
\end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.75\linewidth]{Experiments/images/Zwicker}
    \caption{Zwicker}\label{fig:Zwicker}
\end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.75\linewidth]{Experiments/images/Schroeder}
    \caption{Schroeder}\label{fig:Schroeder}
\end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.75\linewidth]{Scaling/images/bark_traunmuller_no_fix}
    \caption{Schroeder}\label{fig:bark_traunmuller_no_fix}
\end{figure}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    % \centering
    \hspace*{-1.8cm}
    \arrayrulecolor{mtblborder}
\begin{tabular}{ !{\color{mtblborder}\vrule}l!{\color{mtblborder}\vrule}rcccc| }
    \hline

    \hline
    \rowcolor{mtblcaption} \color{white}\bf{Algorithm}
    & \color{white}\bf{Latency \([ns]\)}
    & \color{white}\bf{Quant.}
    & \color{white}\bf{Max Err. \([\Delta Hz]\)}
    & \color{white}\bf{Mean Err.}
    & \color{white}\bf{Std Err.} \\
    \hline

    \hline
    \rowcolor{mtbl} Traunmuller w/ Fix   & 14 (3 C.C) & U10/5 & N.A & N.A & N.a \\
    \hline

    \hline
    \rowcolor{wtbl} Traunmuller w/o Fix  & 9 (2 C.C) &  U9/4  & 0.0443 & 0.0015 & 0.0180 \\
    \hline

    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{Traunmuller's Bark scale implementations performance comparison}
\label{tbl:bark_implementations_performance}
\end{table}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    \centering
    \arrayrulecolor{ytblborder}
\begin{tabular}{ !{\color{ytblborder}\vrule}l!{\color{ytblborder}\vrule}rrrrr| }
    \hline

    \hline
    \rowcolor{ytblcaption} \color{white}\bf{Algorithm}
    & \color{white}\bf{FF}
    & \color{white}\bf{LUT}
    & \color{white}\bf{DSP}
    & \color{white}\bf{LUTRAM}
    & \color{white}\bf{BRAM} \\
    % & \color{white}\bf{ORM}
    % & \color{white}\bf{Clean} \\
    \hline

    \hline
    \rowcolor{ytbl} Traunmuller w/ Fix   & 43(0.02\%) & 302(0.26\%) & 1(<1\%) & 0(0\%) & 0(0\%)  \\
    \hline

    \hline
    \rowcolor{wtbl} Traunmuller w/o Fix      & 27(0.01\%) & 284(0.24\%) & 1(<1\%) & 0(0\%)  & 0(0\%)    \\
    \hline

    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{Traunmuller's Bark scale implementations resource utilization table}
\label{tbl:Bark_resource_util}
\end{table}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    \centering
    \arrayrulecolor{gtblborder}
\begin{tabular}{ |l|cc| }
    \hline

    \hline
    \rowcolor{gtblcaption} \color{white}\bf{Parameter}
    & \color{white}\bf{Traunmuller w/ Fix}
    & \color{white}\bf{Traunmuller w/o Fix} \\
    \hline\hline
    \rowcolor{wtbl}\multicolumn{3}{|c|}{\bf{Dynamic Power [W]}}\\
    \hline
    \rowcolor{gtbl} Signals                 & 2.380 & 2.192   \\
    \hline

    \hline
    \rowcolor{wtbl} Logic                   & 3.079 & 2.957   \\
    \hline

    \hline
    \rowcolor{gtbl} DSP                     & 1.445 & 0.014  \\
    \hline

    \hline
    \rowcolor{wtbl} I/O                     & 4.022 & 4.022  \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{dynmic}}\) & \textbf{10.923} & \textbf{\color{gtblborder}9.186}  \\
    \hline

    % \hline
    % \rowcolor{gtbl} Bark Scale      & 56(0.02\%) & 218(\%) & 1(<1\%)   \\
    % % \cline{2-8}
    % % \multirow{-2}{*}{\cellcolor{ytbl}\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\
    \hline\hline
    \rowcolor{wtbl}\multicolumn{3}{|c|}{\bf{Static Power [W]}}   \\
    \hline

    \hline
    \rowcolor{gtbl} PL Static               & 0.469 & 0.437  \\
    \hline

    \hline
    \rowcolor{wtbl} PS Static               & 0.017 & 0.016   \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{static}}\) & \textbf{0.486} & \textbf{\color{gtblborder}0.453}   \\
    \hline

    \hline\hline
    \rowcolor{wtbl}\multicolumn{3}{|c|}{\bf{Total Power [W]}}   \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{total}}\)  & \textbf{11.412} & \textbf{\color{gtblborder}9.639}  \\
    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{Traunmuller's Bark scale implementations Power consumption}
\label{tbl:bark_scale_pwr_tbl}
\end{table}

\section{ERB - Equivalent Rectangular Bandwidth}
Like the Bark scaling method, the ERB scale aims
to rescale the audio spectrum in different
bandwidths corresponding to the human hearing ``filters''.

This approach slightly differs from the Bark scale
because the filters' model is according
to a rectangular filter with an equivalent
bandwidth.

\begin{align}\label{eq:erb_eq}
    ERBs = 11.17\ln (47.065 - \frac{676170.42}{f + 14678.5})
\end{align}

A proposed approximation is given by:
\begin{align}\label{eq:erb_approx_eq}
    ERBs = 21.4 \cdot \log_{10} (1 + 0.00437f)
\end{align}

% \subsection{ERB Critical Bands}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.75\linewidth]{Scaling/images/erb}
    \caption{LUT based ERB FPGA implementation results}\label{fig:erb_fpga}
\end{figure}

\begin{figure}[H]
    \centering
    \includegraphics[width=0.75\linewidth]{Scaling/images/erb_approx}
    \caption{LUT based ERB approx. FPGA implementation results}\label{fig:erb_approx}
\end{figure}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    \centering
    % \hspace*{-1.8cm}
    \arrayrulecolor{mtblborder}
\begin{tabular}{ !{\color{mtblborder}\vrule}l!{\color{mtblborder}\vrule}rcccc| }
    \hline

    \hline
    \rowcolor{mtblcaption} \color{white}\bf{Algorithm}
    & \color{white}\bf{Latency \([ns]\)}
    & \color{white}\bf{Quant.}
    & \color{white}\bf{Max Err. \([\Delta C]\)}
    & \color{white}\bf{Mean Err.}
    & \color{white}\bf{Std Err.} \\
    \hline

    \hline
    \rowcolor{mtbl} ERB   & 23 (5 C.C) & U16/10 & 0.0153 & 0.0130 & 0.0018 \\
    \hline

    \hline
    \rowcolor{wtbl} ERB Approx  & 14 (3 C.C) &  U16/10  & 6.210m & -0.408m & 0.657m \\
    \hline

    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{ERB and ERB approx performance comparison}
\label{tbl:erb_scale_performance}
\end{table}

Table\;\ref{tbl:erb_scale_performance} presents the performance
comparison between the implementations of the pure ERB
and the ERB approximation
given by Equations\;\ref{eq:erb_eq}
and \ref{eq:erb_approx_eq}, respectively. The error terms
for the ERBs are measured in \(\Delta C\), indicating the
error in Cams rather than in frequency units (Hz).
Equation\;\ref{eq:cams_hz} can be used to convert Cams to Hz.

\begin{align}\label{eq:cams_hz}
    f = \frac{676170.42}{47.065 - e^{0.0895\cdot C}} - 14678.5
\end{align}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    \centering
    \arrayrulecolor{ytblborder}
\begin{tabular}{ !{\color{ytblborder}\vrule}l!{\color{ytblborder}\vrule}rrrrr| }
    \hline

    \hline
    \rowcolor{ytblcaption} \color{white}\bf{Algorithm}
    & \color{white}\bf{FF}
    & \color{white}\bf{LUT}
    & \color{white}\bf{DSP}
    & \color{white}\bf{LUTRAM}
    & \color{white}\bf{BRAM} \\
    % & \color{white}\bf{ORM}
    % & \color{white}\bf{Clean} \\
    \hline

    \hline
    \rowcolor{ytbl} ERB   & 112(0.05\%) & 824(0.70\%) & 1(<1\%) & 1(0.02\%) & 1.5(1.04\%)  \\
    \hline

    \hline
    \rowcolor{wtbl} ERB Approx      & 103(0.04\%) & 564(0.48\%) & 1(<1\%) & 1(0.01\%)  & 1.5(1.04\%)    \\
    \hline

    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{Mel scaling methods resource utilization table}
\label{tbl:ERB_resource_util}
\end{table}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    \centering
    \arrayrulecolor{gtblborder}
\begin{tabular}{ |l|cc| }
    \hline

    \hline
    \rowcolor{gtblcaption} \color{white}\bf{Parameter}
    & \color{white}\bf{ERB}
    & \color{white}\bf{ERB Approx} \\
    \hline\hline
    \rowcolor{wtbl}\multicolumn{3}{|c|}{\bf{Dynamic Power [W]}}\\
    \hline
    \rowcolor{gtbl} Signals                 & 12.691 & 5.525   \\
    \hline

    \hline
    \rowcolor{wtbl} Logic                   & 17.576 & 7.478   \\
    \hline

    \hline
    \rowcolor{gtbl} DSP                     & 0.067 & 0.049  \\
    \hline

    \hline
    \rowcolor{wtbl} I/O                     & 17.379 & 17.373  \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{dynmic}}\) & \textbf{47.713} & \textbf{\color{gtblborder}31.519}  \\
    \hline

    % \hline
    % \rowcolor{gtbl} Bark Scale      & 56(0.02\%) & 218(\%) & 1(<1\%)   \\
    % % \cline{2-8}
    % % \multirow{-2}{*}{\cellcolor{ytbl}\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\
    \hline\hline
    \rowcolor{wtbl}\multicolumn{3}{|c|}{\bf{Static Power [W]}}   \\
    \hline

    \hline
    \rowcolor{gtbl} PL Static               & 2.971 & 1.510  \\
    \hline

    \hline
    \rowcolor{wtbl} PS Static               & 0.084 & 0.046   \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{static}}\) & \textbf{3.055} & \textbf{\color{gtblborder}1.556}   \\
    \hline

    \hline\hline
    \rowcolor{wtbl}\multicolumn{3}{|c|}{\bf{Total Power [W]}}   \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{total}}\)  & \textbf{50.768} & \textbf{\color{gtblborder}33.075}  \\
    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{ERB vs. ERB approx Power consumption}
\label{tbl:erb_scale_pwr_tbl}
\end{table}

% \begin{table}[H]
%     % for more info see: https://www.overleaf.com/learn/latex/tables
%     \centering
%     \begin{tabular}{|c|r|r|r|r|r|}
%       \hline
%       $N$ & Latency ($\mu s$) & FF & LUT & DSP48 & BRAM \\
%       \hline
%         3  & 4.80  &   3889 (27.6\%)                 &    3901 (54.9\%)                  &   90 (25.0\%) & 0 (0.0\%) \\
%         4  & 6.34  &  63657 (45.1\%)                 &   64149 (90.4\%)                  &  144 (40.0\%) & 0 (0.0\%) \\
%         8  & 12.50 & 231199 (\textcolor{red}{164\%}) &  252446 (\textcolor{red}{356\%})  &  272 (75.6\%) & 0 (0.0\%) \\
%         16 & 24.82 & 895377 (\textcolor{red}{635\%}) & 1040992 (\textcolor{red}{1466\%}) &  144 (40.0\%) & 0 (0.0\%) \\
%        \hline
%     \end{tabular}
%     \caption{\bf{ IQRD Performance:} Latency, Resource Utilization, and Power for \(log_{10}\) LUT on FPGA}
%     \label{tbl:IQRD_perf}
% \end{table}

\section{Summary}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    \centering
    \arrayrulecolor{ytblborder}
\begin{tabular}{ !{\color{ytblborder}\vrule}l!{\color{ytblborder}\vrule}rrrrr| }
    \hline

    \hline
    \rowcolor{ytblcaption} \color{white}\bf{Algorithm}
    & \color{white}\bf{FF}
    & \color{white}\bf{LUT}
    & \color{white}\bf{DSP}
    & \color{white}\bf{LUTRAM}
    & \color{white}\bf{BRAM} \\
    % & \color{white}\bf{ORM}
    % & \color{white}\bf{Clean} \\
    \hline

    \hline
    \rowcolor{ytbl} Log-Based Mel   & 82(0.04\%) & 276(0.23\%) & 1(<1\%) & 10(0.02\%) & 1.5(1.04\%) \\
    \hline

    \hline
    \rowcolor{wtbl} Mel \#1 Generic     & 47(0.02\%) & 269(0.19\%) & 1(<1\%) & 0(0\%)  & 0(0\%)    \\
    \hline

    \hline
    \rowcolor{ytbl} Bark Scale w/ fix     & 43(0.02\%) & 302(0.26\%) & 1(<1\%) & 0(0\%) & 0(0\%)  \\
    \hline

    \hline
    \rowcolor{wtbl} Bark Scale w/o fix     & 27(0.01\%) & 284(0.24\%) & 1(<1\%) & 0(0\%)  & 0(0\%)    \\
    \hline

    \hline
    \rowcolor{ytbl} Approx. ERB     & 103(0.04\%) & 564(0.48\%) & 1(<1\%) & 1(0.01\%)  & 1.5(1.04\%)    \\
    \hline

    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{Mel-Approx, log-based Mel, Bark Scale}
\label{tbl:IQRD_perf}
\end{table}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    % \centering
    \hspace*{-1cm}
    \arrayrulecolor{gtblborder}
\begin{tabular}{ |l|ccccc| }
    \hline

    \hline
    \rowcolor{gtblcaption} \color{white}\bf{Parameter}
    & \color{white}\bf{Mel LUT}
    & \color{white}\bf{Mel Gen}
    & \color{white}\bf{Bark w/}
    & \color{white}\bf{Bark w/o}
    & \color{white}\bf{Approx. ERB} \\
    \hline\hline
    \rowcolor{wtbl}\multicolumn{6}{|c|}{\bf{Dynamic Power [W]}}\\
    \hline
    \rowcolor{gtbl} Signals & 4.947 & 2.916 & 2.380 & 2.192 & 5.525  \\
    \hline

    \hline
    \rowcolor{wtbl} Logic & 6.50 & 3.070 & 3.079 & 2.957 & 7.478  \\
    \hline

    \hline
    \rowcolor{gtbl} DSP & 0.014 & 0.014 & 1.445 & 0.014 & 0.049  \\
    \hline

    \hline
    \rowcolor{wtbl} I/O & 18.236 & 6.378 & 4.022 & 4.022 & 17.373  \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{dynmic}}\) & \textbf{29.697} & \textbf{12.379} & \textbf{10.923} & \textbf{9.186} & \textbf{31.519}  \\
    \hline

    % \hline
    % \rowcolor{gtbl} Bark Scale      & 56(0.02\%) & 218(\%) & 1(<1\%)   \\
    % % \cline{2-8}
    % % \multirow{-2}{*}{\cellcolor{ytbl}\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\
    \hline\hline
    \rowcolor{wtbl}\multicolumn{6}{|c|}{\bf{Static Power [W]}}   \\
    \hline

    \hline
    \rowcolor{gtbl} PL Static               & 2.364 & 0.499 & 0.469 & 0.437 & 1.510  \\
    \hline

    \hline
    \rowcolor{wtbl} PS Static               & 0.068 & 0.018 & 0.017 & 0.016 & 0.046  \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{static}}\) & \textbf{2.432} & \textbf{0.517} & \textbf{0.486} & \textbf{0.453} & \textbf{1.556}  \\
    \hline

    \hline\hline
    \rowcolor{wtbl}\multicolumn{6}{|c|}{\bf{Total Power [W]}}   \\
    \hline

    \hline
    \rowcolor{gtbl} \(\mathbf{P_{total}}\)  & \textbf{32.13} & \textbf{12.896} & \textbf{11.412} & \textbf{9.639} & \textbf{33.075}  \\
    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{Mel-Approx, log-based Mel, Bark Scale Power consumption}
\label{tbl:sum_scale_pwr_tbl}
\end{table}

% \begin{table}[H]
%     % for more info see: https://www.overleaf.com/learn/latex/tables
%     \centering
%     \arrayrulecolor{gtblborder}
% \begin{tabular}{ !{\color{gtblborder}\vrule}l!{\color{gtblborder}\vrule}rrrrrr| }
%     \hline

%     \hline
%     \rowcolor{gtblcaption} \color{white}\bf{Algorithm}
%     & \color{white}\bf{Signals}
%     & \color{white}\bf{Logic}
%     & \color{white}\bf{DSP}
%     & \color{white}\bf{IO}
%     & \color{white}\bf{BRAM}
%     & \color{white}\bf{Total} \\
%     \hline

%     \hline
%     \rowcolor{gtbl} Log Based Mel   & 82(0.04\%) & 276(\%) & 1(<1\%) & 18 & 1.5 & 0 \\
%     \hline

%     \hline
%     \rowcolor{wtbl} Approx. Mel     & 47(0.02\%) & 230(\%) & 1(<1\%) & 0  & 0   & 0 \\
%     \hline

%     \hline
%     \rowcolor{gtbl} Bark Scale      & 56(0.02\%) & 218(\%) & 1(<1\%) & 0  & 0   & 0 \\
%     % \cline{2-8}
%     % \multirow{-2}{*}{\cellcolor{ytbl}\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\
%     \hline

%     \hline
% \end{tabular}
% \arrayrulecolor{black}
% \caption{Mel-Approx, log based Mel, Bark Scale Power consumption}
% \label{tbl:scale_pwr_tbl}
% \end{table}

\begin{table}[H]
    % for more info see: https://www.overleaf.com/learn/latex/tables
    % \centering
    \hspace*{-1.8cm}
    \arrayrulecolor{mtblborder}
\begin{tabular}{ !{\color{mtblborder}\vrule}l!{\color{mtblborder}\vrule}rcccc| }
    \hline

    \hline
    \rowcolor{mtblcaption} \color{white}\bf{Algorithm}
    & \color{white}\bf{Latency \([ns]\)}
    & \color{white}\bf{Quant.}
    & \color{white}\bf{Max Err. \([\Delta Hz]\)}
    & \color{white}\bf{Mean Err.}
    & \color{white}\bf{Std Err.} \\
    \hline

    \hline
    \rowcolor{mtbl} Log-Based Mel   & 14 (3 C.C) & U16/4 & 1.146 & 0.268 & 0.106 \\
    \hline

    \hline
    \rowcolor{wtbl} Mel \#1 Generic     & 9 (2 C.C) &  U16/4  & 0.174 & -0.035 & 0.061 \\
    \hline

    \hline
    \rowcolor{mtbl} Bark Scale w/ fix      & 14 (3 C.C) &  U10/5 & N.A & N.A & N.A \\
    % \cline{2-8}
    % \multirow{-2}{*}{\cellcolor{ytbl}\#1(5)}   & 14.03/17.78 & 27.06 & 13.73 & - & - & - & 7.72 \\
    \hline

    \hline
    \rowcolor{wtbl} Bark Scale w/o fix     & 9 (2 C.C) &  U9/4  & 0.0443 & 1.5m & 0.0015 \\
    \hline

    \hline
    \rowcolor{mtbl} ERB Approx.     & 14 (3 C.C) &  U16/10  & 0.292 & 0.104 & 0.134 \\
    \hline

    \hline
\end{tabular}
\arrayrulecolor{black}
\caption{Mel-Approx, log-based Mel, Bark Scale performance comparison}
\label{tbl:scale_pwr_tbl}
\end{table}


\documentclass{article}

\usepackage[letterpaper, margin=1.3cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage{mathtools}
\usepackage{multicol}
\usepackage{pgfplots}
\usepackage[RPvoltages, american, betterproportions, siunitx]{circuitikz}
\pgfplotsset{compat=1.16}
\pgfplotsset{scaled x ticks=true}

\title{ECE 203 Problem Set 5}
\author{Michael Kwok}
\date{March 2020}
\begin{document}

\maketitle
\begin{multicols}{2}
\section*{1}
\subsection*{a}

\begin{align*}
    \omega_0 &= \frac{1}{\sqrt{L C}} = \boxed{\SI{1390.77}{\radian\per\second}}\\
    f_0 &= \frac{\omega_0}{2\pi} = \boxed{\SI{221.3}{\hertz}}\\
    Q_0 &= \omega_0 R C\\
    &= 1390.77 \cdot 1000 \cdot \num{47d-6} = \boxed{65.37}
\end{align*}

\subsection*{b}

\begin{align*}
    \omega_0 \text{ parallel} &= \omega_0 \text{ series}\\
    f_0 \text{ parallel} &= f_0 \text{ series}\\
    Q_0 \text{ series} &= \frac{1}{Q_0 \text{ parallel}}\\
\end{align*}
\begin{align*}
    \omega_0 &= \boxed{\SI{1390.77}{\radian\per\second}}\\
    f_0 &= \boxed{\SI{221.3}{\hertz}}\\
    Q_0 &= \boxed{0.0153}
\end{align*}

\subsection*{c}

The parallel configuration is better as the quality factor is higher, which by definition means that the filter is more selective.

\section*{2}
\subsection*{a}

\begin{align*}
    Q_0 &= \omega_0 R C\\
    \omega_0 &= 2\pi f_0 \\
    Q_0 &= 2\pi f_0 R C\\
\end{align*}

\begin{align*}
    R  &= \frac{V}{I}\\
       &= \frac{\num{125e-3}}{2e-6}\\
       &= \boxed{\SI{62500}{\ohm}}\\
    RC &= \frac{40}{2\pi \cdot 1000000}\\
    C  &= \frac{\num{6.366197724e-6}}{62500}\\
       &= \SI{1.018591636e-10}{\farad}\\
       &= \boxed{\SI{102}{\pico\farad}}
\end{align*}
\begin{align*}
    \omega_0 &= \frac{1}{\sqrt{LC}}\\
    \num{2\pi e-6} &= \frac{1}{\sqrt{LC}}\\
    LC &= \left(\frac{1}{\num{2\pi e-6}}\right)^2\\
    L &= \boxed{\num{2.5e-4}}
\end{align*}

\subsection*{b}
\begin{align*}
\text{Using Z at } \omega = 2000,\\
R= \boxed{\SI{8}{\kilo\ohm}}
\end{align*}
\begin{align*}
    Z&=\left( \frac{1}{R} + \frac{1}{j \omega L} + j \omega C \right) ^{-1}\\
    \frac{1}{4000} e^{-j \theta} &= \frac{1}{8000} + \frac{1}{1800 L j} + 1800 C j\\
    \frac{1}{4000} \cos \theta &= \frac{1}{8000}\\
    \cos\theta &= \frac{1}{2}\\
    \theta &= \frac{\pi}{3}
\end{align*}
\begin{align*}
    -j\frac{1}{4000} \sin\theta &= -j\left( \frac{1}{1800L} - 1800 C\right)\\
    \frac{1800L}{4000} \sin\theta &= -(1800)^2 LC + 1\\
    \omega_0 &= 2000\\
    &= \frac{1}{\sqrt{LC}}\\
    LC&= \frac{1}{\num{4e6}}\\
\end{align*}
\begin{align*}
    L\sin\theta &= 0.4222\\
    L &= \boxed{\SI{0.488}{\henry}}\\
    C &= \boxed{\SI{5.133e-7}{\farad}}
\end{align*}

\section*{3}
\subsection*{a}
\begin{align*}
    Z_{in} &= 10 + j\omega 3 + \left( \frac{1}{75} + \frac{1}{15 + \frac{675}{j\omega}} \right) ^{-1}\\
    &= \frac{90\omega + (6 \omega^2 - 1275)j}{2\omega - 15j}\\
    &= \frac{\left[ 90\omega + (6 \omega^2 - 1275)j \right] [2\omega + 15j]}{4\omega^2 + 15^2}\\
    &= \frac{90\omega^2 +19125 + \left( 12\omega^3 -1200 \omega j \right)}{4\omega^2 + 15^2}
\end{align*}
\begin{align*}
    12\omega^3-1200\omega &= 0\\
    12\omega^3 &= 1200\omega\\
    \omega^2 &= 100\\
    \omega &= \boxed{\SI{10}{\radian\per\second}}
\end{align*}

\subsection*{b}
\begin{align*}
    Z_{in} &= 10 + 30j + \left( \frac{1}{75} + \frac{1}{15 + \frac{675}{j10}} \right)^{-1}\\
    &= 10 + 30j - 30j + 35\\
    &= \boxed{\SI{45}{\ohm}}
\end{align*}

\section*{4}
Use a test voltage $V_{in}$

\begin{circuitikz}
\draw (0,0) to[V=$V_{in}$] (0,2) -- (4,2);
\draw (0,0) -- (7,0) to[cV] (7,2);
\draw (2,2) to[C, i=$I_C$](2,0);
\draw (4,0) to[R, i=$I_R$](4,2);
\draw (4,2) to[L] (7,2);
\end{circuitikz}

\begin{align*}
    I_C &= V_{in}\num{e-8}j\omega\\
    I_R &= -\frac{V_{in}}{10000}\\
\end{align*}
    Using KCL on node above resistor,
\begin{align*}
    -I_C + I_R &+\frac{V_{in} - \num{e5}I_R}{\num{4.4e-3}j\omega } = 0\\
    -V_{in}\num{e-8}j\omega-\frac{V_{in}}{10000} &+\frac{V_{in} - \num{e5}I_R}{\num{4.4e-3}j\omega} = 0\\
    Y = &\frac{V_{in}\num{e-8}j\omega +\frac{V_{in}}{10000} +\frac{V_{in} \left( 1+\frac{\num{e5}}{10000}\right)}{\num{4.4e-3}j\omega}}{V_{in}}\\
    = &\boxed{\num{e-8}j\omega +\frac{1}{10000} -\frac{2500}{\omega}j}
\end{align*}
Finding $\omega_0$ and $Q_0$.

$\omega_0$ is when coefficient of $j = 0$
\begin{align*}
    \text{Start with: }\num{e-8}j\omega&+\frac{1}{10000} -\frac{2500}{\omega}j\\
    \num{e-8}j\omega &-\frac{2500}{\omega}j = 0\\
    \omega^2 &= \num{2.5e4}\\
    \omega &= \boxed{\SI{500}{\kilo\radian}}\\
    Q_0 &= \omega_0 R C\\
    &\boxed{= 50}
\end{align*}
\section*{5}
\subsection*{a}
$H_{dB} = 20 \log(|\tilde{H}(j\omega)|)$
\begin{enumerate}
    \item $20 \log(0.2) = \boxed{-13.979}$
    \item $20 \log(13) = \boxed{22.3}$
    \item $20 \log(|\frac{100}{23j +21}|) = \log(|\frac{2300 j - 2100}{23^2+21^2}|) = 20 \log(3.21) = \boxed{10.13}$
\end{enumerate}
\subsection*{b}
$|\tilde{H}(j\omega)| = 10^{\frac{H_{dB}}{20}}$
\begin{enumerate}
    \item $|\tilde{H}(j\omega)| = \boxed{39.8}$
    \item $|\tilde{H}(j\omega)| = \boxed{0.447}$
    \item $|\tilde{H}(j\omega)| = \boxed{1.00}$
\end{enumerate}
\end{multicols}
\subsection*{c}
\begin{align*}
    \tilde{H}(j\omega) &= \frac{V_{out}}{V_{in}}\\
    Z &= 1+ \frac{1}{j\omega \num{100e-6}}\\
    \tilde{H}(j\omega) &= \frac{1}{1 + j\omega\num{100e-6}}\\
    H_{dB} &= 20 \log(|\tilde{H}(j\omega)|) = 20\log\left(\frac{1}{\num{e-8}\omega^{2} + 1}\right)\\
    \angle\tilde{H}(j\omega) &= -\arctan\left(0.0001\omega\right)
\end{align*}
\begin{figure}
    \centering
\begin{tikzpicture}
\begin{axis}[xmode=log,
xmin=1,
xmax=1000000,
ymin=-40,
ymax=10,
grid=both]
\addplot table [smooth, x={omega}, y={result}, col sep=comma, mark=none]{res1.csv};
\addplot[gray,ultra thick, opacity=0.6] coordinates {
(1,0)
(10000,0)
(99500, -40)};
\end{axis}
\end{tikzpicture}
    \caption{Magnitude bode plot}
    \label{fig:my_label}
\end{figure}
\begin{figure}
    \centering
\begin{tikzpicture}
\begin{axis}[xmode=log,
xmin=1,
xmax=1000000,
ymin=-135,
ymax=45,
ytick={45,0,-45,-90,-135},
grid=both]
\addplot table [smooth, x={omega}, y={atan}, col sep=comma, mark=none]{res1.csv};
\addplot[gray,ultra thick, opacity=0.6] coordinates {
(1,0)
(1000,0)
(100000,-90)
(1000000, -90)};
\end{axis}
\end{tikzpicture}
    \caption{Phase bode plot}
    \label{fig:label2}
\end{figure}
\end{document}


\section{Algebraic Structures}

\subsection{COFE}

\begin{defn}[Chain]
  Given some set $T$ and an indexed family $({\nequiv{n}} \subseteq T \times T)_{n \in \mathbb{N}}$ of equivalence relations, a \emph{chain} is a function $c : \mathbb{N} \to T$ such that $\All n, m. n \leq m \Ra c (m) \nequiv{n} c (n)$.
\end{defn}

\begin{defn}
  A \emph{complete ordered family of equivalences} (COFE) is a tuple $(T, ({\nequiv{n}} \subseteq T \times T)_{n \in \mathbb{N}}, \lim : \chain(T) \to T)$ satisfying
  \begin{align*}
    \All n. (\nequiv{n}) ~& \text{is an equivalence relation} \tagH{cofe-equiv} \\
    \All n, m.& n \geq m \Ra (\nequiv{n}) \subseteq (\nequiv{m}) \tagH{cofe-mono} \\
    \All x, y.& x = y \Lra (\All n. x \nequiv{n} y) \tagH{cofe-limit} \\
    \All n, c.& \lim(c) \nequiv{n} c(n+1) \tagH{cofe-compl}
  \end{align*}
\end{defn}

\ralf{Copy the explanation from the paper, when that one is more polished.}

\begin{defn}
  An element $x \in A$ of a COFE is called \emph{discrete} if
  \[ \All y \in A. x \nequiv{0} y \Ra x = y\]
  A COFE $A$ is called \emph{discrete} if all its elements are discrete.
\end{defn}

\begin{defn}
  A function $f : A \to B$ between two COFEs is \emph{non-expansive} if
  \[\All n, x \in A, y \in A. x \nequiv{n} y \Ra f(x) \nequiv{n} f(y) \]
  It is \emph{contractive} if
  \[ \All n, x \in A, y \in A. (\All m < n. x \nequiv{m} y) \Ra f(x) \nequiv{n} f(x) \]
\end{defn}

\begin{defn}
  The category $\COFEs$ consists of COFEs as objects, and non-expansive functions as arrows.
\end{defn}
Note that $\COFEs$ is cartesian closed.

\begin{defn}
  A functor $F : \COFEs \to COFEs$ is called \emph{locally non-expansive} if its actions $F_1$ on arrows is itself a non-expansive map.
  Similarly, $F$ is called \emph{locally contractive} if $F_1$ is a contractive map.
\end{defn}

\subsection{RA}

\ralf{Define this, including frame-preserving updates.}

\subsection{CMRA}

\begin{defn}
  A \emph{CMRA} is a tuple $(\monoid, (\mval_n \subseteq \monoid)_{n \in \mathbb{N}}, \mcore{-}: \monoid \to \monoid, (\mtimes) : \monoid \times \monoid \to \monoid, (\mdiv) : \monoid \times \monoid \to \monoid)$ satisfying
  \begin{align*}
    \All n, m.& n \geq m \Ra V_n \subseteq V_m \tagH{cmra-valid-mono} \\
    \All \melt, \meltB, \meltC.& (\melt \mtimes \meltB) \mtimes \meltC = \melt \mtimes (\meltB \mtimes \meltC) \tagH{cmra-assoc} \\
    \All \melt, \meltB.& \melt \mtimes \meltB = \meltB \mtimes \melt \tagH{cmra-comm} \\
    \All \melt.& \mcore\melt \mtimes \melt = \melt \tagH{cmra-core-id} \\
    \All \melt.& \mcore{\mcore\melt} = \mcore\melt \tagH{cmra-core-idem} \\
    \All \melt, \meltB.& \melt \leq \meltB \Ra \mcore\melt \leq \mcore\meltB \tagH{cmra-core-mono} \\
    \All n, \melt, \meltB.& (\melt \mtimes \meltB) \in \mval_n \Ra \melt \in \mval_n \tagH{cmra-valid-op} \\
    \All \melt, \meltB.& \melt \leq \meltB \Ra \melt \mtimes (\meltB \mdiv \melt) = \meltB \tagH{cmra-div-op} \\
    \All n, \melt, \meltB_1, \meltB_2.& \omit\rlap{$\melt \in \mval_n \land \melt \nequiv{n} \meltB_1 \mtimes \meltB_2 \Ra {}$} \\
    &\Exists \meltC_1, \meltC_2. \melt = \meltC_1 \mtimes \meltC_2 \land \meltC_1 \nequiv{n} \meltB_1 \land \meltC_2 \nequiv{n} \meltB_2 \tagH{cmra-extend} \\
    \text{where}\qquad\qquad\\
    \melt \leq \meltB \eqdef{}& \Exists \meltC. \meltB = \melt \mtimes \meltC \tagH{cmra-incl}
  \end{align*}
\end{defn}

Note that every RA is a CMRA, by picking the discrete COFE for the equivalence relation.

\ralf{Copy the rest of the explanation from the paper, when that one is more polished.}

\paragraph{The division operator $\mdiv$.}
One way to describe $\mdiv$ is to say that it extracts the witness from the extension order: If $\melt \leq \meltB$, then $\melt \mdiv \meltB$ computes the difference between the two elements (\ruleref{cmra-div-op}).
Otherwise, $\mdiv$ can have arbitrary behavior.
This means that, in classical logic, the division operator can be defined for any PCM using the axiom of choice, and it will trivially satisfy \ruleref{cmra-div-op}.
However, notice that the division operator also has to be \emph{non-expansive} --- so if the carrier $\monoid$ is equipped with a non-trivial $\nequiv{n}$, there is an additional proof obligation here.
This is crucial, for the following reason:
Considering that the extension order is defined using \emph{equality}, there is a natural notion of a \emph{step-indexed extension} order using the step-indexed equivalence of the underlying COFE:
\[ \melt \mincl{n} \meltB \eqdef \Exists \meltC. \meltB \nequiv{n} \melt \mtimes \meltC \tagH{cmra-inclM} \]
One of the properties we would expect to hold is the usual correspondence between a step-indexed predicate and its non-step-indexed counterpart:
\[ \All \melt, \meltB. \melt \leq \meltB \Lra (\All n. \melt \mincl{n} \meltB) \tagH{cmra-incl-limit} \]
The right-to-left direction here is trick.
For every $n$, we obtain a proof that $\melt \mincl{n} \meltB$.
From this, we could extract a sequence of witnesses $(\meltC_m)_{m}$, and we need to arrive at a single witness $\meltC$ showing that $\melt \leq \meltB$.
Without the division operator, there is no reason to believe that such a witness exists.
However, since we can use the division operator, and since we know that this operator is \emph{non-expansive}, we can pick $\meltC \eqdef \meltB \mdiv \melt$, and then we can prove that this is indeed the desired witness.
\ralf{Do we actually need this property anywhere?}

\paragraph{The extension axiom (\ruleref{cmra-extend}).}
Notice that the existential quantification in this axiom is \emph{constructive}, \ie it is a sigma type in Coq.
The purpose of this axiom is to compute $\melt_1$, $\melt_2$ completing the following square:

\ralf{Needs some magic to fix the baseline of the $\nequiv{n}$, or so}
\begin{center}
\begin{tikzpicture}[every edge/.style={draw=none}]
  \node (a) at (0, 0) {$\melt$};
  \node (b) at (1.7, 0) {$\meltB$};
  \node (b12) at (1.7, -1) {$\meltB_1 \mtimes \meltB_2$};
  \node (a12) at (0, -1) {$\melt_1 \mtimes \melt_2$};

  \path (a) edge node {$\nequiv{n}$} (b);
  \path (a12) edge node {$\nequiv{n}$} (b12);
  \path (a) edge node [rotate=90] {$=$} (a12);
  \path (b) edge node [rotate=90] {$=$} (b12);
\end{tikzpicture}\end{center}
where the $n$-equivalence at the bottom is meant to apply to the pairs of elements, \ie we demand $\melt_1 \nequiv{n} \meltB_1$ and $\melt_2 \nequiv{n} \meltB_2$.
In other words, extension carries the decomposition of $\meltB$ into $\meltB_1$ and $\meltB_2$ over the $n$-equivalence of $\melt$ and $\meltB$, and yields a corresponding decomposition of $\melt$ into $\melt_1$ and $\melt_2$.
This operation is needed to prove that $\later$ commutes with existential quantification and separating conjunction:
\begin{mathpar}
  \axiom{\later(\Exists\var:\type. \prop) \Lra \Exists\var:\type. \later\prop}
  \and\axiom{\later (\prop * \propB) \Lra \later\prop * \later\propB}
\end{mathpar}
(This assumes that the type $\type$ is non-empty.)

\begin{defn}
  An element $\munit$ of a CMRA $\monoid$ is called the \emph{unit} of $\monoid$ if it satisfies the following conditions:
  \begin{enumerate}[itemsep=0pt]
  \item $\munit$ is valid: \\ $\All n, \munit \in \mval_n$
  \item $\munit$ is left-identity of the operation: \\
    $\All \melt \in M. \munit \mtimes \melt = \melt$
  \item $\munit$ is discrete
  \end{enumerate}
\end{defn}

\begin{defn}
  It is possible to do a \emph{frame-preserving update} from $\melt \in \monoid$ to $\meltsB \subseteq \monoid$, written $\melt \mupd \meltsB$, if
  \[ \All n, \melt_f. \melt \mtimes \melt_f \in \mval_n \Ra \Exists \meltB \in \meltsB. \meltB \mtimes \melt_f \in \mval_n \]

  We further define $\melt \mupd \meltB \eqdef \melt \mupd \set\meltB$.
\end{defn}
Note that for RAs, this and the RA-based definition of a frame-preserving update coincide.

\ralf{Describe discrete CMRAs, and how they correspond to RAs.}

\begin{defn}
  A function $f : M \to N$ between two CMRAs is \emph{monotone} if it satisfies the following conditions:
  \begin{enumerate}[itemsep=0pt]
  \item $f$ is non-expansive
  \item $f$ preserves validity: \\
    $\All n, x \in M. x \in \mval_n \Ra f(x) \in \mval_n$
  \item $f$ preserves CMRA inclusion:\\
    $\All x, y. x \mincl y \Ra f(x) \mincl f(y)$
  \end{enumerate}
\end{defn}

\begin{defn}
  The category $\CMRAs$ consists of CMRAs as objects, and monotone functions as arrows.
\end{defn}
Note that $\CMRAs$ is a subcategory of $\COFEs$.
The notion of a locally non-expansive (or contractive) functor naturally generalizes to functors between these categories.

%%% Local Variables:
%%% mode: latex
%%% TeX-master: "iris"
%%% End:


\chapter{Data preparation}
\label{data_preparation}

\section{Word timing}

\textbf{by Bastian Boll} \\

The dataset consists of time intervals \(\lbrack t_\text{start}, t_\text{end}\rbrack\) containing a short tuple of words \((w_1,\dotsc,w_n)\). In order to match our theoretical model for this problem, we try to extract $n$ time points \(t_1,\dotsc,t_n\) such that each word in the interval is labeled with a corresponding time. The naive way is to interpolate linearly between \(t_\text{start}\) and \(t_\text{end}\). Doing this in practice reveals two problems
\begin{enumerate}
	\item The intervals \(\lbrack t_\text{start}, t_\text{end}\rbrack\) do not perfectly match the above mental model in real world subtitle data. Instead, subtitles are typically set to appear about $0.7$ seconds earlier than the respective words are said in the audio.
	\item Speaker pauses, audience laughter, applause and talking speed irregularities make the time points received from a linear interpolation very imprecise.
\end{enumerate}
The first problem is easily adressed by introducing a constant offset of $0.7$ seconds to $t_\text{start}$. The second problem is much harder. Ideally, one would train a classifier to identify the parts of the audio which contain human speech. As the dataset at hand does not include much noise other than human speech, we decided to approximate the effect of such a classifier by merely subtracting all silence from the audio. The difference in data precision gained this way is still large.\\
Extracting a single time point for each word in a continuously spoken audio track is in fact difficult to do. It is to be expected, that even labeling of a respective track by hand is subject to imprecisions. The described method of interpolating linearly after removal of silence already comes close to it with respect to precision and is much more scalable.

% TODO: maybe graphics with waveforms

\section{Reduction of label count}
\label{sec:reduction_labels}

\textbf{by Bastian Boll} \\

With regard to the optimization model described in chapter \ref{chap:algorithm} we need to reduce the number of distinct words (classes) to be considered by the machine learning model. For this purpose, we count the number of occurences for each word(-stem) in the transcripts. We observe the following:
\begin{enumerate}
	\item The dataset consists of $5.3$ million words from $75$ thousand word stems.
	\item About half of all stems only appear once.
	\item 1956 stems appear at least 200 times. They cover 90\% of the text
	\item 1488 stems appear at least 300 times. They cover 89\% of the text.
\end{enumerate}
Based on these insights, we will only consider the 1500 most frequent word stems. Statistically, about one in ten words in the transcript will therefore not be aligned by the algorithm. However, long strings of unaligned words are unlikely to occur, as the 1500 considered words are also distributed fairly evenly in the text.