source: flair-src/trunk/lib/FlairFilter/src/ButterworthLowPass_impl.cpp@ 150

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

m

File size: 3.0 KB
RevLine 
[10]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[10]4// %flair:license}
[7]5// created: 2013/12/10
6// filename: ButterworthLowPass_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 de Butterworth
14//
15//
16/*********************************************************************/
17
18#include "ButterworthLowPass_impl.h"
19#include "ButterworthLowPass.h"
20#include <cvmatrix.h>
21#include <Layout.h>
22#include <GroupBox.h>
23#include <SpinBox.h>
24#include <DoubleSpinBox.h>
25
26using std::string;
27using namespace flair::core;
28using namespace flair::gui;
29using namespace flair::filter;
30
[15]31ButterworthLowPass_impl::ButterworthLowPass_impl(ButterworthLowPass *self,
32 const LayoutPosition *position,
33 string name, int order) {
34 // init UI
35 GroupBox *reglages_groupbox = new GroupBox(position, name);
36 T = new DoubleSpinBox(reglages_groupbox->NewRow(), "period, 0 for auto", " s",
37 0, 10, 0.01);
38 cutoff = new DoubleSpinBox(reglages_groupbox->NewRow(), "cutoff frequency",
39 " Hz", 0, 10000, 0.1, 2, 1);
[7]40
[15]41 cvmatrix_descriptor *desc = new cvmatrix_descriptor(1, 1);
42 desc->SetElementName(0, 0, "output");
43 output = new cvmatrix(self, desc, floatType, name);
[148]44 delete desc;
[7]45
[15]46 f = new PoleFilter(order);
[7]47
[147]48 if (T->Value() != 0) {
[15]49 f->setup(1. / T->Value(), cutoff->Value());
[147]50 }
51
[15]52 f->reset();
[7]53
[15]54 first_update = true;
[147]55 this->order=order;
[7]56}
57
[15]58ButterworthLowPass_impl::~ButterworthLowPass_impl() { delete f; }
[7]59
[15]60void ButterworthLowPass_impl::UpdateFrom(const io_data *data) {
61 float result;
62 cvmatrix *input = (cvmatrix *)data;
[147]63 float delta_t;
64
65 if (T->ValueChanged()) {
[15]66 if (T->Value() != 0) {
67 f->setup(1. / T->Value(), cutoff->Value());
[147]68 settingsChanged(input->Value(0, 0));
[7]69 }
[15]70 }
[7]71
[147]72 if (T->Value() == 0) {
73 delta_t = (float)(data->DataTime() - previous_time) / 1000000000.;
74 f->setup(1. / delta_t, cutoff->Value());
75 } else {
76 delta_t=T->Value();
77 }
78
[15]79 // on prend une fois pour toute les mutex et on fait des accès directs
80 output->GetMutex();
81 input->GetMutex();
[7]82
[147]83 if (cutoff->ValueChanged()) {
[15]84 f->setup(1. / delta_t, cutoff->Value());
[147]85 settingsChanged(input->ValueNoMutex(0, 0));
[15]86 }
[7]87
[15]88 if (first_update == true) {
89 first_update = false;
90 } else {
91 result = f->filter(input->ValueNoMutex(0, 0));
92 output->SetValueNoMutex(0, 0, result);
93 }
[7]94
[15]95 input->ReleaseMutex();
96 output->ReleaseMutex();
[7]97
[15]98 output->SetDataTime(data->DataTime());
99 previous_time = data->DataTime();
[7]100}
[147]101
102//ne gere pas les oscillations (s'arrete des qu'une valeure est bonne a 5%)
103void ButterworthLowPass_impl::settingsChanged(float inputValue) {
104 float result=f->filter(inputValue);
105
106 while(result<inputValue*0.95 || result>inputValue*1.05) {
107 result=f->filter(inputValue);
108 }
109}
Note: See TracBrowser for help on using the repository browser.