Convolution.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 
11 #include "Convolution.h"
12 #include <vector>
13 
14 Convolution::Convolution(double _dt, unsigned int _range) {
16  setup(_dt, _range);
17 }
18 
20 }
21 
22 void Convolution::reset(void) {
23  f_buffer.clear();
24  g_buffer.clear();
25  integrator.reset();
26  buffer_size = 0;
27  return;
28 }
29 
30 void Convolution::setup(double _dt, unsigned int _range) {
31  dt = _dt;
32  range = _range;
33  integrator.setup(_dt, 0); // integrator range is inf (if range of integrator > 0, integrator remove f(0)*g(t) first)
34  reset();
35  return;
36 }
37 
38 void Convolution::update (double _f, double _g) {
39  f_buffer.push_back(_f);
40  g_buffer.push_back(_g);
41  buffer_size++;
42  if (range > 0 && buffer_size > range) { // restrict buffer size
43  f_buffer.pop_front();
44  g_buffer.pop_front();
45  buffer_size--;
46  }
47  return;
48 }
49 
50 double Convolution::calculate(void) {
51  // calc f(x) * g(t-x) buffer
52  std::vector<double> fg_buffer;
53  for (int i = 0; i < buffer_size; i++) {
54  fg_buffer.push_back(f_buffer[i] * g_buffer[(buffer_size -1) - i]);
55  }
56  // calc integration
57  integrator.reset();
58  for (int i = 0; i < buffer_size; i++) {
59  integrator.update(fg_buffer[i]);
60  }
61  return integrator.calculate();
62 }
double calculate(void)
Definition: Integrator.cpp:65
std::deque< double > f_buffer
Definition: Convolution.h:29
void setup(double _dt, unsigned int _range)
Definition: Convolution.cpp:30
double calculate(void)
Definition: Convolution.cpp:50
unsigned int range
Definition: Convolution.h:28
png_uint_32 i
long long buffer_size
Definition: Convolution.h:31
Convolution Calculator.
double dt
Definition: Convolution.h:27
void setup(double _dt, unsigned int _range)
Definition: Integrator.cpp:32
void update(double _x)
Definition: Integrator.cpp:39
Convolution(double _dt=0.005, unsigned int _range=0)
Definition: Convolution.cpp:14
void reset(void)
Definition: Integrator.cpp:23
void reset(void)
Definition: Convolution.cpp:22
~Convolution(void)
Definition: Convolution.cpp:19
std::deque< double > g_buffer
Definition: Convolution.h:30
Integrator integrator
Definition: Convolution.h:32
void update(double _f, double _g)
Definition: Convolution.cpp:38


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Sat Dec 17 2022 03:52:20