Forums > MaxMSP

question about ifft for a beginner

Jul 06 2012 | 1:09 am

i can generate spectrums that have a similar fft to .wavs that i want to broadly emulate [noisy kind of audio] but when i invert them to play they seem to always end up as a couple of loud clicks at start and beginning and some very quiet fuzz in between. boring!

is creating fft in order to invert it a thankless task? i mean limited to things like sine waves?

i hope that makes sense :o if not maybe i cn explain some more…

Jul 06 2012 | 6:01 am

Not completely sure of what you’re trying to do – maybe you might want to post an example…

Anyway, if you’re aware enough about how Fourier transforms work, have a look at this:


Jul 06 2012 | 9:02 pm

e.g. if i do an fft of two sounds and find the average and ifft that it doen’t sound anything like the original soudsn. that’s to be expected right?

Jul 06 2012 | 11:03 pm

let me try to rephrase that. i’m trying to make a set of sound files with a similar fft to the top left one here. however, whenever i make the desireed data and then apply ifft to it, i always get a signal that starts and ends with a very sharp peak, so that the sound is far too quiet for most of its length – just starting and beginning with a very loud click. this is not what was desired.

am i doing something wrong?

Jul 07 2012 | 9:21 am

Frankly, I still don’t understand what you’re trying to do… simply cycling on a set of values and computing their ifft will give you an harmonic spectrum, whose fundamental is the fft frame rate. If you want to create more complex sounds, the Xavier Rodet’s paper I posted above explains a technique.

Of course I might be wrong, but are you sure you have a grasp of the maths behind the Fourier transform?

Jul 07 2012 | 12:53 pm


no i don’t, exceptthat the idea is to find the sine wave frequencies that combine to make the wave. that’s not the point atm. i thought that ifft reverrted the application of fft – is that right?

the problem is that whenever i make data represtenting a frequency spectrum, and apply ifft to it, i seems to always get a waveform that starts and ends with a click and is very quiet in between. am i doing something wrong to always get that result?

not specific to max/msp :)

Jul 07 2012 | 2:38 pm

well, that’s exactly the point… fft doesn’t "find the sine wave frequencies that combine to make the wave". it’s more complex than that… probably there are great online resources explaining how it works, but I got it when I read this book:
no joke, if you don’t have a great training in maths (which is my case) a children’s book is the best you can find! – and I can assure you, it contains everything you want to know.

Jul 07 2012 | 9:12 pm

I you’d post a patch we could probably see whats wrong. But out of your description and lack of expertise I would guess that you did not care of the windowing. I never ever used fft~and ifft~, as dealing with the windowing is a pain.
Since the existence of pfft~ there are very rare occasions only for math professors who would still use these objects…

in short: use pfft~ and the world will shine in a nice spectrum again…


Jul 08 2012 | 6:15 pm

ok, i’m gonna try pfft. there’s even a turorial on it 8)

i was not actually using max/msp, i just figured that here would be a cool / useful place to ask about fourier.

honestly i’m not ready to get to grips with the maths… if i can perform ifft so that not every signal that is returned is the same then i might.
what i’m trying to do is find out if spectrum analysis can be used to determine if some sound is "harsh" or discomforting. i am not sure if this might bear and interesting results? maybe spectrums that are low on noise??

Jul 08 2012 | 8:12 pm

so i was talking with someone, and they say fft isn’t the way to go with this but: spectrograms.

where do i start? i want to devise a way of measuring the harshness of a recording. perhaps this will be certain frequencies [unpleasantness] perhaps the presence of noise. i dunno yet! but can anyone help me get started with spectrograms – i suppose i’d like to be able to export data so that i can run statistical tests on it??


Jul 08 2012 | 10:25 pm

is there a spectrum analyzer i can export the results to .txt??

Jul 08 2012 | 11:24 pm

you should look at the zsa suite of externals for audio analysis– they use the fft in a more sophisticated, perceptually oriented and musically meaningful manner

Jul 09 2012 | 2:02 am


one thing which suggests i’m confusing myself, is that max/msp seems to want amp and *phase* as inputs, rather than amp and freq. if anyone understand why that might confuse me – why is that?

edit oh i can get the time/freq/amp data into a stats program, i’ve just got to figure out what to run on them ha.

Jul 09 2012 | 2:57 am

