question about ifft for a beginner
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…
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:
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?
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?
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?
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 :)
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.
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…
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??
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??
is there a spectrum analyzer i can export the results to .txt??
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
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.
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.
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.
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
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…
"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 ;)
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 :)
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.
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. --Copy all of the following text. Then, in Max, select New From Clipboard.----------begin_max5_patcher---------- 2751.3oc0c0sjahiE9Z2OEZ8ko53AIgDvd0r69XL0TcgMxtIACd.b2I8TSd1 WjNXavMHjswpoqTwNHLvgOc9SG8Ik+9gYyWl8CQwbz+F8GnYy96GlMS0jrgY 0GOa91verJIrP8ylmJdMa42l+HbpRwO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zpBtC8bL0+4JP3G1oNN+.ruZD5dmN3VeKLwL00p.Kyj7UmfhD0 xYQXjMgi8kIrIxjEccXhJN0tQhnAFfStd1WlFDmrajnyffdxrwtCckxmdxDy ngt5O8J5FytwrYlz24dg9B3pX1t3F+OvRqCHTmZ9twpO3V0.cLMeeKpAZjkJ eBpAFXWuGlTzRlm8KjpQdzrnLYTFWVNKPlIk2xtYbwMFmH1UlvlHSt1KSBS7 7ysag44lT2FW65ehaR8HXVVG2j5kxsqu.Oil.C6NpBOS567rqebilTEuaouq 5f+4g+OP3OSbP -----------end_max5_patcher-----------
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!
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!
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.
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…)
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…
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.
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: https://cycling74.com/forums/topic/question-about-ext_sysparallel-h/
ps: if this thread goes on on this subject, it would probably be good moving it to the dev forum…
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 :)
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) ?
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…
Forums > MaxMSP