Compute the spectral centroid in maxmsp

Sep 20, 2012 at 2:36pm

Compute the spectral centroid in maxmsp

Hello,

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. –
#64436
Sep 20, 2012 at 8:30pm

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.

#232424
Sep 20, 2012 at 9:06pm

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.

#232425
Sep 21, 2012 at 8:23am

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

#232426
Sep 21, 2012 at 6:27pm

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.

#232427

You must be logged in to reply to this topic.