DSPRelated.com
Forums

AGC before FFT in piano frequency analysis

Started by Robert Scott March 3, 2004
I have a 6-second sample of a single piano note from which I need to
extract the frequencies of the components that are near, but not
quite, harmonics of the fundamental.  I have been doing this by
finding appropriately-spaced local maxima in the FFT power spectrum,
and then using quadratic interpolation (using the amplitude of the
immediate bin neighbors together with the amplitude of the peak bin)
to estimate the frequency of each peak.  But now I am wondering if I
will get an improvement in accuracy if I subject the time-domain
series to fairly strong AGC before doing the FFT.  I know that it will
bring up the noise toward the end of the note's decay, but if I don't
use AGC, isn't my FFT going to be determined mostly by the
high-amplitude portion of the sample (i.e. the first 2 seconds)?


-Robert Scott
 Ypsilanti, Michigan
(Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)
I wouldn't have thought it would make too much difference as long as you
don't try to compare the results of one FFT with another.  i.e. you would
expect some change in amplitude and frequency content over time but if you
compress the dynamic range of the signal as a whole you would not expect the
picture of one frequency relative to another at any point in time to change
that much from the non-compressed case.

In any case, have you tried it?  If you do, try a fast attack and relatively
long release time constant in your compressor set with a high ratio (amount
of change in output amplitude/change in input amplitude when input signal is
above a pre-set threshold) and low threshold (so the compressor is working
for most of the interesting dynamic range of the signal).  A short release
time constant < approx. 500mS will result in significant distortion due to
amplitude modulation, and a distortion of your results.

Hope this is of some help.
--
Dave Wooff
dave@dmwooff.freeserve.co.uk
Robert Scott <no-one@dont-mail-me.com> wrote in message
news:404622d5.3080330@news.provide.net...
> I have a 6-second sample of a single piano note from which I need to > extract the frequencies of the components that are near, but not > quite, harmonics of the fundamental. I have been doing this by > finding appropriately-spaced local maxima in the FFT power spectrum, > and then using quadratic interpolation (using the amplitude of the > immediate bin neighbors together with the amplitude of the peak bin) > to estimate the frequency of each peak. But now I am wondering if I > will get an improvement in accuracy if I subject the time-domain > series to fairly strong AGC before doing the FFT. I know that it will > bring up the noise toward the end of the note's decay, but if I don't > use AGC, isn't my FFT going to be determined mostly by the > high-amplitude portion of the sample (i.e. the first 2 seconds)? > > > -Robert Scott > Ypsilanti, Michigan > (Reply through this forum, not by direct e-mail to me, as automatic reply
address is fake.)
Hello Robert,

Despite the fact that AGC changes freq. content a little bit I want to 
point out that mostly the "tone" of an instrument is not constant over playing it.
Some years ago I wanted to write a note recognition system for a guitar 
and I found out that the harmonic content is dramatically changing over 
time. Nevertheless you don't look at harmonics also your content of interest 
may change over time.
So first I would try to split your 6 seconds into 6 fft's over 1 second to 
be shure that the relation between the amplitudes you are looking at stays constant.
(If that is not true AGC must change your result)

                                            Wolfgang

"Robert Scott" <no-one@dont-mail-me.com> schrieb im Newsbeitrag news:404622d5.3080330@news.provide.net...
> I have a 6-second sample of a single piano note from which I need to > extract the frequencies of the components that are near, but not > quite, harmonics of the fundamental. I have been doing this by > finding appropriately-spaced local maxima in the FFT power spectrum, > and then using quadratic interpolation (using the amplitude of the > immediate bin neighbors together with the amplitude of the peak bin) > to estimate the frequency of each peak. But now I am wondering if I > will get an improvement in accuracy if I subject the time-domain > series to fairly strong AGC before doing the FFT. I know that it will > bring up the noise toward the end of the note's decay, but if I don't > use AGC, isn't my FFT going to be determined mostly by the > high-amplitude portion of the sample (i.e. the first 2 seconds)? > > > -Robert Scott > Ypsilanti, Michigan > (Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)
On Tue, 9 Mar 2004 08:43:40 +0100, "Wolfgang" <never@nowhere.com>
wrote:

