summaryrefslogtreecommitdiff
path: root/exercise07
diff options
context:
space:
mode:
Diffstat (limited to 'exercise07')
-rw-r--r--exercise07/exercise07.tex161
-rw-r--r--exercise07/helpers/ex_7_1.py69
2 files changed, 230 insertions, 0 deletions
diff --git a/exercise07/exercise07.tex b/exercise07/exercise07.tex
index a054be1..763425d 100644
--- a/exercise07/exercise07.tex
+++ b/exercise07/exercise07.tex
@@ -39,6 +39,167 @@
\begin{solution}
\begin{tasks}
+ \task
+ The length of both codes is $N = 4$.
+ \begin{equation*}
+ \begin{split}
+ \left\langle \vect{C}_{4,1}, \vect{C}_{4,2} \right\rangle &= \sum\limits_{i = 0}^{N - 1} C_{4,1}[i] C_{4,2}[i] \\
+ &= 1 \cdot 1 + 1 \cdot (-1) + (-1) \cdot (-1) + (-1) \cdot 1 \\
+ &= 0
+ \end{split}
+ \end{equation*}
+ The inner product of the codes is zero. This means that the codes are orthogonal and are suitable for CDMA.
+
+ \task
+ %TODO Symbol spreading block diagram
+ $\vect{S} = \left[1,1,-1,-1,-1,-1,1,1\right]$
+
+ \task
+ {
+ \tiny
+ $\vect{S}$ is extended by zero. That means, $S[n] = 0 \quad \forall n < 0$ and $S[n] = 0 \quad \forall n \geq 8$.
+ \begin{equation*}
+ S[n] = \left[\ldots,0,0,0,0,\underline{1},1,-1,-1,-1,-1,1,1,0,0,0,0,\ldots\right]
+ \end{equation*}
+ \begin{remark}
+ The underline marks the sample at $n = 0$.
+ \end{remark}
+
+ Same zero-extension is applied to the codes.
+ \begin{equation*}
+ C_{4,1}[n] = \left[\ldots,0,0,0,0,\underline{1},1,-1,-1,0,0,0,0,\ldots\right]
+ \end{equation*}
+
+ Now, the cross-correlation can be applied.
+ \begin{equation*}
+ \mathrm{R}_{XY}[n] = \sum\limits_{i = -\infty}^{+\infty} X[n] \cdot Y[n+i]
+ \end{equation*}
+
+ The cross-correlation effectively slides the code over the chips.
+ %TODO Figure
+
+ \begin{equation*}
+ \begin{split}
+ \mathrm{R}_{SC_{4,1}}[-3] &= S[-3] \cdot C_{4,1}[0] + S[-2] \cdot C_{4,1}[1] + S[-1] \cdot C_{4,1}[2] + S[0] \cdot C_{4,1}[3] \\
+ &= (0) \cdot (1) + (0) \cdot (1) + (0) \cdot (-1) + (1) \cdot (-1) \\
+ &= -1 \\
+ \mathrm{R}_{SC_{4,1}}[-2] &= S[-2] \cdot C_{4,1}[0] + S[-1] \cdot C_{4,1}[1] + S[0] \cdot C_{4,1}[2] + S[1] \cdot C_{4,1}[3] \\
+ &= (0) \cdot (1) + (0) \cdot (1) + (1) \cdot (-1) + (1) \cdot (-1) \\
+ &= -2 \\
+ \mathrm{R}_{SC_{4,1}}[-1] &= S[-1] \cdot C_{4,1}[0] + S[0] \cdot C_{4,1}[1] + S[1] \cdot C_{4,1}[2] + S[2] \cdot C_{4,1}[3] \\
+ &= (0) \cdot (1) + (1) \cdot (1) + (1) \cdot (-1) + (-1) \cdot (-1) \\
+ &= 1 \\
+ \mathrm{R}_{SC_{4,1}}[0] &= S[0] \cdot C_{4,1}[0] + S[1] \cdot C_{4,1}[1] + S[2] \cdot C_{4,1}[2] + S[3] \cdot C_{4,1}[3] \\
+ &= (1) \cdot (1) + (1) \cdot (1) + (-1) \cdot (-1) + (-1) \cdot (-1) \\
+ &= 4 \\
+ \mathrm{R}_{SC_{4,1}}[1] &= S[1] \cdot C_{4,1}[0] + S[2] \cdot C_{4,1}[1] + S[3] \cdot C_{4,1}[2] + S[4] \cdot C_{4,1}[3] \\
+ &= (1) \cdot (1) + (-1) \cdot (1) + (-1) \cdot (-1) + (-1) \cdot (-1) \\
+ &= 2 \\
+ \mathrm{R}_{SC_{4,1}}[2] &= S[2] \cdot C_{4,1}[0] + S[3] \cdot C_{4,1}[1] + S[4] \cdot C_{4,1}[2] + S[5] \cdot C_{4,1}[3] \\
+ &= (-1) \cdot (1) + (-1) \cdot (1) + (-1) \cdot (-1) + (-1) \cdot (-1) \\
+ &= 0 \\
+ \mathrm{R}_{SC_{4,1}}[3] &= S[3] \cdot C_{4,1}[0] + S[4] \cdot C_{4,1}[1] + S[5] \cdot C_{4,1}[2] + S[6] \cdot C_{4,1}[3] \\
+ &= (-1) \cdot (1) + (-1) \cdot (1) + (-1) \cdot (-1) + (1) \cdot (-1) \\
+ &= -2 \\
+ \mathrm{R}_{SC_{4,1}}[4] &= S[4] \cdot C_{4,1}[0] + S[5] \cdot C_{4,1}[1] + S[6] \cdot C_{4,1}[2] + S[7] \cdot C_{4,1}[3] \\
+ &= (-1) \cdot (1) + (-1) \cdot (1) + (1) \cdot (-1) + (1) \cdot (-1) \\
+ &= -4 \\
+ \mathrm{R}_{SC_{4,1}}[5] &= S[5] \cdot C_{4,1}[0] + S[6] \cdot C_{4,1}[1] + S[7] \cdot C_{4,1}[2] + S[8] \cdot C_{4,1}[3] \\
+ &= (-1) \cdot (1) + (1) \cdot (1) + (1) \cdot (-1) + (0) \cdot (-1) \\
+ &= -1 \\
+ \mathrm{R}_{SC_{4,1}}[6] &= S[6] \cdot C_{4,1}[0] + S[7] \cdot C_{4,1}[1] + S[8] \cdot C_{4,1}[2] + S[9] \cdot C_{4,1}[3] \\
+ &= (1) \cdot (1) + (1) \cdot (1) + (0) \cdot (-1) + (0) \cdot (-1) \\
+ &= 2 \\
+ \mathrm{R}_{SC_{4,1}}[7] &= S[7] \cdot C_{4,1}[0] + S[8] \cdot C_{4,1}[1] + S[9] \cdot C_{4,1}[2] + S[10] \cdot C_{4,1}[3] \\
+ &= (1) \cdot (1) + (0) \cdot (1) + (0) \cdot (-1) + (0) \cdot (-1) \\
+ &= 1 \\
+ \end{split}
+ \end{equation*}
+
+ The cross-correlation peak is at $n = 0$, indicating that $\vect{S}$ is correlated to $\vect{C}_{4,1}$ and is spread by $\vect{C}_{4,1}$.
+ }
+
+ \task
+ {
+ \tiny
+ Zero-extension of $\vect{C}_{4,2}$.
+ \begin{equation*}
+ C_{4,2}[n] = \left[\ldots,0,0,0,0,\underline{1},-1,-1,1,0,0,0,0,\ldots\right]
+ \end{equation*}
+
+ Cross-correlation:
+ \begin{equation*}
+ \begin{split}
+ \mathrm{R}_{SC_{4,2}}[-3] &= S[-3] \cdot C_{4,2}[0] + S[-2] \cdot C_{4,2}[1] + S[-1] \cdot C_{4,2}[2] + S[0] \cdot C_{4,2}[3] \\
+ &= (0) \cdot (1) + (0) \cdot (-1) + (0) \cdot (-1) + (1) \cdot (1) \\
+ &= 1 \\
+ \mathrm{R}_{SC_{4,2}}[-2] &= S[-2] \cdot C_{4,2}[0] + S[-1] \cdot C_{4,2}[1] + S[0] \cdot C_{4,2}[2] + S[1] \cdot C_{4,2}[3] \\
+ &= (0) \cdot (1) + (0) \cdot (-1) + (1) \cdot (-1) + (1) \cdot (1) \\
+ &= 0 \\
+ \mathrm{R}_{SC_{4,2}}[-1] &= S[-1] \cdot C_{4,2}[0] + S[0] \cdot C_{4,2}[1] + S[1] \cdot C_{4,2}[2] + S[2] \cdot C_{4,2}[3] \\
+ &= (0) \cdot (1) + (1) \cdot (-1) + (1) \cdot (-1) + (-1) \cdot (1) \\
+ &= -3 \\
+ \mathrm{R}_{SC_{4,2}}[0] &= S[0] \cdot C_{4,2}[0] + S[1] \cdot C_{4,2}[1] + S[2] \cdot C_{4,2}[2] + S[3] \cdot C_{4,2}[3] \\
+ &= (1) \cdot (1) + (1) \cdot (-1) + (-1) \cdot (-1) + (-1) \cdot (1) \\
+ &= 0 \\
+ \mathrm{R}_{SC_{4,2}}[1] &= S[1] \cdot C_{4,2}[0] + S[2] \cdot C_{4,2}[1] + S[3] \cdot C_{4,2}[2] + S[4] \cdot C_{4,2}[3] \\
+ &= (1) \cdot (1) + (-1) \cdot (-1) + (-1) \cdot (-1) + (-1) \cdot (1) \\
+ &= 2 \\
+ \mathrm{R}_{SC_{4,2}}[2] &= S[2] \cdot C_{4,2}[0] + S[3] \cdot C_{4,2}[1] + S[4] \cdot C_{4,2}[2] + S[5] \cdot C_{4,2}[3] \\
+ &= (-1) \cdot (1) + (-1) \cdot (-1) + (-1) \cdot (-1) + (-1) \cdot (1) \\
+ &= 0 \\
+ \mathrm{R}_{SC_{4,2}}[3] &= S[3] \cdot C_{4,2}[0] + S[4] \cdot C_{4,2}[1] + S[5] \cdot C_{4,2}[2] + S[6] \cdot C_{4,2}[3] \\
+ &= (-1) \cdot (1) + (-1) \cdot (-1) + (-1) \cdot (-1) + (1) \cdot (1) \\
+ &= 2 \\
+ \mathrm{R}_{SC_{4,2}}[4] &= S[4] \cdot C_{4,2}[0] + S[5] \cdot C_{4,2}[1] + S[6] \cdot C_{4,2}[2] + S[7] \cdot C_{4,2}[3] \\
+ &= (-1) \cdot (1) + (-1) \cdot (-1) + (1) \cdot (-1) + (1) \cdot (1) \\
+ &= 0 \\
+ \mathrm{R}_{SC_{4,2}}[5] &= S[5] \cdot C_{4,2}[0] + S[6] \cdot C_{4,2}[1] + S[7] \cdot C_{4,2}[2] + S[8] \cdot C_{4,2}[3] \\
+ &= (-1) \cdot (1) + (1) \cdot (-1) + (1) \cdot (-1) + (0) \cdot (1) \\
+ &= -3 \\
+ \mathrm{R}_{SC_{4,2}}[6] &= S[6] \cdot C_{4,2}[0] + S[7] \cdot C_{4,2}[1] + S[8] \cdot C_{4,2}[2] + S[9] \cdot C_{4,2}[3] \\
+ &= (1) \cdot (1) + (1) \cdot (-1) + (0) \cdot (-1) + (0) \cdot (1) \\
+ &= 0 \\
+ \mathrm{R}_{SC_{4,2}}[7] &= S[7] \cdot C_{4,2}[0] + S[8] \cdot C_{4,2}[1] + S[9] \cdot C_{4,2}[2] + S[10] \cdot C_{4,2}[3] \\
+ &= (1) \cdot (1) + (0) \cdot (-1) + (0) \cdot (-1) + (0) \cdot (1) \\
+ &= 1 \\
+ \end{split}
+ \end{equation*}
+
+ The cross-correlation has no clear peaks, indicating that $\vect{S}$ and $\vect{C}_{4,2}$ are uncorrelated.
+ }
+
+ \task
+ {
+ \tiny
+ Autocorrelation is the cross-correlation of the (zero-extended) code $\vect{C}_{4,2}$ with itself.
+
+ \begin{equation*}
+ \begin{split}
+ \mathrm{R}_{C_{4,2}C_{4,2}}[-3] &= C_{4,2}[-3] \cdot C_{4,2}[0] + C_{4,2}[-2] \cdot C_{4,2}[1] + C_{4,2}[-1] \cdot C_{4,2}[2] + C_{4,2}[0] \cdot C_{4,2}[3] \\
+ &= (0) \cdot (1) + (0) \cdot (-1) + (0) \cdot (-1) + (1) \cdot (1) \\
+ &= 1 \\
+ \mathrm{R}_{C_{4,2}C_{4,2}}[-2] &= C_{4,2}[-2] \cdot C_{4,2}[0] + C_{4,2}[-1] \cdot C_{4,2}[1] + C_{4,2}[0] \cdot C_{4,2}[2] + C_{4,2}[1] \cdot C_{4,2}[3] \\
+ &= (0) \cdot (1) + (0) \cdot (-1) + (1) \cdot (-1) + (-1) \cdot (1) \\
+ &= -2 \\
+ \mathrm{R}_{C_{4,2}C_{4,2}}[-1] &= C_{4,2}[-1] \cdot C_{4,2}[0] + C_{4,2}[0] \cdot C_{4,2}[1] + C_{4,2}[1] \cdot C_{4,2}[2] + C_{4,2}[2] \cdot C_{4,2}[3] \\
+ &= (0) \cdot (1) + (1) \cdot (-1) + (-1) \cdot (-1) + (-1) \cdot (1) \\
+ &= -1 \\
+ \mathrm{R}_{C_{4,2}C_{4,2}}[0] &= C_{4,2}[0] \cdot C_{4,2}[0] + C_{4,2}[1] \cdot C_{4,2}[1] + C_{4,2}[2] \cdot C_{4,2}[2] + C_{4,2}[3] \cdot C_{4,2}[3] \\
+ &= (1) \cdot (1) + (-1) \cdot (-1) + (-1) \cdot (-1) + (1) \cdot (1) \\
+ &= 4 \\
+ \mathrm{R}_{C_{4,2}C_{4,2}}[1] &= C_{4,2}[1] \cdot C_{4,2}[0] + C_{4,2}[2] \cdot C_{4,2}[1] + C_{4,2}[3] \cdot C_{4,2}[2] + C_{4,2}[4] \cdot C_{4,2}[3] \\
+ &= (-1) \cdot (1) + (-1) \cdot (-1) + (1) \cdot (-1) + (0) \cdot (1) \\
+ &= -1 \\
+ \mathrm{R}_{C_{4,2}C_{4,2}}[2] &= C_{4,2}[2] \cdot C_{4,2}[0] + C_{4,2}[3] \cdot C_{4,2}[1] + C_{4,2}[4] \cdot C_{4,2}[2] + C_{4,2}[5] \cdot C_{4,2}[3] \\
+ &= (-1) \cdot (1) + (1) \cdot (-1) + (0) \cdot (-1) + (0) \cdot (1) \\
+ &= -2 \\
+ \mathrm{R}_{C_{4,2}C_{4,2}}[3] &= C_{4,2}[3] \cdot C_{4,2}[0] + C_{4,2}[4] \cdot C_{4,2}[1] + C_{4,2}[5] \cdot C_{4,2}[2] + C_{4,2}[6] \cdot C_{4,2}[3] \\
+ &= (1) \cdot (1) + (0) \cdot (-1) + (0) \cdot (-1) + (0) \cdot (1) \\
+ &= 1 \\
+ \end{split}
+ \end{equation*}
+ }
\end{tasks}
\end{solution}
diff --git a/exercise07/helpers/ex_7_1.py b/exercise07/helpers/ex_7_1.py
new file mode 100644
index 0000000..81a62d6
--- /dev/null
+++ b/exercise07/helpers/ex_7_1.py
@@ -0,0 +1,69 @@
+#!/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
+import scipy.signal
+
+C1 = numpy.array([1,1,-1,-1])
+C2 = numpy.array([1,-1,-1,1])
+D = numpy.array([1,-1])
+
+S = numpy.array([0,0,0,0,1,1,-1,-1,-1,-1,1,1,0,0,0,0])
+
+def cross(d, dn, c, name):
+ print("\\begin{equation*}")
+ print("\\begin{split}")
+ for n in range(len(d)-len(c)+1):
+ res = 0
+ syms = []
+ vals = []
+ for k in range(4):
+ syms.append("%s[%d] \\cdot %s[%d]" % (dn, (n+k-4), name, (k)))
+ vals.append("(%d) \\cdot (%d)" % (d[n+k], c[k]))
+ res += d[n+k] * c[k]
+ print("\\mathrm{R}_{%s%s}[%d] &= %s \\\\" % (dn, name, (n-4), " + ".join(syms)))
+ print(" &= %s \\\\" % (" + ".join(vals)))
+ print(" &= %d \\\\" % res)
+ #print(" &= %s = \\underline{\\underline{%d}} \\\\" % (" + ".join(vals), res))
+ print("\\end{split}")
+ print("\\end{equation*}")
+
+print("c) ================================")
+cross(S, "S", C1, "C_{4,1}")
+
+print("d) ================================")
+cross(S, "S", C2, "C_{4,2}")
+
+print("e) ================================")
+C2ext = numpy.array([0,0,0,0,1,-1,-1,1,0,0,0,0])
+cross(C2ext, "C_{4,2}", C2, "C_{4,2}")