fft tuning

rama's icon

hi guys -

trying build a basic fft analyzer for general spectral information, and also as a base for a polyphonic tuner. (have already tried the fiddle~ based externals (fiddle~, analyzer~, pitch~) but have had a number of issues with these). i seem to be getting close using pfft~ but i'm running into a couple problems coordinating the index with the amp/phase calculation.

using this equation inside pfft~ that i pulled from a past post on the forum:

frequency = phasediff*(samplerate/(hopsize*(2pi))) + fftindex*fftfundamental

but for some reason, using a test cycle~ tone, and peek~ to scroll through the calculated frequencies written to the buffer~, i'm two main issues i think:

1) the amplitude and frequency indexes get off from each other, sometimes the peak amplitude will be 1-2 indexes above or below the test tone, sometimes it will be perfect.

this seems to vary with the pitch of the sine wave as well as with the fft size. i'm guessing it has something to do with the way i'm using the buffer~, or maybe could it be some kind of timing issue?

2) more generally, once aligned, the freq/amp readings seems to spread into the neighboring bins - which i've also read can happen - but i'd like to figure out how to focus it more if possible.

i'm pretty new to fft - so maybe i'm doing something else wrong?
any advice would be great.

cheers,

rama

here's the patch (two parts with the pfft~):

save this first one as: pfft_bincalc2
//////////////////////////////////

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

//////////////////////////
and here's the main patch

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

rama's icon

sorry about the broken sentences above - rereading i think i edited it down too much : )

i'm guessing now both of those problems above are connected - does anyone know how to "cook" the bin reading? (ala fiddle~ etc.) maybe this is the way to go?

will try going through the fiddle docs some more. i hesitate because using fiddle~ and pitch~ i get incorrect 2nd and 3rd pitches. and analyzer~ crashes my system, seems like i'm the only one though. (mbp os 10.4 and now also on 10.5).

sorting the data using coll for this seems not to be ideal. i really have no clue as to programming c or java externals - but maybe i have to in order to deal with the data in the buffer...hmm.

well - i'll keep at it!

let me know if anyone has any ideas

cheers,

rama

here's a new version of the patch.

///////// save as: fft_bincalc4

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

///////// main patch:

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