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

Last change on this file since 49 was 15, checked in by Bayard Gildas, 8 years ago

sources reformatted with flair-format-dir script

File size: 2.5 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);
[7]44
[15]45 output->SetValue(0, 0, 0);
[7]46
[15]47 f = new PoleFilter(order);
[7]48
[15]49 if (T->Value() != 0)
50 f->setup(1. / T->Value(), cutoff->Value());
51 f->reset();
[7]52
[15]53 first_update = true;
[7]54}
55
[15]56ButterworthLowPass_impl::~ButterworthLowPass_impl() { delete f; }
[7]57
[15]58void ButterworthLowPass_impl::UpdateFrom(const io_data *data) {
59 float result;
60 cvmatrix *input = (cvmatrix *)data;
[7]61
[15]62 if (T->ValueChanged() || cutoff->ValueChanged()) {
63 if (T->Value() != 0) {
64 f->setup(1. / T->Value(), cutoff->Value());
65 } else {
66 first_update = true;
[7]67 }
[15]68 }
[7]69
[15]70 // on prend une fois pour toute les mutex et on fait des accès directs
71 output->GetMutex();
72 input->GetMutex();
[7]73
[15]74 if (T->Value() == 0) {
75 float delta_t = (float)(data->DataTime() - previous_time) / 1000000000.;
76 f->setup(1. / delta_t, cutoff->Value());
77 }
[7]78
[15]79 if (first_update == true) {
80 first_update = false;
81 } else {
82 result = f->filter(input->ValueNoMutex(0, 0));
83 output->SetValueNoMutex(0, 0, result);
84 }
[7]85
[15]86 input->ReleaseMutex();
87 output->ReleaseMutex();
[7]88
[15]89 output->SetDataTime(data->DataTime());
90 previous_time = data->DataTime();
[7]91}
Note: See TracBrowser for help on using the repository browser.