%!TEX root = ../thesis.tex
\section{Background}
% 1.	Structural analysis and design: history and what is desired for.
\paragraph{}
Structural engineering is one of the aspects in civil engineering that aims at the design of the structure which supports the loads without failure.
The loads imposed may be any physical forces due to gravity, wind action, vibration, temperature change, etc.
In the ancient age, it helped the people to build and maintain mega-structure such as pyramid and sphinx in Egypt.
Nowadays, thanks to the tremendous development in mathematics and material science, an increasingly wider range of different complex structures becomes possible to analysis.

% 2.	Computer aided-design and its application in structural engineering and others
\paragraph{}
As a result of the increasingly complicated geometry in structural engineering and the birth of the computer, Computer Aided Design (CAD) has been developed in 1980s \citep{Dav2008}.
The first Unigraphics System (for 2D modelling and drafting) was sold by United Computing in 1975 \citep{Ste2010}.
Nowadays, CAD has been widespread and won significant popularity.
A predominant amount of the designs delivered to structural engineers are generated by the help of commercial CAD softwares.
Besides, the CAD has also been extended to other fields especially mechanical and aerospace engineering where extreme complex geometry are treated.

% 3.	Finite element method (this needs to be expanded) and other numerical method (meshless, XFEM, particle based methods, etc.
\paragraph{}
The traditional structural analysis method which depends on a closed form mathematical solution becomes incapable to handle the highly complicated geometric input.
This motivated the Finite element method (FEM) which constitutes a general tool for the numerical solution of partial differential equations in engineering and applied science to be proposed \citep{Ucb2010}.
It did not achieve enormous popularity until early 1950s, when digital computer was developed.
After that, the method was refined with the help of variational methods from Lord Rayleigh (1870) and W. Ritz (1909) as well as the Galerkin's weighted-residual approach \citep{Fel1994}.
Then, great amount of research has been conducted on the FEM in terms of mathematics and applications, contributing to its dominance over numerical method in solid mechanics and structural analysis by the beginning of the 1990s \citep{Clo1980}.
Although it is a principle method for solving complex problems in the engineering field, lack of the local mesh refinement and the inability to formulate unbounded domain restrict the usage of the FEM in some area.
As a consequence, other numerical methods such as Boundary Element Method (BEM) \citep{Li2011,WARDLE1984525} and the Extended FEM (X-FEM) \citep{Moes1999} were proposed.
In BEM, only the boundary was discretised, contributing to a reduction of the spatial dimension by one.
Besides, the problem involves the unbounded domain can be solved naturally.
Nevertheless, the fundamental solution satisfying the governing differential equations in the domain must be available.
Unfortunately, this fundamental solution may be extremely complex.
The X-FEM extended the FEM to solve problems with localized features that are not efficiently resolved by mesh refinement.
Compared to the traditional FEM, the X-FEM exhibits a strong ability of modeling the fractures in the material.

% 4.	Finite element mesh generation and meshing burden (say Yan’s paper on mesh generation and Albert’s thesis)
\paragraph{}
The FEM could be one of the most popular numerical methods in engineering analysis.
In the FEM, a meshing procedure that discretize the problem domain into individual elementary components or ``elements'' is necessary.
The solution of the whole system is calculated by assembling its discretized elements.
However, creation of mesh in FEM can be expensive in terms of time and human resource.
Numerous studies have been conducted for an automatic mesh generation algorithm \citep{owen2000,Blacker1993,doi:10.1002/fld.1650081003,doi:10.1093/comjnl/24.2.167}.

% 5.	Adaptive finite element analysis
\paragraph{}
When complex geometric input is involved, chances are that a considerably fine mesh is required to capture the localized phenomena.
However, a naive implemented mesh generation algorithm usually produce a uniform mesh where small elements are created even though they are only necessary in limited areas.
Hence the adaptive finite element analysis was proposed to maximize the quality of the numerical solution for a given amount of the computational effort.
In this method, tiny elements are generated at the required areas only and coarse mesh is expected for the rest.
Since the stress or the displacement is unknown before the numerical method is conducted, an adaptive mesh can be difficult to be generated based on the geometry and boundary condition only.
As a consequence, the concept of the ``posteriori error estimator'' was introduced to estimate the error contribution of each element based on the solution calculated from the FEM \citep{Duval2018, doi:10.1002/gamm.201490020,PRUDHOMME20091887,BAUMAN2009799}.

% 6.	Isogeometric analysis
\paragraph{}
In the existing computational methods, the geometry is interpolated by high order polynomials and the exact geometry is neglected due to its intricacy.
However, the accuracy of adopting it into computational mechanics seems to be limited \citep{Sza2004}.
Tensor product Non-Uniform Rational B-spline (NURBS) is a well-known curve and surface representation method and has been adopted as a standard in computer graphics, computer-aided-design (CAD) \citep{Nas2003} and Initial Graphics Exchange Specification (IGES) since 1983 \citep{IGES1983}.
Nowadays, the employment of rational polynomial functions in description of geometry in CAD/CAM applications is becoming more and more extensive \citep{Pie1987} and the CAD has been widespread and won even more popularity than the FEM does.
While, the geometric descriptions adopted by engineers today for CAD and that for analysis are totally different.
Furthermore, frequent design modifications in fast pace, modern society restricts the usage of analysis if a new mesh cannot be created in a short duration.
\paragraph{}
Creation of mesh in FEM can be expensive in terms of time and human resource.
One possible solution is trying to replace the geometric modelling tool in FEM by something more CAD-like.
NURBS, for example, is a standard mathematical model utilized in CAD industry.
Exact CAD geometric boundary is achieved with the help of the NURBS curve and surface.
This idea to be geometrically exact with a minimum discretization was adopted in Isogeometric analysis developed in 2005 \citep{Hug2005b} and further refined recently \citep{Zhang2007,Hug2005b,Cot2006,Cot2009,Baz2006a,Baz2006b}.
Furthermore, a simplified mesh refinement method by omitting the necessity for communication with the CAD geometry once the initial shape was received is also targeted \citep{Cot2007}.
It shows advantage in the structure analysis, fluid mechanics \citep{Buf2011} and dynamics \citep{Cot2006}.

% 7.	Scaled boundary finite element method
\paragraph{}
A Scaled Boundary finite element method (SBFEM) which has similarity with both the FEM and the BEM is proposed to eradicate the necessity of fundamental solution in BEM.
SBFEM is a novel semi-analytical approach developed by Wolf and Song \citep{Wol1999}.
As a method developed based on the FEM and the BEM, the SBFEM is a fundamental-solution-less boundary element method which keeps the benefits of the both as well as provides some effective solutions to the limitations to the FEM and the BEM \citep{Wol1999}.
The fundamental solution is no longer required, spatial dimension is reduced by one as only the boundary is meshed with surface elements which leads to a decline in the number of unknowns and achievement of infinite boundary \citep{Wol2003}.

%  ------------------------------------------- %

\section{State of the problem}
\label{intro_sec:problem}
\paragraph{}
In current Isogeometric analysis, accuracy problems with numerical integration of a rational polynomials attract significant attention \citep{Hug2010,Sev2011,Aur2012}.
Furthermore, incapability to create a set of control points to fit an inhomogeneous essential boundary condition may lead to considerable errors and lower converge speed due to the non-interpolatory characteristics of the NURBS \citep{Wang2010,Wol2011,Koo2013}.
Besides, although numerous amount of research has been conducted on improving the algorithm efficiency \citep{Boo1972,Qin1996,Cho1990,Gra1992,Pan2001,Wang2012}, most of the time is devoted to calculate the basis function which restricts the usage of high order basis function in 3D problems.
Moreover, one of the most critical problems in the existing Isogeometric analysis lies in the dimension incompatibility.
It is based on FEM where 3D NURBS solids are required for meshing in 3D problems but only the boundary is described in CAD system.
Further meshing process for converting input surface data to higher dimension physical geometry in isogeometric analysis has been referred to as ``analysis-aware modelling'' \citep{Coh2010}.
Considerable research on solving this incompatibility by domain parameterization has been performed using a variety of methods \citep{Yang2007,Aig2009,Mar2009,Qian2011}.

% mesh generation
\paragraph{}
the conventional FEM allows only hexahedron, tetrahedron, wedge and pyramid in 3D and triangular and quadrilateral elements in 2D which poses a heavy burden on mesh generation.
In order to achieve a reasonably accurate result, the mesh of the traditional FEM is required to conform to the boundary of the problem domain.
One rough estimate provided by \cite{Hug2005} suggests that more than half of the overall analysis time is spent on meshing in the industries such as automotive and aerospace where complex shapes are involved.
As a consequence, it could be necessary to develop an automatic mesh generation algorithm using limited types of shapes \citep{Frey:2007:MGA:1205626}.

% adaptive mesh refinement
\paragraph{}
Numerous research has been conducted on the ``posteriori error estimator'' to achieve an adaptive analysis and it has been developed in the FEM \citep{doi:10.1002/nme.1620330702,doi:10.1002/nme.1620330703, BOROOMAND1999127, ZIENKIEWICZ1999111, Ainsworth1993}, the BEM \citep{Zhao1998, Guiggiani1990, KAMIYA1992223} and the SBFEM \citep{NME:NME439}.
However, some of these error estimators require extra works such as stress recovery.
Besides, it could be difficult to determine the most suitable error indicator to a given problem.
Furthermore, the threshold is taken manually which limits the usage of several indicators as the number of the threshold grows quadratically as the number of the estimators increases.

%  ------------------------------------------- %
\section{Objective and significance}
\paragraph{}
As discussed in Sec.~\ref{intro_sec:problem}, there are several limitations associated with the existing numerical methods.
This thesis aims at developing a complete and systematic numerical method where all procedures are conducted without human involvement for an arbitrary geometric input in both 2D and 3D situations.
After the design files (IGES file and STL file in 3D) are delivered in electronic form, the proposed method shall be able to parse the geometric input, generate the mesh (quadtree in 2D and octree in 3D), determine the result using SBFEM and refine the mesh based on the error estimator automatically.
The SBFEM is adopted as it requires only the boundary information and hence provides a seamless integration with the CAD modeling.
The main objectives of this thesis are as follows
\begin{enumerate}
    \item Minimize human effort spent on structural analysis
    \item Be compatible with arbitrary geometric input in both 2D and 3D
    \item Generate high quality mesh
    \item Retain exact geometry
    \item Develop a robust, extensible and flexible error estimator
\end{enumerate}
Accomplishing tasks mentioned above makes significant contributions to solve the practical engineering problems automatically.
Furthermore, a new error estimator trained using machine learning algorithm allows unlimited number of indicators to be used.

%  ------------------------------------------- %
\section{Outline of the thesis}
\paragraph{}
In the next chapter, a literature review on the existing numerical methods including the Isogeometric analysis and the SBFEM, the automatic mesh generation algorithm and the adaptive mesh refinement is presented.
The advantages and disadvantages of different methods are critically discussed.

\paragraph{}
In Chapter 3, the idea of the isogeometric analysis is extended to the SBFEM to solve 2D problem including linear elasticity and linear elastic fracture mechanics.
The NURBS basis functions are adopted as the shape functions in the SBFEM instead of the conventional Legendre polynomials.
Some key formulations in linear elasticity and linear elastic fracture mechanics in the SBFEM using the NURBS shape functions are derived.
In order to perform a numerical integration on piecewise polynomials, a knot insertion is adopted to convert a piecewise polynomial to multiple non-piecewise polynomials.
NURBS curve fitting is also introduced to enforce the stress boundary condition.

\paragraph{}
Chapter 4 implements an IGES adaptor which can convert the geometric information stored in IGES file into polylines.
A quad-tree based mesh generation algorithm is developed to handle arbitrary geometric input from these polylines.
In order to retain the exact geometry, the intersection point on the polyline is projected back onto the original NURBS curve.
The projection is accelerated using the convex hull property and the quick hull algorithm is hence introduced.
Hard point treatment is developed in order to handle the multiple material interfaces, sharp edges or cracks.
Optimization algorithms such as bucket sort are adopted to improve the computational efficiency of the mesh generation.
Stress analysis is conducted on 2D linear elasticity problems.

\paragraph{}
In Chapter 5, an adaptive mesh refinement algorithm is proposed by the help of machine learning.
Expressions related to the eigenvalues of the SBFEM formulation together with some key geometric properties of the scaled boundary finite element are obtained as the error indicators.
The models trained by the Multilayer Perceptron (MLP), the Support Vector Machine (SVM) using radial kernel function and the random forest are compared and the MLP model which achieves the best performance is used.
In order to improve the accuracy of the MLP, regularization methods including bagging and dropout are adopted.
Due to the lack of eigenvalue error indicator in first order triangular element, method that eliminates these situation is produced.
A matrix representation of NURBS curves is presented to achieve a higher efficiency and stability in calculating the intersections between a line and a NURBS curve.
Stress analysis is conducted on 2D linear elasticity problems.

\paragraph{}
Chapter 6 references an octree based automatic mesh generation algorithm based on the STL file in 3D \citep{Liu2017}.
In order to retain the exact geometry, a method that can project intersection points on the triangular surfaces back to their origin NURBS surfaces is developed.
Another method that can calculate the intersection point between an edge in the scaled boundary finite element and the NURBS surface is also presented for the purpose of exact geometry.
The matrix representation of the NURBS surface in 3D is introduced to improve the computational efficiency and stability of the calculation of the intersection.
Splitting NURBS surfaces is adopted to accelerate the algorithm in both point projection and intersection calculation.
The computational efficiency of them are further improved by utilizing the strong hull properties of the NURBS surface and hence the quick hull algorithm in 3D is introduced.

\paragraph{}
Chapter 7 presents conclusions to the research.
Possible future works are proposed.


\documentclass[12pt]{article}
\usepackage{hyperref}
\usepackage{fancyvrb}
\textwidth=7in
\textheight=9.5in
\topmargin=-1in
\headheight=0in
\headsep=.5in
\hoffset  -.85in
\hypersetup{colorlinks=true}
\setlength{\parskip}{\baselineskip}%
\setlength{\parindent}{0pt}%

\pagestyle{empty}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
\begin{document}

\begin{center}
{\bf CS314 - Operating Systems Homework 2 (Fall '16)
}
\end{center}

\setlength{\unitlength}{1in}
\section{Administrivia}
Homeworks should be done individually and turned in via Moodle.

LaTeX version of this file is here: \verb#/home/cs314/hw2.tex# To
generate a pdf with your solutions copy the above file to someplace in your home directory and compile with
\verb#pdflatex hw2.tex#

\section{Get On With It}
\begin{enumerate}
\item (20 pts) Consider the following C code:
\begin{verbatim}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int a = 0;
int main(){
  fork();
  printf("%d\n", ++a);
  fork();
  printf("%d\n", ++a);
  fork();
  printf("%d\n", ++a);
  exit(0);
}
\end{verbatim}
\begin{itemize}
\item (10 pts) Including the original process, how many processes end up calling
  exit()? Show your work or modified code and output showing the correct
  count.

  The correct answer is 8. I arrived at the solution by realizing that the final \verb#printf("%d\n", ++a);# is being
  called as often as the \verb#exit(0);# statement, so by compiling the code and running the BASh command
  \verb#./a.out | grep 3 | wc -l# would return the number of times ``3'' was printed, which would be the equal to
  the number of processes.

  Additionally, since \verb#fork()# creates two processes for every one, by raising two to the number of instances of \verb#fork()#, we can get the total number of processes, in this case $2^3 = 8$.
\item (10 pts) What is one possible output of this program? Explain.

  One possible outcome would be
\begin{verbatim}
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
\end{verbatim}
This is because the processes are shuffled randomly together, and do not execute in any particular order except when in reference to itself.
\end{itemize}

\item (20 pts) Included here is a trivial threaded program. The intended
  purpose is to construct a list of numbers from 1 to MAX-1, where each
  number occurs only once. Run the
  program on os.cs.s.siue.edu and report what you observe in the
  output (hint: use wc to count the number of lines in the output),
  answering the questions: Is the output correct? If it is incorrect,
  why is it incorrect?

  Now, if you've found that the output is incorrect, fix the program
  to produce the intended output. Describe what you've done,
  explaining why it works. Include your source as part of the answer.

  Also, In your answer, include the execution times you've observed for both
  the original program and for one you've fixed to produce correct
  output. (see: \verb$man time$) Try to answer at least the following:
  How is the execution time different? Why is it different? How does
  the result change your expectations of improving performance by
  dividing work into threads?

\begin{Verbatim}[fontsize=\scriptsize]
#include <stdio.h>
#include <pthread.h>

#define MAX 100000
FILE* out;

int main()  {
  pthread_t f3_thread, f2_thread, f1_thread;
  void *f1();
  int i = 0;
  out = fopen("numbers", "w+");
  pthread_create(&f1_thread,NULL,f1,&i);
  pthread_create(&f2_thread,NULL,f1,&i);
  pthread_create(&f3_thread,NULL,f1,&i);
  pthread_join(f1_thread, NULL);
  pthread_join(f2_thread, NULL);
  pthread_join(f3_thread, NULL);
  fclose(out);
  return 0;
}

void *f1(int *x){
  while(*x < MAX){
    fprintf(out,"%d\n", *x);
    (*x)++;
  }
  pthread_exit(0);
}
\end{Verbatim}

This code is problematic as it has a race condition intrinsic to its execution. It relies on the shared integer i to
know which number to print out next. The problem therefore arises when a number is being processed when the thread is interrupted,
and the next thread begins to process the same value.

A possible solution to the problem is to re-write the code like this
\begin{Verbatim}[fontsize=\scriptsize]
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>

#define MAX 100000
FILE* out;
sem_t sem;

int main()  {
  pthread_t f3_thread, f2_thread, f1_thread;
  void *f1();
  int i = 0;
  sem_init(&sem, 0, 1);
  out = fopen("numbers", "w+");
  pthread_create(&f1_thread,NULL,f1,&i);
  pthread_create(&f2_thread,NULL,f1,&i);
  pthread_create(&f3_thread,NULL,f1,&i);
  pthread_join(f1_thread, NULL);
  pthread_join(f2_thread, NULL);
  pthread_join(f3_thread, NULL);
  fclose(out);
  return 0;
}

void *f1(int *x){
  while(*x < MAX){
    sem_wait(&sem);
    //We need to check that condition again
    if(*x < MAX)
    {
	fprintf(out,"%d\n", *x);
	(*x)++;
    }
    sem_post(&sem);
  }
  pthread_exit(0);
}
\end{Verbatim}

This code uses a semaphore to restrict access to the check-print-modify section of
code. The semaphore will only allow one thread to enter the critical section at
once, and the first thing it does is check that its value for \verb#i# is still
a valid one. The tradeoff here is for time. The original program executes in
around 30 ms, whereas my corrected version takes around 90 ms. This is because
the corrected program has times where a thread might be idle, whereas the
uncorrected version has all its threads running throughout execution.

\item (20 pts) Here is another trivial threaded program. Each thread simply
  prints the value of the passed argument (ignore compiler warnings;
  we are abusing the argument pointer to pass an integer). Enter this
  program and run it a bunch of times. You'll notice that the order of
  thread execution is random. Without changing main(), use semaphores
  to enforce that threads always get executed in order, so that what
  is printed are the values 1, 2, and 3, in that order.

  \begin{Verbatim}[fontsize=\scriptsize]
#include <stdio.h>
#include <pthread.h>

int main()  {
  pthread_t thread1, thread2, thread3;
  void *f1();

  pthread_create(&thread1,NULL,f1,1);
  pthread_create(&thread2,NULL,f1,2);
  pthread_create(&thread3,NULL,f1,3);
  pthread_join(thread1, NULL);
  pthread_join(thread2, NULL);
  pthread_join(thread3, NULL);

  return 0;
}

void *f1(int x){

  printf("%d\n", x);

  pthread_exit(0);
}

  \end{Verbatim}

  A possible solution to this is shown here.

\begin{Verbatim}[fontsize = \scriptsize]
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>

#define NUM_THREADS 3

sem_t turnstile1, turnstile2, mutex;
int count = 0, cycles = 0;

int main()  {
  pthread_t thread1, thread2, thread3;
  void *f1();
  sem_init(&turnstile1, 0, 0);
  sem_init(&turnstile2, 0, 1);
  sem_init(&mutex, 0, 1);

  pthread_create(&thread1,NULL,f1,1);
  pthread_create(&thread2,NULL,f1,2);
  pthread_create(&thread3,NULL,f1,3);
  pthread_join(thread1, NULL);
  pthread_join(thread2, NULL);
  pthread_join(thread3, NULL);

  return 0;
}

void *f1(int x)
{
  while(cycles < NUM_THREADS)
  {
    //Rendezvous
    sem_wait(&mutex);
    count++;
    if(count == NUM_THREADS)
    {
      sem_wait(&turnstile2);
      sem_post(&turnstile1);
    }
    sem_post(&mutex);
    sem_wait(&turnstile1);

    //Critical point
    if(cycles + 1 == x)
    {
      printf("%d\n", x);
      cycles++;
    }

    sem_post(&turnstile1);
    //Rendezvous part 2
    sem_wait(&mutex);
    count--;
    if(count == 0)
    {
      sem_wait(&turnstile1);
      sem_post(&turnstile2);
    }
    sem_post(&mutex);
    sem_wait(&turnstile2);
    sem_post(&turnstile2);
  }
  pthread_exit(0);
}

  \end{Verbatim}

  This is a general solution for any known number of threads. It is a reusable barrier modifed to
  allow single access to a critical section, where the number is printed if it is the correct
  number. When all the numbers have been printed, the loop terminates, and all the threads are
  released.

\item (20 pts) Rewrite the example from the ``Dining Philosophers''
slide (Chapter 2 slides; also found in Figure 2-47 in Tanenbaum)
to working C code. Write a main() that creates five threads (one
for each philosopher). Demonstrate that your solution works by
printing something when each philosopher changes state. Let the
program exit when each philosopher has eaten at least twice.

\begin{Verbatim}[fontsize = \scriptsize]
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>

#define N        5
#define LEFT     ( i + N - 1) % N
#define RIGHT    ( i + 1) % 1
#define THINKING 0
#define HUNGRY   1
#define EATING   2
#define MEALS    2

int state[N];

pthread_t threads[N];

sem_t mutex;
sem_t s[N];

void *philosopher(int*);
void take_forks(int);
void put_forks(int);
void test(int);
void think(int);
void eat(int);

int main()
{
  sem_init(&mutex, 0, 1);
  for(int i = 0; i < N; i++)
  {
    sem_init(s + i, 0, 1);
  }
  for(int i = 0; i < N; i++)
  {
    pthread_create(threads + i, NULL, philosopher, &i);
  }
  for(int i = 0; i < N; i++)
  {
    pthread_join(threads[i], NULL);
  }
  return 0;
}

void *philosopher(int *i)
{
  for(int j = 0; j < MEALS; j++)
  {
    think(*i);
    take_forks(*i);
    eat(*i);
    put_forks(*i);
  }

  pthread_exit(0);
}

void take_forks(int i)
{
  sem_wait(&mutex);
  state[i] = HUNGRY;
  test(i);
  sem_post(&mutex);
  sem_wait(s + i);
}

void put_forks(int i)
{
  sem_wait(&mutex);
  state[i] = THINKING;
  test(RIGHT);
  test(LEFT);
  sem_post(&mutex);
}

void test(int i)
{
  if(state[i] == HUNGRY && state[LEFT] != EATING && state[RIGHT] != EATING)
  {
    state[i] = EATING;
    sem_post(s + i);
  }
}

void think(int i)
{
  printf("Philosopher %d: Hmm...\n", i);
}

void eat(int i)
{
  printf("Philosopher %d: Nom\n", i);
}

\end{Verbatim}

\item (20 pts) Write a shell script that produces a file of sequential numbers by
reading the last number in the file, adding 1 to it, and then
appending it to the file. Run one instance of the script in the
background and one in the foreground, each accessing the same
file. Show an example from the output of the race condition
manifesting itself. What is the critical region? Modify the script to
prevent the race. See the notes that follow.

Here's a basic bash script to get you started:
\begin{verbatim}
#!/bin/bash
if [ ! -f numbers ]; then echo 0 > numbers; fi
count=0
while [[ $count != 100 ]]; do
#maybe some code goes here
count=`expr $count + 1`
#perhaps some more code goes here
done
\end{verbatim}

Output from the race condition looks something like this.
\begin{Verbatim}[fontsize = \scriptsize]
0
1
2
2
3
3
4
5
5
6
7
8
9
10
11
7
8
8
9
9
10
10
11
12
13
14
14
15
15
16
16
17
17
18
18
19
19
20
20
21
22
22
23
23
24
25
25
26
26
27
27
28
28
29
29
30
30
31
31
32
32
33
33
34
35
35
36
36
37
37
38
39
40
41
42
43
44
45
46
47
48
48
49
50
50
51
51
52
52
53
53
54
54
55
56
56
57
57
58
58
59
60
61
61
62
62
63
64
64
65
65
66
66
67
67
68
68
69
69
70
70
71
71
72
72
73
73
74
74
75
76
77
78
79
79
80
80
81
82
83
83
84
84
85
86
86
87
87
88
88
89
89
90
90
91
91
92
92
93
93
94
94
95
95
96
96
97
97
98
98
99
100
100
101
101
102
102
103
103
104
104
105
106
106
107
107
108
108
109
109
110
110
111
111
112
112
113
114
115
116
117
\end{Verbatim}

The critical section is the read in and the append to file was the critical
section. I used a busy waiting solution where the script will check constantly
against the existance of the lock file. I release the mutex by rm-ing the
lock file.

\begin{Verbatim}
#!/bin/bash
if [ ! -f numbers ]; then echo 0 > numbers; fi
count=0
while [[ $count != 100 ]]; do
    while true; do
	if ln numbers numbers.lock 2> /dev/null; then break; fi;
    done
    next=`tail -n 1 numbers`
    next=`expr $next + 1`
    echo $next >> numbers
    count=`expr $count + 1`
    rm numbers.lock
done
\end{Verbatim}

\end{enumerate}

\section{What to Turn In}
Turn in one file, preferrably a tgz or zip, containing the answers to
the questions above, along with all working code, where applicable.

\end{document}


%----------------------------------------------------------------------
\chapter{Implementation}
\label{chap:code-implementation}
%----------------------------------------------------------------------
\section{Software overview}
\label{sec:software-overview}
The code of the ODE solvers software that I have developed is available on GitHub via this link: \href{https://github.com/FarmHJ/numerical-solver}{\underline{\emph{GitHub repository}}}. GitHub is a good
platform for version control and collaborations. Software with version control can keep track of changes made to the code. It is very useful for large projects with collaborations. Aside from having version control, the software is fully documented. Details on its structure and functions are available at the link: \href{https://numerical-solver.readthedocs.io/en/latest/index.html}{\underline{\emph{software documentation}}}. Finally, the software is also full-tested to ensure the correctness of the code. More details of the testing infrastructure are given in later sections.

To showcase the features of the code and to give a brief summary of the quality of the code, badges are displayed on the main page of the GitHub repository, as shown in Figure \ref{fig:badges}. These badges indicate that the code is tested to work using several python versions and operating systems. The badge `codecov' shows the code coverage of the software, which will be described in details in the Section \ref{sec:testing}, together with the testing infrastructure. Finally, there is a status badge `Doctest' to verify that the documentation of the software is built successfully.

\begin{figure}
    \includegraphics[width=0.95\columnwidth]{badges}
    \caption{Badges on Github repository.}
    \label{fig:badges}
\end{figure}

\section{Implemented numerical methods}
\label{sec:implemented-methods}
The numerical methods implemented in this software are classified into three classes: one-step methods, predictor-corrector methods and adaptive methods. The methods included are:
\begin{enumerate}
    \item One-step methods
    \begin{itemize}
        \item Euler's explicit method
        \item Euler's implicit method
        \item Trapezium rule method
        \item Four-stage Runge-Kutta method
    \end{itemize}
    \item Predictor-corrector method
    \begin{itemize}
        \item Euler-Trapezoidal method
    \end{itemize}
    \item Adaptive methods
    \begin{itemize}
        \item BS23 algorithm
        \item RKF45 algorithm
    \end{itemize}
\end{enumerate}

The main code containing these numerical methods can be found at the link: \href{https://github.com/FarmHJ/numerical-solver/blob/main/solver/methods.py}{\underline{\emph{methods code}}}.

\section{Unit testing}
\label{sec:testing}
In the process of developing the software, a unit testing infrastructure was put in place. The purpose of the unit testing is to create a robust and sustainable software. All codes are fully tested whilst being written (this is known as test-driven development) to ensure correctness and making future maintenance of the code much easier.

Code coverage is a measurement of the percentage of codes covered in the unit testing process. It is usual to aim for 100\% code coverage. However, a 100\% code coverage does not necessarily mean that the code is correct and free of errors. Nevertheless, it provides some confidence that the code is implemented correctly.

Every method in this software is tested using the `unittest' Python library, a unit testing framework. The numerical solution produced by each method is tested to be the same solution as the manually calculated solution. The methods are mostly tested against the test problem Eqs.~\eqref{eqn:example_model}-\eqref{eqn:example-end}.

\section{Testing initialisation of problem}
\label{sec:test_init}
The initialisations of each class are tested to ensure that variables are initialised correctly and input type satisfies the requirements. For example,

\begin{lstlisting}[language=Python, caption= {initialisation testing}, title={Testing initialisation of problem}, label={code:test_init}]
def test__init__(self):

    def func(x, y):
        return [-y[0]]
    x_min = 0
    x_max = 1
    initial_value = [1]
    mesh_points = 10

    problem = solver.OneStepMethods(
        func, x_min, x_max, initial_value, mesh_points)

    # Test initialisation
    self.assertEqual(problem.x_min, 0)
    self.assertEqual(problem.mesh_points, 10)

    # Test raised error for callable function
    with self.assertRaises(TypeError):
        solver.OneStepMethods(
            x_min, x_min, x_max, initial_value, mesh_points)

    # Test raised error if initial_value not list
    with self.assertRaises(TypeError):
        solver.OneStepMethods(
            func, x_min, x_max, 1, mesh_points)
\end{lstlisting}
A simple model with known solution is first initialised. Required inputs were checked to make sure the problem is set up properly, in line 14 and 15 of the code snippet above. To ensure that the inputs to the function are of the desired data type, errors are raised whenever the user inputs a wrong data type. The unit testing also tests that these errors are raised appropriately (line 17 to 25) whenever the data type does not satisfy the requirements.

\section{Testing function}
\label{sec:test_func}
After making sure the problem is properly initialised, we then test that the numerical methods are working correctly. Take the adaptive method, BS23 algorithm, as an example, the testing of a method is as follows:
\begin{lstlisting}[language=Python, caption= {testing of function}, title={Testing execution of method}, label={code:test_func}]
def test_ode23(self):

    def func(x, y):
        return [-y[0]]
    x_min = 0
    x_max = 1
    initial_value = [1]

    problem = solver.AdaptiveMethod(
        func, x_min, x_max, initial_value, initial_mesh=0.5)
    mesh, soln = problem.ode23()

    # Test end point of mesh
    self.assertGreaterEqual(mesh[-1], 1.0)

    # Test mesh point
    self.assertAlmostEqual(mesh[1], 0.3483788976565)

    # Test solution at first stepsize
    self.assertAlmostEqual(soln[1][0], 0.7052580305097)
\end{lstlisting}
The method is first tested that it executes the computations up to the maximum mesh value indicated. Then, it is checked that the first adaptive mesh point and its solution, obtained from the software, matches the value computed manually.

\section{Conclusion}
\label{sec:software-conclusion}
The software can solve any initial value problem of the general form Eqs.~\eqref{eqn:initial_value_start}-\eqref{eqn:initial_value} using the implemented numerical methods as listed in Section \ref{sec:implemented-methods}. The software can also handle initial value problems of higher dimension. An example of the use of the software can be found at the link: \\ \href{https://nbviewer.jupyter.org/github/FarmHJ/numerical-solver/blob/main/examples/fitzhugh_nagumo.ipynb}{\underline{\emph{Example use of software}}}. All methods are tested, not only making sure all lines are tested, but also testing their functionalities. Moreover, the results from all notebooks (see Appendix \ref{chap:link}) behaves as expected by theory. The time efficiency of the software is not a major concern of the project, thus some methods might take long periods of time to run.

The purpose of setting up a software with version control, documentation and testing is to create a robust and reusable software. These software engineering methods can give confidence in the correctness of the code and aid in the future maintenance of the code. By implementing these methods to this software, it will allow me to gain experience in developing the software engineering techniques that I will use throughout my D.Phil..


\section{DCGAN}
The \gls{DCGAN} architecture was a big step for \acp{GAN} when it was introduced, it defined a set of recommendations for building networks that would be more stable and scalable, by fully leveraging the power of convolutional layers in both generator and discriminator \cite{dcgan2015}. The architecture of the \gls{DCGAN} was used as a basis for all following experiments in this document.

The goal of the tests in this section was to try and find what properties of the \gls{DCGAN} were relevant, what configurations could be used to tackle different situations, and to question the validity of using transposed convolutions has a way of upscaling the latent vector to the full resolution of the image, since it can produce artifacts \cite{deconvolutionArtifacts2016} and it is being replaced in recent approaches (e.g. \cite{styleGAN2018}) by more conventional upsampling techniques followed by a simple dimension preserving convolution.

\subsection{MNIST}
Training the \gls{DCGAN} on the \gls{MNIST} dataset produced the results seen in \autoref{fig:dcgan_mnist_metrics}.\begin{figure}[hbt]
    \centering
    \caption{Metrics when training a DCGAN on MNIST}
    \includegraphics[width=0.9\textwidth]{chapters/Experiments/DCGAN/mnist_metrics.pdf}
    \fonte{From the author (2021)}
    \label{fig:dcgan_mnist_metrics}
\end{figure}

There are a couple of things that can be observed in these results. First, observe how the number of dimensions in the latent space does not seem to be very relevant, unless it becomes too small, as seen for the case of \texttt{LDIM=2}, which produced the worst results. This makes sense since it is harder for the generator to learn a map from the smaller space to all possible images, in other words, its capacity is too small to produce the complexity in the data.

The effect of this can be seen in \autoref{fig:dcgan_mnist_ldim2}, these are samples produced by the generator with only two dimensions of latent space. The samples were chosen in a training epoch where it is particularly clear that the generator is producing some relatively good samples, but it suffers to map the small volume of the latent space into all possible digits, resulting in mode collapse.
\begin{figure}[hbt]
    \centering
    \caption{Samples taken from a DCGAN with low dimensions of latent space}
    \includegraphics[width=0.5\textwidth]{chapters/Experiments/DCGAN/mnist_ldim2.png}
    \fonte{From the author (2021)}
    \label{fig:dcgan_mnist_ldim2}
\end{figure}

But note that by just raising the number of dimensions from 2 to 6 is already enough to fix this problem, after that, the number of increased dimensions has little effect, since the generator already has all the capacity it needs to represent the simple data from the \gls{MNIST} dataset.

The results in \autoref{fig:dcgan_mnist_metrics} cannot give a definitive answer about the influence of the batch size, although there is some indication that bigger batches may not be ideal. This is seen for the case with batch size of 128 that produced the second least favorable results, and in a lesser extent for the test with batch size of 64.

Last point of note is the effect of the upsampling technique used, to better visualize this it is helpful to group the metrics shown in \autoref{fig:dcgan_mnist_metrics} into the particular sets of interest, this approach will be used repeatedly for the rest of this document. \autoref{fig:dcgan_mnist_upsampling} highlights the results per type of upsampling used.
\begin{figure}[hbt]
    \centering
    \caption{Effects of upsampling when training a DCGAN on MNIST}
    \includegraphics[width=\textwidth]{chapters/Experiments/DCGAN/mnist_upsampling.pdf}
    \fonte{From the author (2021)}
    \label{fig:dcgan_mnist_upsampling}
\end{figure}

It can be seen by this figure that the bilinear upsampling technique generally performs better than transposed convolutions in the case of \gls{MNIST}, as later results will show, this does not imply that it will always be the case.

\autoref{fig:dcgan_mnist_samples} shows samples produced by the best model experimented in these tests, with configuration (\texttt{BS=32 LDIM=12 UP=Bilinear}).
\begin{figure}[hbt]
    \centering
    \caption{Samples when training a DCGAN on MNIST}
    \includegraphics[width=0.5\textwidth]{chapters/Experiments/DCGAN/mnist_samples.png}
    \fonte{From the author (2021)}
    \label{fig:dcgan_mnist_samples}
\end{figure}

\subsection{Fashion MNIST}
Training the \gls{DCGAN} on the Fashion MNIST dataset produced the results seen in \autoref{fig:dcgan_fashion_metrics}.
\begin{figure}[hbt]
    \centering
    \caption{Metrics when training a DCGAN on Fashion MNIST}
    \includegraphics[width=\textwidth]{chapters/Experiments/DCGAN/fashion_metrics.pdf}
    \fonte{From the author (2021)}
    \label{fig:dcgan_fashion_metrics}
\end{figure}

Again the use of bigger batches has produced weaker results, with the case for a batch size of 64 producing the least favorable overall results between all tests. This may be for the fact that smaller batch sizes have more updates per epoch since they divide the dataset into more batches and each batch is a parameter update. However, at least for the case of the batch size of 128 seen in \autoref{fig:dcgan_mnist_metrics}, bigger batches seem to have more difficulty to step beyond a certain point. It may be that bigger batches would produce better results given more epochs of training, and they are a small amount faster to calculate per epoch in relation to smaller batches, but for the rest of the tests they were not evaluated more deeply.

One thing to note in \autoref{fig:dcgan_fashion_metrics} is the extreme jump seen on test (\texttt{BS=32 LDIM=16 UP=TrpConv}) at epoch number $10$, this can be seen to a smaller extent in many cases throughout the following experiments, but this was the most extreme one. It is not clear why this happens, the author's hypothesis is that the generator stepped into a particular steep region of the loss surface, but was quickly pointed in the right direction by the larger gradients of the discriminator in the next updates.

Again, by highlighting the use of the upsampling techniques it is possible to obtain the results seen in \autoref{fig:dcgan_fashion_upsampling}. In this case, the transposed convolutions showed the best results, while bilinear upsampling had the least favorable overall. The nearest neighbour interpolation was also tested in this case and here it also performed better than bilinear.
\begin{figure}[hbt]
    \centering
    \caption{Effects of upsampling when training a DCGAN on Fashion MNIST}
    \includegraphics[width=\textwidth]{chapters/Experiments/DCGAN/fashion_upsampling.pdf}
    \fonte{From the author (2021)}
    \label{fig:dcgan_fashion_upsampling}
\end{figure}

Lastly, the samples from the lowest \gls{FCD} obtained by the test (\texttt{BS=16 LDIM=32 UP=TrpConv}) can be seen in \autoref{fig:dcgan_fashion_samples}. Note how the generator does not have a good sense of symmetry, producing shirts with long sleeves in a single arm. This is a very common occurrence in \acp{GAN}, even modern models will suffer from this; for example, \acp{GAN} can produce faces where the eyes do not have the same color, or place different earrings in each ear \cite{gan_asymmetry2018}.
\begin{figure}[hbt]
    \centering
    \caption{Samples when training a DCGAN on Fashion MNIST}
    \includegraphics[width=0.5\textwidth]{chapters/Experiments/DCGAN/fashion_samples.png}
    \fonte{From the author (2021)}
    \label{fig:dcgan_fashion_samples}
\end{figure}

\subsection{CIFAR-10}
\autoref{fig:dcgan_cifar_metrics} shows the results of training the \gls{DCGAN} on the \gls{CIFAR}-10 dataset. One thing to note here is how both the \gls{CS} and \gls{FCD} metrics show weaker results when compared to the previous results.
\begin{figure}[hbt]
    \centering
    \caption{Metrics when training a DCGAN on CIFAR-10}
    \includegraphics[width=\textwidth]{chapters/Experiments/DCGAN/cifar_metrics.pdf}
    \fonte{From the author (2021)}
    \label{fig:dcgan_cifar_metrics}
\end{figure}

When making the experiments, it was found that the \gls{CIFAR}-10 dataset is considerably harder than the other datasets, even when compared with the CelebA and Flowers datasets. The author's hypothesis is that this is due to the relatively low number of images for each class in \gls{CIFAR}-10, (only $6000$ for each), and that the classes are significantly different from each other, making it very hard for the generator to learn the details in all of them.

Recall that the classes in \gls{CIFAR}-10 are: \texttt{airplane}, \texttt{automobile}, \texttt{bird}, \texttt{cat}, \texttt{deer}, \texttt{dog}, \texttt{frog}, \texttt{horse}, \texttt{ship} and \texttt{truck}. These images are significantly more varied than the other datasets used, even the dataset of human faces, CelebA, can later be seen to be relatively homogeneous.

With these results it is possible to see once again a clear difference between upscaling techniques. This time, in accordance with what was seen for Fashion MNIST, the transposed convolution gives the best results. In these tests it was also experimented the use of one sided label smoothing, although the results still do not show any significant difference that allows for making conclusions.

One important thing to note in all the tests on CIFAR made for this document, is the fact that the momentum term of the Adam optimizer (\gls{beta_1}) had a negative impact on the convergence of the models. For \gls{MNIST} and Fashion MNIST this term was kept at the common value of $0.9$ without any problems, however this would result in incomprehensible images and no sort of convergence when training on \gls{CIFAR}-10, to avoid this, \gls{beta_1} was kept at zero.

The samples produced for the best overall \gls{FCD} in the test (\texttt{UP=TrpConv}) are shown in \autoref{fig:dcgan_cifar_samples}. Note how it is possible to see a hint of the \gls{CIFAR}-10 classes in these images, but nothing can be pointed out as a completely sensible real world object.
\begin{figure}[hbt]
    \centering
    \caption{Samples when training a DCGAN on CIFAR-10}
    \includegraphics[width=0.5\textwidth]{chapters/Experiments/DCGAN/cifar_samples.png}
    \fonte{From the author (2021)}
    \label{fig:dcgan_cifar_samples}
\end{figure}


\documentclass{article}
\newsavebox{\oldepsilon}
\savebox{\oldepsilon}{\ensuremath{\epsilon}}
\usepackage[minionint,mathlf,textlf]{MinionPro} % To gussy up a bit
\renewcommand*{\epsilon}{\usebox{\oldepsilon}}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx} % For .eps inclusion
%\usepackage{indentfirst} % Controls indentation
\usepackage[compact]{titlesec} % For regulating spacing before section titles
\usepackage{adjustbox} % For vertically-aligned side-by-side minipages
\usepackage{array, amsmath,  mhchem}
\usepackage[hidelinks]{hyperref}
\usepackage{courier, subcaption}
\usepackage{multirow, enumerate}

\usepackage{float}
\restylefloat{table}

\pagenumbering{gobble}
\setlength\parindent{0 cm}
\renewcommand{\arraystretch}{1.2}
\begin{document}
\large

MCB 135 Problem Set 3 \hfill Due Monday, February 23, 2015 at 2:30 PM

\section*{Problem 1: Transcription Factor Cascade (adapted from Alon 2.4, 30 points)}

Consider a cascade of three transcriptional activators, $X \rightarrow Y \rightarrow Z$. Protein $X$ is initially present in the cell in its inactive form. At time $t=0$, $X$ rapidly becomes active and binds the promoter of $Y$, so that protein $Y$ starts to be produced at a rate $\beta_y$. When $Y$ levels exceed a threshold $K_y$, gene $Z$ begins to be expressed at a rate $\beta_z$. All proteins have the same degradation/dilution rate $\alpha$.

\begin{enumerate}[a)]
\setlength{\itemsep}{0pt}
\item Using the information above, find an expression for the time derivative of $Y$. Integrate to find $Y(t)$ given the initial condition $Y(0)=0$. (Hint: A similar derivation is given in Alon Ch. 2.)
\item At what time $\tau$ does expression of $Z$ begin?
\item What is the concentration of protein $Z$ as a function of time?
\item What is the \textit{response time} of the system, i.e., the time between when $X$ is activated and when $Z$ reaches one half of its maximal value?
\end{enumerate}

\section*{Problem 2: Multistep Ultrasensitivity (Ingalls 6.8.7, 40 points)}

In a 2005 paper, Jeremy Gunawardena presented a straightforward analysis of multistep ultrasensitivity and revealed that it is not well-described by Hill functions\footnote{\href{http://www.pnas.org/content/102/41/14617.abstract}{Gunawardena, J. (2005). Multisite protein phosphorylation makes a good threshold but can be a poor switch. \textit{PNAS}}}.\\

Consider a protein $S$ that undergoes a sequential chain of $n$ phosphorylations, all of which are catalyzed by the same kinase $E$, but each of which requires a separate collision event. Let $S_k$ denote the protein with $k$ phosphate groups attached. Suppose the phosphatase $F$ acts in a similar multistep manner. The reaction scheme is then
\[ \ce{S_0 <=> S_1 <=>} \cdots  \ce{<=> S_n } \]

In steady state, the net reaction rate at each step is zero.

\begin{enumerate}[a)]
\setlength{\itemsep}{0pt}
\item Consider the first phosphorylation-dephosphorylation cycle. Expanding the steps in the catalytic mechanism, we have
\[ \ce{S_0 + E <=>[k_{1E}][k_{-1E}] ES_0 ->[k_{catE}] E + S_1} \hspace{1 cm} \textrm{ and } \hspace{1 cm} \ce{S_1 + F <=>[k_{1F}][k_{-1F}] FS_1 ->[k_{catF}] F + S_0} \]

Apply a rapid equilibrium assumption to the association reactions ($S_0 + E \leftrightarrow ES_0$ and \linebreak $S_1 + F \leftrightarrow FS_1$) to describe the reaction rates as
\[ k_{\textrm{catE}} \left[ ES_0 \right] = \frac{k_{\textrm{catE}}}{K_{ME}} \left[ S_0 \right] \left[ E \right] \hspace{1 cm} \textrm{ and } \hspace{ 1cm} k_{\textrm{catF}} \left[ FS_1 \right] = \frac{k_{\textrm{catF}}}{K_{MF}} \left[ S_1 \right] \left[ F \right] \]

where $K_{ME} = k_{-1E}/k_{1E}$, $K_{MF} = k_{-1F}/k_{1F}$, and $[E]$ and $[F]$ are the concentrations of free kinase and phosphatase.

\item Use the fact that at steady state the net phosphorylation-dephosphorylation rate is zero to arrive at the equation
\[ \frac{\left[ S_1 \right]}{\left[ S_0 \right]} = \lambda \frac{\left[ E \right]}{\left[ F \right]}, \hspace{ 1 cm} \textrm{ where } \lambda = \frac{k_{\textrm{catE}}}{k_{\textrm{catF}}} \frac{K_{MF}}{K_{ME}}\]

\item Suppose the kinetic constants are identical for each phosphorylation-dephosphorylation step. In that case, verify that
\[ \frac{\left[ S_2 \right]}{\left[ S_1 \right]} = \lambda \frac{\left[ E \right]}{\left[ F \right]}, \hspace{0.5 cm}  \textrm{ so } \hspace{0.5 cm} \frac{\left[ S_2 \right]}{\left[ S_0 \right]} = \lambda^2 \left( \frac{\left[ E \right]}{\left[ F \right] } \right)^2 \hspace{0.5 cm}  \textrm{ and more generally } \hspace{0.5 cm}  \frac{\left[ S_j \right]}{\left[ S_0 \right]} = \lambda^j  \left( \frac{\left[ E \right]}{\left[ F \right] } \right)^j \]

\item Use the result in part c to write the fraction of protein $S$ that is in the fully phosphorylated form as
\begin{eqnarray}
\frac{\left[ S_n \right]}{\left[ S_{\textrm{total}} \right]} = \frac{\left( \lambda u \right)^n}{1 + \lambda u + \left( \lambda u \right)^2 + \ldots + \left( \lambda u \right)^n} \label{eqn:prob1d}
\end{eqnarray}

where $u=[E]/[F]$ is the ratio of kinase to phosphatase concentrations. Hint: $[S_{\textrm{total}}] = [S_0] + [S_1] + [S_2] + \ldots + [S_n]$.

\item Use the ratio $[E]/[F]$ to approximate the ratio of total concentrations $[E_{\textrm{total}}]/[F_{\textrm{total}}]$, so that equation \ref{eqn:prob1d} describes the system's dose-response. Plot this function (vs. $u$) for various values of $n$. Take $\lambda = 1$ for simplicity. Use your plots to verify Gunawardena's conclusion that for high values of $n$, these dose-response curves exhibit a threshold (in this case, at $u=1$) but their behavior cannot be described as switch-like, as they show near-hyperbolic growth beyond the threshold, regardless of the values of $n$.
\end{enumerate}

\section*{Problem 3: Fixed Point Analysis (Adapted from Ingalls 4.8.3, 30 points)}

Consider the general linear system
\begin{eqnarray*}
\frac{dx}{dt} & = & ax + by\\
\frac{dy}{dt} & = & cx + dy
\end{eqnarray*}

Note that the steady state is $(x,y)=(0,0)$. Choose six sets of parameter values ($a$, $b$, $c$, and $d$) that yield the following behaviors:

\begin{enumerate}[a)]
\setlength{\itemsep}{0pt}
\item Stable node (real negative eigenvalues)
\item Stable spiral point (complex eigenvalues with negative real part)
\item Center (purely imaginary eigenvalues)
\item Unstable spiral point (complex eigenvalues with positive real part)
\item Unstable node (real positive eigenvalues)
\item Saddle point (real eigenvalues of different sign)
\end{enumerate}

In each case, prepare a phase portrait of the system, including a direction field and a few representative trajectories. (Note: Unlike the problem in Ingalls, we will not require that you include the nullclines.) Hint: if either of the off-diagonal entries in the Jacobian matrix are zero, then the eigenvalues are simply the entries on the diagonal.

\end{document}

problem sets/ps3/mcb 135 problem set 3.tex


\section{Strings}

\begin{frame}[fragile]
  \frametitle{What are Strings?}
  \begin{itemize}
  \item Anything quoted is a string
  \item Single quotes, double quotes or triple single/double quotes
  \item Any length --- single character, null string, \ldots
  \end{itemize}
  \begin{lstlisting}
   In[]: 'This is a string'
   In[]: "This is a string too"
   In[]: '''This is a string as well'''
   In[]: """This is also a string"""
   In[]: ''  # empty string
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Why so many?}
  \begin{itemize}
  \item Reduce the need for escaping
  \end{itemize}
  \begin{lstlisting}
   In[]: "Python's strings are powerful!"
   In[]: 'He said, "I love Python!"'
  \end{lstlisting}
  \begin{itemize}
  \item Triple quoted strings can be multi-line
  \item Used for doc-strings
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Assignment \& Operations}
  \begin{lstlisting}
   In[]: a = 'Hello'
   In[]: b = 'World'
   In[]: c = a + ', ' + b + '!'
  \end{lstlisting}
  \begin{itemize}
  \item Strings can be multiplied with numbers
  \end{itemize}
  \begin{lstlisting}
   In[]: a = 'Hello'
   In[]: a * 5
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Accessing Elements}
  \begin{lstlisting}
   In[]: print a[0], a[4], a[-1], a[-4]
  \end{lstlisting}
  \begin{itemize}
  \item Can we change the elements?
  \end{itemize}
  \begin{lstlisting}
   In[]: a[0] = 'H'
  \end{lstlisting}
  \begin{itemize}
  \item Strings are immutable!
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Problem - Day of the Week?}
  \begin{itemize}
  \item Strings have methods to manipulate them
  \end{itemize}
  \begin{block}{Problem}
    Given a list, \texttt{week}, containing names of the days of the
    week and a string \texttt{s}, check if the string is a day of the
    week. We should be able to check for any of the forms like,
    \emph{sat, Sat, SAT}
  \end{block}
  \begin{itemize}
  \item Get the first 3 characters of the string
  \item Convert it all to lower case
  \item Check for existence in the list, \texttt{week}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Slicing}
  \begin{lstlisting}
   In[]: q = "Hello World"
   In[]: q[0:3]
   In[]: q[:3]
   In[]: q[3:]
   In[]: q[:]
   In[]: q[-1:1]
   In[]: q[1:-1]
  \end{lstlisting}
  \begin{itemize}
  \item One or both of the limits, is optional
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Striding}
  \begin{lstlisting}
   In[]: q[0:5:1]
   In[]: q[0:5:2]
   In[]: q[0:5:3]
   In[]: q[0::2]
   In[]: q[2::2]
   In[]: q[::2]
   In[]: q[5:0:-1]
   In[]: q[::-1]
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{String Methods}
  \begin{lstlisting}
   In[]: s.lower()
   In[]: s.upper()
    s.<TAB>
  \end{lstlisting}
  \begin{itemize}
  \item \alert{Strings are immutable!}
  \item A new string is being returned
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Solution - Day of the Week?}
  \begin{lstlisting}
   In[]: s.lower()[:3] in week
  \end{lstlisting}
  OR
  \begin{lstlisting}
   In[]: s[:3].lower() in week
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{\texttt{join} a list of strings}
  \begin{itemize}
  \item Given a list of strings
  \item We wish to join them into a single string
  \item Possibly, each string separated by a common token
  \end{itemize}
  \begin{lstlisting}
  In[]: email_list = ["info@fossee.in",
                  "enquiries@fossee.in",
                  "help@fossee.in"]
  \end{lstlisting}
  \begin{lstlisting}
  In[]: '; '.join(email_list)
  In[]: ', '.join(email_list)
  \end{lstlisting}
\end{frame}

\section{Conditionals}

\begin{frame}[fragile]
  \frametitle{\texttt{if-else} block}
  \begin{lstlisting}
  In[]: a = 5
  In[]: if a % 2 == 0:
  ....:    print "Even"
  ....: else:
  ....:    print "Odd"
  \end{lstlisting}
  \begin{itemize}
  \item A code block -- \texttt{:} and indentation
  \item Exactly one block gets executed in the \texttt{if-else}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{\texttt{if-elif-else}}
  \begin{lstlisting}
   In[]: if a > 0:
   ....:     print "positive"
   ....: elif a < 0:
   ....:     print "negative"
   ....: else:
   ....:     print "zero"
  \end{lstlisting}
  \begin{itemize}
  \item Only one block gets executed, depending on \texttt{a}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{\texttt{else} is optional}
  \begin{lstlisting}
  In[]: if user == 'admin':
  ....:     admin_Operations()
  ....: elif user == 'moderator':
  ....:     moderator_operations()
  ....: elif user == 'client':
  ....:     customer_operations()
  \end{lstlisting}
  \begin{itemize}
  \item Note that there is no \texttt{else} block
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Ternary operator}
  \begin{itemize}
  \item \texttt{score\_str} is either \texttt{'AA'} or a string of one
    of the numbers in the range 0 to 100.
  \item We wish to convert the string to a number using \texttt{int}
  \item Convert it to 0, when it is \texttt{'AA'}
  \item \texttt{if-else} construct or the ternary operator
  \end{itemize}
  \begin{lstlisting}
   In[]: if score_str != 'AA':
   ....:     score = int(score_str)
   ....: else:
   ....:     score = 0
  \end{lstlisting}
  \begin{lstlisting}
   In[]: ss = score_str
   In[]: score = int(ss) if ss != 'AA' else 0
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{\texttt{pass}}
  \begin{itemize}
  \item \texttt{pass} is a syntactic filler
  \item When a certain block has no statements, a \texttt{pass} is
    thrown in
  \item Mostly, when you want to get back to that part, later.
  \end{itemize}
\end{frame}

\section{Loops}

\begin{frame}[fragile]
  \frametitle{\texttt{while}}
  \begin{itemize}
  \item Print squares of all odd numbers less than 10 using
    \texttt{while}
  \end{itemize}
  \begin{lstlisting}
  In[]: i = 1

  In[]: while i<10:
  ....:     print i*i
  ....:     i += 2
  \end{lstlisting}
  \begin{itemize}
  \item The loops runs as long as the condition is \texttt{True}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{\texttt{for}}
  \begin{itemize}
  \item Print squares of all odd numbers less than 10 using
    \texttt{for}
  \end{itemize}
  \begin{lstlisting}
  In[]: for n in [1, 2, 3]:
  ....:     print n
  \end{lstlisting}
  \begin{itemize}
  \item \texttt{for} iterates over each element of a sequence
  \end{itemize}
  \begin{lstlisting}
  In[]: for n in [1, 3, 5, 7, 9]:
  ....:     print n*n

  In[]: for n in range(1, 10, 2):
  ....:     print n*n
  \end{lstlisting}
  \begin{itemize}
  \item \alert{range([start,] stop[, step])}
  \item Returns a list; Stop value is not included.
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{\texttt{break}}
  \begin{itemize}
  \item breaks out of the innermost loop.
  \item Squares of odd numbers below 10 using \texttt{while} \&
    \texttt{break}
  \end{itemize}
  \begin{lstlisting}
  In[]: i = 1

  In[]: while True:
  ....:     print i*i
  ....:     i += 2
  ....:     if i>10:
  ....:         break
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{\texttt{continue}}
  \begin{itemize}
  \item Skips execution of rest of the loop on current iteration
  \item Jumps to the end of this iteration
  \item Squares of all odd numbers below 10, not multiples of 3
  \end{itemize}
  \begin{lstlisting}
  In[]: for n in range(1, 10, 2):
  ....:     if n%3 == 0:
  ....:         continue
  ....:     print n*n
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Problem - Day of the Week?}
  \begin{itemize}
  \item Strings have methods to manipulate them
  \end{itemize}
  \begin{block}{Problem}
    Given a list, \texttt{week}, containing names of the days of the
    week and a string \texttt{s}, check if the string is a day of the
    week. We should be able to check for any of the forms like,
    \emph{sat, saturday, Sat, Saturday, SAT, SATURDAY}
  \end{block}
  \begin{itemize}
  \item Get the first 3 characters of the string
  \item Convert it all to lower case
  \item Check for existence in the list, \texttt{week}
  \end{itemize}
\end{frame}

\section{Lists}

\begin{frame}[fragile]
  \frametitle{Creating Lists}
  \begin{lstlisting}
   In[]: empty = []

   In[]: p = ['spam', 'eggs', 100, 1.234]
   In[]: q = [[4, 2, 3, 4], 'and', 1, 2, 3, 4]
  \end{lstlisting}
  \begin{itemize}
  \item Lists can be empty, with no elements in them
  \item Lists can be heterogeneous -- every element of different kind
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Accessing Elements}
  \begin{lstlisting}
  In[]: print p[0], p[1], p[3]

  In[]: print p[-1], p[-2], p[-4]
  In[]: print p[10]
  \end{lstlisting}
  \begin{itemize}
  \item Indexing starts from 0
  \item Indexes can be negative
  \item Indexes should be in the valid range
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Accessing Elements \& length}
  \begin{lstlisting}
  In[]: print p[0], p[1], p[3]

  In[]: print p[-1], p[-2], p[-4]
  In[]: print len(p)
  In[]: print p[10]
  \end{lstlisting}
  \begin{itemize}
  \item Indexing starts from 0
  \item Indexes can be negative
  \item Indexes should be within the \texttt{range(0, len(p))}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Adding \& Removing Elements}
  \begin{itemize}
  \item The append method adds elements to the end of the list
  \end{itemize}
  \begin{lstlisting}
  In[]: p.append('onemore')
  In[]: p
  In[]: p.append([1, 6])
  In[]: p
  \end{lstlisting}
  \begin{itemize}
  \item Elements can be removed based on their index OR
  \item based on the value of the element
  \end{itemize}
  \begin{lstlisting}
   In[]: del p[1]
   In[]: p.remove(100)
  \end{lstlisting}
  \begin{itemize}
  \item \alert{When removing by value, first element is removed}
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Concatenating lists}
  \begin{lstlisting}
  In[]: a = [1, 2, 3, 4]
  In[]: b = [4, 5, 6, 7]
  In[]: a + b
  In[]: print a+b, a, b
  \end{lstlisting}
  \begin{itemize}
  \item A new list is returned; None of the original lists change
  \end{itemize}
  \begin{lstlisting}
   In[]: c = a + b
   In[]: c
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Slicing \& Striding}
  \begin{lstlisting}
  In[]: primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
  In[]: primes[4:8]
  In[]: primes[:4]

  In[]: num = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
  In[]: num[1:10:2]
  In[]: num[:10]
  In[]: num[10:]
  In[]: num[::2]
  In[]: num[::-1]
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Sorting}
  \begin{lstlisting}
  In[]: a = [5, 1, 6, 7, 7, 10]
  In[]: a.sort()
  In[]: a
  \end{lstlisting}
  \begin{itemize}
  \item \texttt{sort} method sorts the list in-place
  \item Use \texttt{sorted} if you require a new list
  \end{itemize}
  \begin{lstlisting}
  In[]: a = [5, 1, 6, 7, 7, 10]
  In[]: sorted(a)
  In[]: a
  \end{lstlisting}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Reversing}
  \begin{lstlisting}
  In[]: a = [5, 1, 6, 7, 7, 10]
  In[]: a.reverse()
  In[]: a
  \end{lstlisting}
  \begin{itemize}
  \item \texttt{reverse} method reverses the list in-place
  \item Use \texttt{[::-1]} if you require a new list
  \end{itemize}
  \begin{lstlisting}
  In[]: a = [5, 1, 6, 7, 7, 10]
  In[]: a[::-1]
  In[]: a
  \end{lstlisting}
\end{frame}


\chapter{Foundations}

\section{Categories of Ideas: Entity, Species, Genus}

In order to explain learning procedures we must understand objects and types from computer
programming as well as observations and esimation from statistics.  To assist with these
conceptual foundations we use the taxonomy from \cite[Chapter~1,Section~1]{stepanov2009elements}
to describe entities, species, and genus.


\subsection{Effect of Gravitational waves on objects}

Gravitational waves carry the fluctuations of space along with them. So if they move through an object, since space itself will oscillate, even the object which occupies space will oscillate according to the wave. Thus the shape of object will change periodically.

\subsubsection{Plus polarized effect}
When a plus polarized wave passes through the object, since such gravitational wave makes space-time oscillate in X and Y axes only. So the points in space along axis will come close during compression and go far during stretching. Thus the object itself will be compressed and stretched along the axes, perpendicular to the direction of propagation of wave.

\subsubsection{Cross polarized effect}
When a cross polarized wave passes through the object, since such gravitational wave makes space-time oscillate along the line which makes an inclination of 45$\degree$ with X and Y axes (i.e. along the line $x=y$ and $x=-y$). So the points in space along those line will come close during compression and go far during stretching. Thus the object itself will be compressed and stretched along those lines, perpendicular to the direction of propagation of wave.
\\

\begin{figure}[h]
    \centering
    \includegraphics[scale=0.42]{images.tex/effect_of_gw.jpeg}
    \caption{Shape of the object when gravitational wave passes through it when the phase difference of wave changes by $\pi/2$.\\
    \textbf{Source :-} Wavelet graphs for the detection of gravitational waves : application to eccentric binary black holes by Philippe Bacon}
\end{figure}

\begin{figure}[h]
    \centering
    \includegraphics[scale=0.4]{images.tex/polarization.jpeg}
    \caption{Pictorial representation of two Linear polarization of gravitational waves. \\ Source:- \url{https://www.researchgate.net/figure/fig4_228909324}}
\end{figure}

\pagebreak

gw-physics-and-ligo/3 Properties.tex/3.2 Effect of gw on object.tex


\documentclass[11pt,a4paper]{article}

% These are extra packages that you might need for writing the equations:
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage{hyperref}
\usepackage{listings}
\usepackage{xcolor}
\lstset {language=C++,
		 basicstyle=\ttfamily,
         keywordstyle=\color{blue}\ttfamily,
         stringstyle=\color{red}\ttfamily,
         commentstyle=\color{purple}\ttfamily,
         morecomment=[l][\color{magenta}]{\#},
       	 basicstyle=\tiny}

% You need the following package in order to include figures in your report:
\usepackage{graphicx}

% With this package you can set the size of the margins manually:
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\begin{document}

% Enter the exercise number, your name and date here:
\noindent\parbox{\linewidth}{
 \parbox{.25\linewidth}{ \large ICP, Exercise 05 }\hfill
 \parbox{.5\linewidth}{\begin{center} \large Beat Hubmann \end{center}}\hfill
 \parbox{.2\linewidth}{\begin{flushright} \large Oct 27, 2018 \end{flushright}}
}
\noindent\rule{\linewidth}{2pt}

\section{Introduction}

A Monte Carlo method to approximate the high-dimensional conditioned integration to calculate the average distance
between the centers of hard spheres in a box was implemented and examined for convergence.

\section{Algorithm Description}
To calculate the average sphere center distance as in equation~\ref{eqn:1}, the Monte Carlo approximation as in equation~\ref{eqn:2}
is calculated. The algorithm was implemented as in the written task description except for one change: Based on instructor suggestion,
a new configuration is generated in one go: $ n \cdot \text{\# dim} $ random numbers are generated in a contiguous batch and the resulting
configuration only then gets checked for validity. If an overlap between spheres is found, the complete configuration is thrown away and
 a new one is generated with a different random number generator seed. This is repeated until a valid configuration is found or
 a treshold of attempts is reached. \\

\begin{equation}
<d_{mean}> = \frac{1}{Z} \int d_{mean} \, d^3 r_1 \ldots d^3 r_n, \qquad Z = \int d^3 r_1 \ldots d^3 r_n
\label{eqn:1}
\end{equation}

\begin{equation}
<d_{mean}> \backsimeq \frac{1}{M} \sum_{k=1}^{M} d_{mean}^k
\label{eqn:2}
\end{equation}

 The overall algorithm description thus is: \\
 \begin{itemize}

 \item Generate configuration $k$ with $n$ sphere centers in a batch
 \item Check configuration validity; repeat if invalid, abort if repetition treshold reached and no valid configuration
 \item Calculate $d_{mean}^k$ for generated configuration
 \item Repeat until $M$ configurations generated to calculate $<d_{mean}> = \frac{1}{M}\sum_{k=1}^{M}d_{mean}^k$

\end{itemize}

\section{Results}

The program was implemented as described above and submitted with this report.
For a three-dimensional box with edge length $L=1$ and a sphere radius fixed at $R = 0.01$, experiments were run for $n \in \{2, 4, 8, 16, 32\}$ over ensemble
sizes $M \in \{1, 2, 4, 8, \ldots, 2^{20}\}$. For all experiments, the spheres were allowed to sit on the edges (in thus in extremis in the corners)
of the box (i.e. not all spheres were necessarily completely inside the box). While this has no relevance for the objective of the experiment
as such and can be easily compensated by adjusting $L$, it has an effect on the volume fraction $\nu$ discussed at the end.
The obtained data are all reflected by figure~\ref{fig:1}.

\begin{figure}[ht]
\begin{center}
\includegraphics[scale=0.9]{figure1.eps}
\end{center}
\caption{Convergence of $<d_{mean}>$ for different numbers of spheres $n$ and ensemble sizes $M$ (constant sphere radius $R=0.01$, constant box side length $L=1.0$).}
\label{fig:1}
\end{figure}

\section{Discussion}
As one would expect, it is evident that configurations with larger amounts of spheres $n$ converge quicker in the sense of ensemble size $M$ than configurations
with a low amount of spheres. This is because a higher $n$ "encourages" a uniform distribution of spheres in the box.
Also as expected, no matter what the number of spheres, all configurations eventually converge to the same value for $d_{mean}$ as the ensemble size $M$ increases.
Interestingly, the chosen approach of generating a complete configuration in a batch enforced rather low volume fractions $\nu$: Even when allowing for
$10^6$ attempts to generate a valid configuration, values of $n \gtrapprox 60$ at a sphere radius of $R = 0.01$ often resulted in aborts for a lot (but not all)
initial seeds. Therefore, experiments were adjusted to keep $\nu \lessapprox 60 \cdot \frac{4}{3}\pi \frac{R^3}{L^3} \approx 2.5 \cdot 10^{-4}$.

\begin{thebibliography}{99}

\bibitem{herrmann}
	Herrmann, H. J.,
	Singer, H. M.,
	Mueller L.,
	Buchmann, M.-A.,\\
	\emph{Introduction to Computational Physics - Lecture Notes},\\
	ETH Zurich,\\
	2017.

\end{thebibliography}

\end{document}


\documentclass[10pt]{article}
\usepackage{geometry}
\geometry{a4paper}
\pagestyle{myheadings}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{array}  % for table column M
\usepackage{makecell} % to break line within a cell
\usepackage{verbatim}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{xcolor}
\usepackage{ifthen}
\usepackage{setspace}
\usepackage{enumerate}% http://ctan.org/pkg/enumerate
\usepackage{placeins} % for FloatBarrier
\usepackage[makeroom]{cancel}
\usepackage[absolute,overlay]{textpos}
\usetikzlibrary{calc, angles,quotes}
\usetikzlibrary{pgfplots.fillbetween, backgrounds}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{pgfplots.groupplots}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{plotmarks}
\usetikzlibrary{decorations.markings}

\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}

\DeclareGraphicsExtensions{.pdf,.png,.jpg}
\graphicspath{{../figs/}}

\definecolor{blue2}{RGB}{51, 105, 232}
\definecolor{red2}{RGB}{213, 15, 37}
\definecolor{green2}{RGB}{0, 153, 37}

\input{preamble.tex}

%%%%%%%%%%%%% SOLUTIONS %%%%%%%%%%%%%%%%%
\def\SOLUTIONS{0} % change to 1 to produce solutions
\def\SolutionsColor{red2}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Header
\if\SOLUTIONS1
	\markboth{\em \color{\SolutionsColor} \textbf{EE264: Midterm Solutions}}{\em \color{\SolutionsColor} \textbf{EE264: Midterm Solutions}}
    \title{EE 264 Midterm Solutions}
\else
	\markboth{\em EE264: Midterm, August 1st -- Summer 2018}{\em EE264: Midterm, July 23 -- Summer 2018}
    \title{EE 264 Midterm}
\fi

% Document
\begin{document}
\input{cover.tex}
\pagebreak

\section*{Problem 1: Short questions (30 points)}

Please answer each of the following questions. Lengthy explanations or extensive derivations are not necessary. You may answer the questions with a few sentences, equations, or clearly labeled sketches or diagrams.

\begin{description}
\item[(a)] (3 points) Consider a linear and time invariant system with impulse response $h[n]$. The input to this system is the signal $x[n] = \delta[n] - 0.8\delta[n-3]$, where $\delta[n]$ is the unit impulse. Give an expression for the output $y[n]$ and its Fourier transform Fourier transform $Y(e^{j\omega}) = \mathcal{F}\{y[n]\}$. Your answers should be a function of $h[n]$ or $H(e^{j\omega})$.

\if\SOLUTIONS1
{\color{\SolutionsColor}
	The output is obtained by performing a convolution sum:
	\begin{equation}
		y[n] = \sum_{m=-\infty}^{\infty} x[m]h[n-m] = h[n] + h[n-3].
	\end{equation}

	Knowing $h[n]$ and we can easily compute it's Fourier transform: $H(e^{j\omega}) = H(e^{j\omega}) + H(e^{j\omega})e^{-j\omega 3}$.
}
\else\vspace{3cm}
\fi

%
\item[(b)] (6 points) Write the $z$-transform of the linear time invariant system defined by the difference equation:
\begin{equation}
y[n] - 0.5y[n-1] = x[n] - 2x[n-2],
\end{equation}
and determine if each statement about this system is \underline{true} or \underline{false}. Give a brief reason to support your assertion.

\begin{enumerate}\setlength\itemsep{2em}
  \item This system is causal
  \item This system is IIR
  \item The impulse response of this system converges to $h[n] \approx \sqrt{2}$ as $n\to \infty$
  \item This system has constant group delay over all frequencies
  \item This system has a causal and stable inverse.
\end{enumerate}

\if\SOLUTIONS1
{\color{\SolutionsColor} Applying the linearity and time-shift properties of the $z$-transform:
\begin{equation*}
H(z) = \frac{Y(z)}{X(z)} = \frac{1 - 2z^{-2}}{1 - 0.5z^{-1}} = \frac{z^2 - 2}{z(z - 0.5)}
\end{equation*}

\begin{enumerate}
  \item True. The output does not depend on future samples.
  \item True. The system has an pole away from the origin.
  \item False. The system is stable, since all poles are inside the unit circle. Thus, the impulse response must be absolute summable, and consequently $h[n] \to 0$, as $n\to\infty$.
  \item False. It is not FIR, and linear phase rational IIR systems do no exist.
  \item False. There zeros outside the unit circle.
\end{enumerate}
}
\else\vspace{4cm}
\fi

%
\item[(c)] (3 points) Consider the two systems defined below
\begin{equation}
	H_1(z) = \frac{1}{3}(1 + z^{-1} + z^{-2})\qquad H_2(z) = \frac{1 + z^{-1}}{1 - 0.5z^{-1}}.
\end{equation}
Suppose that we apply the signal $x[n] = \cos(n\pi/3)$ to both systems. Which system would produce the output signal with highest magnitude? Justify. Answers without justification will not receive any credit.

\if\SOLUTIONS1
{\color{\SolutionsColor}
System 2 would produce an output signal with highest magnitude because system 1 has a zero at frequency $\omega = \pi/3$, which is exactly the frequency of the input signal. Thus, the output of system 1 to signal $x[n]$ is zero.
}
\else\vspace{3cm}
\fi

\item[(d)] (6 points) The random signal $x[n]$ is such that at any given time $n$, we have
\begin{equation}
	x[n] = \begin{cases}
	1, &\text{with probability 0.5} \\
	0, &\text{with probability 0.5} \\
	\end{cases},
\end{equation}
This signal is filtered by a four-point moving average filter $H(z) = \frac{1}{4}(1 + z^{-1} + z^{-2} + z^{-3})$, producing the output signal $y[n]$. Compute the mean value of $y[n]$, $\E(y[n])$.

\if\SOLUTIONS1
{\color{\SolutionsColor}
	The input signal $x[n]$ is a Bernoulli process. Thus, we have
	\begin{equation}
		\E(x[n]) = 0.5(1) + 0.5(0) = 0.5
	\end{equation}

	The mean of a random process after an LTI system is scaled by the magnitude at zero frequency: $\E(y[n]) = H(e^{j0})\E(x[n])$.

	Recall that $z = e^{j\omega}$, thus for $\omega = 0 \implies z = 1$, $H(e^{j0}) = 1$. Therefore, $\E(y[n]) = 0.5$.
}
\else\vspace{5cm}
\fi

%
\item[(e)] (6 points) A zero-mean, discrete-time random signal $r[n]$ has autocorrelation function given by $\phi_{rr}[m] = \sigma^2\delta[m]$. This signal is filtered by a filter whose frequency response is given by

\begin{equation}
	H(e^{j\omega}) = \begin{cases}
	(1 - 4\omega/\pi)e^{-j\omega}, & |\omega| < 0.25\pi \\
	0, & 0.25\pi < |\omega| < \pi
	\end{cases}.
\end{equation}

What is the average power of the output noise filtered by $H(e^{j\omega})$?

\if\SOLUTIONS1
{\color{\SolutionsColor}
	Since the autocorrelation function is an impulse, the input noise has a white power spectrum density (PSD) with average power $\sigma^2$. The PSD of the output signal is simply $\Phi_{yy}(e^{j\omega}) = \sigma^2|H(e^{j\omega})|^2$. And the average power is the area under $\Phi_{yy}(e^{j\omega})$. Thus,

	\begin{align}
		\E(y^2[n]) &= \frac{1}{2\pi}\int_{-\pi}^{\pi} \Phi_{yy}(e^{j\omega})d\omega \\
		&= \frac{1}{2\pi}\int_{-\pi}^{\pi} \sigma^2|H(e^{j\omega})|^2 d\omega.
	\end{align}
	This integral $\int_{-\pi}^{\pi} |H(e^{j\omega})|^2 d\omega$ is simply the area under a triangle of height 1 and base $\pi/2$. Thus, $\E(y^2[n]) = \frac{\sigma^2}{8}$.
}
\else\vspace{6cm}
\fi

\item[(f)] (6 points) The following four facts are known about a LTI system with impulse response $h[n]$ and $z$-transform $H(z)$:
\begin{enumerate}[i]
	\item $h[n]$ is real valued.
	\item $h[n]$ has even symmetry.
	\item $h[n]$ is only zero outside the interval $0 \leq n \leq 4$.
	\item $H(z)$ has a zero at $z = 1/2e^{j\pi/4}$.
\end{enumerate}

Using this information, please answer the following questions. You must justify your answers. If the information given is not sufficient to answer one of the questions, please explain what information is lacking.

\begin{enumerate}
	\item Give all the poles and zeros of $H(z)$?

	\if\SOLUTIONS1
	{\color{\SolutionsColor}
		From (iii) we know that $h[n]$ is FIR with 5 coefficients, or equivalently the order of the filter is $M = 4$. From (ii) we know that $h[n]$ is even symmetric and therefore $h[n]$ has linear phase. Linear phase system with real coefficients (item (i)), have zeros that appear in conjugate reciprocal. Thus, from (iv) we can determine all the other four zeros of $H(z)$. They are $z = \{1/2e^{j\pi/4}, 1/2e^{-j\pi/4}, 2e^{j\pi/4}, 2e^{-j\pi/4}\}$. Since the system is FIR, all poles are at $z = 0$.
	}
	\else\vspace{4cm}
	\fi

	\item Is $H(z)$ system stable?

	\if\SOLUTIONS1
	{\color{\SolutionsColor}
		$H(z)$ is stable because its impulse response is finite, thus it is absolute summable.
	}
	\else\vspace{2cm}
	\fi

	\item Is $H(z)$ a minimum phase system?
		\if\SOLUTIONS1
	{\color{\SolutionsColor}
		This system is not minimum phase because it has zeros outside the unit circle.
	}
	\else\vspace{2cm}
	\fi

	\item Does $H(z)$ have a stable and causal inverse?
	\if\SOLUTIONS1
	{\color{\SolutionsColor}
		This is equivalent to asking whether $H(z)$ is minimum phase, which is answered above.
	}
	\else\vspace{2cm}
	\fi

	\item What is the group delay of $H(z)$?

	\if\SOLUTIONS1
	{\color{\SolutionsColor}
		The group delay of a linear phase FIR filter with $M+1$ coefficients is $M/2$. In this case, $M = 4$, thus the group delay is 2.
	}
	\else\vspace{1cm}
	\fi
\end{enumerate}

\end{description}
\newpage

\section*{Problem 2 (30 points)}
Consider the stable and causal system $H(z)$, whose system function is

\begin{equation}
	H(z) = \frac{(1 - 1.5e^{j3\pi/4}z^{-1})(1 - 1.5e^{-j3\pi/4}z^{-1})}{(1 - 0.5e^{j\pi/4}z^{-1})(1 - 0.5e^{-j\pi/4}z^{-1})}.
\end{equation}

\begin{description}
\item{(a)} (4 points)
Sketch the pole-zero diagram of $H(z)$ in the diagram given in Fig.~\ref{fig:pole-zero-sketch}a.

\begin{figure}[!h]
\centering
	\resizebox{0.45\textwidth}{!}{\input{figs/pole-zero-problem2.tex}}
    \caption{Pole-zero diagram of $H(z)$.} \label{fig:pole-zero-sketch}
\end{figure}

\item{(b)} (5 points) Use the figure blow to sketch the pole-zero diagram of $H_{min}(z)$ and $H_{ap}(z)$ so that $H(z) = H_{min}(z)H_{ap}(z)$, where $H_{min}(z)$ is a minimum-phase system and $H_{ap}(z)$ is an all-pass system.

\begin{figure}[!h]
	\centering
	\resizebox{0.9\textwidth}{!}{\input{figs/min-ap-decomposition.tex}}
	\caption{Minimum-phase and all-pass decomposition of $H(z)$.} \label{fig:min-all-pass}
\end{figure}

\item{(c)} (7 points) We can also decompose the system $H(z)$ such that $H(z) = H_{lin}(z)H_p(z)$, where $H_{lin}(z)$ is a linear phase system, and $H_p(z)$ is an all-pole system (only has zeros at $z = 0$). Sketch the pole-zero diagram of $H_{lin}(z)$ and $H_{p}(z)$ in Fig.~\ref{fig:lin-p}.

\begin{figure}[!h]
	\centering
	\resizebox{0.9\textwidth}{!}{\input{figs/lin-p-decomposition.tex}}
	\caption{Linear-phase / all-pole decomposition of $H(z)$.} \label{fig:lin-p}
\end{figure}

\item{(d)} (7 points) Suppose that we want to cascade another LTI system, $G(z)$, with $H(z)$ to perfectly compensate for the \underline{magnitude response} of $H(z)$. That is, we'd like to find a $G(z)$ such that $|H(e^{j\omega})G(e^{j\omega})| = 1$ for all $\omega$. Sketch the poles and zeros diagram of $G(z)$ in Fig.~\ref{fig:Hz-inverses}.

\if\SOLUTIONS1
{\color{\SolutionsColor}
	To obtain $|H(e^{j\omega})G(e^{j\omega})| = 1$, we must make $G(z) = H_{min}^{-1}(z)$. This way $|H(e^{j\omega})G(e^{j\omega})| = |H_{ap}(e^{j\omega})| = 1$. The poles and zeros diagram is shown in Fig.~\ref{fig:Hz-inverses}.
}
\else\vspace{1cm}
\fi
\item{(e)} (7 points) Now consider that we would like to use a different cascaded system $F(z)$ to perfectly compensate for the \underline{phase response} of $H(z)$. That is, we'd like to find a $F(z)$ such that $H(e^{j\omega})F(e^{j\omega})$ has linear phase. But we \underline{do not} require that $|H(e^{j\omega})F(e^{j\omega})|$ be constant. Sketch the poles and zeros diagram of $F(z)$ in Fig.~\ref{fig:Hz-inverses}.

\FloatBarrier
\begin{figure}[!h]
	\centering
	\resizebox{0.9\textwidth}{!}{\input{figs/Hz-inverses.tex}}
	\caption{Poles and zeros of $G(z)$ (left) and $F(z)$ (right).} \label{fig:Hz-inverses}
\end{figure}
\FloatBarrier

\if\SOLUTIONS1
{\color{\SolutionsColor}
	\begin{align} \nonumber
	H(e^{j\omega})F(e^{j\omega}) &= H_{lin}(e^{j\omega}) \\ \nonumber
	F(e^{j\omega}) &= \frac{H_{lin}(e^{j\omega})}{H(e^{j\omega})} = \frac{1}{H_p(e^{j\omega})} \implies F(z) = H_p^{-1}(z)
	\end{align}
}
\else\vspace{1cm}
\fi
\end{description}

\section*{Problem 3: Negative feedback loop (20 points)}
A linear time-invariant system $F(z)$ with input $x[n]$ and output $y[n]$ is described by the difference equation:
\begin{equation}
	y[n] + 4y[n-2] = x[n] -0.5x[n-1],
\end{equation}
\begin{description}
	\item[(a)] (7 points) Give the transfer function $F(z)$. Is this system causal? Is this system stable? What is the ROC of $F(z)$?

	\if\SOLUTIONS1
	{\color{\SolutionsColor}
		From the difference equation, we can see that the system is causal since it's output $y[n]$ only depends on current and previous samples of the input and output.

		To compute the $z$-transform we just need to apply the linearity and time delay properties of the $z$-transform:
		\begin{align} \nonumber
			Y(z) + 4Y(z)z^{-2} &= X(z) -0.5X(z)z^{-1} \\
			Y(z)(1 + 4z^{-2}) &= X(z)(1 -0.5z^{-1}) \\ \nonumber
			F(z) \equiv \frac{Y(z)}{X(z)} &= \frac{1 -0.5z^{-1}}{1 + 4z^{-2}} \\ \nonumber
			&= \frac{z(z - 0.5)}{z^2 + 4} = \frac{z(z - 0.5)}{(z -2j)(z + 2j)}
		\end{align}
		Thus, this system has two zeros at $z = 0$ and $z = 2$, and two poles at $z = \pm 2j$. As the poles are located outside the unit circle, this system is not stable. The ROC of a causal system is the exterior of a circle whose radius is the outermost poles. Thus, $\mathrm{ROC} = \{|z| > 2\}$.
	}
	\else\vspace{7cm}
	\fi

\end{description}
\noindent Suppose that $F(z)$ is interconnected in a negative-feedback arrangement with a causal, linear time-invariant system $G(z)$, as shown in Fig.~\ref{fig:feedback-loop}.

\begin{figure}[!h]
	\centering
	\resizebox{0.5\textwidth}{!}{\input{figs/feedback_loop.tex}}
	\caption{Negative feedback loop.} \label{fig:feedback-loop}
\end{figure}

\begin{description}

	\item[(b)] (7 points) Derive an expression for the overall system diagram $H(z)$. Your expression should depend on $F(z)$ and $G(z)$ only.

	\if\SOLUTIONS1
	{\color{\SolutionsColor}
		\begin{align} \nonumber
			Y(z) &= X(z)F(z) - Y(z)G(z)F(z) \\
			Y(z)(1 + G(z)F(z)) &= X(z)F(z) \\ \nonumber
			H(z) \equiv \frac{Y(z)}{X(z)} &= \frac{F(z)}{1 + G(z)F(z)}
		\end{align}
	}
	\else\vspace{5cm}
	\fi

	\item[(c)] (6 points) Find $G(z)$ such that $H(z) = 1$. Is the system $G(z)$ stable?

	\noindent Note: By achieving $H(z) = 1$, we're effectively \textit{controlling} the system $F(z)$. That is, we're making $F(z)$ produce whatever output we set it.

	\if\SOLUTIONS1
	{\color{\SolutionsColor}
		\begin{align} \nonumber
		z^{-1} &= \frac{F(z)}{1 + G(z)F(z)} \\ \nonumber
		z^{-1}(1 + G(z)F(z)) &= F(z) \\ \nonumber
		G(z) &= 1 - \frac{1}{F(z)} \\ \nonumber
		G(z) &= 1 - \frac{z^2 + 4}{z(z - 0.5)} \\ \nonumber
		G(z) &= -\frac{2(z + 2)}{z(z - 0.5)} \\ \nonumber
		\end{align}

		$G(z)$ is causal and it has all its poles inside the unit circle. Thus, it is stable.
	}
	\else\vspace{5cm}
	\fi

\end{description}

%\begin{figure}[!h]
%	\centering
%	\resizebox{0.6\textwidth}{!}{\input{figs/mag-autocorr.tex}}
%	\caption{Sketch of the PSD of the output of $h[n]$ for a white noise input.} \label{fig:mag-resp}
%\end{figure}

\newpage
\section*{Problem 4 (30 points)}

Fig.~\ref{fig:sampling_diagram} shows the block diagram of a digital-signal processing system involving sampling, downconversion, and upsampling. The input to this system $x_c(t)$ is a continuous-time signal, whose Fourier transform is shown in Fig.~\ref{fig:sampling_spectrum}a. This signal is band-limited with maximum frequency given by $\Omega_b$. Suppose that the sampling frequency of the continuous-to-digital converter (C-to-D) is $\Omega_s = 2\Omega_b$.

\begin{figure}[!h]
	\centering
	\resizebox{\textwidth}{!}{\input{figs/sampling_diagram.tex}}
	\caption{Block diagram of system for problem 4.}\label{fig:sampling_diagram}
\end{figure}

After sampling, the discrete-time signal $x[n]$ is \textit{down-converted}, which is realized by the time-domain multiplication with the signal $e^{-j\pi n}$. This results in the down-converted signal $x_d[n]$.

After down-conversion, the signal $x_d[n]$ is upsampled by a factor of 2. The resulting signal $x_e[n]$ is filtered by an ideal lowpass filter $H(z)$, whose Fourier transform is given by
\begin{equation}
	H(e^{j\omega}) = \begin{cases}
	1, &|\omega| \leq \pi/4, \\
	0, & \pi/4 < |\omega| < \pi
	\end{cases}.
\end{equation}

\begin{description}
\item[(a)] (28 points) Use the graphs below to sketch the Fourier transform of the signals $x[n]$, $x_d[n]$, $x_e[n]$, $x_f[n]$, obtained after each operation along the system block diagram. Be sure to clearly label all your plots, indicating values in the amplitude and frequency whenever appropriate. Sketches must be clearly labeled and unambiguous to receive full credit.
\end{description}
\begin{figure}[!h]
\centering
	\resizebox{0.87\textwidth}{!}{\input{figs/sampling_spectrum.tex}}
    \caption{Spectrum plots for Problem 4.} \label{fig:sampling_spectrum}
\end{figure}

\begin{description}
\item[(b)]  (2 points) Suppose that we would like to downsample the output signal $x_f[n]$. What is the largest downsampling rate that we could use to downsample $x_f[n]$ and still avoid aliasing? Justify. \\
\if\SOLUTIONS1
{\color{\SolutionsColor}
The largest downsampling factor is 4, since the ideal lowpass filter cutoff frequency is $\pi/4$.
}
\else\vspace{1cm}
\fi

\end{description}
\newpage
%\item[(b)] (6 points) Suppose that $\Omega_c = 8\pi$ rad/s and $\Omega_b = \pi$ rad/s. Draw the spectrum of $x[n]$ when $x_c(t)$ is sampled with sampling frequency $\Omega_s = 2\pi$ rad/s  (much smaller than the Nyquist rate).
%
%\begin{figure}[!h]
%\centering
%	\resizebox{\textwidth}{!}{\input{figs/bandpass_sampling_sol1.tex}}\label{fig:bp_spectrum_sol1}
%\end{figure}
%\if\SOLUTIONS0\vspace{5cm}
%\fi
%
%\item[(c)] (7 points) In part (b) you saw that there is no spectrum overlap, even though $x_c(t)$ was sampled below the Nyquist rate. Is that always possible? Give conditions on the sampling frequency $\Omega_s$ in terms of $\Omega_c$ and $\Omega_b$ so that: (i) the spectrum is centered around $\omega = 0$ as in Figure~\ref{fig:bp_spectrum1}b, \underline{and} (ii) such that there is no spectrum overlap.
%
%\textit{Hint:} The spectrum replicas occur according to the sampling equation:
%\begin{equation}
%X(e^{j\Omega T}) = \frac{1}{T}\sum_{k=-\infty}^\infty X_c(j(\Omega-k\Omega_s))
%\end{equation}
%
%\if\SOLUTIONS1
%{\color{\SolutionsColor}
%Staring with the sampling equation we have the following conditions:
%
%(i) In order to bring the signal down to baseband:
%\begin{align*}
%0 - k\Omega_s = \Omega_c \implies \Omega_c = -k\Omega_s
%\end{align*}
%for some negative integer $k$.
%
%(ii) The ($-k-1$)th spectrum replica must fall at least at $-2\Omega_b$ in order to avoid spectrum overlap. Therefore,
%\begin{align*} \nonumber
%-2\Omega_b - (k-1)\Omega_s &\geq \Omega_c \\ \nonumber
%-2\Omega_b - (k-1)\Omega_s &\geq -k\Omega_s \tag{since $\Omega_c = -k\Omega_s$} \\
%\Omega_s &\geq 2\Omega_b
%\end{align*}
%}
%\else\vspace{10cm}
%\fi
%
%
%\item[(d)] (5 points) Repeat part (b), but now assume that $\Omega_c = 7\pi$ rad/s and $\Omega_b = \pi$ rad/s. Sampling is still performed with sampling frequency $\Omega_s = 2\pi$ rad/s.
%
%\textit{Note:} Although there isn't spectrum overlap in this case either, further processing would be necessary to center the spectrum around $\omega = 0$, as in Figure~\ref{fig:bp_spectrum1}b.
%
%\begin{figure}[!h]
%\centering
%	\def\SolD{1}
%	\resizebox{\textwidth}{!}{\input{figs/bandpass_sampling_sol1.tex}} \label{fig:bp_spectrum_sol1}
%\end{figure}
%\if\SOLUTIONS0\vspace{5cm}
%\fi
%
%\end{description}
%
%\newpage
%\section*{Problem 4: (20 points)}
%The diagram of Figure~\ref{fig:sampling_diagram} represents the initial DSP of a high-speed application. Since fast ADCs are expensive, the design engineers decided to perform Nyquist-rate sampling and upsample the signal immediately after the ADC, as illustrated in Figure~\ref{fig:sampling_diagram}. The lowpass filter $H(z)$ after upsampling is used to eliminate unwanted spectrum replicas of the signal and of quantization noise. The additive white  noise introduced by the quantizer has average power $\sigma_Q^2$.
%
%
%
%\begin{description}
%\item[(a)] (8 points) The plot below shows the spectrum $X(e^{j\omega})$ with signal (triangular shape) and quantization noise (dashed red line) components. Use the empty graphs below to sketch $X_e(e^{j\omega})$ and $Y(e^{j\omega})$. In your plots, draw both the signal and noise components. Assume that $H(z)$ is the ideal lowpass filter with cutoff frequency $\pm\pi/2$ and \underline{unit gain}.
%
%\textit{Hint:} consider signal and noise separately.
%
%\FloatBarrier
%\begin{figure}[!h]
%\centering
%	\resizebox{0.9\textwidth}{!}{\input{figs/spectrum_upsampled.tex}} \label{fig:spectrum_upsample}
%\end{figure}
%\FloatBarrier
%
%\item[(b)] (6 points) Now assume that $H(z)$ is the first-order lowpass filter given by
%\begin{equation}
%H(z) = \frac{1 + cz^{-1}}{1 - cz^{-1}}, \qquad 0 < c < 1.
%\end{equation}
%
%Assume that this filter is implemented using the transposed direct form II with signal values and filter coefficients scaled as Q15 integers. The result of multiplications is quantized to 16-bits (15 bits plus sign) \underline{immediately after} the multiplications and \underline{before} any additions are done. Draw the signal flow graph diagram of this system. In your drawing include noise sources representing the quantization of the multiplications. Label each noise source with average power $\sigma_{15}^2$. You may combine noise sources whenever possible. In addition, circle \underline{all nodes} in which overflow may happen.
%
%\textit{Note:} You do not need to include noise sources in multiplications by 1.
%
%\if\SOLUTIONS1
%{\color{\SolutionsColor}
%Overflow may happen in any node in which additions are performed. Multiplications do not overflow.
%
%The noise sources were combined into one with average power $2\sigma_{15}^2$. Note that since $b_0 = 1$, in this case, then this multiplication is not performed and therefore we should not include a noise source for it.
%
%\FloatBarrier
%\begin{figure}[h!]
%\centering
%	\def\SolD{1}
%	\resizebox{0.5\textwidth}{!}{\input{figs/IIR_transposed_direct_form_II.tex}}
%\end{figure}
%\FloatBarrier
%}
%\else\vspace{7cm}
%\fi
%
%\item{(c)} (6 points) Write an equation for the PSD of the total noise at the output of $H(z)$. The total noise includes quantization noise from the quantizer and roundoff noise from your filter implementation in part (b). Write your answer in terms of $\sigma_{15}^2$, $\sigma_{Q}^2$, and $c$.
%
%\if\SOLUTIONS1
%{\color{\SolutionsColor}
%Using superposition, we see that the quantization noise is filtered by $H(z)$, while the roundoff noise is filtered only by the poles of $H(z)$, which we'll denoted by $\frac{1}{A(z)}$. Therefore,
%
%\begin{align*}
%\Phi_{ff}(e^{j\omega}) &= \sigma_Q^2|H(e^{j\omega})|^2 + 2\sigma_{15}^2\frac{1}{|A(e^{j\omega})|} \\
%&= \sigma_Q^2|H(e^{j\omega})|^2 + 2\sigma_{15}^2\frac{1}{|A(e^{j\omega})|} \\
%& = \frac{\sigma_Q^2(1 + c^2 + 2c\cos\omega) + 2\sigma_{15}^2}{1 + c^2 - 2c\cos\omega}
%\end{align*}
%
%}
%\else\vspace{5cm}
%\fi
%\end{description}

\end{document}