# Quantum Computing

**text to come**

$$
\begin{equation}
   \Psi(x,t)=\Psi(x,t)_a+\Psi(x,t)_b,
\label{_auto1} \tag{1}
\end{equation}
$$

$$
\begin{equation}
    |q\rangle = \alpha \vert 0 \rangle + \beta |1\rangle,
\label{_auto2} \tag{2}
\end{equation}
$$

$$
\begin{equation}
    |q\rangle = \frac{1}{\sqrt{2}}(\vert 0 \rangle + |1\rangle),
\label{_auto3} \tag{3}
\end{equation}
$$

$$
\begin{equation}
    |\psi\rangle = a_0|\psi\rangle_0+a_1|\psi\rangle_1+a_2|\psi\rangle_2+a_3|\psi\rangle_3+a_4|\psi\rangle_4+a_5|\psi\rangle_5+a_6|\psi\rangle_6+a_7|\psi\rangle_7,
\label{eq:dataord} \tag{4}
\end{equation}
$$

$$
\begin{equation}
    \hat{H}\vert 0 \rangle=
    \frac{1}{\sqrt{2}}(\vert 0 \rangle +|1\rangle),
\label{_auto4} \tag{5}
\end{equation}
$$

$$
\begin{equation}
    \hat{H}|1\rangle=
    \frac{1}{\sqrt{2}}(\vert 0 \rangle -|1\rangle).
\label{_auto5} \tag{6}
\end{equation}
$$

$$
\begin{equation}
    \hat{H}\hat{H}\vert 0 \rangle=
    \hat{H}\frac{1}{\sqrt{2}}(\vert 0 \rangle +|1\rangle)
    =\vert 0 \rangle,
\label{_auto6} \tag{7}
\end{equation}
$$

$$
\begin{equation}
    \hat{H}\hat{H}|1\rangle=
    \hat{H}\frac{1}{\sqrt{2}}(\vert 0 \rangle -|1\rangle)
    =|1\rangle.
\label{_auto7} \tag{8}
\end{equation}
$$

$$
\begin{equation}
   \vert 0 \rangle=\left(\begin{array}{c} 1 \\ 0\end{array}   \right),
\label{_auto8} \tag{9}
\end{equation}
$$

$$
\begin{equation}
   |1\rangle=\left(\begin{array}{c} 0 \\ 1\end{array}   \right),
\label{_auto9} \tag{10}
\end{equation}
$$

og

$$
\begin{equation}
   \hat{H}=\frac{1}{\sqrt{2}}
   \left(\begin{array}{cc} 1 & 1 \\ 1& -1\end{array}   \right).
\label{_auto10} \tag{11}
\end{equation}
$$

$$
\begin{equation}
   \hat{H}_{\mathrm{NOT}}=
   \left(\begin{array}{cc} 0 & 1 \\ 1& 0\end{array}   \right).
\label{_auto11} \tag{12}
\end{equation}
$$

$$
\begin{equation}
   \hat{H}_{\mathrm{NOT}}\vert 0 \rangle=
   \left(\begin{array}{cc} 0 & 1 \\ 1& 0\end{array}\right)
   \left(\begin{array}{c} 1 \\ 0\end{array}   \right)=
   \left(\begin{array}{c} 0 \\ 1\end{array}   \right)=|1\rangle,
\label{_auto12} \tag{13}
\end{equation}
$$

$$
\begin{equation}
   \hat{H}_{\mathrm{NOT}}|1\rangle=
   \left(\begin{array}{cc} 0 & 1 \\ 1& 0\end{array}\right)
   \left(\begin{array}{c} 0 \\ 1\end{array}   \right)=
   \left(\begin{array}{c} 1 \\ 0\end{array}   \right)=\vert 0 \rangle.
\label{_auto13} \tag{14}
\end{equation}
$$

$$
\begin{equation}
   \hat{H}_{\Phi}\vert 0 \rangle=e^{i\phi}\vert 0 \rangle,
\label{_auto14} \tag{15}
\end{equation}
$$

og

$$
\begin{equation}
   \hat{H}_{\Phi}|1\rangle=|1\rangle,
\label{_auto15} \tag{16}
\end{equation}
$$

$$
\begin{equation}
   \hat{H}_{\Phi}=
   \left(\begin{array}{cc} e^{i\phi} & 0 \\ 0& 1\end{array}   \right).
\label{_auto16} \tag{17}
\end{equation}
$$

$$
\begin{equation}
    |q\rangle_{in} = \alpha \vert 0 \rangle_{in} + \beta |1\rangle_{in},
\label{_auto17} \tag{18}
\end{equation}
$$

$$
\begin{equation}
    |q\rangle_{ut}=\hat{H}|q\rangle_{in} =
    \frac{1}{\sqrt{2}}((\alpha+\beta)\vert 0 \rangle_{ut} +
    (\alpha-\beta)|1\rangle_{ut}),
