Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some bugs in mel filterbanks. #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions speechpy/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ def filterbanks(
coefficients (int): (fftpoints//2 + 1). Default is 257.
sampling_freq (float): the samplerate of the signal we are working
with. It affects mel spacing.
low_freq (float): lowest band edge of mel filters, default 0 Hz
low_freq (float): lowest band edge of mel filters, default 300 Hz
high_freq (float): highest band edge of mel filters,
default samplerate/2

Returns:
array: A numpy array of size num_filter x (fftpoints//2 + 1)
which are filterbank
"""
high_freq = high_freq or sampling_freq / 2
low_freq = low_freq or 300
if high_freq is None:
high_freq = sampling_freq / 2
if low_freq is None:
low_freq = 300
s = "High frequency cannot be greater than half of the sampling frequency!"
assert high_freq <= sampling_freq / 2, s
assert low_freq >= 0, "low frequency cannot be less than zero!"
Expand All @@ -74,9 +76,11 @@ def filterbanks(
# The frequency resolution required to put filters at the
# exact points calculated above should be extracted.
# So we should round those frequencies to the closest FFT bin.

fftpoints = (coefficients - 1) * 2
freq_index = (
np.floor(
(coefficients +
(fftpoints +
1) *
hertz /
sampling_freq)).astype(int)
Expand Down