Forums

Frequency response of DFT single bin

Started by Jon Harris September 10, 2003
I'm trying to find and plot the frequency response of a single bin from a
DFT/FFT.  Then, as an extension, I'd also like to do the same for the
Goertzel algorithm implemented with non-integer 'k', i.e. centered at an
arbitrary frequency.  Any pointers or tips?  Matlab code would be ideal.




Jon Harris wrote:
> > I'm trying to find and plot the frequency response of a single bin from a > DFT/FFT. Then, as an extension, I'd also like to do the same for the > Goertzel algorithm implemented with non-integer 'k', i.e. centered at an > arbitrary frequency. Any pointers or tips? Matlab code would be ideal.
I've got a not-too-embarrasing C implementation of the goertzel transform here: http://leesburg.bittware.com/goertzel.tgz It has an open_goertzel() function that calculates a floting-point k based on a center frequency (freq) and sample rate (fs). I dunno why I coded freq and fs as ints though. -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas@bittware.com http://www.bittware.com (703) 779-7770 Unix IS user friendly. It's just more particular about its friends.
"Jim Thomas" <jthomas@bittware.com> wrote in message
news:3F5F67A8.2913BFE6@bittware.com...
> Jon Harris wrote: > > > > I'm trying to find and plot the frequency response of a single bin from
a
> > DFT/FFT. Then, as an extension, I'd also like to do the same for the > > Goertzel algorithm implemented with non-integer 'k', i.e. centered at an > > arbitrary frequency. Any pointers or tips? Matlab code would be ideal. > > I've got a not-too-embarrasing C implementation of the goertzel > transform here: > > http://leesburg.bittware.com/goertzel.tgz > > It has an open_goertzel() function that calculates a floting-point k > based on a center frequency (freq) and sample rate (fs). I dunno why I > coded freq and fs as ints though.
Jim - perhaps you can help me understand this better (even though you claim ignorance). Some of the S/W guys on my team seem to adopt integer data types for frequency, time, sample rate, etc even if I insist on floats. I haven't had success in getting a reasonable explanation out of them as to why (I guess if it works I should be happy). When I write code, my instinct is to go with floats (or doubles), but then I can't really call myself a typical s/w engineer. I do understand the floats are susceptible to floating point errors - is there any other reason? Are floating point errors really that big a deal? Cheers Bhaskar
> > -- > Jim Thomas Principal Applications Engineer Bittware, Inc > jthomas@bittware.com http://www.bittware.com (703) 779-7770 > Unix IS user friendly. It's just more particular about its friends.
Bhaskar Thiagarajan wrote:
> > Jim - perhaps you can help me understand this better (even though you claim > ignorance). > Some of the S/W guys on my team seem to adopt integer data types for > frequency, time, sample rate, etc even if I insist on floats. I haven't had > success in getting a reasonable explanation out of them as to why (I guess > if it works I should be happy). When I write code, my instinct is to go with > floats (or doubles), but then I can't really call myself a typical s/w > engineer. I do understand the floats are susceptible to floating point > errors - is there any other reason? Are floating point errors really that > big a deal?
I will continue to plead ignornace for as long as I can. I dunno why they want to do that. I often encode frequency as an int, but I almost always use a float to represent time (and I almost always represent time in seconds). Looking over the goertzel code, I notice that the only time I use freq or fs, I cast it to a float, so it prolly shoulda been a float all along. In the code I'm being paid to work on at the moment, I'm using an int to store the sample rate because the codec I'm interfacing to wants it that way. -- Jim Thomas Principal Applications Engineer Bittware, Inc jthomas@bittware.com http://www.bittware.com (703) 779-7770 Unix IS user friendly. It's just more particular about its friends.
Jim Thomas wrote:
> Bhaskar Thiagarajan wrote: > >>Jim - perhaps you can help me understand this better (even though you claim >>ignorance). >>Some of the S/W guys on my team seem to adopt integer data types for >>frequency, time, sample rate, etc even if I insist on floats. I haven't had >>success in getting a reasonable explanation out of them as to why (I guess >>if it works I should be happy). When I write code, my instinct is to go with >>floats (or doubles), but then I can't really call myself a typical s/w >>engineer. I do understand the floats are susceptible to floating point >>errors - is there any other reason? Are floating point errors really that >>big a deal? > > > I will continue to plead ignornace for as long as I can. I dunno why > they want to do that. I often encode frequency as an int, but I almost > always use a float to represent time (and I almost always represent time > in seconds). > > Looking over the goertzel code, I notice that the only time I use freq > or fs, I cast it to a float, so it prolly shoulda been a float all > along. > > In the code I'm being paid to work on at the moment, I'm using an int to > store the sample rate because the codec I'm interfacing to wants it that > way. >
I'll venture a guess. Back in the old days, one used knobs, led's, and other archaic forms of user interface. One might have used some sort of digital encoder to select something like a frequency. Integers would have a nice smooth vernier control as you hunt for a specific frequency.
"Stan Pawlukiewicz" <stanp@nospam_mitre.org> wrote in message
news:bjo33t$a04$1@newslocal.mitre.org...
> Jim Thomas wrote: > > Bhaskar Thiagarajan wrote: > > > >>Jim - perhaps you can help me understand this better (even though you
claim
> >>ignorance). > >>Some of the S/W guys on my team seem to adopt integer data types for > >>frequency, time, sample rate, etc even if I insist on floats. I haven't
had
> >>success in getting a reasonable explanation out of them as to why (I
guess
> >>if it works I should be happy). When I write code, my instinct is to go
with
> >>floats (or doubles), but then I can't really call myself a typical s/w > >>engineer. I do understand the floats are susceptible to floating point > >>errors - is there any other reason? Are floating point errors really
that
> >>big a deal? > > > > > > I will continue to plead ignornace for as long as I can. I dunno why > > they want to do that. I often encode frequency as an int, but I almost > > always use a float to represent time (and I almost always represent time > > in seconds). > > > > Looking over the goertzel code, I notice that the only time I use freq > > or fs, I cast it to a float, so it prolly shoulda been a float all > > along. > > > > In the code I'm being paid to work on at the moment, I'm using an int to > > store the sample rate because the codec I'm interfacing to wants it that > > way. > > > > I'll venture a guess. > > Back in the old days, one used knobs, led's, and other archaic forms of > user interface. One might have used some sort of digital encoder to > select something like a frequency. Integers would have a nice smooth > vernier control as you hunt for a specific frequency.
It seems to me that the answer is really simple: The data samples are *indexed* according to these numbers. So, it's natural to associate indices with integers - perhaps with a scale factor..... Could that be all there is to it? e.g. We talk about x(nT) all the time. Here "n" is an integer representing an index in "time". Fred
Thanks Jim, I'll take a look.  Also, I found some good stuff here thanks to
our friend Julius O. Smith III:
http://www-ccrma.stanford.edu/~jos/mdft/Frequencies_Cracks.html#fig:dftfilte
r
http://www-ccrma.stanford.edu/~jos/mdft/Figure_6_3.html#sec:dftfilterml

