Apollo 10.0
自动驾驶开放平台
apollo::audio::MovingDetection类 参考

#include <moving_detection.h>

apollo::audio::MovingDetection 的协作图:

Public 成员函数

 MovingDetection ()=default
 
std::vector< std::complex< double > > fft1d (const std::vector< double > &signals)
 
MovingResult Detect (const std::vector< std::vector< double > > &signals)
 
MovingResult DetectSingleChannel (const std::size_t channel_index, const std::vector< double > &signal)
 

详细描述

在文件 moving_detection.h31 行定义.

构造及析构函数说明

◆ MovingDetection()

apollo::audio::MovingDetection::MovingDetection ( )
default

成员函数说明

◆ Detect()

MovingResult apollo::audio::MovingDetection::Detect ( const std::vector< std::vector< double > > &  signals)

在文件 moving_detection.cc24 行定义.

25 {
26 int approaching_count = 0;
27 int departing_count = 0;
28 for (std::size_t i = 0; i < signals.size(); ++i) {
29 while (signal_stats_.size() <= i) {
30 signal_stats_.push_back({});
31 }
32 MovingResult result = DetectSingleChannel(i, signals[i]);
33 if (result == APPROACHING) {
34 ++approaching_count;
35 } else if (result == DEPARTING) {
36 ++departing_count;
37 }
38 }
39 if (approaching_count > departing_count) {
40 return APPROACHING;
41 }
42 if (approaching_count < departing_count) {
43 return DEPARTING;
44 }
45 return UNKNOWN;
46}
MovingResult DetectSingleChannel(const std::size_t channel_index, const std::vector< double > &signal)

◆ DetectSingleChannel()

MovingResult apollo::audio::MovingDetection::DetectSingleChannel ( const std::size_t  channel_index,
const std::vector< double > &  signal 
)

在文件 moving_detection.cc48 行定义.

49 {
50 static constexpr int kStartFrequency = 3;
51 static constexpr int kFrameNumStored = 10;
52 std::vector<std::complex<double>> fft_results = fft1d(signals);
53 SignalStat signal_stat = GetSignalStat(fft_results, kStartFrequency);
54 signal_stats_[channel_index].push_back(signal_stat);
55 while (static_cast<int>(signal_stats_[channel_index].size()) >
56 kFrameNumStored) {
57 signal_stats_[channel_index].pop_front();
58 }
59 // TODO(kechxu) refactor the following initial version
60 MovingResult power_result = AnalyzePower(signal_stats_[channel_index]);
61 if (power_result != UNKNOWN) {
62 return power_result;
63 }
64 MovingResult top_frequency_result =
65 AnalyzeTopFrequence(signal_stats_[channel_index]);
66 return top_frequency_result;
67}
std::vector< std::complex< double > > fft1d(const std::vector< double > &signals)

◆ fft1d()

std::vector< std::complex< double > > apollo::audio::MovingDetection::fft1d ( const std::vector< double > &  signals)

在文件 moving_detection.cc105 行定义.

106 {
107 int n = static_cast<int>(signal.size());
108 fftw_complex in[n]; // NOLINT
109 fftw_complex out[n]; // NOLINT
110 for (int i = 0; i < n; ++i) {
111 in[i][0] = signal[i];
112 in[i][1] = 0.0;
113 }
114
115 fftw_plan p = fftw_plan_dft_1d(n, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
116 fftw_execute(p);
117
118 std::vector<std::complex<double>> output;
119 output.reserve(n);
120 for (int i = 0; i < n; ++i) {
121 output.emplace_back(out[i][0], out[i][1]);
122 }
123 return output;
124}

该类的文档由以下文件生成: