# Z-Transform and DFT

I have $$H(z) = \frac{\left[b_0 + b_1 \cdot z^{-1}\right]}{\left[1 + a_1z^{-1} + a_2 \cdot z^{-2}\right]}$$.

Why is it that I can calculate the spectrum between $$0$$ and $$0.5 \cdot f_s$$ by calculating $$B_k = \mathrm{DFT}([b_0,b_1],\ N)$$ and $$Ak = \mathrm{DFT}([1,a_1,a_2],\ N)$$ and then calculate $$\frac{B_k}{A_k}\ \mathrm{for}\ k = 0,1,2,...,\frac{N}{2}$$ and $$f_k = k \cdot f_s/N$$ Hz.

Here $$\frac{B_k}{A_k}$$ is the spectrum for $$H(z)$$ when $$z = e^{j \cdot 2 \pi \cdot f_k/f_s}$$, where $$f_s$$ = sampling frequency and $$N$$ = number of points.

Actually you have asked two questions :

1. Why is it that $$H(e^{jw})$$ can be obtained using the numerator and denominator of $$H(z)$$?

2. Why do you need to compute that $$H(z)$$ at $$z = e^{j2\pi \frac{f_k}{f_s}}$$ for $$k\in \{0,1,2,...,\frac{N}{2} \}$$ ?

It is true that z-transforms provide us the facility to figure out frequency response of a filter from the Constant Coefficient Difference Equation of the system directly, and following is how and why.

1. $$H(z)$$ is a transfer function, which means it can always be thought as obtained from the some input-output relation and that relation by looking at $$H(z)$$ can be figured out as below assuming $$x[n], y[n]$$ are input and output of the system : $$H(z) = \frac{Y(z)}{X(z)}, and$$ $$y[n] + a_1.y[n-1] + a_2.y[n-2] = b_0.x[n] + b_1.x[n-1],$$

By definition, z-transform computed at unit circle gives us the filter response, which means replacing $$z$$ with $$e^{j\omega}$$ will give us the filer response of underlying CCDE(constant Coefficient Difference Equation).

So, take DTFT of this causal realizable system instead of z-transform and you will get: $$Y(e^{j\omega}) + a_1.e^{-j\omega}Y(e^{j\omega}) + a_2.e^{-j2\omega}Y(e^{j\omega}) = b_0.X(e^{j\omega}) + b_1.e^{-j\omega}X(e^{j\omega})$$ $$=> H(e^{j\omega}) = \frac{Y(e^{j\omega})}{X(e^{j\omega})} = \frac{b_0 + b_1.e^{-j\omega}}{1 + a_1.e^{-j\omega} + a_2.e^{-j2\omega}}$$ Figure out that $$(b_0 + b_1.e^{-j\omega})$$ is nothing but, $$DTFT \{ [b_0, b_1] \}$$, i.e. Discrete time fourier transform of a finite length sequence $$\{ b_0, b_1 \}$$ and similarly, the denominator is the discrete time fourier transform of$$\{ 1, a_1, a_2 \}$$. Just write the DTFT-summation for these finite length sequences, and you will get it.

Now, DFT is just sampled version of DTFT and hence when you are computing DFT of sequences $$\{ b_0, b_1 \}$$, you are actually sampling DTFT of the sequence at particular digital frequencies. That is why taking DTFT or DFT of those sequences and dividing them can be used to get the spectrum.

1. DTFTs are $$2\pi$$-Periodic functions of $$\omega$$ and we generally look at $$\omega \in [-\pi, \pi]$$. But if you sample the $$H(e^{j\omega})$$ at N equidistant points for $$\omega \in [0, 2\pi)$$, then what you get is N-DFT. Notice that $$\omega = 2\pi$$ is not included.

Now, N defines how closely these points will be placed, and you can only know $$H(e^{j\omega})$$ at $$\omega = \frac{2\pi k}{N}$$ for $$k=0,1,2,3...,N-1$$.

And, sampling frequency $$f_s$$ defines that continuous frequency $$[-\frac{f_s}{2}, \frac{f_s}{2}]$$ will be mapped to digital frequency $$\omega \in [-\pi, \pi]$$ after sampling.

Combining both these information, you can understand that the N-point DFT will give you the spectrum values of $$H(e^{j\omega})$$ only at : $$\omega = \frac{2\pi.k}{N} <=> f = \frac{2.k.f_s}{N.2} = \frac{k.f_s}{N},$$ (just replaced $$\pi$$ with $$\frac{f_s}{2}$$).

Now, for symmetrical spectrum, it is sufficient to know the spectrum only for $$\omega \in [0, \pi]$$ which means only first $$\frac{N}{2}$$ points of DFTs needs to be divided , i.e. compute $$\frac{B_k}{A_k}$$ only for $$k=0,1,2,3,....,\frac{N}{2}$$.

$$|H(e^{j2\pi f_k/f_s})|$$ for $$f_k = k f_s/N$$ = $$|H(z)|_{z=e^{j\omega_0}}$$. When you compute this, you are computing the value of $$Z$$ transform at $$z = 1e^{j\omega_0 }$$, where $$\omega_0 = 2\pi k/N$$.

For magnitude, $$|H(z)| = \frac{|B(z)|}{|A(z)|}$$. Hence $$H(e^{j\omega_0}) = \frac{|B(e^{j\omega_0})|}{|A(e^{j\omega_0})|}$$ = $$\frac{\tilde{B(k)}}{\tilde{A(k)}}$$, where $$\tilde{B}$$ is the $$DFT([b_0,b_1],N)$$ and $$\tilde{A}$$ is the $$DFT([1,a_1,a_2],N)$$. Both the DFT should be of same size and you need to do point by point division of $$\tilde{B}$$ and $$\tilde{A}$$.