summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Le <philipp-le-prviat@freenet.de>2020-05-30 01:24:13 +0200
committerPhilipp Le <philipp-le-prviat@freenet.de>2021-03-04 01:31:57 +0100
commitb03522adcd508f1c15878565e881bb8b8e37ec13 (patch)
tree8f9d19a05894226a0c26f41a0cc4a970587d221b
parent4adcc6e2ce83cca88ef7dd78582d8b5bc5617d05 (diff)
downloaddcs-lecture-notes-b03522adcd508f1c15878565e881bb8b8e37ec13.zip
dcs-lecture-notes-b03522adcd508f1c15878565e881bb8b8e37ec13.tar.gz
dcs-lecture-notes-b03522adcd508f1c15878565e881bb8b8e37ec13.tar.bz2
WIP: Exercise 4
-rw-r--r--chapter04/content_ch04.tex16
-rw-r--r--exercise04/exercise04.tex126
-rw-r--r--exercise04/helpers/ex_4_2.py63
3 files changed, 187 insertions, 18 deletions
diff --git a/chapter04/content_ch04.tex b/chapter04/content_ch04.tex
index 6cd3635..d219f91 100644
--- a/chapter04/content_ch04.tex
+++ b/chapter04/content_ch04.tex
@@ -1871,7 +1871,7 @@ Rounding is a common model for quantization. \textit{Remark:} There are other me
The most common implementations distribute the $K$ discrete values equally between an interval of the continuous values $[\underline{\hat{X}}_L, \underline{\hat{X}}_H]$. So, the discrete values are spaced by
\begin{equation}
- \Delta \underline{\hat{X}} = \frac{\underline{\hat{X}}_H - \underline{\hat{X}}_L}{K - 1} \qquad \forall \, K \geq 1
+ \Delta \underline{\hat{X}} = \frac{\underline{\hat{X}}_H - \underline{\hat{X}}_L}{K - 1} \qquad \forall \, K \geq 2, K \in \mathbb{N}
\end{equation}
The mapping between $\underline{x}[n]$ and $\underline{x}_Q[n]$ is therefore \emph{linear}.
@@ -1906,9 +1906,9 @@ The mapping between $\underline{x}[n]$ and $\underline{x}_Q[n]$ is therefore \em
ymin=0,
ymax=9,
xtick={0, 1, ..., 8},
- xticklabels={$0$, $\hat{X}_L$, $\hat{X}_L + \Delta \hat{X}$, $\hat{X}_L + 2 \Delta \hat{X}$, $\hat{X}_L + 3 \Delta \hat{X}$, $\hat{X}_L + 4 \Delta \hat{X}$, $\hat{X}_L + 5 \Delta \hat{X}$, $\hat{X}_L + 6 \Delta \hat{X}$, $\hat{X}_H$},
+ xticklabels={$0$, $\hat{X}_L = \hat{X}_L + 0 \Delta \hat{X}$, $\hat{X}_L + 1 \Delta \hat{X}$, $\hat{X}_L + 2 \Delta \hat{X}$, $\hat{X}_L + 3 \Delta \hat{X}$, $\hat{X}_L + 4 \Delta \hat{X}$, $\hat{X}_L + 5 \Delta \hat{X}$, $\hat{X}_L + 6 \Delta \hat{X}$, $\hat{X}_H = \hat{X}_L + 7 \Delta \hat{X}$},
ytick={0, 1, ..., 8},
- yticklabels={$0$, $\hat{X}_L$, $\hat{X}_L + \Delta \hat{X}$, $\hat{X}_L + 2 \Delta \hat{X}$, $\hat{X}_L + 3 \Delta \hat{X}$, $\hat{X}_L + 4 \Delta \hat{X}$, $\hat{X}_L + 5 \Delta \hat{X}$, $\hat{X}_L + 6 \Delta \hat{X}$, $\hat{X}_H$},
+ yticklabels={$0$, $\hat{X}_L = \hat{X}_L + 0 \Delta \hat{X}$, $\hat{X}_L + 1 \Delta \hat{X}$, $\hat{X}_L + 2 \Delta \hat{X}$, $\hat{X}_L + 3 \Delta \hat{X}$, $\hat{X}_L + 4 \Delta \hat{X}$, $\hat{X}_L + 5 \Delta \hat{X}$, $\hat{X}_L + 6 \Delta \hat{X}$, $\hat{X}_H = \hat{X}_L + 7 \Delta \hat{X}$},
]
\addplot[red, thick] coordinates {(0, 1) (1.5, 1)};
\addplot[red, thick, dashed] coordinates {(1.5, 1) (1.5, 2)};
@@ -1935,13 +1935,13 @@ The mapping between $\underline{x}[n]$ and $\underline{x}_Q[n]$ is therefore \em
\draw (Cmp1.-) to[short] ++(-1cm, 0);
\draw (Cmp2.-) to[short] ++(-1cm, 0);
\draw (Cmpn.-) to[short] ++(-1cm, 0);
- \draw ([shift={(-1cm,1.5cm)}] Cmp1.-) node[vcc]{$U_{ref}$} to[R,l=$R$,-*] ([shift={(-1cm,0)}] Cmp1.-)
+ \draw ([shift={(-1cm,1.5cm)}] Cmp1.-) node[vcc]{$U_{ref}$} to[R,l=$\frac{1}{2}R$,-*] ([shift={(-1cm,0)}] Cmp1.-)
to[R,l=$R$,-*] ([shift={(-1cm,0)}] Cmp2.-)
to[short] ++(0,-1.5cm)
to[open] ([shift={(-1cm,1.5cm)}] Cmpn.-)
to[short,-*] ([shift={(-1cm,0)}] Cmpn.-)
to[short] ([shift={(-1cm,-1.5cm)}] Cmpn.-)
- to[R,l=$R$] ([shift={(-1cm,-3cm)}] Cmpn.-) node[rground]{};
+ to[R,l=$\frac{1}{2}R$] ([shift={(-1cm,-3cm)}] Cmpn.-) node[rground]{};
\draw ([shift={(-4cm,0)}] Cmp1.+) node[left]{$u_{in}(t)$} to[short,o-] (Cmp1.+);
\draw ([shift={(-2cm,0)}] Cmp1.+) to[short,*-] ([shift={(-2cm,0)}] Cmp2.+) to[short,-] (Cmp2.+);
@@ -1985,9 +1985,9 @@ The discrete values of $\underline{x}_Q[n]$ are coded as computer readable symbo
$\underline{x}_Q[n]$ & Data & Data (binary) \\
\hline
\hline
- $\hat{X}_L$ & 0 & 000 \\
+ $\hat{X}_L = \hat{X}_L + 0 \Delta \hat{X}$ & 0 & 000 \\
\hline
- $\hat{X}_L + \Delta \hat{X}$ & 1 & 001 \\
+ $\hat{X}_L + 1 \Delta \hat{X}$ & 1 & 001 \\
\hline
$\hat{X}_L + 2 \Delta \hat{X}$ & 2 & 010 \\
\hline
@@ -1999,7 +1999,7 @@ The discrete values of $\underline{x}_Q[n]$ are coded as computer readable symbo
\hline
$\hat{X}_L + 6 \Delta \hat{X}$ & 6 & 110 \\
\hline
- $\hat{X}_H$ & 7 & 111 \\
+ $\hat{X}_H = \hat{X}_L + 7 \Delta \hat{X}$ & 7 & 111 \\
\hline
\end{tabular}
\end{table}
diff --git a/exercise04/exercise04.tex b/exercise04/exercise04.tex
index 27551d4..44dea36 100644
--- a/exercise04/exercise04.tex
+++ b/exercise04/exercise04.tex
@@ -15,7 +15,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}[subtitle={Sampling Periodic Signals}]
\begin{equation*}
- u(t) = \SI{2}{V} \cos\left(2\pi \SI{2}{MHz} t + \SI{60}{\degree}\right)
+ 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)$.
@@ -54,15 +54,121 @@
\end{solution}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%\begin{question}[subtitle={Sampling Non-Periodic Signals}]
-% \begin{tasks}
-% \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}]
diff --git a/exercise04/helpers/ex_4_2.py b/exercise04/helpers/ex_4_2.py
new file mode 100644
index 0000000..a57907b
--- /dev/null
+++ b/exercise04/helpers/ex_4_2.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python3
+
+# SPDX-License-Identifier: BSD-3-Clause
+#
+# Copyright 2020 Philipp Le
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+# THE POSSIBILITY OF SUCH DAMAGE.
+
+
+import numpy
+
+def latex_table(ar):
+ return " & ".join(["$"+str(it)+"$" for it in ar])
+
+x = numpy.array([0.25, 1, -0.5, 0.5, -0.5, -1, -0.5, -0.75])
+print("$x[n]$ & "+latex_table(x))
+
+w = 0.54 - 0.46 * numpy.cos(2*numpy.pi*numpy.array([0,1,2])/2)
+w = numpy.concatenate([w, numpy.zeros(1)])
+print("$w[n]$ & "+latex_table(w))
+
+x_w = x[0:4]*w
+print("$x_w[n]$ & "+latex_table(x_w))
+
+Xft = numpy.fft.fft(x_w)
+Xft_abs = numpy.abs(Xft)
+Xft_phase = numpy.angle(Xft)
+print("$\\underline{X}_w[k]$ & "+latex_table(Xft))
+print("$|\\underline{X}_w[k]|$ & "+latex_table(Xft_abs))
+print("$\\arg\\left(\\underline{X}_w[k]\\right)$ & "+latex_table(Xft_phase))
+
+phi=2*numpy.pi*numpy.array([0,1,2,3])/4
+omega=phi/1e-3
+f=omega/(2*numpy.pi)
+print("$\\phi[k]$ & "+latex_table(phi))
+print("$\\omega[k]$ & "+latex_table(omega))
+print("$f[k]$ & "+latex_table(f))
+