DSPRelated.com
Forums

FIR filtering in the Fourier domain

Started by Philip de Groot July 8, 2005
Rune Allnor wrote:
> > 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.
Winfilter allows one to specify them as FIRs. Download it and see. It's very interesting, but I haven't yet figured out how to make good use of it. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Jerry Avins <jya@ieee.org> wrote in news:4Z6dnZRSTIkhSk7fRVn-sg@rcn.net:

> 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
Hello, I have used winfilter to create a FIR filter (including source code), but the result was awful. Worse than with the OLS Fourier filtering. Therefore, I studied the ScopeFIR tutorial and tried the trial version (thanks for the tip Jerry) and learned quite a lot by doing so (I recommend it to everyone who is interested to start from the ScoreFIR tutorial. It is a good starting point!). I also learned that the filter I created in WinFilter was a faulty one (not enough taps and therefore the specifications were not properly met...). Off course, I started with a bandpass filter, but the number of taps to obtain a convenient filter was very high (179). The trial version won't show the coefficients, but executing real-time code with such a large number of taps is in general not a good idea. Therefore, I was forced to study lowpass filters. These require the lowest number of taps. I do not have any problem with a large transition band, as long as the high frequency noise is significantly reduced. With 3 taps, this is very well possible! These are my filter specifications: Fs: 44100 Hz Passband upper frequency: 800 (might be 0 as well, does not really show up in the plots) Passband lower frequency: 22050 (just the whole scale; with 3 taps, the response is fastly decreasing after 6500 Hz anyway). Passband Ripple: 3 dB Stopband Attenuation: 40 dB Hopefully, the slow decrease in signal also prevents the occurrence of audible artifacts, which I suffered most. I started this whole exercise to get rid of them in the first place. Hopefully, this works fine, but if anyone has good suggestions, please let me know! Regards, Philip
Philip de Groot wrote:

...

> I have used winfilter to create a FIR filter (including source code), > but the result was awful. Worse than with the OLS Fourier filtering.
There are two issues here that you should seperate: 1. FIR design Use some program (winfilter, scopeFIR, matlab, scilab, ...) to compute the filter coefficients according to your specifications. 2. FIR implementation Once you have the coefficients, you can implement the FIR either by time domain convolution or by frequency domain multiplication. Remember, these two methods are equivalent and, given some specific filter and input signal, result in exactly the same (modulo some numerical errors) output signal! ...
> Hopefully, the slow decrease in signal also prevents the occurrence of > audible artifacts, which I suffered most. I started this whole exercise > to get rid of them in the first place.
The most common error that people who come here make is that they try to correct some problem by using a algorithm of their design, find that it doesn't work, and wonder why. It would be much more sensible to state the problem and ask whether anybody here has designed an algorithm that works to solve their problem (instead of going off and trying to cook up some ad hoc solution). In this spirit I ask you: what are the artefacts that you wanted to reduce in the first place? Why do you want to filter? Regards, Andor
"Andor" <an2or@mailcircuit.com> wrote in news:1121245285.319577.119480
@g14g2000cwa.googlegroups.com:

