DSPRelated.com
Forums

Average frequency

Started by MadJock December 2, 2003
How would I go about finding the average frequency of a discrete signal?
I'm using MATLAB, and I want to split a *.wav file into n pieces and find
the average frequency of each.

Cheers

MadJock


MadJock wrote:

> How would I go about finding the average frequency of a discrete signal? > I'm using MATLAB, and I want to split a *.wav file into n pieces and find > the average frequency of each.
You mean split it in the time direction? That isn't obvious, because one important part of digital audio processing is splitting up different frequencies. I would say take the Fourier transform, or the square of the FT (power averages better than amplitude), and then average over that. It might be that median gives a better result than mean. You might also use a log scale for either axis, or both. -- glen
> > How would I go about finding the average frequency of a discrete signal? > > I'm using MATLAB, and I want to split a *.wav file into n pieces and
find
> > the average frequency of each. > > You mean split it in the time direction? That isn't obvious, because > one important part of digital audio processing is splitting up different > frequencies. > > I would say take the Fourier transform, or the square of the FT (power > averages better than amplitude), and then average over that. > > It might be that median gives a better result than mean. You might also > use a log scale for either axis, or both. > > -- glen
Sorry - I wasn't clear enough there. Yes, I mean split it in the time domain. My problem, however, is that I am unsure about how to get an average frequency. FTs are no problem, and squaring the FT is even less of a problem. How do I go from the DFT to an average frequency? I'm not sure the median would work, because I am sampling everything at the same rate (22.1kHz) and that means that all frequencies up to 11.05kHz will have some value. So the median would always be the same - am I correct? MadJock
MadJock wrote:

>>>How would I go about finding the average frequency of a discrete signal? >>>I'm using MATLAB, and I want to split a *.wav file into n pieces and >>> find the average frequency of each.
(snip)
> Sorry - I wasn't clear enough there. Yes, I mean split it in the time > domain. My problem, however, is that I am unsure about how to get an > average frequency. FTs are no problem, and squaring the FT is even less of > a problem. How do I go from the DFT to an average frequency?
> I'm not sure the median would work, because I am sampling everything at the > same rate (22.1kHz) and that means that all frequencies up to 11.05kHz will > have some value. So the median would always be the same - am I correct?
Start with a FT, absolute value and maybe square it, and consider it as a histogram, some number of items (intensity units) in each bin. Now move a pointer across the frequency axis. The point at which equal number of items are on each side of the pointer is the median. It will not always be 11.05kHz. For the mean, you sum the frequency times the intensity, and divide that by the sum of the intensity. You could also do either axis, or both, on a log scale. There is also the mode, which is the frequency of the bin with the most items (units). I don't know which one will give a number closer to the perception someone might have about the sound. -- glen
"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
news:8q6zb.282770$275.1001444@attbi_s53...
> MadJock wrote: > > >>>How would I go about finding the average frequency of a discrete
signal?
> >>>I'm using MATLAB, and I want to split a *.wav file into n pieces and > >>> find the average frequency of each. > > (snip) > > > Sorry - I wasn't clear enough there. Yes, I mean split it in the time > > domain. My problem, however, is that I am unsure about how to get an > > average frequency. FTs are no problem, and squaring the FT is even less
of
> > a problem. How do I go from the DFT to an average frequency? > > > I'm not sure the median would work, because I am sampling everything at
the
> > same rate (22.1kHz) and that means that all frequencies up to 11.05kHz
will
> > have some value. So the median would always be the same - am I correct? > > Start with a FT, absolute value and maybe square it, and consider it as > a histogram, some number of items (intensity units) in each bin. Now > move a pointer across the frequency axis. The point at which equal > number of items are on each side of the pointer is the median. It will > not always be 11.05kHz. > > For the mean, you sum the frequency times the intensity, and divide that > by the sum of the intensity. You could also do either axis, or both, > on a log scale. > > There is also the mode, which is the frequency of the bin with the most > items (units). > > I don't know which one will give a number closer to the perception > someone might have about the sound. > > -- glen
I would think it would depend on the type of sound source. If it is a single fairly stable sinusoidal component, then I would think the mode would be the way to go though median and mean would probably be pretty close. If it is a musical signal, i.e. fundamental + harmonics (+ noise probably), then the mode would definitely be the best bet. Any strong harmonics would skew the median and mean so that it would be above the fundamental. So I guess I would take the largest bin of the FT and use that for starters. A more sophisticated approach could be to see if several nearby bins are close in magnitude, and if so, average them. There is also the issue with a "missing" or lower-level fundamental in some musical sources that you may need to deal with. A bit more detail on your application would probably help us give better answers.
MadJock wrote:

   ...