-Jon

"Jim Thomas" <jthomas@bittware.com> wrote in message
news:3F5F67A8.2913BFE6@bittware.com...
> Jon Harris wrote: > > > > I'm trying to find and plot the frequency response of a single bin from
a
> > DFT/FFT. Then, as an extension, I'd also like to do the same for the > > Goertzel algorithm implemented with non-integer 'k', i.e. centered at an > > arbitrary frequency. Any pointers or tips? Matlab code would be ideal. > > I've got a not-too-embarrasing C implementation of the goertzel > transform here: > > http://leesburg.bittware.com/goertzel.tgz > > It has an open_goertzel() function that calculates a floting-point k > based on a center frequency (freq) and sample rate (fs). I dunno why I > coded freq and fs as ints though. > > -- > Jim Thomas Principal Applications Engineer Bittware, Inc > jthomas@bittware.com http://www.bittware.com (703) 779-7770 > Unix IS user friendly. It's just more particular about its friends.
Stan Pawlukiewicz <stanp@nospam_mitre.org> wrote in message news:<bjo33t$a04$1@newslocal.mitre.org>...

> Back in the old days, one used knobs, led's, and other archaic forms of > user interface. One might have used some sort of digital encoder to > select something like a frequency. Integers would have a nice smooth > vernier control as you hunt for a specific frequency.
At the chance of displaying my ignorance, what is a "vernier control"? I have seen the term once or twice before and I can't find it in my dictionary. Rune
Rune Allnor wrote:
> Stan Pawlukiewicz <stanp@nospam_mitre.org> wrote in message news:<bjo33t$a04$1@newslocal.mitre.org>... > > >>Back in the old days, one used knobs, led's, and other archaic forms of >>user interface. One might have used some sort of digital encoder to >>select something like a frequency. Integers would have a nice smooth >>vernier control as you hunt for a specific frequency. > > > At the chance of displaying my ignorance, what is a "vernier control"? > I have seen the term once or twice before and I can't find it in my > dictionary. > > Rune
My apologies. In the part of the woods I grew up, central Connecticut (high school shop had more stuff than UCONN's), the knob on a micrometer was called often called a vernier, some called the focus knob on telescope eye piece a vernier. The term was loosely applied to many fine scaled adjustment knobs on machines and instruments. Floating point numbers are sort of log spaced. Integers have a uniform increment. My basic point is that I would use integers if I wanted an adjustment to emulate a micrometer vernier.
Rune Allnor wrote:
> > Stan Pawlukiewicz <stanp@nospam_mitre.org> wrote in message news:<bjo33t$a04$1@newslocal.mitre.org>... > > > Back in the old days, one used knobs, led's, and other archaic forms of > > user interface. One might have used some sort of digital encoder to > > select something like a frequency. Integers would have a nice smooth > > vernier control as you hunt for a specific frequency. > > At the chance of displaying my ignorance, what is a "vernier control"? > I have seen the term once or twice before and I can't find it in my > dictionary. > > Rune
I assume you know what a Vernier scale is, and how to read one. If not, see http://www.phy.ntnu.edu.tw/java/ruler/vernier.html As an analogy with a Vernier scale which allows one to read a coarse scale with high precision, controls that allow fine adjustments, like the extra narrow-range voltage control on a power supply are called Vernier knobs, with or without capitalizing the inventor's name. (On a microscope, it is called "fine focus". If Stan were describing one without knowing the usual nomenclature -- hardly conceivable! -- he might call it "vernier focus".) Jerry -- Engineering is the art of making what you want from things you can get. &#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;