I came across a nice article the other day. The company, Netrino, actually has lots of good articles. This was the code fragment(doesn’t compile without some adding some straighforward declarations and definitions, etc.) in the article(without the comments)

sample = input();

x[oldest] = sample;

y = 0;

for (k = 0; k < N; k++)

y += h[k] * x[(oldest + k) % N];

oldest = (oldest + 1) % N;

output(y);

This is fine for illustration(which was what this article was doing). In a real-time DSP environment though, you would never use the modulus operator(too computationally expensive). Instead:

x[oldest] = sample;

y = 0.0;

for (k = 0; k < N; k++)

{

if( (oldest + k) < N )

y += h[k] * x[(oldest + k)];

else {

y += h[k] * x[(oldest + k)-N];

}

}

if((oldest + 1) < N)

oldest += 1;

else

oldest = 0;

output(y);

In fact, even the built-in sin, cos etc. of the C math library are not used. Instead lookup tables are used.

### Like this:

Like Loading...

*Related*