Re: Is this the optimal FIR filter on all platforms?

From: Johan Bergman (johan.bergman_at_ericsson.com)
Date: 10/26/03


Date: Sun, 26 Oct 2003 17:43:09 +0100

Hi Arthur, thanks for your reply!

> What in the world is an FIR filter? (Finite impulse-response, yes,
> yes, I know, I looked it up. Point is, practically nobody in this
> newsgroup will know, either, and they'll *all* have to look it up
> if they really want to help you. You're making it harder for people
> to help you when you don't define your terms.)

Sorry, maybe I should have described the background a bit better. An FIR
filter is one of the basic filter types in digital signal processing, and my
example shows one of the ways to realize it. For FIR filter this long (10000
taps), it would actually make more sence to choose another realization based
on FFTs (Fast Fourier Transforms). But first I would like to see how fast I
can make the realization in the example.

> Well, first let's clean up your code and see what it looks like
> then. Clean code is always easier to operate on. :-)

OK then! :-)

> #include <stdlib.h>
>
> int main(void)
> {
> int nrof_lags = 10000; /* Could both of these be #defines? */
> int nrof_taps = 10000; /* That would help a little. */
>
> int *coeffs = malloc(nrof_taps * sizeof *coeffs);
> int *input = malloc((nrof_taps+nrof_lags) * sizeof *input);
> int *output = malloc(nrof_lags * sizeof *output);
> int i, j;
>
> for (i=0; i < nrof_lags; ++i)
> {
> int sum = 0;
> for (j=0; j < nrof_taps; ++j)
> sum += coeffs[j] * input[i+j];
> output[i] = sum;
> }
>
> free(coeffs);
> free(input);
> free(output);
> return 0;
> }

Thanks for the cleanup!

> How's the code do now?

Sorry, it is slightly slower than my (admittedly terrible) original code.

BR,
Johan



Relevant Pages

  • [PATCH] ftrace: set_ftrace_notrace feature
    ... to be able to filter away functions from the trace than just to filter ... not be recorded in the trace. ... struct ftrace_page { ... unsigned char *old, unsigned char *new, int enable) ...
    (Linux-Kernel)
  • Re: convert grayscale images to color
    ... "sea" schreef in bericht ... public int filterRGB ... Now, filter the Image: ... FilteredImageSource, myFilter)); ...
    (comp.lang.java.programmer)
  • Re: Is this the optimal FIR filter on all platforms?
    ... What in the world is an FIR filter? ... Clean code is always easier to operate on. ... [Some regulars strongly believe in 'int main'. ... Okay, yeah, 'const' is great. ...
    (comp.lang.c)
  • Re: Tricky Request Filtering Issue
    ... filter has been wired up results in a double firing of the filter's Read ... Request and Response filters at the start of each transaction. ... public override int Read ... stream in, and write it out modified anyway your want. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: changing Request.InputStream
    ... Filter that can be writable. ... If there is a filter of the request then ... public override int Read ... Here I want to change the buffer ...
    (microsoft.public.dotnet.framework.aspnet)