DSPRelated.com
Forums

FIR Coefficients

Started by Himanshu Chauhan April 24, 2005
Hello,

I have been working on a low-pass FIR filter using Hamming and Blackman
window.
What I have is a function named "get_filter_kernel" which calculates
the filter kernel.

Now, If I wish to implement a FIR interpolator, can I use this filter
kernel for my purpose. Are the filter kernel and Filter coefficients
one and the same thing?

Thanks and regards
--Himanshu


=====================================================
Its more important that you don't stop questioning.
                                      - A. Einstein
=====================================================

"Himanshu Chauhan" <hs.chauhan@gmail.com> wrote in message 
news:1114321769.454916.100300@l41g2000cwc.googlegroups.com...
> Hello, > > I have been working on a low-pass FIR filter using Hamming and Blackman > window. > What I have is a function named "get_filter_kernel" which calculates > the filter kernel. > > Now, If I wish to implement a FIR interpolator, can I use this filter > kernel for my purpose. Are the filter kernel and Filter coefficients > one and the same thing? > > Thanks and regards > --Himanshu
*You* defined "get_filter_kernel", right? What does it do? Fred
Well get_filter_kernel returns the _filter_kernel_ in a buffer provided
to it.
The following is the code (its based on WindowedSinc Filter)


/* The length of the window */
windowLen =3D pFilterStruct->bufferSize;

/* If the window length is not an even number, exit */
if (windowLen % 2)
{
   retValue =3D ERROR_INVALID_PARAMS;
   goto HandleOccurredError;
}

/* Allocate buffer for windowed output */
windowStruct.pBuffer =3D (PBUFFER_T)calloc(windowLen + 1,
sizeof(BUFFER_T));

if (!windowStruct.pBuffer)
{
  retValue =3D ERROR_LOW_MEMORY;
  goto HandleOccurredError;
}

/* set the window length */
windowStruct.windowLength =3D windowLen;

/* Get a window length window according to type */
switch(winType){
    /* Get Blackman window */
    case kWindowTypeBlackman:
    retValue =3D GetBlackmanWindow(&windowStruct);
    break;

   /* Get Hamming window */
   case kWindowTypeHamming:
      retValue =3D GetHammingWindow(&windowStruct);
     break;

   /* No window was specified */
    default:
    retValue =3D ERROR_NO_WINDOW_DEFINED;
			break;
 }


/* Calculate the filter kernel */
pBufferPointer =3D pFilterStruct->pOutBuffer;
for (counter =3D 0; counter <=3D windowLen; counter++)
{
    /* calculate the sinc function sin(x)/(x) */
    if (counter =3D=3D (windowLen / 2)){
       *(pBufferPointer + counter) =3D 2 * PI *
(pFilterStruct->cutoffFreq);
	continue;
     }
    *(pBufferPointer + counter) =3D sin(2 * PI *
pFilterStruct->cutoffFreq * (counter - (windowLen / 2))) / (counter -
    (windowLen / 2));
    *(pBufferPointer + counter) /=3D counter - (windowLen / 2);

     /* multiply the obtained window */
     *(pBufferPointer + counter) *=3D (*(windowStruct.pBuffer +
counter));
}

retValue =3D ERROR_NO_ERROR;

HandleOccurredError:
	if (windowStruct.pBuffer && retValue)
		free(windowStruct.pBuffer);

	return (retValue);


-------------------------------------------><------------------------------=
----------
the above code returns the filter kernel according to the specified
cutoff frequency and the
length of the window to use.

I use this returned kernel to convolve again the signal in question.
My question is the values that are in the return buffer, are they what
we call FIR coefficients?
I have read somethere, the coefficients have one to one correspondence
to impulse response.
In that case, may be i am wrong in taking the aforementioned values as
coefficients.

Thanks and regards
-- Himanshu

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=AD=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Its more important that you don't stop questioning.
                                      - A. Einstein
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=AD=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Hello,

>I have read somethere, the coefficients have one to one correspondence
>to impulse response. >In that case, may be i am wrong in taking the aforementioned values as
>coefficients.
I am sorry I made a wrong statement there. But does that mean that I can use this filter kernel as FIR coefficients? Thanks Himanshu
Himanshu Chauhan wrote:
> Hello, > > >>I have read somethere, the coefficients have one to one correspondence > > >>to impulse response. >>In that case, may be i am wrong in taking the aforementioned values as > > >>coefficients. > > > I am sorry I made a wrong statement there. But does that mean that I > can use this filter kernel as FIR coefficients? > > Thanks > Himanshu
Himanshu, It's mostly a language problem, but partly your lack of understanding of what your code actually does. The filter kernel is the set of FFT coefficients -- same thing. There's a limit to what can be accomplished via cut-and-paste. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Hello Jerry,

This might be because of lack of understanding because I am newbie in
this field.
But I think its not kind enough to call someone's work to be lame or
copy-pasted.
May be I am making mistakes and not understanding things but thats we
all do when
we are learning something new.

Please, dont mind if any of my words hurt you.

BTW, I still didn't get my answer :-)

Regards
--Himanshu

Hi Jerry!

