getting the peak frequency from a buffer

frnce78975's icon

There must be some easy way to do this that I'm overlooking: I want to scan the audio in a buffer and get the peak frequency. I know how to use myriad of spectral analysis software and the spectroscope object, but I don't see an obvious way to display the frequency with the greatest amplitude in Max. Seems like a trivial task. I must be going about this the wrong way.

I'm an experienced Max user for several, but new to the forum, and am more familiar with the Max side than the MSP side. Any help would be greatly appreciated. I've been scouring through the forum for a while now.

pid's icon

couldn't you just get it with 'peek~' and a 'peak' also? and maybe a 'trough' for fun. or maybe i misunderstand...

frnce78975's icon

I believe peak~ just outputs an amplitude value. I need a frequency value with the highest amplitude.

The sonograph example patch (in fft-fun) seems like a close start, but there doesn't seem to be an easy way to parse the data from spectroscope~ which is essentially what I want to do. I don't need the GUI part of spectroscope, just the frequency with the highest amplitude.

Thanks.

MIB's icon

have you considered doing your own fft analysis? have a loop at pfft~. you will need a way to store and order the data. I would recommend ircam's ftm for that (coll probably won't cut it). I would use [fmat] to store and order your amplitude and frequency data for each bin and probably a second [fmat] to keep track of the loudest frequency in each frame. this should do the trick (or at least get you started).
Come the weekend I might have time to whip together a crude example if need be...

frnce78975's icon

Thanks MIB--that gives me a lot to think about. I tried pairing the amplitude values with frequency values that I got from analyzer~ into a coll, but I soon realized that coll was not the way to go.

An example patch would be VERY much appreciated as I have not used the IRCAM externals you mentioned.

Emmanuel Jourdan's icon

You might want to check zsa.descriptors. There's a basic peak analyzer, definitely not the best on earth, but you might get some decent results.

frnce78975's icon

thanks! I definitely will!

frnce78975's icon

I believe my patch now does what I originally wanted it to do. I don't want to impose, but would someone mind taking a look and verifying that the data I'm getting is what I think I'm getting?

The zip file above is contains my main patch and two files from Emmanuel Jordan's zsa.descriptors.

To reiterate, this patch performs an FFT on incoming data and outputs the frequency of the peak amplitudes for the first four peaks of the signal.

Continued thanks to everyone!!

Martin Weiss's icon

Hey! I want to do exactly what you did. However, your patch isn't online anymore. Can you re-upload?

Steve Rogers's icon

Hello,

I am trying to do this as well, could you re-post your file or does anyone else know how to do this? I am trying to get the frequency values (numeric) for the first few peaks in the spectrogram.

Thanks,
Steve

yilinyilin's icon

Hi,FRNCE,
Could you please offer any suggestions or clues on this problem? or Any one know how to do that? Thanks!