> Philip de Groot wrote: > > ... > >> I have used winfilter to create a FIR filter (including source code), >> but the result was awful. Worse than with the OLS Fourier filtering. > > There are two issues here that you should seperate: > 1. FIR design > Use some program (winfilter, scopeFIR, matlab, scilab, ...) to compute > the filter coefficients according to your specifications. > > 2. FIR implementation > Once you have the coefficients, you can implement the FIR either by > time domain convolution or by frequency domain multiplication. > Remember, these two methods are equivalent and, given some specific > filter and input signal, result in exactly the same (modulo some > numerical errors) output signal! > ... > >> Hopefully, the slow decrease in signal also prevents the occurrence
of
>> audible artifacts, which I suffered most. I started this whole
exercise
>> to get rid of them in the first place. > > The most common error that people who come here make is that they try > to correct some problem by using a algorithm of their design, find
that
> it doesn't work, and wonder why. It would be much more sensible to > state the problem and ask whether anybody here has designed an > algorithm that works to solve their problem (instead of going off and > trying to cook up some ad hoc solution). > > In this spirit I ask you: what are the artefacts that you wanted to > reduce in the first place? Why do you want to filter? > > Regards, > Andor > >
Hello Andor, I want to stabilize "speech" in broadcast recordings in real-time (FM band). Therefore, the speech frequency range (800-6500 Hz) should be amplified whereas the frequency regions that fall outside of this should be reduced. Most importantly, the high frequencies should be removed (to improve broadcasts that are somewhat difficult to receive). Preferably without distorting the orginal audio signal to much. That's my challenge. When I started this little project, I had never heard of software audio filters like FIR or IIR, but - due to my scientific background - I was aware of Fourier analysis and thought: well, if I want to get rid of undesired frequencies, simply take the fft, set the undesired frequencies on zero, and do a ifft. As you undoubtedly know, this approach does not work very well. This is why I started searching on the subject and - at first - wanted to stay with my nicely customized and highly C++-code optimized (inverse) Fourier transformations. I put a lot of effort in it... However, I read that time-domain filtering prevent the problem that I suffer. And when I tried the winfilter software and saw how simple it is to apply a fir-filter in the time domain, I decided that I might try to use the time domain as well. Furthermore, if the number of taps is sufficiently low, time domain filtering *might* outperform the frequency domain filtering. The reason why I have the audible artifacts is because I am using frame blocks of 1024 samples (actually: 2048 because it is stereo). In the Fourier transformations, the whole frame block is used which causes these ringing artifacts at the end of the frame blocks. This problem needs to be solved and I thought that overlap add (OLA) or overlap save (OLS) was the solution for these kind of problems. But it did not work out in my situation, but I have to add to this that I do not known whether this is due to "bad filtering" (I just set all undesired frequencies on 0) or due to the OLS algorithm that cannot fix it all (in theory it should). I have noticed that keeping the lowest frequencies greatly improves the audio quality. But I do not quite understand why. Using a lowpass filter also means keeping the lowest frequenties. Therefore, I hope that the filter design that I proposed previously will finally work out. Is this lap of text a bit clear to you? Regards, Philip
> > I have used winfilter to create a FIR filter (including source code), > but the result was awful. Worse than with the OLS Fourier filtering. > Therefore, I studied the ScopeFIR tutorial and tried the trial version > (thanks for the tip Jerry) and learned quite a lot by doing so (I > recommend it to everyone who is interested to start from the ScoreFIR > tutorial. It is a good starting point!). I also learned that the filter > I created in WinFilter was a faulty one (not enough taps and therefore > the specifications were not properly met...). > > Off course, I started with a bandpass filter, but the number of taps to > obtain a convenient filter was very high (179). The trial version won't > show the coefficients, but executing real-time code with such a large > number of taps is in general not a good idea. >
Hello Philip, My program will design such filters and output the coefficients and it is free. See my earlier link for the program. Let me know if you have any questions. Clay
"Philip de Groot" <groot877@zonnet.nl> wrote in message 
news:Xns9692A07A07EC9groot877zonnetnl@137.224.11.5...
> "Andor" <an2or@mailcircuit.com> wrote in news:1121245285.319577.119480 > > I want to stabilize "speech" in broadcast recordings in real-time (FM > band). Therefore, the speech frequency range (800-6500 Hz) should be > amplified whereas the frequency regions that fall outside of this should > be reduced. Most importantly, the high frequencies should be removed (to > improve broadcasts that are somewhat difficult to receive). Preferably > without distorting the orginal audio signal to much. That's my > challenge.
About your frequency range, speech, especially from male talkers, has significant energy in frequencies lower than 800 Hz. The common telephone specification keeps components down to 300 Hz. A bit lower is even better, maybe even down to 100-150 Hz to capture a deep-voiced talker.
"Jon Harris" <jon99_harris7@hotmail.com> wrote in
news:v1aBe.73$LG4.42@trnddc04: 

