DFT in max? Or More precise FFT when getting frequency?
Hi,
Is it possible to run a Discrete Fourier Transform in Max? I'm looking at the FFT tutorials and seeing that FFT requires number-of-FFT-samples to be a power of two, and the spectral frame size to also be a power of two. I was able to create an FFT with arguments that used floating point values, that used powers of two successfully. But is it possible to have like 100.227249 as an argument even if it doesn't throw an error because its technically a power of two? If so how does it treat samples? Is it able to work with samples in decimals or do these arguments also need to be a integer and not a float and a power of two?
I ask because, ideally I'd like to set a target frequency, say 440 or whatever frequency, and then set up my FFT so that its bins are looking exactly for that frequency. The FFT with power of two constraint allows for very very close precision if floating point values work. But I was wondering if it was possible to be more exact maybe using a DFT instead since it wouldn't be constrained to a power of two?
Thanks!
i believe it is theoretically possible to build a "real" DFT in gen~, but it sill still be much more expensive compared to pfft~ in MSP.
what about combining an FFT analyzer with 4096 bins and a frequencyshifter with +/-5.35Hz ? ;)
Hi Roman,
Thanks for the reply. I’m not sure I understand how or if that would solve the problem I’m trying to solve. If I have a frequency coming in that is unknown, and I shift the bins, wouldn’t that shift the frequency of the sound coming in? I’m trying analyze the sound coming in, so I would need to be able to shift the bins without shifting the signal right ? I might be missing something though because I’m kind of new to fft in max and frequency analysis that is very precise.
I ask about dft because I’m interesting in finding the most precise way of measuring the frequency of a signal coming in.
i was thinking about a scenario where the input material only consists of pure tones of unknown frequencies. beause this is the only scenario where a perfect analysis could apply to.
then the combination of a traditional frequency shifter and a 4096-FFT would give you a quite accurate mechanism to find its frequency.
(otoh, if the input is only pure tones, you could also clacluate the frequency by the amplitudes the FFT gives you for those 2 bands which show an amplitude)
speaking of tones, that is part of the problem: what kind of signals do you want to analyse, and if it is pure tones, when don´t you know their frequeny already?
for the classic pitch tracking of more complex audio signals DFT/FFT is quite unusual, and there is half a dozen of different approaches for different applications how to do pitch tracking...
Hi, I’m sending analog sine oscillator input from a hardware synth. So the tone is fairly pure but not a digital oscillator. I’d like to figure out how to get the most precise measurement possible of its frequency for tuning purposes.
So if I had a target of 440 hz that I wanted to tune the oscillator to using an fft of 4096, that doesn’t give me a bin of exactly 440 hz. Are you suggesting that I would then shift the incoming unknown frequency to match the closest bin in the 4096 fft that is closest to 440? Or shift all of the bins so that one of them is 440 and then apply an offset after the fft to correct for the bin shifting ?
I should also note that I’m sending control voltages out of max that drive the tuning on the oscillator and that voltage to frequency isn’t a linear scale. So ideally it seems like, if I could somehow know which floating point value in max, which drives a control voltage, corresponds to the frequency output, is basically what I’m trying to do, but to the highest precision possible in max.
yes exactly, while i meant it more as a joke, it would technically work in certain situations: when you have a frequencyshifter and a an FFT analzer, you can turn the knob on the frequencyshifter until the FFT only shows amplitudes > 0 on a single band.
an FFT of 4096 (i think modern versions of max can go a bit further, unfortunately it is still somewhat limited) has one "frequency band" which goes from 430,640 to 441,406 Hz
(44100/4096==10.766, lowest band starting to count at 0 Hz)
so we can assume a "center frequency" of 436.023
a tone of 440 Hz as input would cause 2 bands of the analyzer to show amplitudes (because FFT filters are not as "brickwall" as people think)
now move the shifter up and down a bit to find out the range in which only one FFT band reacts - the center of this range is the frequency of the input.
this assumes that you already tried fiddle~, sigmund~, retune~, fluid.pitch and the zsa objects so that you have somethign to compare it to.
the answer which one is the "best" might be different when it is also important to track pitch changes, complex material, or if you need to avoid realtime latency. ;)
for a true DFT in gen~ i am at a loss...
Thanks for the info, it makes a little more sense. I’m not sure what center frequency is exactly though and how accurate that is or how to calculate it. Is it an average ?
Frequency band makes more sense where it’s a range and that 440 would fall somewhere with that band you described.
I have tried sigmund and fiddle. I’ve noticed that sigmund has a lot of jitter and is definitely pretty precise down to about a tenth of a hertz. But yeah for what I’m trying to do, I’d like to get more precision and no jitter or if there is jitter like in the 1000ths of hz. This might be just wishful thinking though.
I’m going to look into dfts and gen and keep researching.