Skip to content

Commit

Permalink
Add exploration of linear interp filter freq response
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-thompson committed Nov 28, 2015
1 parent dd53330 commit 3359e43
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions filters/lerp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import matplotlib.pyplot as plt
import numpy as np

from scipy import signal

f, (ax1, ax2) = plt.subplots(2, sharex=True)

for i in np.linspace(0.0, 1.0, 11):
# A linear interpolation filter with a factor of `i`.
w, h = signal.freqz([(1.0 - i), i])

# Scale x-axis to Hz.
x = w * 44100 / (2 * np.pi)

# Plot amplitude response on the dB scale.
ax1.plot(x, 20 * np.log10(abs(h)), color='c', alpha=1.0 - i)

# Plot phase response in radians.
ax2.plot(x, np.unwrap(np.angle(h)), color='c', alpha=1.0 - i)

ax1.set_title('Amplitude Response (dB)')
ax2.set_title('Phase Response (radians)')

ax2.set_yticks(np.linspace(-1.0, 0.0, 5) * np.pi)
ax2.set_yticklabels([r'$-\pi$', r'$-\frac{3\pi}{4}$', r'$-\frac{\pi}{2}$',
r'$-\frac{\pi}{4}$', r'$0$'])

ax1.axis('tight')
ax2.axis('tight')

ax1.grid()
ax2.grid()

plt.show()

0 comments on commit 3359e43

Please sign in to comment.