26 using namespace kaldi;
31 frequency_(frequency),
35 double operator() (
double t)
const {
36 double omega_t = t *
M_2PI * frequency_;
37 return sin_magnitude_ * sin(omega_t)
38 + cos_magnitude_ * cos(omega_t);
51 BaseFloat time_interval = num_samp / samp_freq;
57 int32 num_zeros = 3 + rand() % 10;
60 int32 num_resamp = 50 + rand() % 100;
65 for (
int32 i = 0;
i < num_resamp;
i++) {
70 resample_points(
i) = (rand() % num_samp) / samp_freq;
77 BaseFloat window_width = num_zeros / (2.0 * lowpass_freq);
81 max_t = time_interval - (1.0 / samp_freq) - window_width;
88 BaseFloat window_freq = 1.0 / (2.0 * window_width),
89 freq_margin = 2.0 * window_freq;
94 (lowpass_freq - freq_margin) * (1.0 / (1.0 +
RandUniform()));
99 resample_points, num_zeros);
106 for (
int32 i = 0;
i < num_samp;
i++) {
108 sample_values(0,
i) = test_func(t);
113 if (rand() % 2 == 0) {
123 for (
int32 i = 0;
i < num_resamp;
i++) {
126 x2 = resampled_values(0,
i),
127 error = fabs(x1 - x2);
129 KALDI_VLOG(1) <<
"Error is " << error <<
", t = " << t
130 <<
", samp_freq = " << samp_freq <<
", lowpass_freq = " 131 << lowpass_freq <<
", test_freq = " << test_signal_freq
132 <<
", num-zeros is " << num_zeros;
134 if (t > min_t && t < max_t) {
135 if (num_zeros == 3) {
141 KALDI_VLOG(1) <<
"[not checking since out of bounds]";
162 std::min(samp_freq, resamp_freq) * 0.95 * 0.5 / (1.0 +
RandUniform());
165 int32 num_zeros = 3 + rand() % 10;
168 int32 num_resamp = ceil(time_interval * resamp_freq);
171 for (
int32 i = 0;
i < num_resamp;
i++)
172 resample_points(
i) =
i /
static_cast<BaseFloat>(resamp_freq);
179 resample_points, num_zeros);
184 sample_values.
Row(0).CopyFromVec(test_signal);
192 lowpass_freq, num_zeros);
196 linear_resampler.
Resample(test_signal,
true, &resampled_vec);
199 KALDI_LOG <<
"ArbitraryResample: " << resampled_values.
Row(0);
200 KALDI_LOG <<
"LinearResample: " << resampled_vec;
206 int32 input_dim_seen = 0;
207 while (input_dim_seen < test_signal.
Dim()) {
208 int32 dim_remaining = test_signal.
Dim() - input_dim_seen;
209 int32 piece_size = rand() % std::min(dim_remaining + 1, 10);
210 KALDI_VLOG(1) <<
"Piece size = " << piece_size;
213 bool flush = (piece_size == dim_remaining);
214 linear_resampler.
Resample(in_piece, flush, &out_piece);
215 int32 old_output_dim = resampled_vec2.
Dim();
217 resampled_vec2.
Range(old_output_dim, out_piece.
Dim())
218 .CopyFromVec(out_piece);
219 input_dim_seen += piece_size;
223 KALDI_LOG <<
"ArbitraryResample: " << resampled_values.
Row(0);
224 KALDI_LOG <<
"LinearResample[broken-up]: " << resampled_vec2;
230 int32 num_samp = 150 + rand() % 100;
231 BaseFloat samp_freq = 1000, resamp_freq = 4000;
233 int32 num_zeros = 10;
241 0.8 * samp_freq / 2.0, num_zeros);
242 linear_resampler_filter.
Resample(signal_orig,
true, &signal);
249 samp_freq / 2.0, num_zeros);
251 linear_resampler.
Resample(signal,
true, &signal_upsampled);
255 samp_freq / 2.0, num_zeros);
259 linear_resampler2.
Resample(signal_upsampled,
true, &signal_downsampled);
262 int32 samp_discard = 30;
264 signal.
Dim() - (2 * samp_discard));
267 signal.
Dim() - (2 * samp_discard));
270 self2 =
VecVec(signal2_middle, signal2_middle),
271 cross =
VecVec(signal_middle, signal2_middle);
272 KALDI_LOG <<
"Self1 = " << self1 <<
", self2 = " << self2
273 <<
", cross = " << cross;
280 for (
int32 x = 0; x < 50; x++)
282 for (
int32 x = 0; x < 50; x++)
284 for (
int32 x = 0; x < 50; x++)
289 }
catch(
const std::exception &e) {
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void Resample(const VectorBase< BaseFloat > &input, bool flush, Vector< BaseFloat > *output)
This function does the resampling.
float RandUniform(struct RandomState *state=NULL)
Returns a random number strictly between 0 and 1.
void UnitTestArbitraryResample()
float RandGauss(struct RandomState *state=NULL)
void UnitTestLinearResample2()
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
Class ArbitraryResample allows you to resample a signal (assumed zero outside the sample region...
void Resample(const MatrixBase< BaseFloat > &input, MatrixBase< BaseFloat > *output) const
This function does the resampling.
MatrixIndexT Dim() const
Returns the dimension of the vector.
void SetRandn()
Set vector to random normally-distributed noise.
TestFunction(double frequency)
A class representing a vector.
LinearResample is a special case of ArbitraryResample, where we want to resample a signal at linearly...
#define KALDI_ASSERT(cond)
static void AssertEqual(float a, float b, float relative_tolerance=0.001)
assert abs(a - b) <= relative_tolerance * (abs(a)+abs(b))
void UnitTestLinearResample()
Real VecVec(const VectorBase< Real > &a, const VectorBase< Real > &b)
Returns dot product between v1 and v2.
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
static bool ApproxEqual(float a, float b, float relative_tolerance=0.001)
return abs(a - b) <= relative_tolerance * (abs(a)+abs(b)).
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).