>Hello Robert, > >Despite the fact that AGC changes freq. content a little bit I want to >point out that mostly the "tone" of an instrument is not constant over playing it. >Some years ago I wanted to write a note recognition system for a guitar >and I found out that the harmonic content is dramatically changing over >time. Nevertheless you don't look at harmonics also your content of interest >may change over time. >So first I would try to split your 6 seconds into 6 fft's over 1 second to >be shure that the relation between the amplitudes you are looking at stays constant. >(If that is not true AGC must change your result)
I am not interested in the amplitudes of the harmonics at all. I am only interested in their frequencies. Due to the stiffness of the piano wire, the harmonics are not really harmonics, but are near-harmonic frequencies called partials. For example, the relative frequencies of a particular string might be: 1.00 2.01 3.04 4.11 5.19 6.22 It is these numbers that I want to measure. It is true that the exact frequency of the partials changes a little during the 6 seconds because the decaying amplitude does slightly affect the frequency. But this effect on a piano is not nearly as pronounced as on a guitar where the strings are relatively looser. Right now, the best measurement I have been able to make does not use the FFT at all, but rather uses piece-wise quadrature demodulation of the time series to attempt to track the phase of each partial in one-second chunks over the course of the 6-second sample; it is sort of a phased-locked loop. The phase is defined with respect to a synthesized sine wave very near the actual frequency. Then the difference between the phase in the 6th second and the phase in the 1st second gives me the frequency. But I am trying to see if I can get the same accuracy using an FFT and quadratic bin interpolation. -Robert Scott Ypsilanti, Michigan (Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)
In article 404dc1d5.1303397@news.provide.net, Robert Scott at
no-one@dont-mail-me.com wrote on 03/09/2004 08:08:

> I am not interested in the amplitudes of the harmonics at all. I am > only interested in their frequencies. Due to the stiffness of the > piano wire, the harmonics are not really harmonics, but are > near-harmonic frequencies called partials. For example, the relative > frequencies of a particular string might be: > > 1.00 2.01 3.04 4.11 5.19 6.22
i don't think it is that far off. i look around and see if i can find some stats, but i truly do not think the 6th harmonic is detuned to the extent you say
> It is these numbers that I want to measure.
so you are trying to track the exact frequencies of what is often called a "quasi-harmonic" or "quasi-periodic" tone? are you planning to write your own code to do this?
> It is true that the exact > frequency of the partials changes a little during the 6 seconds > because the decaying amplitude does slightly affect the frequency. > But this effect on a piano is not nearly as pronounced as on a guitar > where the strings are relatively looser. > > Right now, the best measurement I have been able to make does not use > the FFT at all, but rather uses piece-wise quadrature demodulation of > the time series to attempt to track the phase of each partial in > one-second chunks over the course of the 6-second sample; it is sort > of a phased-locked loop. The phase is defined with respect to a > synthesized sine wave very near the actual frequency. Then the > difference between the phase in the 6th second and the phase in the > 1st second gives me the frequency. But I am trying to see if I can > get the same accuracy using an FFT and quadratic bin interpolation.
you got some of this down right. you might want to go to the harmony-central.com site and check this out:
> http://www.harmony-central.com/Synth/Articles/Wavetable_101/Wavetable-101.pdf
if you can make a pretty good pitch detector (that is really a period estimator), you can measure the change of phase of each harmonic and use that to compute how much each one is detuned from the exact harmonic value. r b-j
Robert Scott wrote:

(snip, including previously snipped question about FFT and
applying AGC to piano notes.)

> I am not interested in the amplitudes of the harmonics at all. I am > only interested in their frequencies. Due to the stiffness of the > piano wire, the harmonics are not really harmonics, but are > near-harmonic frequencies called partials. For example, the relative > frequencies of a particular string might be:
> 1.00 2.01 3.04 4.11 5.19 6.22
> It is these numbers that I want to measure. It is true that the exact > frequency of the partials changes a little during the 6 seconds > because the decaying amplitude does slightly affect the frequency. > But this effect on a piano is not nearly as pronounced as on a guitar > where the strings are relatively looser.
I would say that the gain control might be useful in this problem. In general, I wouldn't suggest it, though. One is that it is a form of amplitude modulation, though a fairly low frequency form so it shouldn't really affect the frequencies much. Just to be sure I understand the question, as far as I know each piano note has two or three strings that are intentionally not tuned exactly the same. Are you also measuring that? Another possibility is to determine the fundamental amplitude and phase, subtract that, and FFT the result. Also, remember that the FFT, by definition, assumes periodic signals. If you FFT a six second sample the FFT will give the result of repeating that sample every six seconds. -- glen
Hello Robert,

A book you may wish to find is Quinn and Hannan's "The Estimation and
Tracking of Frequency."

You may also wish to look at Peter Kootsookos' Frequency estimation page at:

http://www.itee.uq.edu.au/~kootsoop/freqalgs.htm


Clay


The book's minimal errata can be found at:

http://www.ma.umist.ac.uk/bgq/bookerr.pdf

-- 
Clay S. Turner, V.P.
Wireless Systems Engineering, Inc.
Satellite Beach, Florida 32937
(321) 777-7889
www.wse.biz
csturner@wse.biz



