Re: Any help about FIR filter algorithm




mariya skrev:
> Hello
>
> Can anyone tell me how i can get an output array from the following piece
> of code.

You are using C or C++? The curly braces indicate you use one of them,
the lack of data formats indicates you don't.

> nm1=N-1;
> yn=0;

Please proviode memory allocations for your buffers.
It will be easier to criticise your code if you allocate
memory, it shows a bit more clearly how you think.

> for(k=0; k<nm1; ++){ /* shift data to make room for new sample */
> x[nm1-k]=x[nm1-k-1];
> x[0]=xn;
> }

You don't have to do it like this, you could use one large buffer
and pointers. But then, you seem to have problems with memory
handling, so leave this as is for now.

> for(k=0; k<N; ++k){
> yn=yn+h[k]*x[k]; /* filter data and compute output sample */
> }

Here you compute one sample that was initialized above.
It is not clear where in memory the accummulated sum will be
stored.

> return(yn); /* filter output sample */
>
> I do understand the basic formula about the FIR filters but as i am trying
> to implement it , i am a bit lost about how to store my outputs in array.

The key here seems to be how to allocate memory for the buffers
and arrays. You need to decide on data types first (float or int
in C/C++), and you need to learn how to allocate memory ("malloc"
in C, "new" in C++).

Once you know how to do that, you are well on your way to get your
function working.

> Any net pages about this algo will be helpfull too!

I think you are close enough, the problem is not the FIR filter
as such, but how to make C/C++ (if you use one of these?) do what
you need it to do. Once the data buffers are sorted out, most of
the work is done.

Rune

.



Relevant Pages

  • Re: Vector length in bytes
    ... An array of pointers is likely to be much smaller than the buffers it points to, but that would be the size of the array. ... The buffers OTOH are probably what you want transmit, but if you used a general memory counting algorithm, you'd likely have the size of the array of pointers included. ...
    (comp.lang.java.programmer)
  • Re: Garbage Collection Issues in long-standing services
    ... The problem with sockets is the unmanaged memory buffers used by the ... (probably a byte array) ... The result is that, depending of the number of buffers, ... > reference between CS and AP, so I don't explicitly set each reference to ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: safe strcpy()?
    ... >sizes of buffers or other objects. ... >No. C is a fairly low-level language. ... suggested I put a char array w/ a large length as the first variable in the ... >For dynamically allocated memory, ...
    (SecProg)
  • Re: Comparing byte arrays
    ... *per byte array* you end up with an extra 6K *in total*. ... Work through the example - you only end up with 4 times as much memory ... You'd either have to loop on each stream to get a full ... buffer, then compare the buffers, or manage two partial buffers, ...
    (microsoft.public.dotnet.general)
  • Re: Fast string operations
    ... Looping: I thought looping over arrays in managed code was "slow" ... array handling and such. ... The problem with TrimHelper is that it always returns a new string instance. ... The customer perceives this as a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)

Loading