#First-Order IIR Filter
The first order IIR filter is the simplest case of IIR filter. Both numerator (b) and denominator (a) of the transfer function of the filter are polynomials of order 1.

##Modules


```python
from numpy import pi, abs,array, arccos, angle
from scipy.signal import freqz
import matplotlib.pyplot as plt
```

## Filter *Coefficients*
```
            jw                 -jw              -jwM
   jw    B(e  )    b[0] + b[1]e    + ... + b[M]e
H(e  ) = ------ = -----------------------------------
            jw                 -jw              -jwN
         A(e  )    a[0] + a[1]e    + ... + a[N]e
```
\begin{align}
H(z)=\frac{\alpha }{1-(1-\alpha )z^{-1}}
\end{align}
<br>
\begin{align}
H(z)=\frac{b_{0}}{1+(-a_{1})z^{-1}}=\frac{b_{0}z}{z+(-a_{1})}
\end{align}


```python
b = array([1/10])
a = array([1, -0.9]) ;a1=0.9
```

##Magnitude response


```python
w, h = freqz(b,a, worN=1024)
plt.figure(dpi=130)
plt.plot(w, abs(h), linewidth=2)
plt.xlabel('Normalized frequency')
plt.ylabel('Magnitude')
plt.title('Magnitude Response $a_{1}=%.2f$'%-a[1])
plt.xlim(0, pi)
wc=arccos((((a[1]**2)-((b[0]**2)*2)+1)/(2*-a[1])))
plt.axvline(wc, color='red') 
plt.axhline(0.707, color='green') 
plt.text(pi/2-0.2, .707+0.01, r'$\left | H(\omega) \right |=.707$',fontsize=8)
plt.text(wc-0.06, 0.3, r'$\omega=%.2f$' %wc, rotation=90,fontsize=8)
plt.yticks([0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1])
plt.grid(True)
plt.show()
```

##Phase response



```python
plt.figure(dpi=130)
plt.plot(w, 180 * angle(h) / pi) 
plt.title('Phase Response $a_{1}=%.2f$'%-a[1])
plt.xlabel('Normalized frequency')
plt.ylabel('Phase [°]')
plt.grid(True)
plt.show()
```

# Author
<a href="https://twitter.com/efectomiller"> Marcelo Gutiérrez</a>

6d612c5722e0275a99dadb96a8f732dc4a9697cc
ipynb
Jupyter Notebook
IIR Filter/First_Order_IIR_filter.ipynb
frhaedo/dsp
a6941f915b602e9daf4b53c69c63be28e3e9df1d
Apache-2.0
IIR Filter/First_Order_IIR_filter.ipynb
frhaedo/dsp
a6941f915b602e9daf4b53c69c63be28e3e9df1d
Apache-2.0
2021-04-03T19:15:05.000Z
2021-04-03T19:15:05.000Z
IIR Filter/First_Order_IIR_filter.ipynb
frhaedo/dsp
a6941f915b602e9daf4b53c69c63be28e3e9df1d
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES