I've a program that does a bandpass filtering using DFT. Firstly I do a real-to-half-complex DFT, then, i set to zero all the samples that are not in my wanted frequency range, and then do a half-complex-to-real DFT. It works, the problem is that it creates artifacts at the two limit frequencies, due to the first and last samples of the transformed wave that are rarely near zero. I went through documentation on google but couldnt understand how to make properly a good bandpass filter, and in spite of what I read I still cant figure out what IIR's and FIR's do. Can someone tell me how to make a correct bandpass filter?
DFT and bandpass filters
Started by ●June 2, 2005
Reply by ●June 2, 20052005-06-02
Michel Rouzic wrote:> I've a program that does a bandpass filtering using DFT. > > Firstly I do a real-to-half-complex DFT, then, i set to zero all the > samples that are not in my wanted frequency range, and then do a > half-complex-to-real DFT. > > It works, the problem is that it creates artifacts at the two limit > frequencies, due to the first and last samples of the transformed wave > that are rarely near zero. > > I went through documentation on google but couldnt understand how to > make properly a good bandpass filter, and in spite of what I read I > still cant figure out what IIR's and FIR's do. > > Can someone tell me how to make a correct bandpass filter?You have made a filter with a very sharp cutoff. (Not infinite, but the width of one bin.) Such a filter rings. Reduce the steepness of the cutoff to reduce or eliminate the ringing. Apply a suitable window to the remaining bins before the IFFT. Even a linear taper of the last half-dozen bins will be an improvement, although there are better ones. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●June 2, 20052005-06-02
Michel Rouzic wrote:> I've a program that does a bandpass filtering using DFT. > > Firstly I do a real-to-half-complex DFT, then, i set to zero all the > samples that are not in my wanted frequency range, and then do a > half-complex-to-real DFT. > > It works, the problem is that it creates artifacts at the two limit > frequencies, due to the first and last samples of the transformed wave > that are rarely near zero. > > I went through documentation on google but couldnt understand how to > make properly a good bandpass filter, and in spite of what I read I > still cant figure out what IIR's and FIR's do. > > Can someone tell me how to make a correct bandpass filter? >When you zero the DFT bins all you do is setting the spectrum to zero at these discrete frequencies only, but in some cases such as the sharp cutoff filter that you have implemented, you may get artifacts in the continuous (or "analog") frequency range in between the DFT's discrete frequencies (i.e. frequencies you cannot directly access by the DFT bins). (The "uncertainty" principle, & Gibbs phenomenon)). Those may be described and measured as the filter's side lobes and their corresponding attenuation. Like others have mentioned, you need to design a smoother-cutoff filter, a filter that has more attenuated side-lobes (chose your most suitable tradeoff between bandwidth + cutoff sharpness and side lobe attenuation). You may then "sample" it in the DFT domain (magnitude and phase), and multiply your signal's DFT by this filter's DFT (complex numbers' multiplication). You may chose to take an approximated approach, for example by not performing complex number operations, but that would lead to some distortion which you may or may not tolerate. Dr. DSP
Reply by ●June 2, 20052005-06-02
Here's a crash course on filtering using DFT: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When you zero the DFT bins all you do is setting the spectrum to zero at these discrete frequencies only, but there is still uncertainty in what happens to the rest of the spectrum, i.e. to the continuous (or "analog") frequency range in between the DFT's discrete frequencies (i.e. frequencies you cannot directly access by the DFT bins). (See: "uncertainty" principle, & Gibbs phenomenon)) In some cases such as the sharp cutoff filter that you have implemented, you may get artifacts in the continuous (or "analog") frequency range in between the DFT's discrete frequencies. This is due to the fact that you have in fact implemented a square Band-Stop Filter having prominent side lobes (in between the DFT bins), which resulting the artifacts you have noted. Like others have mentioned, you need to design a smoother-cutoff filter, a filter that has better attenuated side-lobes (choose your most suitable tradeoff between bandwidth + cutoff sharpness and side lobe attenuation). Then, to apply the filter you may then "sample" it in the DFT domain (complex numbers such as magnitude and phase), and multiply your signal's DFT by this filter's DFT (complex numbers' multiplication). In order to do the filtering correctly, look also at techniques such as overlap-add/save and other issues related to using cyclic convolution for performing linear convolution. You may opt taking an approximated approach, for example by not performing complex number operations, but that would lead to some distortion which you may or may not tolerate. Dr. DSP Michel Rouzic wrote:> I've a program that does a bandpass filtering using DFT. > > Firstly I do a real-to-half-complex DFT, then, i set to zero all the > samples that are not in my wanted frequency range, and then do a > half-complex-to-real DFT. > > It works, the problem is that it creates artifacts at the two limit > frequencies, due to the first and last samples of the transformed wave > that are rarely near zero. > > I went through documentation on google but couldnt understand how to > make properly a good bandpass filter, and in spite of what I read I > still cant figure out what IIR's and FIR's do. > > Can someone tell me how to make a correct bandpass filter? >
Reply by ●June 3, 20052005-06-03
PiBZb3UgaGF2ZSBtYWRlIGEgZmlsdGVyIHdpdGggYSB2ZXJ5IHNoYXJwIGN1dG9mZi4gKE5vdCBp bmZpbml0ZSwgYnV0IHRoZQo+IHdpZHRoIG9mIG9uZSBiaW4uKSBTdWNoIGEgZmlsdGVyIHJpbmdz LiBSZWR1Y2UgdGhlIHN0ZWVwbmVzcyBvZiB0aGUKPiBjdXRvZmYgdG8gcmVkdWNlIG9yIGVsaW1p bmF0ZSB0aGUgcmluZ2luZy4gQXBwbHkgYSBzdWl0YWJsZSB3aW5kb3cgdG8KPiB0aGUgcmVtYWlu aW5nIGJpbnMgYmVmb3JlIHRoZSBJRkZULiBFdmVuIGEgbGluZWFyIHRhcGVyIG9mIHRoZSBsYXN0 Cj4gaGFsZi1kb3plbiBiaW5zIHdpbGwgYmUgYW4gaW1wcm92ZW1lbnQsIGFsdGhvdWdoIHRoZXJl IGFyZSBiZXR0ZXIgb25lcy4KPgo+IEplcnJ5Cj4gLS0KPiBFbmdpbmVlcmluZyBpcyB0aGUgYXJ0 IG9mIG1ha2luZyB3aGF0IHlvdSB3YW50IGZyb20gdGhpbmdzIHlvdSBjYW4gZ2V0Lgo+IK+vr6+v r6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+v r6+vr6+vr6+vCgp3aGF0IHdvdWxkIGJlIGEgZ29vZCBvdmVybGFwcGluZyB3aW5kb3c/IChvdmVy bGFwcGluZyBiZWNhdXNlIG15IHBsYW4KaXMgdG8gZG8gYmFuZHBhc3NlcyB0byBidWlsZCBhIHNw ZWN0cm9ncmFtKQo=
Reply by ●June 3, 20052005-06-03
Trying to remember a little from college... As others have pointed out, the way you are going about it leads to artifacts on conversion back to time domain. You can do it without leaving the time domain by cascading a low-pass filter and a high pass filter. The high pass filter cutoff frequency would be the low frequency in the band and the low pass filter cutoff frequency would be the high frequency in the band. For the high pass filter, let fc equal your lower cutoff freqency and A=2*pi*fc/fs, (fs is sampling frequency), the high pass equation is, for each sample n, y(n)=x(n)-Ay(n-1). For the lowpass filter, let B=2*pi*fc/fs, y(n)=B(x(n-1)-y(n-1)). I got this by transforming the respective transfer functions from the s-domain to the z-domain, then taking the inverse transform back to the discrete time domain. Best as I remember, this is how to do it. Please point out if I am wrong, I'm trying to brush up a little bit. These filters are simple first-order and will result in 3-dB attenuation at the cutoff frequency. For steeper attenuation curves, you need to go to higher order filters. "Michel Rouzic" <Michel0528@yahoo.fr> wrote in message news:1117725804.275031.78400@g14g2000cwa.googlegroups.com...> I've a program that does a bandpass filtering using DFT. > > Firstly I do a real-to-half-complex DFT, then, i set to zero all the > samples that are not in my wanted frequency range, and then do a > half-complex-to-real DFT. > > It works, the problem is that it creates artifacts at the two limit > frequencies, due to the first and last samples of the transformed wave > that are rarely near zero. > > I went through documentation on google but couldnt understand how to > make properly a good bandpass filter, and in spite of what I read I > still cant figure out what IIR's and FIR's do. > > Can someone tell me how to make a correct bandpass filter? >
Reply by ●June 3, 20052005-06-03
Michel Rouzic wrote: ...> what would be a good overlapping window? (overlapping because my plan > is to do bandpasses to build a spectrogram)Then you want no window at all, but instead, overlap the FFTs in such a way that the artifacts of adjacent ones cancel. Google for "overlap-add" and "overlap-save". Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●June 3, 20052005-06-03
Michael:> my plan is to do bandpasses to > build a spectrogramCan't you just take the output of the DFT for your spectrogram? Why convert the signal back to time domain?
Reply by ●June 3, 20052005-06-03
Frunobulax wrote: ...> Best as I remember, this is how to do it. Please point out if I am wrong, > I'm trying to brush up a little bit. These filters are simple first-order > and will result in 3-dB attenuation at the cutoff frequency. For steeper > attenuation curves, you need to go to higher order filters.There are direct band-pass filters. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●June 3, 20052005-06-03
I realize that, I am just giving the simplest thing to do. Seems to me if you add the transfer functions in the s-domain for the two filters you will arrive at a bandpass filter with a second order polynomial in the denominator, something like Bs/(s^2+Bs+w^2), where B is quality factor and w is bandpass center frequency. "Jerry Avins" <jya@ieee.org> wrote in message news:Qu6dndTZtONCIj3fRVn-pA@rcn.net...> Frunobulax wrote: > > ... > >> Best as I remember, this is how to do it. Please point out if I am wrong, >> I'm trying to brush up a little bit. These filters are simple first-order >> and will result in 3-dB attenuation at the cutoff frequency. For steeper >> attenuation curves, you need to go to higher order filters. > > There are direct band-pass filters. > > Jerry > -- > Engineering is the art of making what you want from things you can get. > �����������������������������������������������������������������������