// FIRFilter.h: interface for the FIRFilter class.
|
//
|
//////////////////////////////////////////////////////////////////////
|
|
#ifndef AFX_FIRFILTER_H__2606F3F5_42AA_4DB8_84F6_771D94AE518C__INCLUDED_
|
#define AFX_FIRFILTER_H__2606F3F5_42AA_4DB8_84F6_771D94AE518C__INCLUDED_
|
|
#include <vector>
|
#include <math.h>
|
|
template <class T>
|
class FIRFilter
|
{
|
public:
|
FIRFilter(double *coeffs, int numCoeffs)
|
{
|
if (numCoeffs > 0)
|
{
|
for (int i=0; i<numCoeffs; i++)
|
{
|
coeff.push_back(coeffs[i]);
|
history.push_back(0);
|
}
|
}
|
this->numCoeffs = numCoeffs;
|
int bits = sizeof(T) * 8;
|
maxValue = pow(2, bits-1) - 1;
|
minValue = - pow(2, bits-1);
|
}
|
|
virtual ~FIRFilter()
|
{
|
}
|
|
int DoFIR(void *in, void *out, int numSamples)
|
{
|
T *input = (T*)in;
|
T *output = (T*)out;
|
for (int i=0; i<numSamples; i++)
|
{
|
history.insert(history.begin(), (long)(input[i]));
|
history.pop_back();
|
double result = 0;
|
for (int j=0; j<numCoeffs; j++)
|
{
|
result += history[j] * coeff[j];
|
}
|
result = result > maxValue ? maxValue : result;
|
result = result < minValue ? minValue : result;
|
output[i] = (T)result;
|
}
|
return 0;
|
}
|
|
private:
|
std::vector<long> history;
|
std::vector<double> coeff;
|
int numCoeffs;
|
double minValue, maxValue;
|
};
|
|
#endif // !defined(AFX_FIRFILTER_H__2606F3F5_42AA_4DB8_84F6_771D94AE518C__INCLUDED_)
|