Probably I had been rude! I am sorry for that.
But my problem boils down to one thing -- "How to calculate the
filter coefficients for FIR filters"
I don't want to use any packages. I want to learn this. I want to
learn how these packages are doing this.

Please help me out!

Thanks and regards
--Himanshu

"Himanshu Chauhan" <hs.chauhan@gmail.com> wrote in message
news:1114451061.586788.164480@l41g2000cwc.googlegroups.com...
> Hi Jerry! > > Probably I had been rude! I am sorry for that. > But my problem boils down to one thing -- "How to calculate the > filter coefficients for FIR filters" > I don't want to use any packages. I want to learn this. I want to > learn how these packages are doing this. > > Please help me out!
There are 2 main methods in use: 1) the window method and 2) optimized linear programming methods. The first one is much more practical to implement yourself. Basically, you start with an ideal filter response. For example, for a low-pass filter, this is a sinx/x (commonly called sinc) waveform. But this function has infinite length, and as such cannot be practically implemented. So we add a window function to limit the data to a specified "window" that we will actually use for the filter. The longer the window, the closer the match we can achieve to the ideal. A much better and more thorough explanation of this can be found here: http://www.bores.com/courses/intro/filters/4_window.htm

Himanshu Chauhan wrote:
> > Hello Jerry, > > This might be because of lack of understanding because I am newbie in > this field. > But I think its not kind enough to call someone's work to be lame or > copy-pasted. > May be I am making mistakes and not understanding things but thats we > all do when > we are learning something new. > > Please, dont mind if any of my words hurt you. > > BTW, I still didn't get my answer :-)
Well some people are so concerned about how well you communicate the question they neglect to communicate an answer very well. The answer is yes Your 'kernel' are the FIR coefficients. And so far, I don't see any error in your thinking that you can use a set of coefficients such as you have for interpolation. But as I'm sure you already know lots of things can go wrong, so don't take that as a guarantee. -jim ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
"Himanshu Chauhan" <hs.chauhan@gmail.com> wrote in message 
news:1114416377.370772.202130@l41g2000cwc.googlegroups.com...
Well get_filter_kernel returns the _filter_kernel_ in a buffer provided
to it.
The following is the code (its based on WindowedSinc Filter)


/* The length of the window */
windowLen = pFilterStruct->bufferSize;

****************************************************************

Himanshu,

I'm sorry, I still don't understand.  I'm afraid that I don't read code all 
that well or quickly...
Is this the code of get_filter_kernel?  The name doesn't appear anywhere in 
the listing....
Are there parameters being passed in the call?  I can but imagine from a 
cursory inspection of the listing.  I surely can't tell what they might be.
I'm sure I'm demonstrating my ignorance.

It would perhaps be easier to abstract what is going on into large blocks.
It appears you're using the windowing method to design FIR filters.
Here is my simple version of how that works:
1) Express an ideal filter response in the frequency domain.  Note that the 
filter response has to "mirror" in frequency.  i.e. a simple lowpass filter 
will have gain 1.0 from f=0 to f1 and zero from f1 to fs/2.  It will also 
have gain of 1.0 from fs-f1 to fs minus one sample for a total of N samples. 
The number of spectral samples has to be at least the length of the filter 
you intend / need.
2) IFFT the ideal filter.
3) Multiply the resulting time record by the window of choice - defined over 
a time interval of choice - which should be N samples.
4) The resulting time samples are the filter coefficients / weights that 
will be used in computing filter output in the time domain - if the time 
domain signals are continuous then this is a running convolution.

Another way to do the same thing:
1) Express an ideal filter response in the frequency domain.  Note that the 
filter response has to "mirror" in frequency.  i.e. a simple lowpass filter 
will have gain 1.0 from f=0 to f1 and zero from f1 to fs/2.  It will also 
have gain of 1.0 from fs-f1 to fs minus one sample for a total of N samples. 
The number of spectral samples has to be at least the length of the filter 
you intend / need.
2) Get the window of choice and define for a time interval of choice.
3) zero pad the window of choice out to N samples.
4) FFT the zero-padded window of choice.
5) Convolve the ideal filter and the FFT of the window in the frequency 
domain - making sure that there are enough zero samples around fs/2 to 
accomodate the ends of the convolution.
6) IFFT the result
7) The resulting time samples are the filter coefficients / weights that 
will be used in computing filter output in the time domain.

Regarding terminology:
A "kernel" is generally something that's the core of an integral.

In the above, a "window kernel" might be the FFT of a time window - because 
you need to convolve the ideal frequency response with this "window kernel".

In the above, a "filter kernel" might be the (infinite) Inverse Fourier 
Transform of an ideal filter - because one could conceptually convolve this 
with a signal in time.  But that's not practical.

In the above, a "filter kernel" might be the time-windowed IFFT of an ideal 
filter that will actually be used in a time-domain convolution 
implementation of a filter.

Read about the following:
Windowing method of FIR filter design.
Fourier Transform pairs and the duality of time multiplication and frequency 
convolution and the duality of time convolution and frequency 
multiplication.  These are fundamental to what I've described above.

Fred