> "Philip de Groot" <groot877@zonnet.nl> wrote in message > news:Xns9692A07A07EC9groot877zonnetnl@137.224.11.5... >> "Andor" <an2or@mailcircuit.com> wrote in >> news:1121245285.319577.119480 >> >> I want to stabilize "speech" in broadcast recordings in real-time (FM >> band). Therefore, the speech frequency range (800-6500 Hz) should be >> amplified whereas the frequency regions that fall outside of this >> should be reduced. Most importantly, the high frequencies should be >> removed (to improve broadcasts that are somewhat difficult to >> receive). Preferably without distorting the orginal audio signal to >> much. That's my challenge. > > About your frequency range, speech, especially from male talkers, has > significant energy in frequencies lower than 800 Hz. The common > telephone specification keeps components down to 300 Hz. A bit lower > is even better, maybe even down to 100-150 Hz to capture a deep-voiced > talker. > > >
OK, thanks. I did not realise this...
Philip de Groot wrote:
> "Andor" <an2or@mailcircuit.com> wrote in news:1121245285.319577.119480 > @g14g2000cwa.googlegroups.com: > > >>Philip de Groot wrote: >> >>... >> >> >>>I have used winfilter to create a FIR filter (including source code), >>>but the result was awful. Worse than with the OLS Fourier filtering. >> >>There are two issues here that you should seperate: >>1. FIR design >>Use some program (winfilter, scopeFIR, matlab, scilab, ...) to compute >>the filter coefficients according to your specifications. >> >>2. FIR implementation >>Once you have the coefficients, you can implement the FIR either by >>time domain convolution or by frequency domain multiplication. >>Remember, these two methods are equivalent and, given some specific >>filter and input signal, result in exactly the same (modulo some >>numerical errors) output signal! >>... >> >> >>>Hopefully, the slow decrease in signal also prevents the occurrence > > of > >>>audible artifacts, which I suffered most. I started this whole > > exercise > >>>to get rid of them in the first place. >> >>The most common error that people who come here make is that they try >>to correct some problem by using a algorithm of their design, find > > that > >>it doesn't work, and wonder why. It would be much more sensible to >>state the problem and ask whether anybody here has designed an >>algorithm that works to solve their problem (instead of going off and >>trying to cook up some ad hoc solution). >> >>In this spirit I ask you: what are the artefacts that you wanted to >>reduce in the first place? Why do you want to filter? >> >>Regards, >>Andor >> >> > > > Hello Andor, > > I want to stabilize "speech" in broadcast recordings in real-time (FM > band). Therefore, the speech frequency range (800-6500 Hz) should be > amplified whereas the frequency regions that fall outside of this should > be reduced. Most importantly, the high frequencies should be removed (to > improve broadcasts that are somewhat difficult to receive). Preferably > without distorting the orginal audio signal to much. That's my > challenge.
There's a lot of misdirected hard work been done here. I trust that it was at least educational. I;d like to add a bit to the education.
> When I started this little project, I had never heard of software audio > filters like FIR or IIR, but - due to my scientific background - I was > aware of Fourier analysis and thought: well, if I want to get rid of > undesired frequencies, simply take the fft, set the undesired > frequencies on zero, and do a ifft. > > As you undoubtedly know, this approach does not work very well. This is > why I started searching on the subject and - at first - wanted to stay > with my nicely customized and highly C++-code optimized (inverse) > Fourier transformations. I put a lot of effort in it...
You have it now. It will be useful for something someday. (But I bet that the free (but licensed) FFTW is faster.)
> However, I read that time-domain filtering prevent the problem that I > suffer.
The simplest way, and sometimes the fastest way. Be aware that FFT-multiply-IFFT can reproduce what a time-domain FIR does bit for bit, but you have to do it right.
> And when I tried the winfilter software and saw how simple it is > to apply a fir-filter in the time domain, I decided that I might try to > use the time domain as well. Furthermore, if the number of taps is > sufficiently low, time domain filtering *might* outperform the frequency > domain filtering. > > The reason why I have the audible artifacts is because I am using frame > blocks of 1024 samples (actually: 2048 because it is stereo). In the > Fourier transformations, the whole frame block is used which causes > these ringing artifacts at the end of the frame blocks. This problem > needs to be solved and I thought that overlap add (OLA) or overlap save > (OLS) was the solution for these kind of problems. But it did not work > out in my situation, but I have to add to this that I do not known > whether this is due to "bad filtering" (I just set all undesired > frequencies on 0) or due to the OLS algorithm that cannot fix it all (in > theory it should). I have noticed that keeping the lowest frequencies > greatly improves the audio quality. But I do not quite understand why.
It certainly is "bad filtering". Whether you wrote OLS properly remains to be known. You can test it by taking the FFT of an FIR filter's coefficients (zero padded to the length of the working FFT) and using it as the bin multipliers, not just zero and one as you tried. Note that if you FFT the filter coefficients and your audio data using decimation in time and do the IFFT using decimation in frequency (or vice versa), you will need no bit-reversed addressing.)
> Using a lowpass filter also means keeping the lowest frequenties. > Therefore, I hope that the filter design that I proposed previously will > finally work out.
For really good and short FIR filters, read the paper, then download and compile the software at http://www.cs.princeton.edu/~ken/meteor. ScopeFIR is a lot easier and nearly as good. Two more comments: You shouldn't need over 100 taps for a band-pass filter, but 3 seems much too low for a low-pass. A high-pass may be all you need anyway. Decent voice audio goes below 400 Hz. Telephones go down to 300, and male voices sound noticeably more natural when the band goes down to 200. 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;
Try

http://www.mds.com/

see QED design.

It was very good for a beginner like me.

Does FIR IIR etc.

I am not associated with MDS in any way exepct that I have purchased
their product.


Mark


