From af0e45a3195b86970cda03b9b4805e9bf28beae7 Mon Sep 17 00:00:00 2001 From: yorange1 <28107329+yorange1@users.noreply.github.com> Date: Fri, 5 Nov 2021 11:20:36 +0800 Subject: [PATCH 1/2] Fix mel filterbanks freq_index compute error. --- speechpy/feature.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/speechpy/feature.py b/speechpy/feature.py index 3b194fd..276425f 100755 --- a/speechpy/feature.py +++ b/speechpy/feature.py @@ -74,9 +74,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) From 02a748e94d97e32c55e428b84526b484154b4b7c Mon Sep 17 00:00:00 2001 From: yorange1 <28107329+yorange1@users.noreply.github.com> Date: Fri, 5 Nov 2021 11:24:08 +0800 Subject: [PATCH 2/2] Fix mel filterbanks freq band edge initialization error. --- speechpy/feature.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/speechpy/feature.py b/speechpy/feature.py index 276425f..7024776 100755 --- a/speechpy/feature.py +++ b/speechpy/feature.py @@ -44,7 +44,7 @@ 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 @@ -52,8 +52,10 @@ def filterbanks( 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!"