"Robert Scott" <no-one@dont-mail-me.com> wrote in message
news:404dc1d5.1303397@news.provide.net...
> On Tue, 9 Mar 2004 08:43:40 +0100, "Wolfgang" <never@nowhere.com> > wrote: > > >Hello Robert, > > > >Despite the fact that AGC changes freq. content a little bit I want to > >point out that mostly the "tone" of an instrument is not constant over
playing it.
> >Some years ago I wanted to write a note recognition system for a guitar > >and I found out that the harmonic content is dramatically changing over > >time. Nevertheless you don't look at harmonics also your content of
interest
> >may change over time. > >So first I would try to split your 6 seconds into 6 fft's over 1 second
to
> >be shure that the relation between the amplitudes you are looking at
stays constant.
> >(If that is not true AGC must change your result) > > I am not interested in the amplitudes of the harmonics at all. I am > only interested in their frequencies. Due to the stiffness of the > piano wire, the harmonics are not really harmonics, but are > near-harmonic frequencies called partials. For example, the relative > frequencies of a particular string might be: > > 1.00 2.01 3.04 4.11 5.19 6.22 > > It is these numbers that I want to measure. It is true that the exact > frequency of the partials changes a little during the 6 seconds > because the decaying amplitude does slightly affect the frequency. > But this effect on a piano is not nearly as pronounced as on a guitar > where the strings are relatively looser. > > Right now, the best measurement I have been able to make does not use > the FFT at all, but rather uses piece-wise quadrature demodulation of > the time series to attempt to track the phase of each partial in > one-second chunks over the course of the 6-second sample; it is sort > of a phased-locked loop. The phase is defined with respect to a > synthesized sine wave very near the actual frequency. Then the > difference between the phase in the 6th second and the phase in the > 1st second gives me the frequency. But I am trying to see if I can > get the same accuracy using an FFT and quadratic bin interpolation. > > > -Robert Scott > Ypsilanti, Michigan > (Reply through this forum, not by direct e-mail to me, as automatic reply
address is fake.)
On Tue, 09 Mar 2004 11:58:35 -0500, robert bristow-johnson
<rbj@surfglobal.net> wrote:

>In article 404dc1d5.1303397@news.provide.net, Robert Scott at >no-one@dont-mail-me.com wrote on 03/09/2004 08:08: > >> I am not interested in the amplitudes of the harmonics at all. I am >> only interested in their frequencies. Due to the stiffness of the >> piano wire, the harmonics are not really harmonics, but are >> near-harmonic frequencies called partials. For example, the relative >> frequencies of a particular string might be: >> >> 1.00 2.01 3.04 4.11 5.19 6.22 > >i don't think it is that far off.
No, I agree. I was just picking numbers out the the air to illustrate the concept, not to convey specific results.
>...you might want to go to the >harmony-central.com site and check this out: > >> http://www.harmony-central.com/Synth/Articles/Wavetable_101/Wavetable-101.pdf > >if you can make a pretty good pitch detector (that is really a period >estimator), you can measure the change of phase of each harmonic and use >that to compute how much each one is detuned from the exact harmonic value.
Thanks for the referece. I have looked at it briefly, but it will take much longer to absorb it. It seems to be focused a lot on synthesis. My application is piano tuning. By measuring the "inharmonicity" of a number of piano strings, a specific stretched tuning can be derived custom for that piano. Another problem that I did not mention is that the partials are themselves not always pure, but can be composed of several very closely-spaced components, giving rise to a "false beat". Pitch detection in this case is particularly hard because phase tracking may be undefined. -Robert Scott Ypsilanti, Michigan (Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)
On Tue, 09 Mar 2004 17:03:24 GMT, glen herrmannsfeldt
<gah@ugcs.caltech.edu> wrote:

> >Just to be sure I understand the question, as far as I know each >piano note has two or three strings that are intentionally not tuned >exactly the same. Are you also measuring that?
No, I am measuring a characteristic of a single string. That characterisic is called "inharmonicity", and it is the degree to which the higher-order partials deviate in frequency from the pure integer multiples of the fundamental frequency. -Robert Scott Ypsilanti, Michigan (Reply through this forum, not by direct e-mail to me, as automatic reply address is fake.)
glen herrmannsfeldt wrote:

   ...

> Just to be sure I understand the question, as far as I know each > piano note has two or three strings that are intentionally not tuned > exactly the same. Are you also measuring that?
Glen, The lowest notes have only one string, but most notes are, as you write, produces by two or three. In a properly tuned piano, these strings are not tuned to the same pitch, but they are close enough so that their common bridge forces them to vibrate in unison. (A piano so far out of tune that the strings of a single note vibrate independently sounds characteristically "hollow".) The staggered tuning reduces the efficiency with which energy is transferred from the strings to the bridge. Energy passes instead from string to string and back again, in the manner of classical coupled pendulums. This effect reduces both the initial loudness of a note and its rate of decay. When the several strings are tuned in unison, the piano is loud and "thunky"; when they're properly detuned, the piano is softer, and it "sings". 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;