Philip de Groot wrote:
> "Andor" <an2or@mailcircuit.com> wrote in news:1121245285.319577.119480 > @g14g2000cwa.googlegroups.com: > > > Philip de Groot wrote: > > > > ... > > > >> I have used winfilter to create a FIR filter (including source code), > >> but the result was awful. Worse than with the OLS Fourier filtering. > > > > There are two issues here that you should seperate: > > 1. FIR design > > Use some program (winfilter, scopeFIR, matlab, scilab, ...) to compute > > the filter coefficients according to your specifications. > > > > 2. FIR implementation > > Once you have the coefficients, you can implement the FIR either by > > time domain convolution or by frequency domain multiplication. > > Remember, these two methods are equivalent and, given some specific > > filter and input signal, result in exactly the same (modulo some > > numerical errors) output signal! > > ... > > > >> Hopefully, the slow decrease in signal also prevents the occurrence > of > >> audible artifacts, which I suffered most. I started this whole > exercise > >> to get rid of them in the first place. > > > > The most common error that people who come here make is that they try > > to correct some problem by using a algorithm of their design, find > that > > it doesn't work, and wonder why. It would be much more sensible to > > state the problem and ask whether anybody here has designed an > > algorithm that works to solve their problem (instead of going off and > > trying to cook up some ad hoc solution). > > > > In this spirit I ask you: what are the artefacts that you wanted to > > reduce in the first place? Why do you want to filter? > > > > Regards, > > Andor > > > > > > Hello Andor, > > I want to stabilize "speech" in broadcast recordings in real-time (FM > band). Therefore, the speech frequency range (800-6500 Hz) should be > amplified whereas the frequency regions that fall outside of this should > be reduced. Most importantly, the high frequencies should be removed (to > improve broadcasts that are somewhat difficult to receive). Preferably > without distorting the orginal audio signal to much. That's my > challenge. > > When I started this little project, I had never heard of software audio > filters like FIR or IIR, but - due to my scientific background - I was > aware of Fourier analysis and thought: well, if I want to get rid of > undesired frequencies, simply take the fft, set the undesired > frequencies on zero, and do a ifft. > > As you undoubtedly know, this approach does not work very well. This is > why I started searching on the subject and - at first - wanted to stay > with my nicely customized and highly C++-code optimized (inverse) > Fourier transformations. I put a lot of effort in it...
Well, highly optimized (I)FFTs are nice tools, but even the best hammer doesn't do much good where a saw is needed. The filtering problem you describe - as well as the solution - is a common on one. The problem is that "setting the frequencies to 0" doesn't work, since the DFT provides a disxcretely sampled spectrum, and this approach leaves no control of the frequency components in between the discrete coefficients. Which is why more elaborate filter design algorithms have been designed.
> However, I read that time-domain filtering prevent the problem that I > suffer. And when I tried the winfilter software and saw how simple it is > to apply a fir-filter in the time domain, I decided that I might try to > use the time domain as well. Furthermore, if the number of taps is > sufficiently low, time domain filtering *might* outperform the frequency > domain filtering.
Perhaps. It depends on whether you are doing on-line (real-time) or off-line processing. I would not be surprised if time-domain filtering would be preferable for on-line filtering, due to easier implementation and no artefacts due to block boundaries, as with the OLA and OLS methods.
> The reason why I have the audible artifacts is because I am using frame > blocks of 1024 samples (actually: 2048 because it is stereo). In the > Fourier transformations, the whole frame block is used which causes > these ringing artifacts at the end of the frame blocks. This problem > needs to be solved and I thought that overlap add (OLA) or overlap save > (OLS) was the solution for these kind of problems. But it did not work > out in my situation, but I have to add to this that I do not known > whether this is due to "bad filtering" (I just set all undesired > frequencies on 0) or due to the OLS algorithm that cannot fix it all (in > theory it should).
Could be both. I have noted that there have been several threads here on comp.dsp, where people who use OLA or OLS filtering have problems with merging the blocks seamlessly.
> I have noticed that keeping the lowest frequencies > greatly improves the audio quality. But I do not quite understand why.
This could be due to psycho acoustics, an expression that can be interpreted in at least two ways. The properties of the human audio perception system plays an at least as big part in this, as mere DSP.
> Using a lowpass filter also means keeping the lowest frequenties. > Therefore, I hope that the filter design that I proposed previously will > finally work out.
If you use your filtered signals as input to a broadcast system, I'd expect the system to have some higher and lower cut-off frequencies. You would probably want to tune your signal to the system. There is an off chance that the interaction by a (relatively) broad-band signal and a not-quite-as-broad-band transmission system might cause audible artifacts, although I can't quite see how that would happen. It might be wise to use some sort of band-pass filter, where you can control (at least in the design stage) the upper and lower cut-off frequencies. Rune