CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: fir filter

Threaded View

  1. #1
    Join Date
    Aug 2005
    Location
    southampton, UK
    Posts
    1,320

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured