DSPRelated.com
Forums

FIR filtering in the Fourier domain

Started by Philip de Groot July 8, 2005
Hello,

I am aware that many questions regarding FIR-filtering are posted here and 
many links to websites to help people out are also included. But these 
links are becoming complicated and I want to know something simple. 
Therefore, I am asking.

I have a Fourier transform and want to remove frequencies below 600 Hz and 
above 6500 Hz and apply a IDFT. I can use a FIR filter (in the frequency 
domain) to do so, but I want to know:

1. How exactly to multiply the Fourier transform with the FIR coefficients.
2. Where to obtain the FIR coefficients (there are many websites; please 
recommend).

That's it! Thank you in advance.

Regards,

Philip


Philip de Groot wrote:
> Hello, > > I am aware that many questions regarding FIR-filtering are posted here and > many links to websites to help people out are also included. But these > links are becoming complicated and I want to know something simple. > Therefore, I am asking.
Sure, your question is simple enought. It would be naive, though, to expect a simple answer just because the question is simple.
> I have a Fourier transform and want to remove frequencies below 600 Hz and > above 6500 Hz and apply a IDFT. I can use a FIR filter (in the frequency > domain) to do so, but I want to know: > > 1. How exactly to multiply the Fourier transform with the FIR coefficients.
You don't. What you need to do, is to DFT both the signal and the filter, and multiply the spectra. Then IDFT the result. Make sure to include enough space to avoid wrap-around effects.
> 2. Where to obtain the FIR coefficients (there are many websites; please > recommend).
I don't know my way around such web sites, I'd recommend a good book on DSP, the Oppenheim Schafer & Bucy book from 1999 or proakis & Manolakis' 1996 book being those I know of that include FIR filter design. The basic procedure goes roughly as follows: - Decide a pass band (in normalized frequency relative to the sampling frequency) - Decide on stop bands with attenuation in normalized frequency - Compute the impulse response of an ideal filter (it will become some sort of sin(wt)/wt function) - Estimate the length of the filter from the distance between pass band edge and stop band edge - Apply a windowing function to reduce certain side effects. Be aware that this filter design algorithm could be the "climax" of a one-semester intro course in DSP, so you should be prepared to spend some time learning your way around it.
> That's it! Thank you in advance.
Y'welcome. Rune
"Philip de Groot" <groot877@zonnet.nl> wrote in message 
news:Xns968DAAD70D456groot877zonnetnl@137.224.11.5...
> Hello, > > I am aware that many questions regarding FIR-filtering are posted here and > many links to websites to help people out are also included. But these > links are becoming complicated and I want to know something simple. > Therefore, I am asking. > > I have a Fourier transform and want to remove frequencies below 600 Hz and > above 6500 Hz and apply a IDFT. I can use a FIR filter (in the frequency > domain) to do so, but I want to know: > > 1. How exactly to multiply the Fourier transform with the FIR > coefficients. > 2. Where to obtain the FIR coefficients (there are many websites; please > recommend).
1) Decide on an array length N that you will be working with for the data in the DFT / IDFT. 2) Decide on the sampling interval in time, T / the sampling frequency 1/T. 3) A simple way to design the filter you want would be the windowing method: Initial (ideal) filter response: 0->600: 0; 600->6500: 1; 6500->fs/2: 0 This defined on N points in frequency from f=0 to fs-1/NT. So the function would be a real function that looks like this ... and you can figure out the exact indices of the edges: 0->600: 0; 600->6500: 1; 6500->(fs-6500): 0; (fs-6500)->(fs-600): 1; (fs-600)->fs-1/NT: 0 4) IDFT the ideal filter. Then multiply by a window function like Kaiser or simple raised cosine or.... your choice. (Doing this is equivalent to convolving in the frequency domain with the FFT of the window. It makes the filter less sharp than the ideal shape - but for good reasons. However, it's harder to describe doing it that way because the number of points in the sequences varies). 5) FFT the result, yielding an N-point sequence in frequency. Save this. 6) Point-by-point multiply each N-sample signal sequence by this filter function. You may ask: why bother with the windowing? It's because otherwise you will otherwise cause time-domain aliasing which may not be what you want or expect. If you don't want to use the windowing method, you might design a FIR filter using one of the many tools. You can pick the length you desire / need. Then append enough zeros at the end to get to N samples in time. Then FFT the N-sample sequence and use that in step 6 above. Fred
"Philip de Groot" <groot877@zonnet.nl> wrote in message 
news:Xns968DAAD70D456groot877zonnetnl@137.224.11.5...
> Hello,
snip
> > 1. How exactly to multiply the Fourier transform with the FIR > coefficients. > 2. Where to obtain the FIR coefficients (there are many websites; please > recommend). > >
Hello Philip, You can use my program for free to make the coefs for FIR filters. Yes the interface is crude, but it works well. Here is the link: http://personal.atl.bellsouth.net/p/h/physics/Fir.zip I wrote the code quite a while back - MS-DOS and using a '286. So I optimized it to run really fast on slow systems. Since there are no instructions with it, I'll tell you here how to use it. 1) Unzip the file to get FIR.EXE 2) Run it 3) Select the type of filter you want - For a lowpass (or any symmetric response filter) pick M for multiband. The other two options will result in antisymmtric responses - i.e. have 90 degree phase shifts. 4) Pick the number of taps - you can change this number easily later. Pick 31 to start 5) Enter your sample rate. For example pick 8000. 6) Enter the number of bands. For a simple lowpass, enter 2. 7) Enter the pass band specification. For example let's say it is from 0 to 1000 Hz. And we desire the pass gain to be 1. We will also let the weighting be one. So enter for band 1: 0 1000 1 1 8) Now enter the stop band's data. For example let the stop band go from 1500 Hz to half of the sampling rate. The desired gain here is 0. And we can let the weight also equal 1. (The weighting affects the amount of relative ripple in the band when compared to other bands.) So enter: 1500 4000 0 1 NOTE: Enter the bands in order of increasing frequency. 9) The screen will show a filter that is now made with 38.69 dB of rejection and the passband ripple is 0.1dB. Here you can enter new frequency bands to change the weighting since the passband is very smooth. Or you can simply up the order until the desired rejection is reached. You will notice the + and - functions here for quickly adjusting the filter's order. You may plot the filter's response either magnitude or log magnitude to see what the filter looks like. Enter ESC to exit the plot. When you finally get a filter that meets your specification, pick the "Calculate Filter Coefficients" option on the menu. And it will ask you if you wish to quantize the impulse response. This is useful to see the effects of coef. quantization. The plots will now give you an option of seeing the quantized response. So enter "Y" if you wish to quantize. Next you will be asked to enter the number of bits. For fun pick 8. You can always redo this later. Next you will be asked if the output is to be in 56000 mode. Answer yes if you are programming a Moto DSP i assembly. Otherwise, enter "N". Now two things happen. A scrollable window pops up where you can look at the coefs. And a file was just written, FIL.DAT (same directory as the fir.exe file's), with the filter's coefs in it. This file's format is c-style if you answered no to the moto question, otherwise you get a moto assembler type of file. The scrollable window responds to up and down arrows. When done looking at the numbers, hit ESC to get back to the filter's main window. Now if you plot the response, you may look at the response due to the quantized numbers. The red points on the graph are the extrema resulting from the Remez approximation. Have fun. If you wish to go make Hilbert transformers or differentiators, the method is similar. Just pick that option when the fir.exe is started. Enjoy, Clay S. Turner
hi philip,

you can try my digital filter freeware (with code generator).

http://www.winfilter.20m.com

regards,
Adrian

Philip de Groot <groot877@zonnet.nl> wrote in
news:Xns968DAAD70D456groot877zonnetnl@137.224.11.5: 

> Hello, > > I am aware that many questions regarding FIR-filtering are posted here > and many links to websites to help people out are also included. But > these links are becoming complicated and I want to know something > simple. Therefore, I am asking. > > I have a Fourier transform and want to remove frequencies below 600 Hz > and above 6500 Hz and apply a IDFT. I can use a FIR filter (in the > frequency domain) to do so, but I want to know: > > 1. How exactly to multiply the Fourier transform with the FIR > coefficients. 2. Where to obtain the FIR coefficients (there are many > websites; please recommend). > > That's it! Thank you in advance. > > Regards, > > Philip > >
Hello, Thank you for your responses so far. Starting from your responses, I have been experimenting a bit (that's why I am a little bit late with responding). I found some information on the internet regarding OLA and OLS (OverLap Add and OverLap Save) method to (at least) decrease artifacts at the sampling edges: http://www.musicdsp.org/phpWiki/index.php/filtering%20in%20the% 20frequency%20domain I incorporated the OLS method, but had to conclude that still (annoying) artifacts can be heard. The amount of work to apply OLS and, probably, the requirement to perform some windowing (which is smoothing, I guess?) increases the processor requirements considerably, so I decided I might try as well a real FIR filter using the WinFilter application of Adrian. The generated C-code is very easy to implement, but it's drawback is that a loop (1024 samples) within a loop (ntap=31) needs to be executed. And I need to have a buffer to include at most 30 samples beyond the current buffer (this is already there, but needs some modifications). The FIR filter specifications are (please comment on this): -Bessel band pass filter -Filter order: 4 -Sampling frequency: 44100 Hz -F1 and F2 frequencies: 800 and 6500 Hz. I decided to use a Bessel filter because I found some additional information on this filter type on the internet, saying that this filter reduces overshoot or ringing (compared to Butterworth and Chebychev filters): http://www.maxim-ic.com/appnotes.cfm/appnote_number/733 The expense that I have to pay is that the stop-band is less steep. This is no problem for me at all. So, I just try this filter out, listen to its performance, and determine the processor load to decide whether its performance is acceptable or not. If anyone has any comments or suggestions, please feel free to let me know. Regards, Philip
Philip de Groot <groot877@zonnet.nl> wrote in
news:Xns969166C8F683Egroot877zonnetnl@137.224.11.5: 

> Philip de Groot <groot877@zonnet.nl> wrote in > news:Xns968DAAD70D456groot877zonnetnl@137.224.11.5: > >> Hello, >> >> I am aware that many questions regarding FIR-filtering are posted >> here and many links to websites to help people out are also included. >> But these links are becoming complicated and I want to know something >> simple. Therefore, I am asking. >> >> I have a Fourier transform and want to remove frequencies below 600 >> Hz and above 6500 Hz and apply a IDFT. I can use a FIR filter (in the >> frequency domain) to do so, but I want to know: >> >> 1. How exactly to multiply the Fourier transform with the FIR >> coefficients. 2. Where to obtain the FIR coefficients (there are many >> websites; please recommend). >> >> That's it! Thank you in advance. >> >> Regards, >> >> Philip >> >> > > Hello, > > Thank you for your responses so far. Starting from your responses, I > have been experimenting a bit (that's why I am a little bit late with > responding). > > I found some information on the internet regarding OLA and OLS > (OverLap Add and OverLap Save) method to (at least) decrease artifacts > at the sampling edges: > > http://www.musicdsp.org/phpWiki/index.php/filtering%20in%20the% > 20frequency%20domain > > I incorporated the OLS method, but had to conclude that still > (annoying) artifacts can be heard. The amount of work to apply OLS > and, probably, the requirement to perform some windowing (which is > smoothing, I guess?) increases the processor requirements > considerably, so I decided I might try as well a real FIR filter using > the WinFilter application of Adrian. The generated C-code is very easy > to implement, but it's drawback is that a loop (1024 samples) within a > loop (ntap=31) needs to be executed. And I need to have a buffer to > include at most 30 samples beyond the current buffer (this is already > there, but needs some modifications). >
Correction: this is not true. The past samples remain in a static buffer and I can continue with the current samples. Sorry for that.
> The FIR filter specifications are (please comment on this): > -Bessel band pass filter > -Filter order: 4 > -Sampling frequency: 44100 Hz > -F1 and F2 frequencies: 800 and 6500 Hz. > > I decided to use a Bessel filter because I found some additional > information on this filter type on the internet, saying that this > filter reduces overshoot or ringing (compared to Butterworth and > Chebychev filters): > > http://www.maxim-ic.com/appnotes.cfm/appnote_number/733 > > The expense that I have to pay is that the stop-band is less steep. > This is no problem for me at all. So, I just try this filter out, > listen to its performance, and determine the processor load to decide > whether its performance is acceptable or not. > > If anyone has any comments or suggestions, please feel free to let me > know. > > Regards, > > Philip >

Philip de Groot wrote:

> I found some information on the internet regarding OLA and OLS (OverLap > Add and OverLap Save) method to (at least) decrease artifacts at the > sampling edges: > > http://www.musicdsp.org/phpWiki/index.php/filtering%20in%20the% > 20frequency%20domain > > I incorporated the OLS method, but had to conclude that still (annoying) > artifacts can be heard. The amount of work to apply OLS and, probably, > the requirement to perform some windowing (which is smoothing, I guess?) > increases the processor requirements considerably, so I decided I might > try as well a real FIR filter using the WinFilter application of Adrian. > The generated C-code is very easy to implement, but it's drawback is > that a loop (1024 samples) within a loop (ntap=31) needs to be executed. > And I need to have a buffer to include at most 30 samples beyond the > current buffer (this is already there, but needs some modifications). > > The FIR filter specifications are (please comment on this): > -Bessel band pass filter > -Filter order: 4 > -Sampling frequency: 44100 Hz > -F1 and F2 frequencies: 800 and 6500 Hz. > > I decided to use a Bessel filter because I found some additional > information on this filter type on the internet, saying that this filter > reduces overshoot or ringing (compared to Butterworth and Chebychev > filters):
[snip] I just thought I'll let you know there is a chance you might be comparing apples and oranges here. Bessel, Butterworth and Chebyshev filters are more or less well-known IIR filters, that work somewhat differently than FIR filters. Rune
Philip de Groot wrote:
> Philip de Groot <groot877@zonnet.nl> wrote in > news:Xns968DAAD70D456groot877zonnetnl@137.224.11.5: > > >>Hello, >> >>I am aware that many questions regarding FIR-filtering are posted here >>and many links to websites to help people out are also included. But >>these links are becoming complicated and I want to know something >>simple. Therefore, I am asking. >> >>I have a Fourier transform and want to remove frequencies below 600 Hz >>and above 6500 Hz and apply a IDFT. I can use a FIR filter (in the >>frequency domain) to do so, but I want to know: >> >>1. How exactly to multiply the Fourier transform with the FIR >>coefficients. 2. Where to obtain the FIR coefficients (there are many >>websites; please recommend). >> >>That's it! Thank you in advance. >> >>Regards, >> >>Philip >> >> > > > Hello, > > Thank you for your responses so far. Starting from your responses, I > have been experimenting a bit (that's why I am a little bit late with > responding). > > I found some information on the internet regarding OLA and OLS (OverLap > Add and OverLap Save) method to (at least) decrease artifacts at the > sampling edges: > > http://www.musicdsp.org/phpWiki/index.php/filtering%20in%20the% > 20frequency%20domain > > I incorporated the OLS method, but had to conclude that still (annoying) > artifacts can be heard. The amount of work to apply OLS and, probably, > the requirement to perform some windowing (which is smoothing, I guess?) > increases the processor requirements considerably, so I decided I might > try as well a real FIR filter using the WinFilter application of Adrian. > The generated C-code is very easy to implement, but it's drawback is > that a loop (1024 samples) within a loop (ntap=31) needs to be executed. > And I need to have a buffer to include at most 30 samples beyond the > current buffer (this is already there, but needs some modifications). > > The FIR filter specifications are (please comment on this): > -Bessel band pass filter > -Filter order: 4 > -Sampling frequency: 44100 Hz > -F1 and F2 frequencies: 800 and 6500 Hz. > > I decided to use a Bessel filter because I found some additional > information on this filter type on the internet, saying that this filter > reduces overshoot or ringing (compared to Butterworth and Chebychev > filters): > > http://www.maxim-ic.com/appnotes.cfm/appnote_number/733 > > The expense that I have to pay is that the stop-band is less steep. This > is no problem for me at all. So, I just try this filter out, listen to > its performance, and determine the processor load to decide whether its > performance is acceptable or not. > > If anyone has any comments or suggestions, please feel free to let me > know.
I don't understand Adrian's FIR design. I've played with it, but I can only guess what's happening. To me, it seems reasonable that, given some number of coefficients, one ought to adjust them to make a filter that best fits the specification, and not mimic some analog prototype (as we do with IIRs.) compare the results from Winfilter with those from ScopeFIR (from http://www.iowegian.com). I hope Adrian will enlighten us about how his FIR filters are designed and why that's good. Overshoot and ringing accompany sharp transitions in frequency response. Many FIR design programs allow the transition width to be specified. 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;
Philip de Groot wrote:

   ...

> Correction: this is not true. The past samples remain in a static buffer > and I can continue with the current samples. Sorry for that.
Is that a circular buffer? The inner loop you wrote about is a MAC sequence (multiply and accumulate). Some processors have instructions to execute (or facilitate) that. 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;