source: flair-src/trunk/lib/FlairFilter/src/LowPassFilter_impl.cpp@ 147

Last change on this file since 147 was 147, checked in by Sanahuja Guillaume, 7 years ago

modif euler/lowpass

File size: 3.3 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5// created: 2011/05/01
6// filename: LowPassFilter_impl.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: objet permettant le calcul d'un filtre passe bas
14//
15//
16/*********************************************************************/
17
18#include "LowPassFilter_impl.h"
19#include "LowPassFilter.h"
20#include <cvmatrix.h>
21#include <Layout.h>
22#include <GroupBox.h>
23#include <SpinBox.h>
24#include <DoubleSpinBox.h>
25
26#define PI ((float)3.14159265358979323846)
27
28using std::string;
29using namespace flair::core;
30using namespace flair::gui;
31using namespace flair::filter;
32
33LowPassFilter_impl::LowPassFilter_impl(const LowPassFilter *self,
34 const LayoutPosition *position,
35 string name,
36 const cvmatrix *init_value) {
37
38 if (init_value != NULL) {
39 // init output matrix of same size as init
40 cvmatrix_descriptor *desc =new cvmatrix_descriptor(init_value->Rows(), init_value->Cols());
41
42 for (int i = 0; i < init_value->Rows(); i++) {
43 for (int j = 0; j < init_value->Cols(); j++) {
44 desc->SetElementName(i, j, init_value->Name(i, j));
45 }
46 }
47 output = new cvmatrix(self, desc,init_value->GetDataType().GetElementDataType(), name);
48 for (int i = 0; i < init_value->Rows(); i++) {
49 for (int j = 0; j < init_value->Cols(); j++) {
50 output->SetValue(i, j, init_value->Value(i,j));
51 }
52 }
53 } else {
54 // if NULL, assume dimension 1, and init=0
55 cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1);
56 desc->SetElementName(0, 0, "output");
57 output = new cvmatrix(self, desc, floatType, name);
58 output->SetValue(0, 0, 0);
59 }
60
61 // init UI
62 GroupBox *reglages_groupbox = new GroupBox(position, name);
63 T = new DoubleSpinBox(reglages_groupbox->NewRow(), "period, 0 for auto", " s",
64 0, 10, 0.01);
65 freq = new DoubleSpinBox(reglages_groupbox->NewRow(), "cutoff frequency",
66 " Hz", 0, 10000, 0.1, 2, 1);
67
68 previous_time=GetTime();
69}
70
71LowPassFilter_impl::~LowPassFilter_impl() {}
72
73void LowPassFilter_impl::UpdateFrom(const io_data *data) {
74 float delta_t;
75 cvmatrix *input = (cvmatrix *)data;
76
77 // on prend une fois pour toute les mutex et on fait des accès directs
78 output->GetMutex();
79 input->GetMutex();
80
81 if (T->Value() == 0) {
82 delta_t = (float)(data->DataTime() - previous_time) / 1000000000.;
83 } else {
84 delta_t = T->Value();
85 }
86 for (int i = 0; i < input->Rows(); i++) {
87 for (int j = 0; j < input->Cols(); j++) {
88 float cutoff=freq->Value();
89 if (cutoff == 0 || freq->ValueChanged()) {
90 output->SetValueNoMutex(i, j, input->ValueNoMutex(i, j));
91 } else {
92 output->SetValueNoMutex(i, j, (1 - 2 * PI * cutoff * delta_t) *
93 output->ValueNoMutex(i, j) +
94 2 * PI * cutoff * delta_t *
95 input->ValueNoMutex(i, j));
96 }
97 }
98 }
99
100 input->ReleaseMutex();
101 output->ReleaseMutex();
102
103 output->SetDataTime(data->DataTime());
104 previous_time = data->DataTime();
105}
Note: See TracBrowser for help on using the repository browser.