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

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

filter and meta

File size: 2.3 KB
Line 
1// created: 2013/12/10
2// filename: ButterworthLowPass_impl.cpp
3//
4// author: Guillaume Sanahuja
5// Copyright Heudiasyc UMR UTC/CNRS 7253
6//
7// version: $Id: $
8//
9// purpose: objet permettant le calcul d'un filtre passe bas de Butterworth
10//
11//
12/*********************************************************************/
13
14#include "ButterworthLowPass_impl.h"
15#include "ButterworthLowPass.h"
16#include <cvmatrix.h>
17#include <Layout.h>
18#include <GroupBox.h>
19#include <SpinBox.h>
20#include <DoubleSpinBox.h>
21
22using std::string;
23using namespace flair::core;
24using namespace flair::gui;
25using namespace flair::filter;
26
27ButterworthLowPass_impl::ButterworthLowPass_impl(ButterworthLowPass* self,const LayoutPosition* position,string name,int order)
28{
29 //init UI
30 GroupBox* reglages_groupbox=new GroupBox(position,name);
31 T=new DoubleSpinBox(reglages_groupbox->NewRow(),"period, 0 for auto"," s",0,10,0.01);
32 cutoff=new DoubleSpinBox(reglages_groupbox->NewRow(),"cutoff frequency"," Hz",0,10000,0.1,2,1);
33
34 cvmatrix_descriptor* desc=new cvmatrix_descriptor(1,1);
35 desc->SetElementName(0,0,"output");
36 output=new cvmatrix(self,desc,floatType,name);
37
38 output->SetValue(0,0,0);
39
40 f= new PoleFilter(order);
41
42 if(T->Value()!=0) f->setup(1./T->Value(), cutoff->Value());
43 f->reset();
44
45 first_update=true;
46}
47
48ButterworthLowPass_impl::~ButterworthLowPass_impl()
49{
50 delete f;
51}
52
53void ButterworthLowPass_impl::UpdateFrom(const io_data *data)
54{
55 float result;
56 cvmatrix *input=(cvmatrix*)data;
57
58 if(T->ValueChanged() || cutoff->ValueChanged())
59 {
60 if(T->Value()!=0)
61 {
62 f->setup (1./T->Value(), cutoff->Value());
63 }
64 else
65 {
66 first_update=true;
67 }
68 }
69
70 //on prend une fois pour toute les mutex et on fait des accès directs
71 output->GetMutex();
72 input->GetMutex();
73
74 if(T->Value()==0)
75 {
76 float delta_t=(float)(data->DataTime()-previous_time)/1000000000.;
77 f->setup (1./delta_t, cutoff->Value());
78 }
79
80 if(first_update==true)
81 {
82 first_update=false;
83 }
84 else
85 {
86 result = f->filter(input->ValueNoMutex(0,0));
87 output->SetValueNoMutex(0,0,result);
88 }
89
90 input->ReleaseMutex();
91 output->ReleaseMutex();
92
93 output->SetDataTime(data->DataTime());
94 previous_time=data->DataTime();
95}
96
Note: See TracBrowser for help on using the repository browser.