### FFT in Max/Msp

Hey, so I was looking at the tutorial #25 in MSP, and I had several questions about using fft. When the sample analyzed is no longer a sinosuid or periodic, it seems that you have to window it to eliminate erroneous signals, but would the artifacts created by the FFT object and the windowing somehow tamper and mishandle the original data? I know you can use pfft~ also, but how would that affect the original data? Also, it suggests splitting data of samples that are longer than 1024 into different sections, but I am hoping to directly perform FFT on at least 10000 samples at a time, so how would the larger amount of samples affect analysis? I also don’t understand why 512 samples is so important (well in the tutorial) and while I know the concept of fundamental frequency, how is 512 samples the fundamental frequency in this case? And in order for FFT to process it, does it have to be a signal first? would I use "*~" or "cycle~" or both? And if the number of samples is not a power of 2, which is needed for the algorithm of FFT, how will that affect how things run?

I will try to give you some answers, but english is not my native language and this is a complicated topic, so I don’t know how much I will be able to help you.

would the artifacts created by the FFT object and the windowing somehow tamper and mishandle the original data?

The reason why you have to window the original signal is that the fourier transform assumes that the signal is periodic. If you take little slices of a longer signal (sample), for example you have a sample that has a length of 20 seconds and you slice it into parts that are 1024 samples long, the fft will assume, that each of these 1024 samples long slices is a periodic waveform and that after the end of each slice (at sample 1023) the waveform jumps back (loops) to the beginning (sample 0).

The problem is, that most of the time the signal value at the end of each slice is different from the signal value at the beginning, because it isn’t a periodic waveform but a small potion of a much longer signal.These "jumps" in the signal create harmonics that aren’t there in the original series. That’s why you have to "fade" each slice in and out, so that at the beginning and the end of each slice the signal value is zero and there are no jumps.

You’re right, this has some effects on the signal, but think about this: if you let the slices overlap in the right way (fading one out while the next already fades in) you could reconstruct the original sample by simply adding the slices again. So windowing doesn’t give you much trouble in practice.

I am hoping to directly perform FFT on at least 10000 samples at a time, so how would the larger amount of samples affect analysis?

If you do a fft on a 1024 samples long signal, it will give you the frequency contents of that 1024 long section, if you take the fft on over 10000 samples long signal it will give you the frequency contents of that over 10000 samples long section. So how long you make the section depends on what you want to do, what you want to analyze. Also it has an effect on the "resolution" of the fft, I will explain that later and of course on the latency, because you have to "collect" the more than 10000 samples before you can perform a fft on it.

I also don’t understand why 512 samples is so important (well in the tutorial) and while I know the concept of fundamental frequency, how is 512 samples the fundamental frequency in this case?

I think you’re mistaking the fundamental frequency of your input signal for the fundamental frequency of the fft. The fourier transform tells you, how to reconstruct a periodic signal by using siniod waves that have integer frequency ratios. So for example, if you do a fft on a 512 samples long signal, the fft will "deconstruct" it into sine waves that have lengths of 512 samples, 256, 128, 64…. and so on plus a dc offset. The fft will give you the amplitude and phase of each of these sine waves (at least after some more calculations).

If you then take a number of sinewave-generators, tune them so that they have a periodicity of 512 samples, 256,128… give them the right phase offset and amplitude and turn them on and add them all together, you will get a 512 samples long periodic waveform, that is exactly the original 512 samples long slice.

The fft doesn’t know anything about the fundamental frequency of some tone that the original signal might consist of. So if you’re playing a flute at 440Hz, that’s not the fundamental frequency of the fft, but the frequency of the sine wave that "fits" into the 512 samples is.

And in order for FFT to process it, does it have to be a signal first? would I use "*~" or "cycle~" or both?

Well yes, the fft analyzes signals. But then again, a digital signal is just a stream of numbers. I don’t know what "*~" or "cycle~" have to do with this. What are you trying to do?

And if the number of samples is not a power of 2, which is needed for the algorithm of FFT, how will that affect how things run?

The number of samples have to be a power of 2 because of the fft algorithm, which is much, much, much faster than a "normal" fourier transform. You could take 16384 (2^14) for example.

The number of samples you choose simply effects the fundamental frequency of the fft (the lowest freq. is the one, that fits into that number of samples) and the "resolution" as all higher frequencies into that the original signal is "deconstructed" are multiple integers of the fundamental frequency.

On http://www.dspguide.com you can find a free online book, that also explains fourier transform as less math as possible.

Forums > MaxMSP