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 #ifndef MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_NORMALIZED_COVARIANCE_ESTIMATOR_H_
12 #define MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_NORMALIZED_COVARIANCE_ESTIMATOR_H_
13 
14 namespace webrtc {
15 
16 // This class iteratively estimates the normalized covariance between two
17 // signals.
18 class NormalizedCovarianceEstimator {
19  public:
20   void Update(float x,
21               float x_mean,
22               float x_var,
23               float y,
24               float y_mean,
25               float y_var);
26   // This function returns an estimate of the Pearson product-moment correlation
27   // coefficient of the two signals.
normalized_cross_correlation()28   float normalized_cross_correlation() const {
29     return normalized_cross_correlation_;
30   }
covariance()31   float covariance() const { return covariance_; }
32   // This function resets the estimated values to zero.
33   void Clear();
34 
35  private:
36   float normalized_cross_correlation_ = 0.f;
37   // Estimate of the covariance value.
38   float covariance_ = 0.f;
39 };
40 
41 }  // namespace webrtc
42 
43 #endif  // MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_NORMALIZED_COVARIANCE_ESTIMATOR_H_
44