-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exploration of linear interp filter freq response
- Loading branch information
1 parent
dd53330
commit 3359e43
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |