fir filter
i have code for fir filter below. The way it's coded means it is really slow during debugging (vs 8). Can anyone identify where the slow bits are or even better, suggest quicker code?
Thanks
Code:
vector<double> filter( const vector<double>& b, const vector<double>& x )
{
vector<double> y;
vector<double> prev_x;
// Cycle for x
for( size_t i = 0; i < x.size(); i++ ) {
double y_n;
prev_x.push_back( x[i] );
if( prev_x.size() > b.size() )
prev_x.erase( prev_x.begin() );
// Cycle for prev_x
size_t nt = prev_x.size();
y_n = 0;
for( size_t j = 0; j < nt; j++ ) {
y_n += b[j] * prev_x[nt-j-1];
}
y.push_back( y_n );
}
return y;
}
by the way vectors are by know means necessary - arrays are ok...
Last edited by dave2k; June 22nd, 2008 at 02:03 PM.
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925