% SPDX-License-Identifier: CC-BY-SA-4.0
%
% Copyright (c) 2020 Philipp Le
%
% Except where otherwise noted, this work is licensed under a
% Creative Commons Attribution-ShareAlike 4.0 License.
%
% Please find the full copy of the licence at:
% https://creativecommons.org/licenses/by-sa/4.0/legalcode

\phantomsection
\addcontentsline{toc}{section}{Exercise 4}
\section*{Exercise 4}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}[subtitle={Sampling Periodic Signals}]
	\begin{equation*}
		u(t) = \SI{2}{V} \cos\left(2\pi \cdot \SI{2}{MHz} \cdot t + \SI{60}{\degree}\right)
	\end{equation*}
	The signal is sampled with a sampling period of $T_S = \SI{125}{\nano\second}$. The first sample taken is $u(t = 0)$.
	
	\begin{tasks}
		\task
		Plot the function from $t = 0$ to $t = \SI{1}{\micro\second}$!
		
		\task
		Calculate the samples $n = 0 \dots 8$!
		
		\task
		What is the DTFT of the signal?
		
		Hints:
		\begin{equation*}
			\begin{split}
				x[n] = e^{-j a n} &= \underline{X}_{\frac{2\pi}{T_S}}\left(e^{-j T_S \omega}\right) = 2 \pi \cdot \delta \left(\omega + a\right) \\
				\cos\left(b\right) &= \frac{1}{2} \left(e^{j b} + e^{-j b}\right)
			\end{split}
		\end{equation*}
		
		\task
		Can the DFT directly applied to the signal? If yes, determine the smallest $N$ and give the values of all $\underline{U}[k]$!
		
		\task
		What is the longest possible sampling period? What must be considered at this sampling period?
		
		\task
		Now, the sampling period is changed to $T_S = \SI{0.5}{\micro\second}$. There is no anti-aliasing filter. The reconstruction filter is an ideal low-pass filter with a cut-off frequency of \SI{50}{kHz}. Give the reconstructed output function in the time domain! Give an explanation in the frequency domain!
	\end{tasks}
\end{question}

\begin{solution}
	\begin{tasks}
	\end{tasks}
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}[subtitle={Sampling Non-Periodic Signals}]
	The signal $x[n]$ is given in the time domain.
	\begin{table}[H]
		\centering
		\begin{tabular}{|l|r|r|r|r|r|r|r|r|}
			\hline
			$n$ & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 \\
			\hline
			\hline
			$x[n]$ & 0.5 & 1 & 0 & 0.5 & -0.5 & -1 & -0.5 & -0.75 \\
			\hline
		\end{tabular}
	\end{table}
	
	\begin{tasks}
		\task
		The signal is windowed with $N = 4$ starting at $x[n = 0]$. A hamming window with $M = 2$ is applied. Calculate the values of $\underline{x}_W[n]$!
		
		Hamming window:
		\begin{equation*}
			w[n] = \begin{cases}0.54 - 0.46 \cos\left(\frac{2 \pi n}{M}\right), &\quad 0 \leq n \leq M,\\ 0, &\quad \text{otherwise}.\end{cases}
		\end{equation*}
		
		\task
		Calculate the discrete Fourier transform of the windowed signal!
		
		\task
		The signal has been sampled with $T_S = \SI{1}{ms}$. What frequency values do the $k$ represent?
	\end{tasks}
\end{question}