\label{_auto18} \tag{19}
\end{equation}
$$

$$
\begin{equation}
   |q\rangle_{ut}=\hat{H}\hat{H}|q\rangle_{in}=|q\rangle_{in}.
\label{_auto19} \tag{20}
\end{equation}
$$

$$
\begin{equation}
   \hat{H}\hat{\Phi}\hat{H}\vert 0 \rangle,
\label{_auto20} \tag{21}
\end{equation}
$$

$$
\begin{equation}
    \frac{1}{\sqrt{2}}((e^{i\phi}+1)\vert 0 \rangle +
    (e^{i\phi}-1)|1\rangle).
\label{_auto21} \tag{22}
\end{equation}
$$

$$
\begin{equation}
   \frac{\vert 0 \rangle_1 |1\rangle_2 + |1\rangle_1\vert 0 \rangle_2}{\sqrt{2}},
\label{eq:superent} \tag{23}
\end{equation}
$$

$$
\begin{equation}
   \frac{|+\rangle_1 |-\rangle_2 - |-\rangle_1|+\rangle_2}{\sqrt{2}},
\label{eq:superent1} \tag{24}
\end{equation}
$$

$$
\begin{equation}
    |q\rangle_{1} = \alpha_1 \vert 0 \rangle_{1} + \beta_1 |1\rangle_{1},
\label{_auto22} \tag{25}
\end{equation}
$$

$$
\begin{equation}
     |q\rangle_{12}= |q\rangle_{1} |q\rangle_{2}
\label{_auto23} \tag{26}
\end{equation}
$$

eller

$$
\begin{equation}
   |q\rangle_{12}=\alpha_1 \alpha_2\vert 0 \rangle_1\vert 0 \rangle_2 +
                  \alpha_1 \beta_2\vert 0 \rangle_1|1\rangle_2 +
                  \beta_1 \alpha_2|1\rangle_1\vert 0 \rangle_2 +
                  \beta_1 \beta_2|1\rangle_1|1\rangle_2,
\label{_auto24} \tag{27}
\end{equation}
$$

$$
\begin{equation}
   |q\rangle_{ut}=\hat{H}|q\rangle_{in},
\label{_auto25} \tag{28}
\end{equation}
$$

$\hat{H}^{\dagger}=\hat{H}$ og $\hat{H}^{\dagger}\hat{H}=1$,

$$
\begin{equation}
   \hat{H}^{\dagger}|q\rangle_{ut}=\hat{H}^{\dagger}\hat{H}|q\rangle_{in}=
   |q\rangle_{in}.
\label{_auto26} \tag{29}
\end{equation}
$$

$$
\begin{equation}
   \vert 0 \rangle_{c}  \vert 0 \rangle_{t}\rightarrow
   \vert 0 \rangle_{c}  \vert 0 \rangle_{t},
\label{_auto27} \tag{30}
\end{equation}
$$

$$
\begin{equation}
   \vert 0 \rangle_{c}  |1\rangle_{t}\rightarrow
   \vert 0 \rangle_{c}  |1\rangle_{t},
\label{_auto28} \tag{31}
\end{equation}
$$

$$
\begin{equation}
   |1\rangle_{c}  \vert 0 \rangle_{t}\rightarrow
   |1\rangle_{c}  |1\rangle_{t},
\label{_auto29} \tag{32}
\end{equation}
$$

$$
\begin{equation}
   |1\rangle_{c}  |1\rangle_{t}\rightarrow
   |1\rangle_{c}  \vert 0 \rangle_{t}.
\label{_auto30} \tag{33}
\end{equation}
$$

$$
\begin{equation}
   \hat{H}_{\mathrm{CNOT}}=
    \left(\begin{array}{cccc} 1 & 0 & 0 &0  \\
                              0 & 1 & 0 &0  \\
                              0& 0 & 0 &1  \\
                              0 & 0 & 1 &0\end{array}\right),
\label{_auto31} \tag{34}
\end{equation}
$$

$\vert 0 \rangle_c\vert 0 \rangle_t$, $\vert 0 \rangle_c|1\rangle_t$, $|1\rangle_c\vert 0 \rangle_t$
$|1\rangle_c|1\rangle_t$.

$$
\begin{equation}
   \vert 0 \rangle_c\vert 0 \rangle_t=\left(\begin{array}{c} 1  \\
                                                 0  \\
                                                 0  \\
                                                 0  \end{array}\right),
\label{_auto32} \tag{35}
\end{equation}
$$

$$
\begin{equation}
   \vert 0 \rangle_c|1\rangle_t=\left(\begin{array}{c} 0  \\
                                                 1  \\
                                                 0  \\
                                                 0  \end{array}\right),
\label{_auto33} \tag{36}
\end{equation}
$$

