📄 firfilter.h
字号:
// 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_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -