summaryrefslogtreecommitdiff
path: root/exercise04
diff options
context:
space:
mode:
Diffstat (limited to 'exercise04')
-rw-r--r--exercise04/exercise04.tex126
-rw-r--r--exercise04/helpers/ex_4_2.py63
2 files changed, 179 insertions, 10 deletions
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))
+