$$
\begin{equation}
   |1\rangle_c\vert 0 \rangle_t=\left(\begin{array}{c} 0  \\
                                                 0  \\
                                                 1  \\
                                                 0  \end{array}\right),
\label{_auto34} \tag{37}
\end{equation}
$$

og

$$
\begin{equation}
   |1\rangle_c|1\rangle_t=\left(\begin{array}{c} 0  \\
                                                 0  \\
                                                 0  \\
                                                 1  \end{array}\right).
\label{_auto35} \tag{38}
\end{equation}
$$

$$
\begin{equation}
   \hat{H}_{\mathrm{CNOT}}|1\rangle_c|1\rangle_t=
    \left(\begin{array}{cccc} 1 & 0 & 0 &0  \\
                              0 & 1 & 0 &0  \\
                              0& 0 & 0 &1  \\
                              0 & 0 & 1 &0\end{array}\right)
                              \left(\begin{array}{c} 0  \\
                                                 0  \\
                                                 0  \\
                                                 1  \end{array}\right)=
\left(\begin{array}{c} 0  \\
                                                 0  \\
                                                 1  \\
                                                 0  \end{array}\right),
\label{_auto36} \tag{39}
\end{equation}
$$

$|1\rangle_c\vert 0 \rangle_t$, dvs. target-biten forandrer verdi fra bit '1'
til bit '0' når kontroll-biten har verdi bit '1'.

## Hamiltonians

A general two-body Hamiltonian for fermionic system
can be written as

$$
\begin{equation}
\label{eq:twobodyH} \tag{40}
H = E_0 + \sum_{ij=1} E_{ij} a^\dag_i a_j
+\sum_{ijkl = 1} V_{ijkl} a^\dag_i a^\dag_j a_l a_k,
\end{equation}
$$

where $E_0$ is a constant energy term, $E_{ij}$ represent all the
one-particle terms, allowing for non-diagonal terms as well. The
one-body term can represent
a chosen single-particle potential, the kinetic energy or other more
specialized terms such as
those discussed in connection with the Hubbard model or the pairing Hamiltonian
discussed below.
The two-body interaction part is given by $V_{ijkl}$ and can be any
two-body interaction, from
Coulomb interaction to the interaction between nucleons.
The sums run over all possible single-particle levels $N$.
Note that
this model includes particle numbers from zero to the number of
available quantum levels, $n$. To simulate states with fixed numbers
of fermions one would have to either rewrite the Hamiltonian or
generate specialized input states in the simulation.

The algorithm which we will develop in this section and in
However,
in our demonstrations of the quantum computing algorithm, we will limit ourselves to
two simple models, which however capture much of the important physics
in quantum mechanical
many-body systems. We will also limit ourselves to spin $j=1/2$
systems, although our algorithm
can also simulate  higher $j$-values, such as those which occur in nuclear, atomic and
molecular physics, it simply uses one qubit for every available
quantum state.
These simple models are the Hubbard model and a pairing
Hamiltonian.
We start with the spin $1/2$ Hubbard model, described by the following Hamiltonian

$$
\begin{equation}
H_H = \epsilon \sum_{i, \sigma} a_{i\sigma}^\dag a_{i\sigma}
-t \sum_{i, \sigma} \left(a^\dag_{i+1, \sigma}a_{i, \sigma}
+a^\dag_{i, \sigma}a_{i+1, \sigma} \right) \notag
\label{_auto37} \tag{41}
\end{equation}
$$

$$
\begin{equation}
 + U \sum_{i=1} a_{i+}^\dag a_{i-}^\dag a_{i-}a_{i+},
\label{eq:hubbard} \tag{42}
\end{equation}
$$

where $a^{\dagger}$ and $a$ are fermion creation and annihilation operators, respectively.
This is a chain of sites where each site has room for one spin up
fermion and one spin down fermion.
The number of sites is $N$, and the sums over $\sigma$ are sums over
spin up and down only.
Each site has a single-particle
energy $\epsilon$. There is a repulsive term $U$ if there is a pair
of particles at the same site. It is energetically favourable to tunnel to
neighbouring sites, described by
the hopping terms with coupling constant $-t$.

The second model-Hamiltonian is the simple pairing Hamiltonian

$$
\begin{equation}
   H_P=\sum_i \varepsilon_i a^{\dagger}_i a_i -\frac{1}{2} g\sum_{ij>0}
           a^{\dagger}_{i}
     a^{\dagger}_{\bar{\imath}}a_{\bar{\jmath}}a_{j},
\label{eq:pairing} \tag{43}
\end{equation}
$$

