Skip to content
Snippets Groups Projects
Commit d7a2b23d authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#3507] Implement FIR general filter with variable number of coefficient

parent 404ce691
Branches
Tags
No related merge requests found
......@@ -30,31 +30,6 @@
#include "dcblocker.h"
FirFilter::FirFilter(std::vector<double> ir) : _impulseResponse(ir),
_length(ir.size()),
_count(0)
{}
FirFilter::~FirFilter() {}
int FirFilter::getOutputSample(int inputSample)
{
_delayLine[_count] = (double)inputSample;
double result = 0.0;
int index = _count;
for(int i = 0; i < _length; i++) {
result = result + _impulseResponse[i] * _delayLine[index--];
if(index < 0)
index = _length-1;
}
_count++;
if(_count >= _length)
_count = 0;
return (int)result;
}
DcBlocker::DcBlocker() : _y(0), _x(0), _xm1(0), _ym1(0) {}
DcBlocker::~DcBlocker() {}
......
......@@ -36,52 +36,6 @@
#include <vector>
#define MAXFILTERSIZE 100
class FirFilter {
public:
/**
* Constructor for this class
*/
FirFilter(std::vector<double> ir);
/**
* SDestructor for this class
*/
~FirFilter();
private:
/**
* Length of the filter
*/
int _length;
/**
* Coefficient of the filter
*/
std::vector<double> _impulseResponse;
/**
* Circular buffer
*/
double _delayLine[MAXFILTERSIZE];
/**
* Counter
*/
int _count;
/**
* Perform filtering on one sample
*/
int getOutputSample(int inputSample);
};
class DcBlocker : public Algorithm {
public:
......
......@@ -33,6 +33,31 @@
#include "delaydetection.h"
#include "math.h"
FirFilter::FirFilter(std::vector<double> ir) : _impulseResponse(ir),
_length(ir.size()),
_count(0)
{}
FirFilter::~FirFilter() {}
int FirFilter::getOutputSample(int inputSample)
{
_delayLine[_count] = (double)inputSample;
double result = 0.0;
int index = _count;
for(int i = 0; i < _length; i++) {
result = result + _impulseResponse[i] * _delayLine[index--];
if(index < 0)
index = _length-1;
}
_count++;
if(_count >= _length)
_count = 0;
return (int)result;
}
DelayDetection::DelayDetection(){}
DelayDetection::~DelayDetection(){}
......@@ -43,7 +68,9 @@ void DelayDetection::putData(SFLDataFormat *inputData, int nbBytes) {}
int DelayDetection::getData(SFLDataFormat *outputData) { return 0; }
void DelayDetection::process(SFLDataFormat *inputData, int nbBytes) {}
void DelayDetection::process(SFLDataFormat *inputData, int nbBytes) {
}
int DelayDetection::process(SFLDataFormat *intputData, SFLDataFormat *outputData, int nbBytes) { return 0; }
......
......@@ -40,6 +40,53 @@
// Segment length in ms for correlation
#define MAX_DELAY 150
#define MAXFILTERSIZE 100
class FirFilter {
public:
/**
* Constructor for this class
*/
FirFilter(std::vector<double> ir);
/**
* SDestructor for this class
*/
~FirFilter();
private:
/**
* Length of the filter
*/
int _length;
/**
* Coefficient of the filter
*/
std::vector<double> _impulseResponse;
/**
* Circular buffer
*/
double _delayLine[MAXFILTERSIZE];
/**
* Counter
*/
int _count;
/**
* Perform filtering on one sample
*/
int getOutputSample(int inputSample);
};
class DelayDetection : public Algorithm {
public:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment