| OLD | NEW | 
|    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  | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|   25 } |   25 } | 
|   26  |   26  | 
|   27 }  // namespace |   27 }  // namespace | 
|   28  |   28  | 
|   29 namespace webrtc { |   29 namespace webrtc { | 
|   30  |   30  | 
|   31 void CovarianceMatrixGenerator::UniformCovarianceMatrix( |   31 void CovarianceMatrixGenerator::UniformCovarianceMatrix( | 
|   32     float wave_number, |   32     float wave_number, | 
|   33     const std::vector<Point>& geometry, |   33     const std::vector<Point>& geometry, | 
|   34     ComplexMatrix<float>* mat) { |   34     ComplexMatrix<float>* mat) { | 
|   35   CHECK_EQ(static_cast<int>(geometry.size()), mat->num_rows()); |   35   RTC_CHECK_EQ(static_cast<int>(geometry.size()), mat->num_rows()); | 
|   36   CHECK_EQ(static_cast<int>(geometry.size()), mat->num_columns()); |   36   RTC_CHECK_EQ(static_cast<int>(geometry.size()), mat->num_columns()); | 
|   37  |   37  | 
|   38   complex<float>* const* mat_els = mat->elements(); |   38   complex<float>* const* mat_els = mat->elements(); | 
|   39   for (size_t i = 0; i < geometry.size(); ++i) { |   39   for (size_t i = 0; i < geometry.size(); ++i) { | 
|   40     for (size_t j = 0; j < geometry.size(); ++j) { |   40     for (size_t j = 0; j < geometry.size(); ++j) { | 
|   41       if (wave_number > 0.f) { |   41       if (wave_number > 0.f) { | 
|   42         mat_els[i][j] = |   42         mat_els[i][j] = | 
|   43             BesselJ0(wave_number * Distance(geometry[i], geometry[j])); |   43             BesselJ0(wave_number * Distance(geometry[i], geometry[j])); | 
|   44       } else { |   44       } else { | 
|   45         mat_els[i][j] = i == j ? 1.f : 0.f; |   45         mat_els[i][j] = i == j ? 1.f : 0.f; | 
|   46       } |   46       } | 
|   47     } |   47     } | 
|   48   } |   48   } | 
|   49 } |   49 } | 
|   50  |   50  | 
|   51 void CovarianceMatrixGenerator::AngledCovarianceMatrix( |   51 void CovarianceMatrixGenerator::AngledCovarianceMatrix( | 
|   52     float sound_speed, |   52     float sound_speed, | 
|   53     float angle, |   53     float angle, | 
|   54     size_t frequency_bin, |   54     size_t frequency_bin, | 
|   55     size_t fft_size, |   55     size_t fft_size, | 
|   56     size_t num_freq_bins, |   56     size_t num_freq_bins, | 
|   57     int sample_rate, |   57     int sample_rate, | 
|   58     const std::vector<Point>& geometry, |   58     const std::vector<Point>& geometry, | 
|   59     ComplexMatrix<float>* mat) { |   59     ComplexMatrix<float>* mat) { | 
|   60   CHECK_EQ(static_cast<int>(geometry.size()), mat->num_rows()); |   60   RTC_CHECK_EQ(static_cast<int>(geometry.size()), mat->num_rows()); | 
|   61   CHECK_EQ(static_cast<int>(geometry.size()), mat->num_columns()); |   61   RTC_CHECK_EQ(static_cast<int>(geometry.size()), mat->num_columns()); | 
|   62  |   62  | 
|   63   ComplexMatrix<float> interf_cov_vector(1, geometry.size()); |   63   ComplexMatrix<float> interf_cov_vector(1, geometry.size()); | 
|   64   ComplexMatrix<float> interf_cov_vector_transposed(geometry.size(), 1); |   64   ComplexMatrix<float> interf_cov_vector_transposed(geometry.size(), 1); | 
|   65   PhaseAlignmentMasks(frequency_bin, |   65   PhaseAlignmentMasks(frequency_bin, | 
|   66                       fft_size, |   66                       fft_size, | 
|   67                       sample_rate, |   67                       sample_rate, | 
|   68                       sound_speed, |   68                       sound_speed, | 
|   69                       geometry, |   69                       geometry, | 
|   70                       angle, |   70                       angle, | 
|   71                       &interf_cov_vector); |   71                       &interf_cov_vector); | 
|   72   interf_cov_vector_transposed.Transpose(interf_cov_vector); |   72   interf_cov_vector_transposed.Transpose(interf_cov_vector); | 
|   73   interf_cov_vector.PointwiseConjugate(); |   73   interf_cov_vector.PointwiseConjugate(); | 
|   74   mat->Multiply(interf_cov_vector_transposed, interf_cov_vector); |   74   mat->Multiply(interf_cov_vector_transposed, interf_cov_vector); | 
|   75 } |   75 } | 
|   76  |   76  | 
|   77 void CovarianceMatrixGenerator::PhaseAlignmentMasks( |   77 void CovarianceMatrixGenerator::PhaseAlignmentMasks( | 
|   78     size_t frequency_bin, |   78     size_t frequency_bin, | 
|   79     size_t fft_size, |   79     size_t fft_size, | 
|   80     int sample_rate, |   80     int sample_rate, | 
|   81     float sound_speed, |   81     float sound_speed, | 
|   82     const std::vector<Point>& geometry, |   82     const std::vector<Point>& geometry, | 
|   83     float angle, |   83     float angle, | 
|   84     ComplexMatrix<float>* mat) { |   84     ComplexMatrix<float>* mat) { | 
|   85   CHECK_EQ(1, mat->num_rows()); |   85   RTC_CHECK_EQ(1, mat->num_rows()); | 
|   86   CHECK_EQ(static_cast<int>(geometry.size()), mat->num_columns()); |   86   RTC_CHECK_EQ(static_cast<int>(geometry.size()), mat->num_columns()); | 
|   87  |   87  | 
|   88   float freq_in_hertz = |   88   float freq_in_hertz = | 
|   89       (static_cast<float>(frequency_bin) / fft_size) * sample_rate; |   89       (static_cast<float>(frequency_bin) / fft_size) * sample_rate; | 
|   90  |   90  | 
|   91   complex<float>* const* mat_els = mat->elements(); |   91   complex<float>* const* mat_els = mat->elements(); | 
|   92   for (size_t c_ix = 0; c_ix < geometry.size(); ++c_ix) { |   92   for (size_t c_ix = 0; c_ix < geometry.size(); ++c_ix) { | 
|   93     float distance = std::cos(angle) * geometry[c_ix].x() + |   93     float distance = std::cos(angle) * geometry[c_ix].x() + | 
|   94                      std::sin(angle) * geometry[c_ix].y(); |   94                      std::sin(angle) * geometry[c_ix].y(); | 
|   95     float phase_shift = -2.f * M_PI * distance * freq_in_hertz / sound_speed; |   95     float phase_shift = -2.f * M_PI * distance * freq_in_hertz / sound_speed; | 
|   96  |   96  | 
|   97     // Euler's formula for mat[0][c_ix] = e^(j * phase_shift). |   97     // 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)); |   98     mat_els[0][c_ix] = complex<float>(cos(phase_shift), sin(phase_shift)); | 
|   99   } |   99   } | 
|  100 } |  100 } | 
|  101  |  101  | 
|  102 }  // namespace webrtc |  102 }  // namespace webrtc | 
| OLD | NEW |