\begin{solution}
	\begin{tasks}
		\task
		At first the signal is truncated. Only the first $4$ samples are considered.
		
		The window function is:
		\begin{equation*}
			w[n] = \begin{cases}0.54 - 0.46 \cos\left(\frac{2 \pi n}{M}\right), &\quad 0 \leq n \leq M,\\ 0, &\quad \text{otherwise}.\end{cases}
		\end{equation*}
		
		The signal is then multiplied with the window:
		\begin{equation*}
			x_w[n] = x[n] \cdot w[n]
		\end{equation*}
		
		\begin{table}[H]
			\centering
			\begin{tabular}{|l|r|r|r|r|}
				\hline
				$n$ & 0 & 1 & 2 & 3 \\
				\hline
				\hline
				$w[n]$ & 0.08 & 1.0 & 0.08 & 0 \\
				\hline
				$x_w[n]$ & 0.02 & 1.0 & -0.04 & 0 \\
				\hline
			\end{tabular}
		\end{table}
		
		\task
		The signal is periodically repeated.
		
		The DFT is calculated over $N = 4$.
		\begin{equation*}
			\underline{X}_w[k] = \mathcal{F}_{\text{DFT}}\left\{\underline{x}[n]\right\} = \sum\limits_{n \in N} \underline{x}[n] \cdot e^{-j 2\pi \frac{k}{N} n}
		\end{equation*}
		
		\begin{table}[H]
			\centering
			\begin{tabular}{|l|r|r|r|r|}
				\hline
				$k$ & 0 & 1 & 2 & 3 \\
				\hline
				$k$ (alternate) & 0 & 1 & -2 & -1 \\
				\hline
				\hline
				$\underline{X}_w[k]$ & $0.98$ & $(0.06-1j)$ & $-1.02$ & $(0.06+1j)$
 \\
				\hline
				$|\underline{X}_w[k]|$ & $0.98$ & $1.00$ & $1.02$ & $1.00$
 \\
				\hline
				$\arg\left(\underline{X}_w[k]\right)$ & $0$ & $-1.51 \approx -\pi$ & $3.14 \approx 2\pi$ & $1.51 \approx \pi$ \\
				\hline
			\end{tabular}
		\end{table}
	
		\task
		\begin{equation*}
			\begin{split}
				\phi[k] &= 2 \pi \frac{k}{N} \\
				\omega[k] &= \frac{\phi[k]}{T_S} \\
				f[k] &= \frac{\omega[k]}{2 \pi} \\
			\end{split}
		\end{equation*}
		
		\begin{table}[H]
			\centering
			\begin{tabular}{|l|r|r|r|r|}
				\hline
				$k$ & 0 & 1 & 2 & 3 \\
				\hline
				$k$ (alternate) & 0 & 1 & -2 & -1 \\
				\hline
				\hline
				$\phi[k]$ & $0$ & $1.57 \approx \pi$ & $3.14 \approx 2 \pi \equiv -2\pi$ & $4.71 \approx 3 \pi \equiv -\pi$ \\
				\hline
				$\omega[k]$ & $\SI{0}{s^{-1}}$ & $\SI{1570.8}{s^{-1}}$ & $\SI{3141.6}{s^{-1}}$ & $\SI{4712.4}{s^{-1}}$
\\
				\hline
				\hline
				$f[k]$ & $\SI{0}{Hz}$ & $\SI{250}{Hz}$ & $\SI{500}{Hz} \equiv \SI{-500}{Hz}$ & $\SI{750}{Hz} \equiv \SI{-250}{Hz}$ \\
				\hline
			\end{tabular}
		\end{table}
	\end{tasks}
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}[subtitle={Quantization}]
	The signal of task 1b) is now quantized. The quantizer has $8$ discrete values. These values are equally distributed between \SI{-2}{V} and \SI{2}{V}. Prior to sampling, the original time-continuous signal passed through an ideal low-pass filter with a cut-off frequency of \SI{4}{MHz}.
	
	\begin{tasks}
		\task
		Define a mapping from the value-continuous samples to the value-discrete samples!
		
		\task
		The value-discrete samples are now pulse-code modulated. How many bits are required?
		
		\task
		Determine the quantization error for each value-discrete sample! How much is the signal-to-noise ratio?
		
		\task
		3 bits are a very poor resolution. How many bits are appropriate for the quantizer to obtain the best signal-to-noise ratio? Effects of the window filter are neglected. Assume that the signal has passed through a processing chain with a total gain of \SI{25}{dB} and noise figure of \SI{12}{dB} prior to quantization. The input of the quantizer has an impedance of \SI{50}{\ohm}. % 14 bits
	\end{tasks}
\end{question}

\begin{solution}
	\begin{tasks}
	\end{tasks}
\end{solution}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\begin{question}[subtitle={Decibel}]
%	\begin{tasks}
%	\end{tasks}
%\end{question}
%
%\begin{solution}
%	\begin{tasks}
%	\end{tasks}
%\end{solution}
