signal-test.cc
Go to the documentation of this file.
1 // feat/signal-test.cc
2 
3 // Copyright 2015 Tom Ko
4 
5 // See ../../COPYING for clarification regarding multiple authors
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 // MERCHANTABLITY OR NON-INFRINGEMENT.
17 // See the Apache 2 License for the specific language governing permissions and
18 // limitations under the License.
19 
20 #include "base/kaldi-common.h"
21 #include "util/common-utils.h"
22 #include "feat/signal.h"
23 
24 namespace kaldi {
25 
27  for (int32 i = 0; i < 5; i++) {
28  int32 signal_length = 400000 + Rand() % 40000;
29  int32 filter_length = 1000 + Rand() % 100;
30  Vector<BaseFloat> signal(signal_length);
31  Vector<BaseFloat> filter(filter_length);
32  signal.SetRandn();
33  filter.SetRandn();
34  Vector<BaseFloat> signal_test(signal);
35  FFTbasedConvolveSignals(filter, &signal_test);
36  FFTbasedBlockConvolveSignals(filter, &signal);
37  AssertEqual(signal, signal_test, 0.000001 * signal.Dim());
38  }
39 }
40 
42  for (int32 i = 0; i < 5; i++) {
43  int32 signal_length = 4000 + Rand() % 400;
44  int32 filter_length = 10 + Rand() % 10;
45  Vector<BaseFloat> signal(signal_length);
46  Vector<BaseFloat> filter(filter_length);
47  signal.SetRandn();
48  filter.SetRandn();
49  Vector<BaseFloat> signal_test(signal);
50  ConvolveSignals(filter, &signal_test);
51  FFTbasedConvolveSignals(filter, &signal);
52  AssertEqual(signal, signal_test, 0.0001 * signal.Dim());
53  }
54 }
55 }
56 
57 int main() {
58  using namespace kaldi;
61  KALDI_LOG << "Tests succeeded.";
62 
63 }
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
Definition: chain.dox:20
void UnitTestFFTbasedConvolution()
Definition: signal-test.cc:41
kaldi::int32 int32
int main()
Definition: signal-test.cc:57
void FFTbasedConvolveSignals(const Vector< BaseFloat > &filter, Vector< BaseFloat > *signal)
Definition: signal.cc:50
void FFTbasedBlockConvolveSignals(const Vector< BaseFloat > &filter, Vector< BaseFloat > *signal)
Definition: signal.cc:77
MatrixIndexT Dim() const
Returns the dimension of the vector.
Definition: kaldi-vector.h:64
int Rand(struct RandomState *state)
Definition: kaldi-math.cc:45
void SetRandn()
Set vector to random normally-distributed noise.
A class representing a vector.
Definition: kaldi-vector.h:406
void ConvolveSignals(const Vector< BaseFloat > &filter, Vector< BaseFloat > *signal)
Definition: signal.cc:34
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
Definition: kaldi-math.h:276
#define KALDI_LOG
Definition: kaldi-error.h:153
void UnitTestFFTbasedBlockConvolution()
Definition: signal-test.cc:26