forked from SuperKogito/spafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_features_rplp.py
115 lines (105 loc) · 2.8 KB
/
test_features_rplp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import pytest
import numpy as np
from spafe.features.rplp import rplp, plp
from spafe.fbanks.bark_fbanks import bark_filter_banks
from spafe.utils.cepstral import normalize_ceps, lifter_ceps
@pytest.mark.test_id(212)
@pytest.mark.usefixtures("sig")
@pytest.mark.usefixtures("fs")
@pytest.mark.parametrize("order", [13, 22])
@pytest.mark.parametrize("pre_emph", [False, True])
@pytest.mark.parametrize("lifter", [None, 0.7, -7])
@pytest.mark.parametrize("normalize", [None, "mvn", "ms"])
def test_rplp(
sig,
fs,
order,
pre_emph,
lifter,
normalize,
):
"""
test RPLP features module for the following:
- check that the returned number of cepstrums is correct.
"""
# compute plps
plps = plp(
sig=sig,
fs=fs,
order=order,
pre_emph=pre_emph,
lifter=lifter,
normalize=normalize,
)
# assert number of returned cepstrum coefficients
if not plps.shape[1] == order:
raise AssertionError
# Test normalize
if normalize:
np.testing.assert_array_almost_equal(
plps,
normalize_ceps(
plp(
sig=sig,
fs=fs,
order=order,
pre_emph=pre_emph,
lifter=lifter,
normalize=None,
),
normalize,
),
3,
)
else:
# Test lifter
if lifter:
np.testing.assert_array_almost_equal(
plps,
lifter_ceps(
plp(
sig=sig,
fs=fs,
order=order,
pre_emph=pre_emph,
lifter=None,
normalize=normalize,
),
lifter,
),
3,
)
# compute bfccs
rplps = rplp(
sig=sig,
fs=fs,
order=order,
pre_emph=pre_emph,
lifter=lifter,
normalize=normalize,
)
# assert number of returned cepstrum coefficients
if not rplps.shape[1] == order:
raise AssertionError
# check predifined fbanks features
fbanks, _ = bark_filter_banks(fs=fs)
predifined_fbanks_feats = rplp(
sig=sig,
fs=fs,
order=order,
pre_emph=pre_emph,
lifter=lifter,
normalize=normalize,
fbanks=fbanks,
)
np.testing.assert_array_almost_equal(rplps, predifined_fbanks_feats, 3)
predifined_fbanks_feats = plp(
sig=sig,
fs=fs,
order=order,
pre_emph=pre_emph,
lifter=lifter,
normalize=normalize,
fbanks=fbanks,
)
np.testing.assert_array_almost_equal(plps, predifined_fbanks_feats, 3)