SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
filterrc.cpp
Go to the documentation of this file.
1 // Copyright (C) 2015 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include <QDebug>
20 #include "dsp/filterrc.h"
21 
22 // Construct 1st order low-pass IIR filter.
24  m_timeconst(timeconst),
25  m_y1(0)
26 {
27  m_a1 = - exp(-1/m_timeconst);
28  m_b0 = 1 + m_a1;
29 }
30 
31 // Reconfigure
33 {
34  m_timeconst = timeconst;
35  m_y1 = 0;
36  m_a1 = - exp(-1/m_timeconst);
37  m_b0 = 1 + m_a1;
38 
39  qDebug() << "LowPassFilterRC::configure: t: " << m_timeconst
40  << " a1: " << m_a1
41  << " b0: " << m_b0;
42 }
43 
44 // Process samples.
45 void LowPassFilterRC::process(const Real& sample_in, Real& sample_out)
46 {
47  /*
48  * Continuous domain:
49  * H(s) = 1 / (1 - s * timeconst)
50  *
51  * Discrete domain:
52  * H(z) = (1 - exp(-1/timeconst)) / (1 - exp(-1/timeconst) / z)
53  */
54 
55  m_y1 = (sample_in * m_b0) - (m_y1 * m_a1);
56  sample_out = m_y1;
57 }
58 
59 
void configure(Real timeout)
Definition: filterrc.cpp:32
void process(const Real &sample_in, Real &sample_out)
Definition: filterrc.cpp:45
Fixed< IntType, IntBits > exp(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2289
Real m_timeconst
Definition: filterrc.h:46
LowPassFilterRC(Real timeconst)
Definition: filterrc.cpp:23
float Real
Definition: dsptypes.h:42