source: flair-src/trunk/lib/FlairFilter/src/unexported/ButterworthLowPass_impl.h@ 147

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

modif euler/lowpass

File size: 3.7 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/*!
6 * \file ButterworthLowPass_impl.h
7 * \brief Classe permettant le calcul d'un filtre passe bas de Butterworth
8 * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
9 * \date 2011/05/01
10 * \version 4.0
11 */
12
13#ifndef BUTTERWORTHLOWPASS_H_IMPL_H
14#define BUTTERWORTHLOWPASS_H_IMPL_H
15
16#include <IODevice.h>
17#include <Butterworth.h>
18
19namespace flair {
20namespace core {
21class cvmatrix;
22}
23namespace gui {
24class LayoutPosition;
25class SpinBox;
26class DoubleSpinBox;
27}
28namespace filter {
29class ButterworthLowPass;
30}
31}
32
33// Storage for Layout
34// de-templatized for pimpl idom
35// comes from iir from Bernd Porr
36class LayoutStorage {
37public:
38 LayoutStorage(int MaxPoles) {
39 this->MaxPoles = MaxPoles;
40 m_pairs = (Iir::PoleZeroPair *)malloc((MaxPoles + 1) / 2 *
41 sizeof(Iir::PoleZeroPair));
42 }
43 ~LayoutStorage() { free(m_pairs); }
44 operator Iir::LayoutBase() { return Iir::LayoutBase(MaxPoles, m_pairs); }
45
46private:
47 Iir::PoleZeroPair *m_pairs;
48 int MaxPoles;
49};
50
51// Storage for Cascade
52// de-templatized for pimpl idom
53// comes from iir from Bernd Porr
54class CascadeStages {
55public:
56 CascadeStages(int MaxStages) {
57 this->MaxStages = MaxStages;
58 m_stages =
59 (Iir::Cascade::Stage *)malloc(MaxStages * sizeof(Iir::Cascade::Stage));
60 m_states =
61 (Iir::DirectFormII *)malloc(MaxStages * sizeof(Iir::DirectFormII));
62 }
63 ~CascadeStages() {
64 free(m_stages);
65 free(m_states);
66 }
67 void reset() {
68 Iir::DirectFormII *state = m_states;
69 for (int i = MaxStages; --i >= 0; ++state)
70 state->reset();
71 }
72
73 template <typename Sample> inline Sample filter(const Sample in) {
74 double out = in;
75 Iir::DirectFormII *state = m_states;
76 Iir::Biquad const *stage = m_stages;
77 for (int i = MaxStages; --i >= 0; ++state, ++stage)
78 out = state->process1(out, *stage);
79 return static_cast<Sample>(out);
80 }
81
82 Iir::Cascade::Storage getCascadeStorage() {
83 return Iir::Cascade::Storage(MaxStages, m_stages);
84 }
85
86private:
87 int MaxStages;
88 Iir::Cascade::Stage *m_stages;
89 Iir::DirectFormII *m_states;
90};
91
92// de-templatized for pimpl idom
93// comes from iir from Bernd Porr
94class PoleFilter : Iir::Butterworth::LowPassBase, public CascadeStages {
95public:
96 PoleFilter(int MaxPoles) : CascadeStages((MaxPoles + 1) / 2) {
97 this->MaxPoles = MaxPoles;
98 m_analogStorage = new LayoutStorage(MaxPoles);
99 m_digitalStorage = new LayoutStorage(MaxPoles);
100 // This glues together the factored base classes
101 // with the templatized storage classes.
102 Iir::Butterworth::LowPassBase::setCascadeStorage(this->getCascadeStorage());
103 Iir::Butterworth::LowPassBase::setPrototypeStorage(*m_analogStorage,
104 *m_digitalStorage);
105 }
106 ~PoleFilter() {
107 delete m_analogStorage;
108 delete m_digitalStorage;
109 }
110 void setup(double sampleRate, double cutoffFrequency) {
111 Iir::Butterworth::LowPassBase::setup(MaxPoles, sampleRate, cutoffFrequency);
112 }
113
114private:
115 int MaxPoles;
116 LayoutStorage *m_analogStorage;
117 LayoutStorage *m_digitalStorage;
118};
119
120class ButterworthLowPass_impl {
121public:
122 ButterworthLowPass_impl(flair::filter::ButterworthLowPass *self,
123 const flair::gui::LayoutPosition *position,
124 std::string name, int order);
125 ~ButterworthLowPass_impl();
126 void UpdateFrom(const flair::core::io_data *data);
127 flair::core::cvmatrix *output;
128
129private:
130 void settingsChanged(float inputValue);
131 flair::gui::DoubleSpinBox *cutoff, *T;
132 PoleFilter *f;
133 bool first_update;
134 flair::core::Time previous_time;
135 int order;
136};
137
138#endif // BUTTERWORTHLOWPASS_H_IMPL_H
Note: See TracBrowser for help on using the repository browser.