Skip to content

Commit

Permalink
Changes to FIR filter bank to truncate frequency bands if less than z…
Browse files Browse the repository at this point in the history
…ero or greater than the nyquist frequency
  • Loading branch information
JohnVinyard committed May 31, 2018
1 parent fda6515 commit 2b3b681
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions zounds/spectral/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from matplotlib import cm
from zounds.nputil import sliding_window
from scipy.signal import hann
from itertools import repeat


def fft(x, axis=-1, padding_samples=0):
Expand Down Expand Up @@ -210,11 +211,16 @@ def fir_filter_bank(scale, taps, samplerate, window):

nyq = samplerate.nyquist

for i, band in enumerate(scale):
if window.ndim == 1:
window = repeat(window, len(scale))

for i, band, win in zip(xrange(len(scale)), scale, window):
start_hz = max(0, band.start_hz)
stop_hz = min(nyq, band.stop_hz)
freqs = np.linspace(
band.start_hz / nyq, band.stop_hz / nyq, len(window))
start_hz / nyq, stop_hz / nyq, len(win))
freqs = [0] + list(freqs) + [1]
gains = [0] + list(window) + [0]
gains = [0] + list(win) + [0]
basis[i] = firwin2(taps, freqs, gains)

return basis
Expand Down

0 comments on commit 2b3b681

Please sign in to comment.