% 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 7}
\section*{Exercise 7}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}[subtitle={DS-CDMA}]
	Two spreading codes are given.
	\begin{itemize}
		\item $\vect{C}_{4,1} = \left[1,1,-1,-1\right]$
		\item $\vect{C}_{4,2} = \left[1,-1,-1,1\right]$
	\end{itemize}

	The data stream is $\vect{D} = \left[1,-1\right]$
	
	\begin{tasks}
		\task
		How much is the inner product of $\vect{C}_{4,1}$ and $\vect{C}_{4,2}$? What does the result mean?
		\task
		The data $\vect{D}$ is spread by $\vect{C}_{4,1}$. Calculate the transmitted chip sequence $\vect{S}$!
		\task
		Calculate the cross-correlation of $\vect{S}$ and $\vect{C}_{4,1}$!
		\task
		Calculate the cross-correlation of $\vect{S}$ and $\vect{C}_{4,2}$!
		\task
		Calculate the autocorrelation of $\vect{C}_{4,2}$!
	\end{tasks}
\end{question}

\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}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}[subtitle={2G cell phone -- GSM}]
	A GSM uses a FDMA/TDMA hybrid multiple access method. The TDMA part uses time-slots of \SI{546.5}{\micro{}s} length. Each time-slot is followed by a \SI{30.5}{\micro{}s} long guard interval. Eight time-slots are grouped into one frame. A user is assigned one of the time-slots in each frame for exclusive use.
	
	\SI{148}{bit} can be transported in one time-slot (excluding the guard interval). \SI{114}{bit} are usable for data.
		
	\begin{tasks}
		\task
		What purpose does the guard interval serve?
		\task
		How much is the frame length?
		\task
		How much is the raw symbol rate?
		\task
		How much is the data rate? One bit is encoded in one symbol.
	\end{tasks}
\end{question}

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}[subtitle={OFDM}]
	An OFDM system has a sub-carrier spacing of \SI{15}{kHz}, a signal bandwidth of \SI{20}{MHz} and a guard band of \SI{2}{MHz}.
	
	\begin{tasks}
		\task
		How much is the symbol duration?
		\task
		How many sub-bands are available?
		\task
		Is the symbol duration affected if the modulation is changed from QPSK to 16-QAM?
		\task
		Give the data rate if a 16-QAM modulation is used. \SI{20}{\percent} of the sub-bands are pilots (for synchronization) and cannot be used for data transmission.
	\end{tasks}
\end{question}

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{question}[subtitle={3G cell phone -- UMTS}]
	A UMTS system uses DS-CDMA with a constant chip rate of \SI{3.84}{MHz} for all users. The data is transmitted in frames with a length of 2560 chips. One frame occupies one time-slot. Each user is assigned a spreading code and a time-slot for transmitting his/her frame.
	
	\begin{tasks}
		\task
		The transmission of frames in time-slots makes the multiple access method of UMTS a hybrid of CDMA and which other technology? Explain this technology!
		\task
		How much is the time-slot length (duration) if guard intervals are neglected?
		\task
		A spreading factor of 8 is chosen. The modulation is QPSK. How much is the symbol rate? How much is the data rate?
		\task
		A voice data stream with \SI{15}{kbit/s} is transmitted using BPSK. How much is the processing gain?
	\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}
