peak finder

tdaeik's icon

hi,
i want to find the highest, say, n peaks from a jit.matrix with magnitude values from a pfft~. is the zsa.freqpeak object from maxobjects.com currently the only freely available option for this? or is there something built into a max/msp/jiter object somewhere which i could use to achieve this? were i to do this myself would javascript be the best option to do this? what if i want to find the peaks from a single fft frame in real time, would java script be too slow for this?
cheers,,

Zachary Seldess's icon

Hi tdaeik,

Something like this, using [mxj buf.Op] might help.

best,
Zachary

Max Patch
Copy patch and select New From Clipboard in Max.

tdaeik's icon

hi zachary,
thanks for your response. this example may take me some days to digest, but thanks for more thought!

tdaeik's icon
Max Patch
Copy patch and select New From Clipboard in Max.

hi,
not that anyones interested but i came up with this solution, basically a column-wise traversal of the matrix, sorting each column and getting the highest n values from that. hopefully i can now do math operations on the highest values in the time i need. cheers,,

tdaeik's icon
Max Patch
Copy patch and select New From Clipboard in Max.

so, i noticed that when the values are all the same, [zl sort] still sorts them, always in the same way. why is this?

Emmanuel Jourdan's icon

An easy way to reorder the peaks is to separate frequencies from the amplitude coming from zsa.freqpeak~ (using zl delace). Then you can simply sort the amplitudes (zl sort) and use the right outlet of zl sort in combination with zl lookup to reorder the frequency properly.

tdaeik's icon

hi,
after reading the papers on your website i see that zsa.freqpeak~ implements the peak detection algorithm i was looking for, so it's just a matter of me to incorporate it into my little patch. cheers,,

Emmanuel Jourdan's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Something like the following.

Julia Merino's icon

Hi Emmanuel,

Just out of curiosity, does the minimum number of peaks in the freqpeak object is always 4?

Thank you

Emmanuel Jourdan's icon

Looks like it can have less peaks : if I send a cycle~ object to zsa.freqpeak~ I get only one peak.

Julia Merino's icon

I was asking this because if I set the attribute peaks to 2 it's giving me 4 peaks anyways.