DSPRelated.com
Forums

DFT and bandpass filters

Started by Michel Rouzic June 2, 2005
Jerry wrote:
> Jon wrote: >> With white noise playing, the display is tilted up to the right, i.e. it shows >> more high frequency content than low. With pink noise, the display looks >> essentially flat. So it looks like it is calibrated so that equal energy per >> octave rather than equal energy per Hz generates a flat response, but there is >> no additional weighting. > > I was wrong then. With a nod to Andor.
Well, in the above case the Jon described, you were right - the high frequency content is emphasized by the analyzer. I guess I'll nod to you :-). Regards, Andor
> Michel, I think you just need to slow down for a moment, sit back, turn > off your computer (well, at least your programming environment) and > think about what you need, and how you want to achieve that. > > I gathered the following: > > 1. You want to program a spectrum analyzer. > > 2. You are thinking about 64bands / octave. A question: to what kind of > signals do you want to apply your analyzer? Music? Speech? Are you sure > you really need 64bands / octave (ie. more than five bands for a single > half-tone)?
yes I do, I got a good reason, my ultimate goal is not to make a simple spectrum analyzer
> 3. You want to use FFT to implement bandbass filters (this is > possible), and at the same time you say that the FFT does not give you > good enough resolution for low frequencies, so you cannot take the > output of the FFT directly for your analyzer.
I think you're talking about what I said when i talked about windowing in the time domain. because when you do a window of 256 samples in the time domain, which can give you 256 different frequencies, from a frequency that has a period of 512 samples to the nyquist frequency, (did i get it right?), in other words, using this method, on sound sampled at 44100 Hz, you cannot catch frequencies under 86Hz, right?
> An example: look at the octave of 20 Hz - 40 Hz. You want a resolution > of 64 bands , ie. 20 / 64 ~= 0.3125 Hz / band. At 44.1 kHz sampling > rate you'll need an FFT of at least 44100 / 0.3125 = 1'241'120 points > to only specify the bandpass filters. You'll need even more if you want > to use fast convolution.
indeed, i calculated something different. the first band, provided that it starts at 20Hz, will have a width of 20 * 2**(1/64), provided that i got 64 bands per octave, which makes 0.625 Hz (right?). now, if i decide that i need lets say 128 samples in the frequency domain, then all i'll have to do is add enough zeros in the time domain to obtain a total of about 9 million samples, and it's not too big because i've already performed FFT's on files containing about 17 million samples.
> There are several ways to achieve what you want. I still maintain that > a simple (but large enough) FFT will give you just that (by using > interpolation in the low frequencies).
interpolation in the low frequencies? well you got me interested, let me know about what it consists in.
> Another option is to use the > bandpass filters, but I would suggest IIR filters (as phase is not > important for the analyzer, and low-frequency bandpass FIR filters are > hard to implement). However, the first step in finding the best > solution is to specify the task. Ask yourself: how many bands (what > information do I want from the analyzer about the signal)? Does it need > to be real-time? What kind of hardware / software will the spectrum > analyzer run on?
I know pretty well how many bands i need (but i wont tell why yet, i first gotta solve my problems of right now before even talking about the future problems). no it doesn't have to be real-time. the hardware it runs on well its just my computer and the software well it's my C program running on cygwin (cant make it run on windows because the FFTW library wont compile with the options for windows, but thats not a problem for the DSP forum i guess) by the way, do you have an opinion on the trick i suggested to obtain more precision in the enveloppe of a band? (in the post you just replied too)
> 1. Window the time domain data > 2. FFT the windowed data > 3. Group the bins into logarithmically spaced groups > 4. Plot your amplitudes based on the grouped bins > 5. Repeat for the next block of data
Well, i don't think that windowing in the time domain is a good idea. plus, i dont think it can get low frequencies, as i'm interested in low frequencies. and just picture that, if i decide to analyse 640 bands, knowing how they are logarithmically spaced, how big would the window in the time domaine have to be? really, i think the idea of doing a bandpass, then and envelope to put it as a line in an image file isnt too bad.
> However, if you want to do a _bandpass_ filter, with the intention of > returning the data to the time domain, my understanding is that you > will also need FIR coefficients which you will multiply the data by in > the frequency domain. In addition, you will need to use Overlap-Add or > Overlap-Save to avoid time-domain wrap-around effects from doing this > multiplication in the frequency domain. Again, this is only if you > intend on returning the data to the time domain as (bandpass) filtered > data.
thats what i dont understand, why do i need to do FIR coefficients and overlap-add or save to do a bandpass filter, considered the way i want to do it? because in the first place my bandpass worked fine, besides the artifacts that can be solved by appling a kind of window function in the frequency domain before performing an IFFT.
> The second link I gave you in the previous post has a good explanation > of what Overlap-Save is, and how to implement it. Overlap-Add and > Overlap-Save are the methods used for FFT convolution. If you don't use > one of these methods and you try to filter in the frequency domain and > return to the time domain, you will get wrap-around effects in the time > domain.
I read your link and after all i read, i still dont really know what overlap-save/add, fft convolution and warp-around effects are or are for.
> Using a time-domain window will reduce artifacts in the frequency > domain.
why?? i really dont understand that! when you perform a FFT, you have no artifacts in the frequency domain
> I'm not clear as to what artifacts you're referring to
well, do this : FFT a sound that at some part contains a silence, zero all the samples that arent in the frequency range that you want to pass, then IFFT, and you'll notice that the silences arent silent anymore and are made of two sines matching to the lowest and highest frequency of your little bandpass filter.
> Michel, I think you just need to slow down for a moment, sit back, turn > off your computer (well, at least your programming environment) and > think about what you need, and how you want to achieve that.
> I gathered the following:
> 1. You want to program a spectrum analyzer.
> 2. You are thinking about 64bands / octave. A question: to what kind of > signals do you want to apply your analyzer? Music? Speech? Are you sure > you really need 64bands / octave (ie. more than five bands for a single > half-tone)?
yes I do, I got a good reason, my ultimate goal is not to make a simple spectrum analyzer
> 3. You want to use FFT to implement bandbass filters (this is > possible), and at the same time you say that the FFT does not give you > good enough resolution for low frequencies, so you cannot take the > output of the FFT directly for your analyzer.
I think you're talking about what I said when i talked about windowing in the time domain. because when you do a window of 256 samples in the time domain, which can give you 256 different frequencies, from a frequency that has a period of 512 samples to the nyquist frequency, (did i get it right?), in other words, using this method, on sound sampled at 44100 Hz, you cannot catch frequencies under 86Hz, right?
> An example: look at the octave of 20 Hz - 40 Hz. You want a resolution > of 64 bands , ie. 20 / 64 ~= 0.3125 Hz / band. At 44.1 kHz sampling > rate you'll need an FFT of at least 44100 / 0.3125 = 1'241'120 points > to only specify the bandpass filters. You'll need even more if you want > to use fast convolution.
indeed, i calculated something different. the first band, provided that it starts at 20Hz, will have a width of 20 * 2**(1/64), provided that i got 64 bands per octave, which makes 0.218 Hz for the first band (right?). now, if i decide that i need lets say 128 samples in the frequency domain, then all i'll have to do is add enough zeros in the time domain to obtain a total of about 26 million samples, and i guess its not too big since i've already performed FFT's about that big
> There are several ways to achieve what you want. I still maintain that > a simple (but large enough) FFT will give you just that (by using > interpolation in the low frequencies).
interpolation in the low frequencies? well you got me interested, let me know about what it consists in.
> Another option is to use the > bandpass filters, but I would suggest IIR filters (as phase is not > important for the analyzer, and low-frequency bandpass FIR filters are > hard to implement). However, the first step in finding the best > solution is to specify the task. Ask yourself: how many bands (what > information do I want from the analyzer about the signal)? Does it need > to be real-time? What kind of hardware / software will the spectrum > analyzer run on?
I know pretty well how many bands i need (but i wont tell why yet, i first gotta solve my problems of right now before even talking about the future problems). no it doesn't have to be real-time. the hardware it runs on well its just my computer and the software well it's my C program running on cygwin (cant make it run on windows because the FFTW library wont compile with the options for windows, but thats not a problem for the DSP forum i guess) by the way, do you have an opinion on the trick i suggested to obtain more precision in the enveloppe of a band? (in the post you just replied too)
Michel wrote:
>> 2. You are thinking about 64bands / octave. A question: to what kind of >> signals do you want to apply your analyzer? Music? Speech? Are you sure >> you really need 64bands / octave (ie. more than five bands for a single >> half-tone)? > > yes I do, I got a good reason, my ultimate goal is not to make a simple > spectrum analyzer
Ok, then the first question to answer is: how many octaves do you need to analyze, and where are they situated relative to the sampling frequency? For example, audible signals encompass about a range of ten octaves, from 20 Hz - 20kHz. Usually, this is sampled at 44.1 kHz (CD). Regards, Andor
Michel Rouzic wrote:
>>1. Window the time domain data >>2. FFT the windowed data >>3. Group the bins into logarithmically spaced groups >>4. Plot your amplitudes based on the grouped bins >>5. Repeat for the next block of data > > > Well, i don't think that windowing in the time domain is a good idea. > plus, i dont think it can get low frequencies, as i'm interested in low > frequencies. and just picture that, if i decide to analyse 640 bands, > knowing how they are logarithmically spaced, how big would the window > in the time domaine have to be? really, i think the idea of doing a > bandpass, then and envelope to put it as a line in an image file isnt > too bad.
I suspect that you're overlooking an important point. To discriminate frequencies f Hz apart. you need 1/f seconds of data. 1 Hz: 1 sec.; 0.1 Hz: 10 sec., etc. 640 separate frequencies in the octabe starting at 20 Hz will be at most 1/32nd Hz apart. You will need 32 seconds of data. At 44.1 KHz, that's nearly a million and a half samples. 256 won't do! Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������

