Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:22:09+00:00 2026-05-31T16:22:09+00:00

Quick question related to IIR filter coefficients. Here is a very typical implementation of

  • 0

Quick question related to IIR filter coefficients. Here is a very typical implementation of a direct form II biquad IIR processor that I found online.

// b0, b1, b2, a1, a2 are filter coefficients
// m1, m2 are the memory locations
// dn is the de-denormal coeff (=1.0e-20f) 

void processBiquad(const float* in, float* out, unsigned length)
{
    for(unsigned i = 0; i < length; ++i)
    {
        register float w = in[i] - a1*m1 - a2*m2 + dn;
        out[i] = b1*m1 + b2*m2 + b0*w;
        m2 = m1; m1 = w;
    }
    dn = -dn;
}

I understand that the “register” is somewhat unnecessary given how smart modern compilers are about this kind of thing. My question is, are there any potential performance benefits to storing the filter coefficients in individual variables rather than using arrays and dereferencing the values? Would the answer to this question depend on the target platform?

i.e.

out[i] = b[1]*m[1] + b[2]*m[2] + b[0]*w;

versus

out[i] = b1*m1 + b2*m2 + b0*w;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:22:10+00:00Added an answer on May 31, 2026 at 4:22 pm

    It really depends on your compiler and the optimization options. Here is my take:

    • Any modern compiler would just ignore register. It is just a hint to the compiler and modern ones just don’t use it.
    • Accessing constant indexes in a loop is usually optimized away when compiling with optimization on. In a sense, using variables or an array as you showed makes no difference.
    • Always, always run benchmarks and look at the generated code for performance critical sections of the code.

    EDIT: OK, just out of curiosity I wrote a small program and got “identical” code generated when using full optimization with VS2010. Here is what I get inside the loop for the expression in question (exactly identical for both cases):

    0128138D  fmul        dword ptr [eax+0Ch]  
    01281390  faddp       st(1),st  
    01281392  fld         dword ptr [eax+10h]  
    01281395  fld         dword ptr [w]  
    01281398  fld         st(0)  
    0128139A  fmulp       st(2),st  
    0128139C  fxch        st(2)  
    0128139E  faddp       st(1),st  
    012813A0  fstp        dword ptr [ecx+8]  
    

    Notice that I added a few lines to output the results so that I make sure compiler does not just optimize away everything. Here is the code:

    #include <iostream>
    #include <iterator>
    #include <algorithm>
    
    class test1 
    {
        float a1, a2, b0, b1, b2;
        float dn;
        float m1, m2;
    
    public:
        void processBiquad(const float* in, float* out, unsigned length)
        {
            for(unsigned i = 0; i < length; ++i)
            {
                float w = in[i] - a1*m1 - a2*m2 + dn;
                out[i] = b1*m1 + b2*m2 + b0*w;
                m2 = m1; m1 = w;
            }
            dn = -dn;
        }
    };
    
    class test2 
    {
        float a[2], b[3];
        float dn;
        float m1, m2;
    
    public:
        void processBiquad(const float* in, float* out, unsigned length)
        {
            for(unsigned i = 0; i < length; ++i)
            {
                float w = in[i] - a[0]*m1 - a[1]*m2 + dn;
                out[i] = b[0]*m1 + b[1]*m2 + b[2]*w;
                m2 = m1; m1 = w;
            }
            dn = -dn;
        }
    };
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        test1 t1;
        test2 t2;
    
        float a[1000];
        float b[1000];
    
        t1.processBiquad(a, b, 1000);
        t2.processBiquad(a, b, 1000);
    
        std::copy(b, b+1000, std::ostream_iterator<float>(std::cout, " "));
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question. What do you think, I have a few sites that use a
Quick question. There is a legacy website (that is not under my control and
I've asked a related question here: Show unmatched html tags in Notepad++ Having only
Hey everyone, I had a quick question that should be easy for someone who
Just a quick question, actually related to the last question I posted. If I
Quick question I've encountered while getting my feet under me in Haskell related to
Quick text-processing question. It's not necessarily related to programming, but this is the best
Quick question: Would it be a good or a bad idea to implement my
Quick question: what is the compiler flag to allow g++ to spawn multiple instances
Quick question regarding CSS and the browser. I tried searching SO and found some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.