\documentclass{article}

\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{float}
\usepackage[margin=1in]{geometry}


\title{Analyzing and Operating on Discrete Time Signals in MATLAB\textsuperscript{\tiny\textregistered}}

\author{Aidan Sharpe \& Elise Heim}

\DeclareMathOperator{\sinc}{sinc}

\begin{document}
\begin{titlepage}
\maketitle
\end{titlepage}

\begin{abstract}
	This lab includes a variety of exercises to enhance knowledge and understanding of digital signal responses. The first couple of exercises involved mathematically deducing the responses of signals. Then MATLAB\textsuperscript{\tiny\textregistered} was utilized to visually confirm calculated behavior. 
\end{abstract}

\section{Introduction}
MATLAB\textsuperscript{\tiny\textregistered} is a very helpful tool for visualizing different signals and better understanding their behavior. The first two tasks include modulating amplitude, and determining periodicity mathematically. Then MATLAB\textsuperscript{\tiny\textregistered} was used to plot different signals in order to verify their periodicity, and if applicable, their period. MATLAB\textsuperscript{\tiny\textregistered} was also used to plot discrete time signals in order to better understand their behavior. In addition, the boundedness of a signal was checked using MATLAB\textsuperscript{\tiny\textregistered} to plot the signal. The energy of an aperiodic signal was also observed using MATLAB\textsuperscript{\tiny\textregistered}, and plotted as a function of time. Finally, this lab utilized MATLAB\textsuperscript{\tiny\textregistered} to explore the functionality of the modulo operator.

\section{Results \& Discussion}
\subsection{Analysis of Amplitude Modulation}
A message, $m(t)$, with a bandwidth, $B=2[\text{kHz}]$ modulates a cosine carrier with a frequency of 10[kHz]. The combined signal is $s(t) = m(t)\cos(20000\pi t)$. Using a Fourier transform on $s(t)$ reveals a maximum frequency at 12[kHz]. In fact, as seen in figure \ref{fig:AM_Fourier_Whitenoise}, by filling the band that $m(t)$ occupies with white noise, the Fourier transform of $s(t)$ contains white noise centered on the carrier frequency with twice the bandwidth of the original signal. The spike that occurs at 10[kHz] is the result of the original signal having a DC term and the carrier frequency having a value of 10[kHz].

\begin{figure}[h]
	\center
	\includegraphics[width=0.5\textwidth]{lab2_1a.png}
	\caption{The Fourier transform of a white noise signal carried at 10[kHz]}
	\label{fig:AM_Fourier_Whitenoise}
\end{figure}

When instead, $m(t)$ had a triangular spectrum of amplitude 1, the spectrum of $s(t)$ was two triangles touching at the base at 10[kHz] as seen in figure \ref{fig:carried_triangle}.

\begin{figure}[h]
	\center
	\includegraphics[width=0.5\textwidth]{lab2_1b.png}
	\caption{The Fourier transform of a signal with a triangular spectrum carried at 10[kHz]}
	\label{fig:carried_triangle}
\end{figure}

\subsection{Periodicity and Sampling Frequency}
Consider the signal $x(t) = \cos(2\pi t/7)$. Given the standard forms, $\cos(2\pi f t)$ and $\cos(\omega t)$, where f is linear frequency and $\omega$ is angular frequency, $f = {1\over7}$ and $\omega = {2\pi \over 7}$. Given sampling frequencies of 1[Hz], 2.5[Hz], 3[Hz], and $\pi$[Hz], the sampling theorem is satisfied. To determine if the sampled signal is periodic, the fundamental time period must be determined by
\begin{equation}
	N = {2\pi \over \omega}
\end{equation}
where $N$ is the fundamental time period and $\omega$ is the angular frequency of the signal. Given $\omega = {2\pi \over 7}$, the fundamental time period is 7[s]. With sampling frequencies of 1[Hz], 2.5[Hz], and 3[Hz], the discrete signal is periodic. However, with a sampling frequency of $\pi$[Hz], the discrete signal is aperiodic. Determining whether a sampled periodic signal is periodic can be done by satisfying the condition:
\begin{equation}
	aN = bT_s
	\label{eqn:periodicity_condition}
\end{equation}
where $a$ and $b$ are integers, $N$ is the fundamental time period, and $T_s$ is the sampling period. The period of the discrete signal if the condition is satisfied is the product of $a$ and $b$. Therefore, for $f_s=1$[Hz], there will be 7 samples per period, for $f_s =2.5$[Hz], there will be 35 samples per period, and for $f_s = 3$[Hz], there will be 21 samples per period. Seen in figure \ref{fig:periodic_sample}, the periodicity and samples per period for $f_s = 1$, 2.5, and 3[Hz] can be determined simply by counting the samples. For $f_s=\pi$[Hz], the aperiodic nature only becomes apparent after observing many samples.
\begin{figure}[h]
	\includegraphics[width=\textwidth]{lab_2_2.png}
	\caption{Sampling a periodic signal at different frequencies}
	\label{fig:periodic_sample}
\end{figure}

\subsection{Plotting Discrete Time Signals}
MATLAB\textsuperscript{\tiny\textregistered} can be very helpful for plotting complicated signals over specific intervals. Using the impulse, unit step, and the \verb|stem| command, one can plot a variety of signals. One such signal is $ \delta(n-5) - 2\delta(n-8) +6\delta(n-11)$ over the interval $0<n<12$, as shown in \ref{fig:various_impulses}. This function comprises three impulse functions that have been shifted and scaled. 
\begin{figure}[H]
	\center
	\includegraphics[width=0.5\textwidth]{lab_2_3a.png}
	\caption{Shifted and scaled impulses}
	\label{fig:various_impulses}