> Sorry - I wasn't clear enough there. Yes, I mean split it in the time > domain. My problem, however, is that I am unsure about how to get an > average frequency. FTs are no problem, and squaring the FT is even less of > a problem. How do I go from the DFT to an average frequency?
... If you can define "average frequency" to your satisfaction, I or someone else here can show you how to calculate it. If you can't, then you don't really know what you're asking, and probably no one else does either. An answer an that case isn't worth much. 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;
In article w25zb.1109$Ji.39@news-binary.blueyonder.co.uk, MadJock at
nooooooooospam@blueyonder.co.uk wrote on 12/02/2003 13:42:

> How would I go about finding the average frequency of a discrete signal? > I'm using MATLAB, and I want to split a *.wav file into n pieces and find > the average frequency of each.
i dunno. the straight forward approach is: 1. window off your segment with a decent window (Kaiser i s'pose). 2. FFT it. 3. magnitude-square it. (assuming it is averaged in terms of energy) 4. multiply each bin with the frequency for that bin (same as bin number) 5. divide by sum of the bin numbers ( N*(N+1)/2 ) 6. viola. r b-j
> Start with a FT, absolute value and maybe square it, and consider it as > a histogram, some number of items (intensity units) in each bin. Now > move a pointer across the frequency axis. The point at which equal > number of items are on each side of the pointer is the median. It will > not always be 11.05kHz. > > For the mean, you sum the frequency times the intensity, and divide that > by the sum of the intensity. You could also do either axis, or both, > on a log scale. > > There is also the mode, which is the frequency of the bin with the most > items (units). > > I don't know which one will give a number closer to the perception > someone might have about the sound. > > -- glen
If I decide to square the FFT, does it make a difference if I square the actual FFT or its magnitude? The perception doesn't matter - I just want to find some sort of difference so I can feed it through a neural net. MadJock
MadJock wrote:

>>Start with a FT, absolute value and maybe square it, and consider it as >>a histogram, some number of items (intensity units) in each bin. Now >>move a pointer across the frequency axis. The point at which equal >>number of items are on each side of the pointer is the median. It will >>not always be 11.05kHz. >> >>For the mean, you sum the frequency times the intensity, and divide that >>by the sum of the intensity. You could also do either axis, or both, >>on a log scale. >> >>There is also the mode, which is the frequency of the bin with the most >>items (units). >> >>I don't know which one will give a number closer to the perception >>someone might have about the sound. >> >>-- glen > > > If I decide to square the FFT, does it make a difference if I square the > actual FFT or its magnitude? > > The perception doesn't matter - I just want to find some sort of difference > so I can feed it through a neural net. > > MadJock
I don't get it (again). What do you mean by "actual" FFT? The sum of the squares of the real and imaginary parts of a bin _is_ the square of the bin's magnitude. 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;
> > How would I go about finding the average frequency of a discrete signal? > > I'm using MATLAB, and I want to split a *.wav file into n pieces and find > > the average frequency of each. > > i dunno. the straight forward approach is: > > 1. window off your segment with a decent window (Kaiser i s'pose). > > 2. FFT it. > > 3. magnitude-square it. (assuming it is averaged in terms of energy) > > 4. multiply each bin with the frequency for that bin (same as bin number) > > 5. divide by sum of the bin numbers ( N*(N+1)/2 ) > > 6. viola. > > r b-j
Robert, Is playing a small string instrument for step #6 strictly necessary in calculating the average? Sorry, couldn't resist because it made me chuckle!