that’s because the frequency is implied by the bin number or index out the right outlet of fftin– the actual frequency for a particular bin number can be calculated by dividing the number of bins into the 1/2 sample rate and then multiplying by the current bin index — sounds like you’ll have to massage your stats data so the frequency is represented as bin number. For your purposes the data could be represented as just an ordered list of amplitudes (or amp-phase pairs) with the first element (or pair) corresponding to bin 0.

Jul 09 2012 | 3:33 am

right, thanks.

just to go on… i decided that what i want to do is run tests on a bunch of noise signals which i have rated for "harshness". i then want to create the harshest possible noise signal from that data… but i don’t want to use iift to create it. i want to use midi or something as a control voltage for a square wave oscillator.

is it possible to run an fft test to get an idea [ideally not just vaguely] what signal will be harshest, then create that signal using one square wave oscillator?

i’m kinda ahead of myself here – but any advice would be sweet :)

edit no wait i’m not sure i need fft anymore, because of the nature of what i’m rating… i’d just have several datasets of 0s and 1s, each with a harshness value, and then want to extrapolate from that.

Jul 09 2012 | 4:05 am

if you have a look at the zsa descriptors there’s all sorts of analyses that can asssist in that, ie htere’s one called ‘brightness’ I think and ‘noisiness’ spectral richness, kurtosis etc that may correlate in some way to your idea of ‘harshness’. definitely worth looking at them to get a handle on what you want and how you can systematize a synthesis method or ‘predict’ an outcome according to your chosen criteria

Jul 09 2012 | 4:57 am

I am not sure if harshness could be found with a spectral distribution alone. You would have to look in the spectrum for inharmonic content, and I think you should also look at the time domain, as the time structure adds to such a description. ZSA would be the best starting point, or set up a neural network and teach it harshness…;-)
This research could be the beginning of a big Ph.D. thesis…

To measure subjective descriptors involves other sciences like psychology on a high level as well…

But you said you want to create harshness with a square wave – you might be in a completely different world… I imagine metal techno kind of sounds… This would not involve any technical analysis, it would involve simply human experience with dinosaur analog synthesizers combined with harsh digital distortion methods…
There is much treatment out there in the world which could be learned how to tweak it to create the harshest sound imaginable – but thats a matter of taste…


Jul 09 2012 | 5:48 am

"metal techno" haha ^_^

here’s some exmaples of square waves – i’m trying to get some people who are into harsh sounds to rate different sections for harshness…

ps i also timestretch noise ahaha ;)

Jul 09 2012 | 7:39 am

so i deleted that mp3 because people were taking it seriously as a work of noise rather than a test of harshness… i;m gonna start asking about stats procedures on different forums now. physicsforums looks good… thanks for replies :)

Jul 11 2012 | 11:40 pm

square waves… can anyone debug my patch / tell me if max/msp can do this?

i have a list of 0s and 1s – these are the square wave pattern. i then used excel to count the number of times a 1 or 0 repeated before the value changed to a 0 or 1 respectively.
so e.g.: 00110100011 becomes 221132

i am now trying to "play" that new data in max. make sense? but all i get is frank digital *noise* – when i know that the original square wave was tonnes richer. am i asking the program to do things it can’t, or have i set up the patch incorrectly?
the txt file that loads is that second data set i have created in excel :)

thanks for any more help.

Jul 12 2012 | 9:03 am

I put something together– thought it would be easy (and probably is for someone cleverer than me), but turned out rather complicated– still doesn’t work perfectly but it’s a start. One thing you need to do is press the button twice to get the expected waveform, so something wrong with my message ordering. Basically it works by converting the text sequence of numbers into a list, which is then used to fill a wave table with either -1 or 1. the table is then looped through by a phasor. Make sure you enclose the number sequence in quotes (ie "11122225554347") or it wont work.

Ideally you’d have an antialiasing filter in there, otherwise it’s rather academic.
anyway hope it helps

-- Pasted Max Patch, click to expand. --

Jul 13 2012 | 6:47 pm

hmm, thanks terry, i’ll try that in a bit : . exciting!