\end{figure}
\noindent
The signal $u(n-3) - 2u(n-8) + u(n-12)$ across $0<n<15$ is seen in figure \ref{fig:various_steps}. This signal consists of three unit steps that have been shifted and scaled.
\begin{figure}[H]
	\center
	\includegraphics[width=0.5\textwidth]{lab_2_3b.png}
	\caption{Shifted and scaled unit steps}
	\label{fig:various_steps}
\end{figure}
\noindent
Plotting the signal $n u(n)$ over the interval $0<n<20$ reveals the discrete ramp function seen in figure \ref{fig:discrete_ramp}. 
\begin{figure}[H]
	\center
	\includegraphics[width=0.5\textwidth]{lab_2_3c.png}
	\caption{A discrete ramp function}
	\label{fig:discrete_ramp}
\end{figure}
\noindent
Plotting the signal $n^2 u(n)$ on the interval, $0<n<10$ reveals a quadratic regulated by the unit step seen in figure \ref{fig:discrete_quadratic}.
\begin{figure}[H]
	\center
	\includegraphics[width=0.5\textwidth]{lab_2_3d.png}
	\caption{Discrete quadratic signal}
	\label{fig:discrete_quadratic}
\end{figure}
\noindent
MATLAB\textsuperscript{\tiny\textregistered} is not limited to these simple signals. The signal $3(n-3)^2 e^{-0.3n} \sin\left(\frac{2n}{3}\right) u(n)$ was plotted from $0<n<30$ as seen in figure \ref{fig:osc_exp_decay}. This signal resembles an under-damped second order response due to the combination of exponential decay and sinusoidal terms.
\begin{figure}[H]
	\center
	\includegraphics[width=0.5\textwidth]{lab_2_3e.png}
	\caption{Oscillating exponential decay}
	\label{fig:osc_exp_decay}
\end{figure}
\noindent
\subsection{Bounded Signals}
A bounded signal has an amplitude that does not exceed a certain value. Using MATLAB\textsuperscript{\tiny\textregistered}, the signal $x(n) = 5\cos(a^2 n)  u(n)$ where $a=\frac{\pi}{4}$ is verified to be bounded as clearly seen in figure \ref{fig:cosine_boundedness}. It is bounded since the amplitude of the signal never has an absolute value greater than 5.
\begin{figure}[H]
	\center
	\includegraphics[width=0.5\textwidth]{lab_2_4a.png}
	\caption{Boundedness of a cosine}
	\label{fig:cosine_boundedness}
\end{figure}
\noindent
The boundedness of $x(n) = A |b|^n  u(n)$ where $A=5$ and $b=\frac{1+j}{2}$ is seen in figure \ref{fig:complex_boundedness}. Since the signal is defined only for non-negative integer values of $n$, and $|b| < 1$, it is bounded by $A|b|^0$, which is 5 in this case.
\begin{figure}[H]
	\center
	\includegraphics[width=0.5\textwidth]{lab_2_4b.png}
	\caption{More complex boundedness}
	\label{fig:complex_boundedness}
\end{figure}

\subsection{Energy of an Aperiodic Signal}
Given a signal $x(n)$ its energy can be calculated by evaluating the discrete sum:
\begin{equation}
	E_x = \sum_n |x[n]|^2.
\end{equation}
Given a periodic signal, the energy will always be infinite, however, some aperiodic signals have finite energy. For example, the signal, $x[n] = {1\over n}u[n-1]$ will have a total energy of $\pi^2 \over 6$. This is easily seen in figure \ref{fig:aperiodic_energy}, where the energy, in red, approaches $\pi^2 \over 6$ in only the first 100 samples.
\begin{figure}[H]
	\center
	\includegraphics[width=0.5\textwidth]{lab_2_5.png}
	\caption{First 100 samples of $x[n]$ and its energy}
	\label{fig:aperiodic_energy}
\end{figure}

\subsection{The Modulo Operation}
The modulo operation is the central operation in modular arithmetic. Essentially, the operation bundles the set of integers into a subset from zero up to, but not including the modulus by wrapping back to zero. This is similar to how a clock starts and ends at 12 o'clock, yet time remains continuous. The modulo operation is a helpful tool for manipulating the order of the terms of a discrete signal. For example, given the signal, $x[n] = \begin{bmatrix} 1 & -5 & 4 & -8 & 6 & -3 & -1\end{bmatrix}$ on the interval $0 \le n \le 6$, the order of the terms can easily be manipulated using 7 as the modulus. By using 7 as the modulus, it is ensured that $n$ remains on the defined interval between 0 and 6. The signal $x[n]$ was manipulated using $x[\langle n+3 \rangle_7]$, $x[\langle n-4 \rangle_7]$, and $x[\langle -n+2 \rangle_7]$, where the angle brackets indicate the modulo operation with a modulus of the subscript. The result of the modulo operation on the sampling times of $x[n]$ are seen in figure \ref{fig:modulo}.
\begin{figure}[H]
	\center
	\includegraphics[width=\textwidth]{lab_2_6.png}
	\caption{Applying the modulo operation to $x[n]$.}
	\label{fig:modulo}
\end{figure}

\section{Conclusions}
In performing various operations in isolation and in conjunction with other operations on discrete and continuous signals, the manipulation of such signals becomes more intuitive. For example, by visualizing the Fourier transform of amplitude modulated signal, it becomes clear that the bandwidth is centered around the carrier frequency and doubled. Again, by visualizing the sampling of a continuous time signal with various sampling frequencies, it the condition to produce a periodic discrete time signal becomes quite clear. The same level of intuition can be reached for boundedness, energy, and the effects of the modulo operation, simply by programatically creating a visual representation. While these simulations are obvious simplifications of reality, having a strong understanding of simple operations is crucial to understanding much more complex systems.

\end{document}
