-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBandPassFilter.cpp
62 lines (52 loc) · 1.9 KB
/
BandPassFilter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "BandPassFilter.h"
BandPassFilter::BandPassFilter(float SampleRate, float Center, float cutOff)
{
cutOffFrequency = cutOff / (float)SampleRate; // cutoff frequency
centerFrequency = Center / (float)SampleRate; // center frequency
passBandRipple = 1.0f; // pass-band ripple
StopBandAttenuation = 40.0f; // stop-band attenuation
if (bandPassHandle)
iirfilt_crcf_destroy(bandPassHandle);
bandPassHandle = iirfilt_crcf_create_prototype(butterwurthType, bandFilterType, sosFormat, filterOrder, cutOffFrequency, centerFrequency, passBandRipple, StopBandAttenuation);
iirfilt_crcf_print(bandPassHandle);
}
BandPassFilter::BandPassFilter()
{
cutOffFrequency = 0;
centerFrequency = 0;
passBandRipple = 1.0f; // pass-band ripple
StopBandAttenuation = 40.0f; // stop-band attenuation
bandPassHandle = nullptr;
}
BandPassFilter::~BandPassFilter()
{
if (bandPassHandle)
iirfilt_crcf_destroy(bandPassHandle);
bandPassHandle = nullptr;
}
void BandPassFilter::SetBandPassFilter(float SampleRate, float Center, float cutOff)
{
cutOffFrequency = cutOff / (float)SampleRate; // cutoff frequency
centerFrequency = Center / (float)SampleRate; // center frequency
passBandRipple = 1.0f; // pass-band ripple
StopBandAttenuation = 40.0f; // stop-band attenuation
if (bandPassHandle)
iirfilt_crcf_destroy(bandPassHandle);
bandPassHandle = iirfilt_crcf_create_prototype(butterwurthType, bandFilterType, sosFormat, filterOrder, cutOffFrequency, centerFrequency, passBandRipple, StopBandAttenuation);
iirfilt_crcf_print(bandPassHandle);
}
void BandPassFilter::executeBandpassFilter(const IQSampleVector &filter_in,
IQSampleVector &filter_out)
{
if (bandPassHandle == nullptr)
{
filter_out = filter_in;
return;
}
for (auto &col : filter_in)
{
std::complex<float> v;
iirfilt_crcf_execute(bandPassHandle, col, &v);
filter_out.insert(filter_out.end(), v);
}
}