atm i’m kinda working on creating the data in max/msp, just because excel only has about a million cells. what’s the longest txt file that max can load or create? anyway, this process is really slow atm – the patch i made is struggling a bit :( .

thanks for the help!

Feb 23 2015 | 12:17 pm

Hey Andrea, are you familiar with the implementation of the paper you mentioned here? I am baffled by the step "fourier transform a window function and shift it to center around the partial frequency".

Here is what I am planning to do:
1. sample the Fourier transform of a window function(ex. hamming) in 256 steps,
2. only store amplitudes of the samples around the central lobe (ie. store the 9 samples nr. 124 – 132 when sampled 256 times)
3. calculate these samples’ associated frequencies after being shifted.

I am not sure if this is the right way as on page 6 "Implementation and performances", it looks like it’s necessary to store the the whole W in 256 samples while I thought I just need the same K (=9 in the paper) samples around the center lobe for calculating the amplitudes of all partial frequencies. Do you know what am I missing?

Thanks for the reply in advance!

Feb 24 2015 | 1:52 am


I’m sorry – I actually studied that paper some years ago, but eventually I concluded that, on the machine I had at the time (it was 2009, I think), plain old additive synthesis could be performed with all the partials I needed, and never tried to implement the inverse fft technique. So I’m afraid I can’t help you.

Out of curiosity, what are you trying to achieve, that can’t be done with ioscbank~, or a good bunch of oscillators in a poly~? How many partials do you need? Additive synthesis (which I am very fond of) has a lot of advantages, including the absence of spectral artifacts and the possibility of finely controlling the evolution of each component in time.


Feb 24 2015 | 3:35 am

Hi Andrea,

I need at least 100 partials for each voice (probably 6-8 voices in total) with the ability to change the pitch and amplitude of each partials simultaneously. Actually I’ve tried both the plain old additive (as a c external, or wrap a bunch of cycle~ in a poly~), and the ioscbank~, but always end up with some performance issues or limitation…

Did you use ioscbank for your purpose? Were you able to change amplitudes and frequencies of individual partials simultaneously?

Still thank you for all the info!! Hopefully I’ll figure out how to sample W eventually (still a newbie on dsp…)


Feb 24 2015 | 5:09 am

To be honest, at some point I needed lots of partials and the ability to control finely their individual amplitude envelopes, so I rolled up my own external. With it, I could run 1000-2000 partials on my 2.4GHz Core2Duo.

Otoh, I was curious to see what I could get with a newer machine, and now I can run a poly~ containing 1024 instance of a cycle~ and a line~ connected to a *~, with only 23% CPU load – which I find pretty impressive…


Feb 24 2015 | 10:06 am

Hi Adrea,

Wow, your external is awesome! I must be doing something wrong with my external then. Do you virtually have 2000 cycle~ in your external? (meaning you have 2000 wavetables for all partials, each table stores the sine wave of different frequencies) or do you have one reference table of basic sine wave, and keep the sampling increments for all partials (since they have different frequencies they will refer to different locations in the reference table at a given frame)? or maybe something else?


  • This reply was modified 1 year by  MF.
Feb 24 2015 | 11:25 pm

I had one wavetable, and kept arrays with all the relevant data. I also had an adsr envelope generator for each partial, and magsmooth/freqsmooth attributes for smooth interpolation between frequency and amplitude vectors, as in ioscbank~.

I had actually spent some time in optimizing the object: most importantly, it was multithreaded. I have to admit, the code is a real mess, but you might want to have a look here:


ps: if this thread goes on on this subject, it would probably be good moving it to the dev forum…

Feb 25 2015 | 1:12 pm

Thanks Andrea! I guess I simply can’t avoid threading if i want to go for the straightforward approach. will look into that.

ps. is you device online? would love to hear how it sounds :)

Feb 25 2015 | 8:44 pm

Hi Andrea,

I have been thinking of ways to implement a highly optimized multi-oscillator object and there are too many topics on the subject worth discussing.

The Max/MSP ext_sysparallel.h API is one.
OpenCL might be another more complex one…

I am curious to see and play with your multithreaded additive synthesis object.
Is it available somewhere (object and source code) ?


– Luigi

Feb 28 2015 | 8:36 am

Hi MF and Luigi (it’s great to hear from you! everything ok? ever coming to Turin? ;) )

To say the truth, I have had plans to release my additive external since I kind of completed it, along with some other funny DSP thingies I had done around that time, but as they are they’re quite a mess, and they do bad things such as crashing at deinstantiation, so I’m a bit reluctant to share them before taking the time to clean things up a bit… on the other hand, the optimizations I performed were rather trivial, but I was really learning my way around at the time – they were my first externals… the time of the bach library was yet to come! ;D

Anyway, the code was basically a big loop running through arrays of parameter sets and table lookup indices, and inside the loop there was (virtually, of course!) a cycle~ and an adsr~. Really, nothing more than this.

Otoh, using OpenCL sounds very interesting – Luigi, if you give it a try I’d love to see what comes out of it…


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

Forums > MaxMSP