34 int32 num_frames = 1 + (
Rand() % 10 * 10);
45 output_feats(num_frames, dim),
46 output_feats2(num_frames, dim);
50 for (
int32 t = 0; t < num_frames; t++) {
51 int32 window_begin, window_end;
57 shift = -window_begin;
58 else if (window_end > num_frames)
59 shift = num_frames - window_end;
61 window_begin += shift;
68 if (window_begin < 0) window_begin = 0;
69 if (window_end > num_frames) window_end = num_frames;
70 int32 window_size = window_end - window_begin;
72 double sum = 0.0, sumsq = 0.0;
73 for (
int32 t2 = window_begin; t2 < window_end; t2++) {
75 sumsq += feats(t2,
d) * feats(t2,
d);
77 double mean = sum / window_size, uncentered_covar = sumsq / window_size,
78 covar = uncentered_covar - mean * mean;
79 covar = std::max(covar, 1.0e-20);
80 double data = feats(t,
d),
81 norm_data = data - mean;
83 if (window_size == 1) norm_data = 0.0;
84 else norm_data /= sqrt(covar);
86 output_feats2(t,
d) = norm_data;
89 if (! output_feats.ApproxEqual(output_feats2, 0.0001)) {
90 KALDI_ERR <<
"Features differ " << output_feats <<
" vs. " << output_feats2;
101 using namespace kaldi;
104 std::cout <<
"Tests succeeded.\n";
106 }
catch (
const std::exception &e) {
107 std::cerr << e.what();
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void UnitTestOnlineCmvn()
int Rand(struct RandomState *state)
void SlidingWindowCmn(const SlidingWindowCmnOptions &opts, const MatrixBase< BaseFloat > &input, MatrixBase< BaseFloat > *output)
Applies sliding-window cepstral mean and/or variance normalization.