Andor wrote:
> Michel wrote: > >> 2. You are thinking about 64bands / octave. A question: to what kind of > >> signals do you want to apply your analyzer? Music? Speech? Are you sure > >> you really need 64bands / octave (ie. more than five bands for a single > >> half-tone)? > > > > yes I do, I got a good reason, my ultimate goal is not to make a simple > > spectrum analyzer > > Ok, then the first question to answer is: how many octaves do you need > to analyze, and where are they situated relative to the sampling > frequency? > > For example, audible signals encompass about a range of ten octaves, > from 20 Hz - 20kHz. Usually, this is sampled at 44.1 kHz (CD). > > Regards, > Andor
well, 10 octaves at most (i think 20 Hz - 20 480 Hz would be way enough) (i consider that i always work with 44.1 kHz sounds because this is what i do most of the time). thats why i said 640 bands, 64 bands/octave, and 10 octaves, but that was just an example (and i'd say that i dont think i'll use more than 10 octaves nor more than 64 bands/octave)
> I suspect that you're overlooking an important point. To discriminate > frequencies f Hz apart. you need 1/f seconds of data. 1 Hz: 1 sec.; 0.1 > Hz: 10 sec., etc. 640 separate frequencies in the octabe starting at 20 > Hz will be at most 1/32nd Hz apart. You will need 32 seconds of data. At > 44.1 KHz, that's nearly a million and a half samples. 256 won't do! > > Jerry > -- > Engineering is the art of making what you want from things you can get. > =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=
=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= =AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF i know! i know that thats why i dont wanna do a window of 256 samples in the time domain. as i said in a previous post, if i do a window of 256 samples in the time domain, provided that it's sampled at 44.1 kHz, the lowest frequency it should detect should be 86 Hz, right? indeed, in my previous post i said i'd even add zeros in the time domain if there isnt enough to obtain lots of samples even in the first band. and damn, i'm glad we're in 2005 cuz if computers couldnt handle gigabytes in RAM/Virtual memory i coudlnt do anything. by the way, dont wanna give me a lil opinion on the trick i talked about earlier about getting sharp envelopes?
Michel Rouzic wrote:
>>I suspect that you're overlooking an important point. To discriminate >>frequencies f Hz apart. you need 1/f seconds of data. 1 Hz: 1 sec.; 0.1 >>Hz: 10 sec., etc. 640 separate frequencies in the octabe starting at 20 >>Hz will be at most 1/32nd Hz apart. You will need 32 seconds of data. At >>44.1 KHz, that's nearly a million and a half samples. 256 won't do! >> >>Jerry >>-- >>Engineering is the art of making what you want from things you can get. >>����������������������������������������������������������������������� > > > i know! i know that thats why i dont wanna do a window of 256 samples > in the time domain. as i said in a previous post, if i do a window of > 256 samples in the time domain, provided that it's sampled at 44.1 kHz, > the lowest frequency it should detect should be 86 Hz, right? indeed, > in my previous post i said i'd even add zeros in the time domain if > there isnt enough to obtain lots of samples even in the first band. > > and damn, i'm glad we're in 2005 cuz if computers couldnt handle > gigabytes in RAM/Virtual memory i coudlnt do anything. > > by the way, dont wanna give me a lil opinion on the trick i talked > about earlier about getting sharp envelopes?
Time domain or frequency: it doesn't matter. You want to resolve the octave from 20 Hz to 40 Hz -- that's 20 Hz -- into 64 frequencies. Even if they're evenly spaced, the separation is 1/32nd of a Hz, so you need 32 seconds worth of data. That's 32*44,100, or 1,411,200 samples in your FFT. (The next higher power of two is 2,097,152.) Why do you keep thinking 256? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Michel Rouzic wrote:
>>I suspect that you're overlooking an important point. To discriminate >>frequencies f Hz apart. you need 1/f seconds of data. 1 Hz: 1 sec.; 0.1 >>Hz: 10 sec., etc. 640 separate frequencies in the octabe starting at 20 >>Hz will be at most 1/32nd Hz apart. You will need 32 seconds of data. At >>44.1 KHz, that's nearly a million and a half samples. 256 won't do! >> >>Jerry >>-- >>Engineering is the art of making what you want from things you can get. >>����������������������������������������������������������������������� > > > i know! i know that thats why i dont wanna do a window of 256 samples > in the time domain. as i said in a previous post, if i do a window of > 256 samples in the time domain, provided that it's sampled at 44.1 kHz, > the lowest frequency it should detect should be 86 Hz, right? indeed, > in my previous post i said i'd even add zeros in the time domain if > there isnt enough to obtain lots of samples even in the first band. > > and damn, i'm glad we're in 2005 cuz if computers couldnt handle > gigabytes in RAM/Virtual memory i coudlnt do anything. > > by the way, dont wanna give me a lil opinion on the trick i talked > about earlier about getting sharp envelopes?
Time domain or frequency: it doesn't matter. You want to resolve the octave from 20 Hz to 40 Hz -- that's 20 Hz -- into 640 frequencies. Even if they're evenly spaced, the separation is 1/32nd of a Hz, so you need 32 seconds worth of data. That's 32*44,100, or 1,411,200 samples in your FFT. (The next higher power of two is 2,097,152.) Why do you keep thinking 256? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������