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.
recursivefilters.cpp
Go to the documentation of this file.
1 // Copyright (C) 2017 Edouard Griffiths, F4EXB //
3 // //
4 // This program is free software; you can redistribute it and/or modify //
5 // it under the terms of the GNU General Public License as published by //
6 // the Free Software Foundation as version 3 of the License, or //
7 // (at your option) any later version. //
8 // //
9 // This program is distributed in the hope that it will be useful, //
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
12 // GNU General Public License V3 for more details. //
13 // //
14 // You should have received a copy of the GNU General Public License //
15 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
17 
18 #include <math.h>
19 #include "recursivefilters.h"
20 
21 #undef M_PI
22 #define M_PI 3.14159265358979323846
23 
24 SecondOrderRecursiveFilter::SecondOrderRecursiveFilter(float samplingFrequency, float centerFrequency, float r) :
25  m_r(r),
26  m_frequencyRatio(centerFrequency/samplingFrequency),
27  m_f(cos(2.0*M_PI*(m_frequencyRatio)))
28 {
29  init();
30 }
31 
33 {}
34 
35 void SecondOrderRecursiveFilter::setFrequencies(float samplingFrequency, float centerFrequency)
36 {
37  m_frequencyRatio = centerFrequency / samplingFrequency;
39  init();
40 }
41 
43 {
44  m_r = r;
45  init();
46 }
47 
49 {
50  m_v[0] = ((1.0f - m_r) * (float) sample) + (2.0f * m_r * m_f * m_v[1]) - (m_r * m_r * m_v[2]);
51  float y = m_v[0] - m_v[2];
52  m_v[2] = m_v[1];
53  m_v[1] = m_v[0];
54 
55  return (short) y;
56 }
57 
59 {
60  m_v[0] = ((1.0f - m_r) * sample) + (2.0f * m_r * m_f * m_v[1]) - (m_r * m_r * m_v[2]);
61  float y = m_v[0] - m_v[2];
62  m_v[2] = m_v[1];
63  m_v[1] = m_v[0];
64 
65  return y;
66 }
67 
69 {
70  for (int i = 0; i < 3; i++)
71  {
72  m_v[i] = 0.0f;
73  }
74 }
75 
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2271
void setFrequencies(float samplingFrequency, float centerFrequency)
int32_t i
Definition: decimators.h:244
SecondOrderRecursiveFilter(float samplingFrequency, float centerFrequency, float r)
#define M_PI