7 #define BUDDA_Q_SCALE 6.f 11 : num_data_(num_data), idx_(0), sum_(0.0) {
49 mNumSample = num_sample;
51 mCutoffFreq = cutoff_frequency;
53 mpBuffer =
new T[num_sample];
54 memset((
void *)mpBuffer, 0,
sizeof(T) * num_sample);
69 for (j = mNumSample - 2; j >= 0; j--) {
70 mpBuffer[j + 1] = mpBuffer[j];
73 mpBuffer[0] = input_value;
74 for (j = 0; j < mNumSample; j++) {
76 value += sqrt_2 / mCutoffFreq * mpBuffer[j] * exp(-1. / sqrt_2 * t) *
77 sin(mCutoffFreq / sqrt_2 * t) * mDt;
90 for (
int i(0); i < mNumSample; ++i) {
100 template <
typename T>
102 Lpf_in_prev[0] = Lpf_in_prev[1] = 0;
103 Lpf_out_prev[0] = Lpf_out_prev[1] = 0;
104 Lpf_in1 = 0, Lpf_in2 = 0, Lpf_in3 = 0, Lpf_out1 = 0, Lpf_out2 = 0;
105 float den = 2500 * t_s * t_s * w_c * w_c + 7071 * t_s * w_c + 10000;
107 Lpf_in1 = 2500 * t_s * t_s * w_c * w_c / den;
108 Lpf_in2 = 5000 * t_s * t_s * w_c * w_c / den;
109 Lpf_in3 = 2500 * t_s * t_s * w_c * w_c / den;
110 Lpf_out1 = -(5000 * t_s * t_s * w_c * w_c - 20000) / den;
111 Lpf_out2 = -(2500 * t_s * t_s * w_c * w_c - 7071 * t_s * w_c + 10000) / den;
114 template <
typename T>
117 template <
typename T>
119 lpf_out = Lpf_in1 * lpf_in + Lpf_in2 * Lpf_in_prev[0] +
120 Lpf_in3 * Lpf_in_prev[1] +
121 Lpf_out1 * Lpf_out_prev[0] +
122 Lpf_out2 * Lpf_out_prev[1];
123 Lpf_in_prev[1] = Lpf_in_prev[0];
124 Lpf_in_prev[0] = lpf_in;
125 Lpf_out_prev[1] = Lpf_out_prev[0];
126 Lpf_out_prev[0] = lpf_out;
129 template <
typename T>
134 template <
typename T>
147 template <
typename T>
159 T den = 4 + 2 * a * w_c * t_s + t_s * t_s * w_c * w_c;
161 Lpf_in1 = 2 * t_s * w_c * w_c / den;
163 Lpf_in3 = -2. * t_s * w_c * w_c / den;
164 Lpf_out1 = -1. * (-8 + t_s * t_s * w_c * w_c * 2) / den;
165 Lpf_out2 = -1. * (4 - 2 * a * w_c * t_s + t_s * t_s * w_c * w_c) / den;
170 template <
typename T>
173 template <
typename T>
176 lpf_out = Lpf_in1 * lpf_in + Lpf_in2 * Lpf_in_prev[0] +
177 Lpf_in3 * Lpf_in_prev[1] +
178 Lpf_out1 * Lpf_out_prev[0] +
179 Lpf_out2 * Lpf_out_prev[1];
191 Lpf_in_prev[1] = Lpf_in_prev[0];
192 Lpf_in_prev[0] = lpf_in;
193 Lpf_out_prev[1] = Lpf_out_prev[0];
194 Lpf_out_prev[0] = lpf_out;
198 template <
typename T>
203 template <
typename T>
216 template <
typename T>
218 Lpf_in_prev[0] = Lpf_in_prev[1] = 0;
219 Lpf_out_prev[0] = Lpf_out_prev[1] = 0;
220 Lpf_in1 = 0, Lpf_in2 = 0, Lpf_in3 = 0, Lpf_out1 = 0, Lpf_out2 = 0;
222 T den = 4 + 2 * a * w_c * t_s + t_s * t_s * w_c * w_c;
226 Lpf_in1 = B * t_s * t_s * w_c * w_c + 2 * J * t_s * w_c * w_c;
227 Lpf_in2 = 2 * B * t_s * t_s * w_c * w_c;
228 Lpf_in3 = B * t_s * t_s * w_c * w_c - 2 * J * t_s * w_c * w_c;
229 Lpf_out1 = -1. * (-8 + t_s * t_s * w_c * w_c * 2) / den;
230 Lpf_out2 = -1. * (4 - 2 * a * w_c * t_s + t_s * t_s * w_c * w_c) / den;
233 template <
typename T>
236 template <
typename T>
238 lpf_out = Lpf_in1 * lpf_in + Lpf_in2 * Lpf_in_prev[0] +
239 Lpf_in3 * Lpf_in_prev[1] +
240 Lpf_out1 * Lpf_out_prev[0] +
241 Lpf_out2 * Lpf_out_prev[1];
242 Lpf_in_prev[1] = Lpf_in_prev[0];
243 Lpf_in_prev[0] = lpf_in;
244 Lpf_out_prev[1] = Lpf_out_prev[0];
245 Lpf_out_prev[0] = lpf_out;
248 template <
typename T>
253 template <
typename T>
266 template <
typename T>
270 Lpf_in_prev[0] = Lpf_in_prev[1] = 0;
271 Lpf_out_prev[0] = Lpf_out_prev[1] = 0;
272 Lpf_in1 = 0, Lpf_in2 = 0, Lpf_in3 = 0, Lpf_out1 = 0, Lpf_out2 = 0;
275 T den = 4 + 2 * a * w_c * t_s + t_s * t_s * w_c * w_c;
277 Lpf_in1 = J * 2 * t_s * w_c * w_c / den;
279 Lpf_in3 = -2. * J * t_s * w_c * w_c / den;
280 Lpf_out1 = -1. * (-8 + t_s * t_s * w_c * w_c * 2) / den;
281 Lpf_out2 = -1. * (4 - 2 * a * w_c * t_s + t_s * t_s * w_c * w_c) / den;
286 template <
typename T>
289 template <
typename T>
291 lpf_out = Lpf_in1 * lpf_in + Lpf_in2 * Lpf_in_prev[0] +
292 Lpf_in3 * Lpf_in_prev[1] +
293 Lpf_out1 * Lpf_out_prev[0] +
294 Lpf_out2 * Lpf_out_prev[1];
295 Lpf_in_prev[0] = lpf_in;
296 Lpf_in_prev[1] = Lpf_in_prev[0];
297 Lpf_out_prev[0] = lpf_out;
298 Lpf_out_prev[1] = Lpf_out_prev[0];
301 template <
typename T>
306 template <
typename T>
319 template <
typename T>
321 : dt_(dt), t_const_(t_const), limit_(limit) {
325 template <
typename T>
330 template <
typename T>
335 template <
typename T>
338 if (fabs(update_value) >
limit_) {
344 template <
typename T>
moving_average_filter(int num_data)
ff01_filter(float t_s, float w_c)
deriv_lp_filter(T w_c, T t_s)
virtual ~moving_average_filter()
virtual ~butterworth_filter(void)
virtual void input(T input_value)
virtual ~ff02_filter(void)
virtual ~ff01_filter(void)
virtual ~digital_lp_filter(void)
virtual void input(T input_value)
virtual void input(T input_value)
virtual void input(T input_value)
virtual void input(T input_value)
virtual ~deriv_lp_filter(void)
ff02_filter(float t_s, float w_c)
digital_lp_filter(T w_c, T t_s)
virtual void input(T input_value)
AverageFilter(T dt, T t_const, T limit)
butterworth_filter(int num_sample, T dt, T cutoff_frequency)
virtual void input(T input_value)