1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "modules/audio_processing/echo_detector/normalized_covariance_estimator.h"
12
13 #include <math.h>
14
15 #include "rtc_base/checks.h"
16
17 namespace webrtc {
18 namespace {
19
20 // Parameter controlling the adaptation speed.
21 constexpr float kAlpha = 0.001f;
22
23 } // namespace
24
Update(float x,float x_mean,float x_sigma,float y,float y_mean,float y_sigma)25 void NormalizedCovarianceEstimator::Update(float x,
26 float x_mean,
27 float x_sigma,
28 float y,
29 float y_mean,
30 float y_sigma) {
31 covariance_ =
32 (1.f - kAlpha) * covariance_ + kAlpha * (x - x_mean) * (y - y_mean);
33 normalized_cross_correlation_ = covariance_ / (x_sigma * y_sigma + .0001f);
34 RTC_DCHECK(isfinite(covariance_));
35 RTC_DCHECK(isfinite(normalized_cross_correlation_));
36 }
37
Clear()38 void NormalizedCovarianceEstimator::Clear() {
39 covariance_ = 0.f;
40 normalized_cross_correlation_ = 0.f;
41 }
42
43 } // namespace webrtc
44