Skip to content

Commit af577d7

Browse files
authored
Merge pull request #63 from SuperKogito/fix-cqcc-shape
fix cqcc size bug
2 parents c7c8499 + 954e94d commit af577d7

23 files changed

+41
-7
lines changed

build.sh

100644100755
File mode changed.

spafe/fbanks/bark_fbanks.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np

spafe/fbanks/gammatone_fbanks.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional, Tuple
1011

1112
import numpy as np

spafe/fbanks/linear_fbanks.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np

spafe/fbanks/mel_fbanks.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np

spafe/features/bfcc.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np

spafe/features/cqcc.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np
@@ -166,7 +167,7 @@ def cqcc(
166167
normalize: Optional[NormalizationType] = None,
167168
number_of_octaves: int = 7,
168169
number_of_bins_per_octave: int = 24,
169-
resampling_ratio: float = 0.95,
170+
resampling_ratio: float = 1.0,
170171
spectral_threshold: float = 0.005,
171172
f0: float = 120,
172173
q_rate: float = 1.0,
@@ -208,7 +209,7 @@ def cqcc(
208209
number_of_bins_per_octave (int) : numbers of bins oer occtave.
209210
(Default is 24).
210211
resampling_ratio (float) : ratio to use for the uniform resampling.
211-
(Default is 0.95).
212+
(Default is 1.00).
212213
spectral_threshold (float) : spectral threshold.
213214
(Default is 0.005).
214215
f0 (float) : fundamental frequency.
@@ -217,7 +218,7 @@ def cqcc(
217218
(Default is 1.0).
218219
219220
Returns:
220-
(numpy.ndarray) : 2d array of BFCC features (num_frames x num_ceps).
221+
(numpy.ndarray) : 2d array of BFCC features (num_frames*resampling_ratio x num_ceps).
221222
222223
Tip:
223224
- :code:`dct` : can take the following options [1, 2, 3, 4].
@@ -283,7 +284,7 @@ def cqcc(
283284
# -> log(.)
284285
# handle zeros: if feat is zero, we get problems with log
285286
features_no_zero = zero_handling(x=power_spectrum)
286-
log_features = np.log(features_no_zero)
287+
log_features = np.log(features_no_zero.T)
287288

288289
# uniform resampling
289290
resampled_features = resample(
@@ -300,4 +301,5 @@ def cqcc(
300301
# normalization
301302
if normalize:
302303
cqccs = normalize_ceps(cqccs, normalize)
304+
303305
return cqccs

spafe/features/gfcc.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional, Tuple
1011

1112
import numpy as np

spafe/features/lfcc.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np

spafe/features/lpc.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np

spafe/features/mfcc.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np

spafe/features/msrcc.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np

spafe/features/ngcc.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np

spafe/features/pncc.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np

spafe/features/psrcc.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np

spafe/features/rplp.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import Optional
1011

1112
import numpy as np
@@ -148,9 +149,7 @@ def __rastaplp(
148149

149150
# equal loudness pre_emphasis
150151
E = lambda w: ((w**2 + 56.8 * 10**6) * w**4) / (
151-
(w**2 + 6.3 * 10**6)
152-
* (w**2 + 0.38 * 10**9)
153-
* (w**6 + 9.58 * 10**26)
152+
(w**2 + 6.3 * 10**6) * (w**2 + 0.38 * 10**9) * (w**6 + 9.58 * 10**26)
154153
)
155154
Y = [E(w) for w in auditory_spectrum]
156155

spafe/utils/cepstral.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
import numpy as np
1011
from scipy.signal import lfilter
1112
from typing_extensions import Literal

spafe/utils/converters.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
import numpy as np
1011
from typing_extensions import Literal
1112

spafe/utils/filters.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
import numpy as np
1011
from scipy import signal
1112
from typing_extensions import Literal

spafe/utils/spectral.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
from typing import List
1011

1112
import numpy as np

spafe/utils/vis.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
import numpy as np
1011

1112
from spafe.utils.converters import hz2mel, hz2bark, hz2erb

spafe/version.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
77
88
"""
9+
910
__version__ = "0.3.2"

tests/test_features_cqcc.py

+14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import scipy.io.wavfile
44
from spafe.utils import vis
55
from spafe.features.cqcc import cqcc
6+
from spafe.utils.preprocessing import framing
67
from spafe.utils.exceptions import ParameterError
78
from spafe.utils.cepstral import normalize_ceps, lifter_ceps
89

@@ -18,6 +19,7 @@
1819
@pytest.mark.parametrize("dct_type", [1, 2, 4])
1920
@pytest.mark.parametrize("lifter", [None, 0.7, -7])
2021
@pytest.mark.parametrize("normalize", [None, "mvn", "ms"])
22+
@pytest.mark.parametrize("resampling_ratio", [1.0, 0.9, 0.3])
2123
def test_cqcc(
2224
sig,
2325
fs,
@@ -29,6 +31,7 @@ def test_cqcc(
2931
dct_type,
3032
lifter,
3133
normalize,
34+
resampling_ratio,
3235
):
3336
"""
3437
test cqcc features module for the following:
@@ -40,6 +43,9 @@ def test_cqcc(
4043
- check normalization.
4144
- check liftering.
4245
"""
46+
# get number of frames
47+
frames, frame_length = framing(sig=sig, fs=fs, win_len=0.025, win_hop=0.01)
48+
num_frames = len(frames)
4349

4450
# check error for number of filters is smaller than number of cepstrums
4551
with pytest.raises(ParameterError):
@@ -50,6 +56,7 @@ def test_cqcc(
5056
nfft=nfft,
5157
low_freq=low_freq,
5258
high_freq=fs,
59+
resampling_ratio=resampling_ratio,
5360
)
5461

5562
# compute features
@@ -64,12 +71,17 @@ def test_cqcc(
6471
dct_type=dct_type,
6572
lifter=lifter,
6673
normalize=normalize,
74+
resampling_ratio=resampling_ratio,
6775
)
6876

6977
# assert number of returned cepstrum coefficients
7078
if not cqccs.shape[1] == num_ceps:
7179
raise AssertionError
7280

81+
# assert number of returned cepstrum coefficients
82+
if not cqccs.shape[0] == int(num_frames * resampling_ratio):
83+
raise AssertionError
84+
7385
# check normalize
7486
if normalize:
7587
np.testing.assert_array_almost_equal(
@@ -86,6 +98,7 @@ def test_cqcc(
8698
dct_type=dct_type,
8799
lifter=lifter,
88100
normalize=None,
101+
resampling_ratio=resampling_ratio,
89102
),
90103
normalize,
91104
),
@@ -108,6 +121,7 @@ def test_cqcc(
108121
dct_type=dct_type,
109122
lifter=None,
110123
normalize=normalize,
124+
resampling_ratio=resampling_ratio,
111125
),
112126
lifter,
113127
),

0 commit comments

Comments
 (0)