Commit 235e4466 authored by Pavel KORSHUNOV's avatar Pavel KORSHUNOV

Fixed bugs, tests, and doctests

parent ca8a4cd2
Pipeline #3908 passed with stages
in 40 minutes and 56 seconds
......@@ -20,7 +20,7 @@ bob::ap::Ceps::Ceps(const double sampling_frequency,
const bool mel_scale, const bool dct_norm, const bool normalize_mean,
const bool rect_filter, const bool inverse_filter, const bool normalize_spectrum,
const bool ssfc_features, const bool scfc_features, const bool scmc_features):
bob::ap::Spectrogram(sampling_frequency, win_length_ms, win_shift_ms, normalize_mean,
bob::ap::Spectrogram(sampling_frequency, win_length_ms, win_shift_ms,
n_filters, f_min, f_max, pre_emphasis_coeff, mel_scale, normalize_mean, rect_filter, inverse_filter,
normalize_spectrum, ssfc_features, scfc_features, scmc_features),
m_n_ceps(n_ceps), m_delta_win(delta_win), m_dct_norm(dct_norm),
......
......@@ -43,7 +43,7 @@ class Ceps: public Spectrogram
* @brief Constructor. Initializes working arrays
*/
Ceps(const double sampling_frequency, const double win_length_ms=20.,
const double win_shift_ms=10., const bool normalize_mean=true, const size_t n_filters=24,
const double win_shift_ms=10., const size_t n_filters=24,
const size_t n_ceps=19, const double f_min=0.,
const double f_max=4000., const size_t delta_win=2,
const double pre_emphasis_coef=0.95, const bool mel_scale=true,
......
......@@ -26,7 +26,6 @@ class DotDict(dict):
cepstral_params = DotDict(dict(win_length_ms=20,
win_shift_ms=10,
normalize_mean=True,
n_filters=20,
f_min=0.,
f_max=4000.,
......@@ -35,6 +34,7 @@ cepstral_params = DotDict(dict(win_length_ms=20,
n_ceps=20,
delta_win=2,
dct_norm=True,
normalize_mean=True,
with_energy=True,
with_delta=True,
with_delta_delta=True
......@@ -222,9 +222,9 @@ def cepstral_comparison_run(cepstral_params):
rate_wavsample = read(pkg_resources.resource_filename(__name__, os.path.join('data', 'sample.wav')))
cepstral = Ceps(rate_wavsample[0], cepstral_params.win_length_ms, cepstral_params.win_shift_ms,
cepstral_params.normalize_mean, cepstral_params.n_filters, cepstral_params.n_ceps,
cepstral_params.f_min, cepstral_params.f_max, cepstral_params.delta_win,
cepstral_params.pre_emphasis_coef, cepstral_params.mel_scale, dct_norm=cepstral_params.dct_norm)
cepstral_params.n_filters, cepstral_params.n_ceps, cepstral_params.f_min, cepstral_params.f_max,
cepstral_params.delta_win, cepstral_params.pre_emphasis_coef, cepstral_params.mel_scale,
cepstral_params.dct_norm, cepstral_params.normalize_mean)
cepstral.with_energy = cepstral_params.with_energy
cepstral.with_delta = cepstral_params.with_delta
if cepstral.with_delta:
......@@ -320,9 +320,9 @@ def test_cepstral_copy():
# # Test comparison operators and copy constructor
rate_wavsample = read(pkg_resources.resource_filename(__name__, os.path.join('data', 'sample.wav')))
cepstral = Ceps(rate_wavsample[0], cepstral_params.win_length_ms, cepstral_params.win_shift_ms,
cepstral_params.normalize_mean, cepstral_params.n_filters, cepstral_params.n_ceps,
cepstral_params.f_min, cepstral_params.f_max, cepstral_params.delta_win,
cepstral_params.pre_emphasis_coef, cepstral_params.mel_scale, dct_norm=cepstral_params.dct_norm)
cepstral_params.n_filters, cepstral_params.n_ceps, cepstral_params.f_min,
cepstral_params.f_max, cepstral_params.delta_win, cepstral_params.pre_emphasis_coef,
cepstral_params.mel_scale, cepstral_params.dct_norm, cepstral_params.normalize_mean, )
c1 = Ceps(cepstral)
c2 = Ceps(c1)
c2.win_length_ms = 27.
......
......@@ -15,7 +15,8 @@ from scipy import signal
from . import Spectrogram
from .test_utils import *
def spectrogram_computation(rate_wavsample, win_length_ms, win_shift_ms, normalize_mean, n_filters, f_min, f_max, pre_emphasis_coef, mel_scale):
def spectrogram_computation(rate_wavsample, win_length_ms, win_shift_ms, n_filters,
f_min, f_max, pre_emphasis_coef, mel_scale, normalize_mean):
#########################
## Initialisation part ##
#########################
......@@ -71,12 +72,14 @@ def spectrogram_computation(rate_wavsample, win_length_ms, win_shift_ms, normali
return numpy.array(features)
def spectrogram_comparison_run(rate_wavsample, win_length_ms, win_shift_ms, normalize_mean, n_filters, f_min, f_max,
pre_emphasis_coef, mel_scale):
c = Spectrogram(rate_wavsample[0], win_length_ms, win_shift_ms, normalize_mean, n_filters, f_min, f_max, pre_emphasis_coef, mel_scale)
def spectrogram_comparison_run(rate_wavsample, win_length_ms, win_shift_ms, n_filters, f_min, f_max,
pre_emphasis_coef, mel_scale, normalize_mean):
c = Spectrogram(rate_wavsample[0], win_length_ms, win_shift_ms, n_filters,
f_min, f_max, pre_emphasis_coef, mel_scale, normalize_mean)
A = c(rate_wavsample[1])
B = spectrogram_computation(rate_wavsample, win_length_ms, win_shift_ms, normalize_mean, n_filters, f_min, f_max, pre_emphasis_coef, mel_scale)
B = spectrogram_computation(rate_wavsample, win_length_ms, win_shift_ms, n_filters,
f_min, f_max, pre_emphasis_coef, mel_scale, normalize_mean)
diff=numpy.sum(numpy.sum((A-B)*(A-B)))
assert numpy.allclose(diff, 0., rtol=1e-07, atol=1e-05)
......@@ -95,5 +98,5 @@ def test_spectrogram():
f_max = 4000.
pre_emphasis_coef = 1.0
mel_scale = True
spectrogram_comparison_run(rate_wavsample, win_length_ms, win_shift_ms, normalize_mean, n_filters, f_min, f_max,
pre_emphasis_coef, mel_scale)
spectrogram_comparison_run(rate_wavsample, win_length_ms, win_shift_ms, n_filters, f_min, f_max,
pre_emphasis_coef, mel_scale, normalize_mean)
......@@ -75,8 +75,8 @@ values are the default ones:
>>> win_length_ms = 20 # The window length of the cepstral analysis in milliseconds
>>> win_shift_ms = 10 # The window shift of the cepstral analysis in milliseconds
>>> n_filters = 20 # The number of filter bands
>>> n_ceps = 20 # The number of cepstral coefficients
>>> n_filters = 24 # The number of filter bands
>>> n_ceps = 19 # The number of cepstral coefficients
>>> f_min = 0. # The minimal frequency of the filter bank
>>> f_max = 4000. # The maximal frequency of the filter bank
>>> delta_win = 2 # The integer delta value used for computing the first and second order derivatives
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment