Forums > MaxMSP

Compute the spectral centroid in maxmsp

September 20, 2012 | 2:36 pm


I’m trying to compute the spectral centroid in max.
The spectral centroid can be see as the barycentre of the magnitudes of the spectrum of frequencies..
I know there are some externals which does that, but I’d like to implement it myself to understand how msp works.

This is what I did. This patch is inspired by the MSP tutorial 26. I use the edge~ object on the third outlet of the fft, to compute the centroid frame by frame.

How you can see, it seems to work if there in only one frequency in the fft (message box 1). In the case of a "real" signal (message box 2, cycle~440). It’s not stable at all.

Why ? Any idea ?

Thanks a lot for your help.

– Pasted Max Patch, click to expand. –
September 20, 2012 | 8:30 pm

I think you’re better off using pfft~ do to a windowed transform. There is a lot of noise at the edges of an unwindowed fft~.

Here’s a main patch:

– Pasted Max Patch, click to expand. –

And here’s what goes in the pfft~:

– Pasted Max Patch, click to expand. –

It’s a little rough, but it’s heading in the right direction.

September 20, 2012 | 9:06 pm

You might also want to have a look to gen~.pfft_centroid.maxpat in the gen example folder. It shows how to calculate the centroid using gen~, the codebox version demonstrates also some of the new gen~ features of Max 6.0.7.

September 21, 2012 | 8:23 am

Thanks a lot for your answers.
I just have max 5, so the gen~ object will be for another time.
To capture the fft frame by frame, the poke~object seems to be very useful.
I’m not sure to understand if the edge~ object if fast enough to make all the frame to be compute, but..well it seems to work!
Thanks again for your help

September 21, 2012 | 6:27 pm

edge~ is not fast enough for my method to be 100% accurate. If the vector size is low, and the scheduler is in audio interrupt, then the result should be reasonably accurate. The gen~ method is better.

Viewing 5 posts - 1 through 5 (of 5 total)

Forums > MaxMSP