The indices $i$ and $j$ run over the number of levels $N$, and the label $\bar{\imath}$
stands for a time-reversed state. The parameter $g$ is the strength of the pairing force
while $\varepsilon_i$ is the single-particle energy of level $i$.
In our case
we assume that the single-particle levels are equidistant (or
degenerate) with a fixed spacing $d$.
Moreover, in our simple model, the degeneracy of the single-particle
levels is set to $2j+1=2$, with $j=1/2$
being the spin of the particle. This gives a set of single-particle
states with the same spin projections as
for the Hubbard model.  Whereas in the Hubbard model we operate with
different sites with
spin up or spin down particles, our pairing models deals thus with
levels  with double degeneracy.
Introducing the pair-creation operator
$S^+_i=a^{\dagger}_{im}a^{\dagger}_{i-m}$,
one can rewrite the Hamiltonian in
Eq. ([43](#eq:pairing)) as

$$
H_P=d\sum_iiN_i+
     \frac{1}{2} G\sum_{ij>0}S^+_iS^-_j,
$$

where  $N_i=a^{\dagger}_i a_i$
is the number operator, and
$\varepsilon_i = id$ so that the single-particle orbitals
are equally spaced at intervals $d$. The latter commutes with the
Hamiltonian $H$. In this model, quantum numbers like seniority
$\cal{S}$ are good quantum numbers, and the eigenvalue problem
can be rewritten in terms of blocks with good seniority.
Loosely
speaking, the seniority quantum number $\cal{S}$ is equal to
the number of unpaired particles.
Furthermore, in  a series of papers, Richardson
obtained the exact solution of the pairing Hamiltonian, with
semi-analytic (since there is still the need for a numerical solution)
expressions for the eigenvalues and eigenvectors. The exact solutions
have had important consequences for several fields, from Bose condensates to
nuclear superconductivity and is currently a very active field of studies, see for example
Finally, for particle numbers up to $P \sim 20$, the above model can be
solved exactly through numerical diagonalization and one can obtain all eigenvalues.
It serves therefore also as an excellent ground for comparison with our algorithm based
on models from quantum computing.

## Basic quantum  gates

Benioff showed that one could make a quantum mechanical Turing machine
by using various  unitary operations on a quantum system.
Benioff  demonstrated
that a quantum computer can calculate anything a
classical computer can. To do this one needs a quantum system and
basic operations that can approximate all unitary operations
on the chosen many-body system. We describe in this subsection the basic ingredients entering
our algorithms.

### Qubits, gates and circuits

In this article we will use the standard model of quantum information,
where
the basic unit of information is the qubit, the quantum bit.
As mentioned in the introduction, any
suitable
two-level quantum system can be a qubit,
it is the smallest system there is with the
least complex dynamics.
Qubits are both abstract measures of information and physical objects.
Actual physical qubits can be ions trapped in magnetic fields where
lasers can access only two energy levels or  the nuclear spins of some of
the atoms in molecules accessed and manipulated by an NMR machine.
Several other ideas have been proposed and some tested.

The computational basis for one qubit is ${\ensuremath{\vert 0 \rangle}}$ (representing for example bit $0$)
for the first state
and ${\ensuremath{|1\rangle}}$ (representing bit $1$) for the second, and for a set of qubits
the tensor products of
these basis states for each qubit form a product basis. Below we write out the different
basis states for a system of $n$ qubits.

$$
\begin{equation}
\label{eq:compBasis} \tag{44}
{\ensuremath{\vert 0 \rangle}} \equiv {\ensuremath{\vert 00\cdots 0 \rangle}} =
      {\ensuremath{\vert 0 \rangle}} \otimes {\ensuremath{| 0 \rangle}} \otimes
          \cdots
\otimes {\ensuremath{\vert 0 \rangle}}
\notag
\end{equation}
$$

$$
\begin{equation}
{\ensuremath{|1\rangle}} \equiv {\ensuremath{\vert 00\cdots 1\rangle}} =
    {\ensuremath{\vert 0 \rangle}} \otimes {\ensuremath{| 0 \rangle}} \otimes
        \cdots
\otimes {\ensuremath{|1\rangle}}
\notag
\label{_auto38} \tag{45}
\end{equation}
$$

$$
\begin{equation}
\vdots \notag
\label{_auto39} \tag{46}
\end{equation}
$$

$$
\begin{equation}
{\ensuremath{|2^n-1\rangle}} \equiv {\ensuremath{|11\cdots 1\rangle}} =
    {\ensuremath{|1\rangle}} \otimes {\ensuremath{| 1\rangle}} \otimes
\cdots \otimes {\ensuremath{|1 \rangle}}.
\notag
\label{_auto40} \tag{47}
\end{equation}
$$

$$
\begin{equation}
\label{_auto41} \tag{48}
\end{equation}
$$

This is a $2^n$-dimensional system and we number the different basis
states using binary numbers corresponding to the order in which they appear in the
tensor product.

Quantum computing means to  manipulate and measure  qubits in such a
way that the results from a measurement yield the solutions to  a given problem.
The quantum operations we need to be able to perform our simulations are
a small set of elementary single-qubit
operations, or single-qubit gates, and one universal two-qubit gate,
in our case the so-called CNOT gate defined below.

To represent quantum computer algorithms graphically we use circuit
diagrams. In a circuit diagram each qubit is represented by a line,
and operations on the different qubits are represented by boxes.

## Number of work qubits versus number of simulation qubits

The largest possible amount of different eigenvalues is $2^s$, where
$s$ is the number of simulation qubits. The resolution in the energy
spectrum we get from measuring upon the work qubits is $2^w$, with $w$ the number of
work qubits.
Therefore the resolution per eigenvalue in a non-degenerate system is
$2^{w-s}$. The higher the degeneracy the less work qubits are needed.

## Number of operations

Counting the number of single-qubit and $\sigma_z\sigma_z$ operations
for different sizes of systems simulated gives us an indication of the
decoherence time needed for different physical realizations of a
quantum simulator or computer. The decoherence time is an average time
in which the state of the qubits will be destroyed by noise, also called
decoherence, while the operation time is the average time an operation takes
to perform on the given system. Their fraction is the number of
operations possible to perform before decoherence destroys the
computation. In table  we have listed the number of
gates used for the pairing model, $H_P$, and the Hubbard model, $H_H$,
for different number of simulation qubits.

     	 $s=2$	 $s=4$	 $s=6$	 $s=8$	 $s=10$	 $s=12$

   $H_P$    	    9        	    119      	    333      	    651      	    1073      	    1598

   $H_H$    	    9        	    51       	    93       	    135      	    177       	    219

Number of two-qubit gates used in simulating the time
  evolution operator of the pairing model, $H_P$, and the Hubbard
  model, $H_H$, for different number of simulation qubits $s$.

We list here some useful relations involving different $\sigma$ matrices,

$$
\begin{equation}
\sigma_x \sigma_z = -i\sigma_y, \quad
\sigma_z \sigma_x = i\sigma_y, \quad [\sigma_x, \sigma_z]=-2i\sigma_y,
\label{_auto42} \tag{49}
\end{equation}
$$

$$
\begin{equation}
\sigma_x \sigma_y = i\sigma_z, \quad
\sigma_y \sigma_x = -i\sigma_z, \quad [\sigma_x, \sigma_y]=2i\sigma_z,
\label{_auto43} \tag{50}
\end{equation}
$$

and

$$
\begin{equation}
\sigma_y \sigma_z = i\sigma_x, \quad
\sigma_z \sigma_y = -i\sigma_x, \quad [\sigma_y, \sigma_z]=2i\sigma_x.
\label{_auto44} \tag{51}
\end{equation}
$$

For any two non-equal $\sigma$-matrices $a$ and $b$ we have

$$
\begin{equation}
aba = -b.
\label{_auto45} \tag{52}
\end{equation}
$$

The Hermitian $\sigma$-matrices $\sigma_x$, $\sigma_y$ and $\sigma_z$
result in the identity matrix when squared

$$
\begin{equation}
\sigma_x^2 = _1_,\quad
\sigma_y^2 = _1_,\quad
\sigma_z^2 = _1_,\quad
\label{_auto46} \tag{53}
\end{equation}
$$

which can be used to obtain  simplified expressions for exponential functions involving $\sigma$-matrices

$$
\begin{equation}
e^{\pm i\alpha \sigma}=\cos(\alpha) _1_ \pm i \sin(\alpha) \sigma.
\label{_auto47} \tag{54}
\end{equation}
$$

The equations we list below are necessary for the relation between  a general unitary
transformation on a set of qubits with  a product of two-qubit unitary
transformations. We have the general equation for $a,b \in \{\sigma_x,\sigma_y, \sigma_z\}$, where $a\neq b$.

$$
\begin{equation}
  e^{-i\pi/4a} b e^{i\pi/4a} = \frac{1}{2} (_1_ -ia) b ( _1_ + ia)
  \notag
\label{_auto48} \tag{55}
\end{equation}
$$

$$
\begin{equation}
  =  \frac{1}{2} (b + aba + i[b,a]) \notag
\label{_auto49} \tag{56}
\end{equation}
$$

$$
\begin{equation}
  = \frac{i}{2}[b,a].
\label{_auto50} \tag{57}
\end{equation}
$$

The more specialized equations read

$$
\begin{equation}
\label{eq:rotations1} \tag{58}
  e^{-i\pi/4 \sigma_x} \sigma_z e^{i\pi/4 \sigma_x} = -\sigma_y,
\end{equation}
$$

$$
\begin{equation}
\label{eq:rotations2} \tag{59}
  e^{-i\pi/4 \sigma_y} \sigma_z e^{i\pi/4 \sigma_y} = \sigma_x,
\end{equation}
$$

$$
\begin{equation}
\label{eq:rotations3} \tag{60}
  e^{-i\pi/4 \sigma_z} \sigma_x e^{i\pi/4 \sigma_z} = \sigma_y,
\end{equation}
$$

$$
\begin{equation}
\label{eq:rotations4} \tag{61}
  e^{-i\pi/4 \sigma_z} \sigma_y e^{i\pi/4 \sigma_z} = -\sigma_x.
\end{equation}
$$

We need also different products of the operator$\sigma_z$  with the  raising and lowering operators

$$
\begin{equation}
\label{eq:pmzs} \tag{62}
  \sigma_+ \sigma_z = -\sigma_+
\end{equation}
$$

$$
\begin{equation}
  \sigma_z \sigma_+ = \sigma_+,
\label{_auto51} \tag{63}
\end{equation}
$$

$$
\begin{equation}
  \sigma_- \sigma_z = \sigma_-,
\label{_auto52} \tag{64}
\end{equation}
$$

$$
\begin{equation}
  \sigma_z \sigma_- = -\sigma_-.
\label{_auto53} \tag{65}
\end{equation}
$$

$$
\begin{equation}
\label{_auto54} \tag{66}
\end{equation}
$$


# Design of Digital Filters

*This jupyter notebook is part of a [collection of notebooks](../index.ipynb) on various topics of Digital Signal Processing. Please direct questions and suggestions to [Sascha.Spors@uni-rostock.de](mailto:Sascha.Spors@uni-rostock.de).*

## Design of Recursive Filters by the Bilinear Transform

Various techniques have been developed to derive digital realizations of analog systems. For instance the [impulse invariance](https://en.wikipedia.org/wiki/Impulse_invariance) method, the [matched Z-transform](https://en.wikipedia.org/wiki/Matched_Z-transform_method) and the [bilinear transform](https://en.wikipedia.org/wiki/Bilinear_transform). The following section introduces the bilinear transform and its application to the digital realization of analog systems and recursive filter design.

### The Bilinear Transform

The bilinear transform is used to map the transfer function $H(s) = \mathcal{L}\{ h(t) \}$ of a continous system to the transfer function $H(z) = \mathcal{Z}\{ h[k] \}$ of a discrete system approximating the continuous system. The transform is designed such that if $H(s)$ is a [rational function](https://en.wikipedia.org/wiki/Rational_function) in $s$ then $H(z)$ is a rational function in $z^{-1}$. The coefficients of the powers of $z^{-1}$ are then the coefficients of the digital system.

Assuming ideal sampling with sampling interval $T$, the frequency variable $s$ of the Laplace transformation is linked to the frequency variable $z$ of the $z$-transform by

\begin{equation}
z = \mathrm{e}^{\,s T}
\end{equation}

For sampled signals the resulting mapping from the $s$-plane into the $z$-plane is shown in the following illustration:

The shading indicates how the different areas are mapped. The imaginary axis $s = \mathrm{j}\,\omega$ is mapped onto the unit circle $z = \mathrm{e}^{\,\mathrm{j}\,\Omega}$, representing the frequency response of the continuous and discrete system. The left half-plane of the $s$-plane is mapped into the unit circle of the $z$-plane.

For the desired mapping of $H(s)$ to $H(z)$ we need the inverse of above equation. It is given as

\begin{equation}
s = \frac{1}{T} \cdot \ln (z)
\end{equation}

However, when introduced into a rational transfer function $H(s)$ this non-linear mapping would not result in the desired rational transfer function $H(z)$. In order to achieve the desired mapping, $\ln(z)$ is expanded into the power series

\begin{equation}
\ln(z) = 2 \left( \frac{z-1}{z+1} + \frac{(z-1)^3}{3(z+1)^3} + \frac{(z-1)^5}{5(z+1)^5} + \dots \right)
\end{equation}

Using only the linear term as approximation of $\ln(z)$ yields the bilinear transform

\begin{equation}
s = \frac{2}{T} \cdot \frac{z - 1}{z + 1}
\end{equation}

and its inverse

\begin{equation}
z = \frac{2 + s T}{2 - s T}
\end{equation}

It worthwhile noting that this mapping rule is a special case of a [conformal map](https://en.wikipedia.org/wiki/Conformal_map).

Let's consider the mapping of the frequency response $H(\mathrm{j}\,\omega) = H(s) \big\vert_{s = \mathrm{j}\,\omega}$ of a continuous system to the frequency response $H_d(\mathrm{e}^{\,\mathrm{j}\,\omega T}) = H_d(z)\big\vert_{z = \mathrm{e}^{\,\mathrm{j}\,\Omega}}$ of a discrete system. Introducing the bilinear transform into the continuous system to yield its discrete counterpart results in

\begin{equation}
H_d(\mathrm{e}^{\,\mathrm{j}\,\Omega}) = H \left( \frac{2}{T} \cdot \frac{z - 1}{z + 1} \right) \Bigg\vert_{z = \mathrm{e}^{\,\mathrm{j}\,\Omega}} = H \Big( \mathrm{j} \; \underbrace{\frac{2}{T} \cdot \tan(\frac{\Omega}{2})}_{\omega} \Big)
\end{equation}

The imaginary axis $s=\mathrm{j}\,\omega$ of the $s$-plane is mapped onto the unit circle $\mathrm{e}^{\,\mathrm{j}\,\Omega}$ of the $z$-plane. Note, that for sampled signals the mapping between the continuous frequency axis $\omega$ and the frequency axis $\Omega$ of the discrete system is $\Omega = \omega T$. However, for the bilinear transform the mapping is non-linear

\begin{align}
\omega &= \frac{2}{T} \cdot \tan(\frac{\Omega}{2}) \\
\Omega &= 2 \arctan(\frac{\omega T}{2})
\end{align}

In the following, this is illustrated for $T=1$

```python
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt

om = np.linspace(-10, 10, 200)
Om = 2*np.arctan(om*1/2)

plt.figure(figsize=(10,4))
plt.plot(om, Om, label=r'$2 \cdot \arctan(\frac{\omega T}{2})$')
plt.plot(om, om, 'k--', label=r'$\omega T$')
plt.xlabel(r'$\omega$')
plt.ylabel(r'$\Omega$')
plt.axis([-10, 10, -np.pi, np.pi])
plt.legend(loc=2)
plt.grid()
```

It is evident that the frequency axis deviates from the linear mapping $\Omega = \omega T$, especially for high frequencies. The frequency response of the digital filter $H_d(\mathrm{e}^{\,\mathrm{j}\,\Omega})$ therefore deviates from the desired continuous frequency response $H(\mathrm{j}\,\omega)$. This is due to the first-order approximation of the mapping from the $s$-plane to the $z$-plane. The effect is known as *frequency warping*. It can be considered explicitly in the filter design stage, as shown in the examples.

Besides this drawback, the bilinear transform has a number of benefits:

* stability and minimum-phase of the continuous filter is preserved. This is due to mapping of the left half-space of the $s$-plane into the unit-circle of the $z$-plane.
* the order of the continuous filter is preserved. This is due to the linear mapping rule.
* no aliasing distortion as observed for the impulse invariance method

The application of the bilinear transform to the design of digital filters is discussed in the following.

### Design of Digital Filter

We aim at designing a digital filter $H_d(z)$ that approximates a given continuous prototype $H(s)$ using the bilinear transform. For instance, the transfer function $H(s)$ may result from the analysis of an analog circuit or filter design technique. The transfer function $H_d(z)$ of the digital filter is then given by

\begin{equation}
H_d(z) = H(s) \Big\vert_{s = \frac{2}{T} \cdot \frac{z - 1}{z + 1}}
\end{equation}

The coefficients of the digital filter are derived by representing the numerator and denominator of $H_d(z)$ as polynomials with respect to $z^{-1}$. For instance, for a continuous system of second order (second order section)

\begin{equation}
H(s) = \frac{\beta_0 + \beta_1 s + \beta_2 s^2}{\alpha_0 + \alpha_1 s + \alpha_2 s^2}
\end{equation}

the bilinear transform results in

\begin{equation}
H_d(z) = \frac{(\beta_2 K^2 - \beta_1 K + \beta_0) \, z^{-2} + (2 \beta_0 - 2 \beta_2 K^2) \,  z^{-1} + (\beta_2 K^2 + \beta_1 K + \beta_0)}
{(\alpha_2 K^2 - \alpha_1 K + \alpha_0) \, z^{-2} + (2 \alpha_0 - 2 \alpha_2 K^2) \,  z^{-1} + (\alpha_2 K^2 + \alpha_1 K + \alpha_0)}
\end{equation}
where $K = \frac{2}{T}$.

As outlined in the previous section, the frequency response of the digital filter $H_d(\mathrm{e}^{\,\mathrm{j}\,\Omega})$ will differ for high frequencies from the desired analog frequency response $H(\mathrm{j}\,\omega)$. For the design of a digital filter from an analog prototype, this can be coped for by replacing corner frequencies with

\begin{equation}
\omega_\text{cw} = \frac{2}{T} \cdot \tan \left(\frac{\omega_\text{c} T}{2} \right)
\end{equation}

where $\omega_\text{cw}$ denotes a *warped* corner frequency $\omega_\text{c}$. This techniques is known as *pre-warping*.

### Examples

The following two examples illustrate the digital realization of an analog system and the design of a recursive filter, respectively.

#### Digital realization of an analog system

A second-order lowpass filter can be realized by the following passive circuit

where $x(t)$ denotes the input signal and $y(t)$ the output signal. Analysis of the circuit reveals its transfer function as

\begin{equation}
H(s) = \frac{Y(s)}{X(s)} = \frac{1}{LC \, s^2 + RC \, s + 1}
\end{equation}

Introducing this into the bilinear transform of a second order section (SOS) given in the previous section yields

\begin{equation}
H_d(z) = \frac{T^2 \, z^{-2} + 2 T^2 \, z^{-1} + T^2}{(4 LC - 2 TRC + T^2) \, z^{-2} + (-8 LC + 2 T^2) \, z^{-1} + (4 LC - 2 TRC + T^2)}
\end{equation}

In the following, the frequency response of the analog filter and its digital realization is compared numerically.

```python
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as sig

fs = 44100  # sampling frequency
fc = 1000  # corner frequency of the lowpass

# coefficients of analog lowpass filter
Qinf = 0.8
sinf = 2*np.pi*fc
C = 1e-6
L = 1/(sinf**2*C)
R = sinf*L/Qinf

B = [0, 0, 1]
A = [L*C, R*C, 1]

# cofficients of digital filter
T = 1/fs
b = [T**2, 2*T**2, T**2]
a = [(4*L*C+2*T*R*C+T**2), (-8*L*C+2*T**2), (4*L*C-2*T*R*C+T**2)]

# compute frequency responses
Om, Hd = sig.freqz(b, a, worN=1024)
tmp, H = sig.freqs(B, A, worN=fs*Om)

# plot results
f = Om*fs/(2*np.pi)
plt.figure(figsize = (10, 4))
plt.semilogx(f, 20*np.log10(np.abs(H)), label=r'$|H(j \omega)|$ of analog filter')
plt.semilogx(f, 20*np.log10(np.abs(Hd)), label=r'$|H_d(e^{j \Omega})|$ of digital filter')
plt.xlabel(r'$f$ in Hz')
plt.ylabel(r'dB')
plt.axis([100, fs/2, -70, 3])
plt.legend(loc=1)
plt.grid()
```

**Exercise**

* Increase the corner frequency `fc` of the analog filter. What effect does this have on the deviations between the analog filter and its digital representation?

#### Design of digital filters from analog prototypes

The design of analog filters is a topic with a long lasting history. Consequently, many analog filter designs are known. For instance

* [Butterworth filters](https://en.wikipedia.org/wiki/Butterworth_filter)
* [Chebyshev_filters](https://en.wikipedia.org/wiki/Chebyshev_filter)
* [Cauer filters](https://en.wikipedia.org/wiki/Elliptic_filter)
* [Bessel filters](https://en.wikipedia.org/wiki/Bessel_filter)

The properties of these designs are well documented and therefore digital realizations are of interest. These can be achieved by the bilinear transform. In Python, the [`scipy.signal`](http://docs.scipy.org/doc/scipy/reference/signal.html) package provides implementations of various analog filter design techniques, as well as an implementation of the bilinear transform.

The design of a Butterworth bandpass using pre-warping is illustrated in the following.

```python
omc = 2*np.pi*np.array([5000, 6000])  # corner frequencies of bandpass
N = 2  # order of filter

# pre-warping of corner frequencies
omcp = 2*fs*np.tan(omc/(2*fs))

# design of analog filters with and without pre-warping
B, A = sig.butter(N, omc, btype='bandpass', analog=True)
Bp, Ap = sig.butter(N, omcp, btype='bandpass', analog=True)

# bilinear transform of analog prototypes
b, a = sig.bilinear(B, A, fs)
bp,ap = sig.bilinear(Bp, Ap, fs)

# compute frequency responses
Om, Hdp = sig.freqz(bp, ap, worN=1024)
Om, Hd = sig.freqz(b, a, worN=1024)
tmp, H = sig.freqs(B, A, worN=fs*Om)

# plot results
f = Om*fs/(2*np.pi)
plt.figure(figsize = (12, 8))
plt.semilogx(f, 20*np.log10(np.abs(H)), label=r'$|H(j \omega)|$ of analog prototype')
plt.semilogx(f, 20*np.log10(np.abs(Hd)), label=r'$|H_d(e^{j \Omega})|$ of digital filter without pre-warping')
plt.semilogx(f, 20*np.log10(np.abs(Hdp)), label=r'$|H_d(e^{j \Omega})|$ of digital filter with pre-warping')
plt.xlabel(r'$f$ in Hz')
plt.ylabel(r'dB')
plt.axis([100, fs/2, -70, 3])
plt.legend(loc=2)
plt.grid()
```

**Exercise**

* What is improved by pre-warping?
* Change the corner frequencies `omc` of the analog prototype and examine the deviations from the analog prototype. When is pre-warping reasonable and when not?

**Copyright**

This notebook is provided as [Open Educational Resource](https://en.wikipedia.org/wiki/Open_educational_resources). Feel free to use the notebook for your own purposes. The text is licensed under [Creative Commons Attribution 4.0](https://creativecommons.org/licenses/by/4.0/), the code of the IPython examples under the [MIT license](https://opensource.org/licenses/MIT). Please attribute the work as follows: *Sascha Spors, Digital Signal Processing - Lecture notes featuring computational examples, 2016-2017*.