Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: webrtc/modules/audio_processing/beamformer/covariance_matrix_generator.cc

Issue 1378973003: Implement new version of the NonlinearBeamformer (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #define _USE_MATH_DEFINES 11 #define _USE_MATH_DEFINES
12 12
13 #include "webrtc/modules/audio_processing/beamformer/covariance_matrix_generator .h" 13 #include "webrtc/modules/audio_processing/beamformer/covariance_matrix_generator .h"
14 14
15 #include <cmath> 15 #include <cmath>
16 16
17 namespace webrtc {
17 namespace { 18 namespace {
18 19
19 float BesselJ0(float x) { 20 float BesselJ0(float x) {
20 #if WEBRTC_WIN 21 #if WEBRTC_WIN
21 return _j0(x); 22 return _j0(x);
22 #else 23 #else
23 return j0(x); 24 return j0(x);
24 #endif 25 #endif
25 } 26 }
26 27
28 float norm(const ComplexMatrix<float>& x) {
Andrew MacDonald 2015/10/06 23:54:31 Norm Add a comment clarifying what it computes.
aluebs-webrtc 2015/10/07 22:08:05 Changed naming and added documentation. Yes, it on
29 RTC_CHECK_EQ(1, x.num_rows());
30 size_t length = x.num_columns();
Andrew MacDonald 2015/10/06 23:54:31 const
aluebs-webrtc 2015/10/07 22:08:05 Done.
31 const complex<float>* elems = x.elements()[0];
32 float result = 0.f;
33 for (size_t i = 0u; i < length; ++i) {
34 result += std::abs(elems[i]) * std::abs(elems[i]);
Andrew MacDonald 2015/10/06 23:54:31 Don't compute std::abs twice. Looks like what you
aluebs-webrtc 2015/10/07 22:08:05 Good point. Done.
35 }
36 return std::sqrt(result);
37 }
38
27 } // namespace 39 } // namespace
28 40
29 namespace webrtc {
30
31 void CovarianceMatrixGenerator::UniformCovarianceMatrix( 41 void CovarianceMatrixGenerator::UniformCovarianceMatrix(
32 float wave_number, 42 float wave_number,
33 const std::vector<Point>& geometry, 43 const std::vector<Point>& geometry,
34 ComplexMatrix<float>* mat) { 44 ComplexMatrix<float>* mat) {
35 RTC_CHECK_EQ(static_cast<int>(geometry.size()), mat->num_rows()); 45 RTC_CHECK_EQ(static_cast<int>(geometry.size()), mat->num_rows());
36 RTC_CHECK_EQ(static_cast<int>(geometry.size()), mat->num_columns()); 46 RTC_CHECK_EQ(static_cast<int>(geometry.size()), mat->num_columns());
37 47
38 complex<float>* const* mat_els = mat->elements(); 48 complex<float>* const* mat_els = mat->elements();
39 for (size_t i = 0; i < geometry.size(); ++i) { 49 for (size_t i = 0; i < geometry.size(); ++i) {
40 for (size_t j = 0; j < geometry.size(); ++j) { 50 for (size_t j = 0; j < geometry.size(); ++j) {
(...skipping 21 matching lines...) Expand all
62 72
63 ComplexMatrix<float> interf_cov_vector(1, geometry.size()); 73 ComplexMatrix<float> interf_cov_vector(1, geometry.size());
64 ComplexMatrix<float> interf_cov_vector_transposed(geometry.size(), 1); 74 ComplexMatrix<float> interf_cov_vector_transposed(geometry.size(), 1);
65 PhaseAlignmentMasks(frequency_bin, 75 PhaseAlignmentMasks(frequency_bin,
66 fft_size, 76 fft_size,
67 sample_rate, 77 sample_rate,
68 sound_speed, 78 sound_speed,
69 geometry, 79 geometry,
70 angle, 80 angle,
71 &interf_cov_vector); 81 &interf_cov_vector);
82 complex<float> norm_factor = norm(interf_cov_vector);
83 interf_cov_vector.Scale(1.f / norm_factor);
72 interf_cov_vector_transposed.Transpose(interf_cov_vector); 84 interf_cov_vector_transposed.Transpose(interf_cov_vector);
73 interf_cov_vector.PointwiseConjugate(); 85 interf_cov_vector.PointwiseConjugate();
74 mat->Multiply(interf_cov_vector_transposed, interf_cov_vector); 86 mat->Multiply(interf_cov_vector_transposed, interf_cov_vector);
75 } 87 }
76 88
77 void CovarianceMatrixGenerator::PhaseAlignmentMasks( 89 void CovarianceMatrixGenerator::PhaseAlignmentMasks(
78 size_t frequency_bin, 90 size_t frequency_bin,
79 size_t fft_size, 91 size_t fft_size,
80 int sample_rate, 92 int sample_rate,
81 float sound_speed, 93 float sound_speed,
(...skipping 11 matching lines...) Expand all
93 float distance = std::cos(angle) * geometry[c_ix].x() + 105 float distance = std::cos(angle) * geometry[c_ix].x() +
94 std::sin(angle) * geometry[c_ix].y(); 106 std::sin(angle) * geometry[c_ix].y();
95 float phase_shift = -2.f * M_PI * distance * freq_in_hertz / sound_speed; 107 float phase_shift = -2.f * M_PI * distance * freq_in_hertz / sound_speed;
96 108
97 // Euler's formula for mat[0][c_ix] = e^(j * phase_shift). 109 // Euler's formula for mat[0][c_ix] = e^(j * phase_shift).
98 mat_els[0][c_ix] = complex<float>(cos(phase_shift), sin(phase_shift)); 110 mat_els[0][c_ix] = complex<float>(cos(phase_shift), sin(phase_shift));
99 } 111 }
100 } 112 }
101 113
102 } // namespace webrtc 114 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698