windowing formulas/agorithms?


    Mar 22 2007 | 11:42 pm
    Hi all,
    Can anyone point me to a good source (preferably online) for formulas/ algorithms for generating the "standard" windowing functions (i.e. gaussian, hanning, blackman, kaiser, etc.) of 512, 1024, etc. points? I'd like to create some 'roll-your-own' abstractions for generating windows and storing them in buffers. I know a few people have already implemented these kinds of things in MaxMSP; I'd like to go through the learning curve of making my own. I plan to use them for a variety of things, starting with granularization of sound files.
    Thanks in advance,
    Best,
    Steven
    ---- Steven M. Miller
    Home SFIFEM Atrium Sound Space OVOS

    • Mar 23 2007 | 12:10 am
      Hi Steven,
      Wikipedia has formulae for a lot of them: http://en.wikipedia.org/wiki/Window_function
      -- Owen
      Steven Miller wrote: > Hi all, > > Can anyone point me to a good source (preferably online) for > formulas/algorithms for generating the "standard" windowing functions > (i.e. gaussian, hanning, blackman, kaiser, etc.) of 512, 1024, etc. > points? I'd like to create some 'roll-your-own' abstractions for > generating windows and storing them in buffers. I know a few people have > already implemented these kinds of things in MaxMSP; I'd like to go > through the learning curve of making my own. I plan to use them for a > variety of things, starting with granularization of sound files. > > Thanks in advance, > > Best, > > Steven >
    • Mar 23 2007 | 12:31 am
      On Mar 22, 2007, at 7:42 PM, Steven Miller wrote: > I know a few people have already implemented these kinds of things > in MaxMSP; I'd like to go through the learning curve of making my > own. I plan to use them for a variety of things, starting with > granularization of sound files.
      Steven: I have a patch that demonstrates how to do this in the GTK. If you download the toolkit from the URL below, look in the extras folder for a patch called "gtk.winMaker". This in the actual patch used to create all the window files used by the toolkit.
      Or am I one of those "few people" to which you refer? :)
      --Nathan
      ------------------- Nathan Wolek, PhD --- nwolek@stetson.edu Assistant Professor of Music Technology Stetson University - DeLand, FL http://www.nathanwolek.com
    • Mar 23 2007 | 12:59 am
      On 3/22/07, Steven Miller wrote: > Hi all, > > Can anyone point me to a good source (preferably online) for > formulas/algorithms for generating the "standard" windowing functions (i.e. > gaussian, hanning, blackman, kaiser, etc.) of 512, 1024, etc. points? I'd > like to create some 'roll-your-own' abstractions for generating windows and > storing them in buffers. I know a few people have already implemented these > kinds of things in MaxMSP; I'd like to go through the learning curve of > making my own. I plan to use them for a variety of things, starting with > granularization of sound files. > > Thanks in advance, > > Best, > > Steven > > > ---- > Steven M. Miller > > Home SFIFEM > Atrium Sound Space > OVOS > > > >
    • Mar 23 2007 | 3:53 pm
      Thanks Owen, Nathan & Mark - much appreciated.
      Nathan, I recalled looking at your window maker abstraction a while back, and was very impressed at how clean & straight-forward it was. I was avoiding looking at it right now, to force myself to figure it out on my own. I may peak (peek~?) at it if I get stuck. Thanks!
      Best,
      Steven
      ---- Steven M. Miller
      Home SFIFEM Atrium Sound Space OVOS
    • Mar 23 2007 | 4:44 pm
      I'm looking at the window functions on Wikipedia...so far so good...until I get to the formula for the Kaiser window. Can anyone help a non-mathematician with implementing the 'zeroth order modified Bessel function of the first kind' in this formula? I followed up to the Wikipedia page for Bessel functions, and my eyes glazed over pretty quickly...
      I'm using [expr] for these window functions, if that helps.
      Thanks!
      ---- Steven M. Miller
      Home SFIFEM Atrium Sound Space OVOS
    • Mar 23 2007 | 5:17 pm
      On Mar 23, 2007, at 11:53 AM, Steven Miller wrote: > Nathan, I recalled looking at your window maker abstraction a while > back, and was very impressed at how clean & straight-forward it > was. I was avoiding looking at it right now, to force myself to > figure it out on my own. I may peak (peek~?) at it if I get stuck. > Thanks!
      The hardest things for me to get my head around was the difference between continuous and discrete-time functions. Most of the math web sites will give you the continuous expression, but sampled waveforms such as sound files are discrete.
      Being a musician that got into programming then went back and took some engineering courses, I never understood why my math/engineering professors seemed obsessed with the continuous. Just tell me what I need to feed the computer and keep your beautiful equations to yourself. ;)
      ------------------- Nathan Wolek, PhD --- nwolek@stetson.edu Assistant Professor of Music Technology Stetson University - DeLand, FL http://www.nathanwolek.com
    • Mar 24 2007 | 3:32 am
    • Mar 24 2007 | 4:24 pm
      Thank you, Jose - I'll dig into this over the weekend!
      On Mar 23, 2007, at 9:32 PM, jose manuel berenguer wrote:
      > Hello >
      > perhaps that can be of some interest... > > > jmb
      ---- Steven M. Miller
      Home SFIFEM Atrium Sound Space OVOS
    • Mar 24 2007 | 6:09 pm
      Thanks, Nathan,
      Luckily, the Wikipedia page Window_function> from which I'm sourcing my equations uses the discrete-time versions, so all is well in that regard.
      I've run into some difficulty with one particular equation: I can't seem to get the Gauss equation worked out in my [expr] and I keep generating 'divide by zero' errors. So, I took a look at the Gauss example in your window maker abstraction...and you're using a completely different equation (at least to my eye). Yours also includes another input variable not called for in the Wikipedia version. Any insights to share? You also have a 'quasi-gaussian' window - what's the difference there?
      Thanks,
      Steven
      On Mar 23, 2007, at 11:17 AM, Nathan Wolek wrote:
      > The hardest things for me to get my head around was the difference > between continuous and discrete-time functions. Most of the math > web sites will give you the continuous expression, but sampled > waveforms such as sound files are discrete. > > Being a musician that got into programming then went back and took > some engineering courses, I never understood why my math/ > engineering professors seemed obsessed with the continuous. Just > tell me what I need to feed the computer and keep your beautiful > equations to yourself. ;) >
      ---- Steven M. Miller
      Home SFIFEM Atrium Sound Space OVOS
    • Mar 24 2007 | 10:00 pm
      On Mar 24, 2007, at 2:09 PM, Steven Miller wrote: > Any insights to share?
      I just sat down an tried to do some math juggling to make them equal and could not. I am sure I am doing something wrong. My books are in my office and I am at home, so I am trying as best I can from memory. I did this patch pre-Wikipedia. :)
      Two points: 1) My first variable is the same as n/N in the Wikipedia formula. This changes the math. 2) The version I use has implemented a "skew" functionality. You can specify where the peak should be, with 0.5 being the mid-point. In the Wikipedia version the peak is fixed at half way through the window. This changes the math even more.
      Hope that provides some insights as to why they are different. I likely did some other programming reductions on the math to make it compute faster. Even though it was not for real-time audio, I am sure I could not fight the compulsion to make it more efficient.
      > You also have a 'quasi-gaussian' window - what's the difference there?
      This one is easier. The quasi-gauss was an invention of Roads for his early work on granular synthesis. Imagine splitting the Gaussian window in half and using these halves as attack and decay portions of your envelopes. Between them you just have a sustain or "straight line". Because the duration of the sustain is now longer, the net effect is louder grains.
      Remember that the Gaussian envelope in used in granular effects primarily as an historical artifact. It is the envelope proposed by Gabor in 1947 when he dreamed up granular synthesis. He had no way to know what it would actually sound like. Whether it is the best remains a matter of taste, more so in granular techniques than in spectral techniques.
      ------------------- Nathan Wolek, PhD --- nwolek@stetson.edu Assistant Professor of Music Technology Stetson University - DeLand, FL http://www.nathanwolek.com
    • Mar 24 2007 | 11:02 pm
      Thanks Nathan, much appreciated! And the quasi-gaussian explanation vaguely jogs my memory from reading 'Microsound' a few years back.
      On Mar 24, 2007, at 4:00 PM, Nathan Wolek wrote:
      > > Hope that provides some insights as to why they are different. I > likely did some other programming reductions on the math to make it > compute faster. Even though it was not for real-time audio, I am > sure I could not fight the compulsion to make it more efficient. >
      ---- Steven M. Miller
      Home SFIFEM Atrium Sound Space OVOS
    • Mar 24 2007 | 11:40 pm
      Here's my implementation of the Wikipedia Gauss window function . It no longer produces 'divide by zero' errors, but it only creates the first half of the function over the entire width of the window. Any ideas what I'm doing wrong?
      ---- Steven M. Miller
      Home SFIFEM Atrium Sound Space OVOS
    • Mar 25 2007 | 9:03 am
      mind your brackets. try this one. v
      On 25 Mar 2007, at 00:40, Steven Miller wrote:
      > > Here's my implementation of the Wikipedia Gauss window function > . It no > longer produces 'divide by zero' errors, but it only creates the > first half of the function over the entire width of the window. Any > ideas what I'm doing wrong? > > max v2; > #N vpatcher 717 201 1324 736; > #P window setfont "Sans Serif" 9.; > #P flonum 409 155 35 9 0. 0.5 3 3 0 0 0 221 221 221 222 222 222 0 0 0; > #P message 336 111 43 196617 size $1; > #P newex 238 71 53 196617 t i i i i; > #P newex 280 91 66 196617 sampstoms~; > #P newex 238 49 91 196617 patcherargs 1024; > #P newex 106 49 67 196617 t b b; > #P newex 336 129 154 196617 buffer~ my-window 23.22; > #P newex 106 221 101 196617 peek~ my-window 1; > #P button 106 25 15 0; > #P newex 106 100 50 196617 uzi 1024; > #P newex 123 177 297 196617 expr exp(-.5*pow((($f1-($f2-1))/2)/ > (($f3*($f2-1))/2)\,2)); > #P newex 106 153 27 196617 t i i; > #N counter 0 0 1024; > #X flags 0 0; > #P newobj 106 129 89 196617 counter 0 0 1024; > #P connect 4 0 7 0; > #P connect 7 0 3 0; > #P connect 3 0 0 0; > #P connect 0 0 1 0; > #P connect 1 0 5 0; > #P connect 1 1 2 0; > #P fasten 10 0 3 1 243 95 151 95; > #P fasten 2 0 5 1 128 207 156 207; > #P connect 7 1 0 3; > #P fasten 10 1 0 4 257 108 187 108; > #P connect 8 0 10 0; > #P fasten 10 2 2 1 271 132 271 132; > #P connect 10 3 9 0; > #P connect 9 1 11 0; > #P connect 11 0 6 0; > #P fasten 12 0 2 2 414 174 414 174; > #P pop; > > ---- > Steven M. Miller >
    • Mar 25 2007 | 11:47 am
      On Mar 24, 2007, at 7:40 PM, Steven Miller wrote: > Any ideas what I'm doing wrong?
      I can remember having this problem, however I cannot seem to recall the solution. I played around with your [expr] formula but it did not jog my memory. I believe this has something to do with why my formula used n/N as a variable.
      I'll take a few minutes on monday to look over my sources when I am back in the office. Maybe there is a problem with the wikipedia article?
      ------------------- Nathan Wolek, PhD --- nwolek@stetson.edu Assistant Professor of Music Technology Stetson University - DeLand, FL http://www.nathanwolek.com
    • Apr 12 2009 | 11:41 pm
      hello
      i am currently generating some envelopes and was wondering how this is represented with the expression object?
      i've had a look at the other patches but i can't quite figure which bits go where
    • Apr 13 2009 | 12:37 am
      The problem I always have is getting the parentheses in the right place, I always end up forgetting a pair which completely changes the equation. Other times I use them everywhere and that makes reading the actual equation impossible! Here's a patch that should show you how things are done.
      lh
    • Apr 13 2009 | 12:47 am
      Mike S wrote on Sun, 12 April 2009 18:41hello
      i am currently generating some envelopes and was wondering how this is represented with the expression object?
      I think this is it:
    • Apr 13 2009 | 12:51 am
      You need an extra set of brackets around the $f2 - 1 bit other wise it will do the division first. The "n" is counting up in integers to a certain amount and the "N" is the total number of steps. Have a look at the patch I just posted to see what I mean.
      lh
    • Apr 13 2009 | 1:06 am
      smill wrote on Thu, 22 March 2007 18:42
      I'd like to create some 'roll-your-own' abstractions for generating windows and storing them in buffers.
      Off-topic a bit, but you might also try this patch, which gets snippets of any longer buffer~ into a multislider and then into another buffer~. So depending on what kind of audio you load into the main one, you could get some interesting waveforms which might be usable in windowing (or they may sound cool just by themselves). The multislider also lets you store presets and interpolate, to make new waveforms between saved ones.
    • Apr 13 2009 | 1:47 am
      for musicians an oscillating and/or repetive and/or selfgenerating function is always continous, even if the same thing is a discrete time whatnot for the silly m4+h3m4+!k4nz_.
      when i dealt with my very first fractal function i found out that any discrete time whathefuck can be "continous" wehen you just restart it from time to time.
    • Apr 13 2009 | 5:17 pm
      thanks for the replies, very helpful
      out of interest i've been trying some of the other window functions on that page.
      I'd quite like to know how to do these
      Bartlett window (zero valued end-points)
      - on this one i'm not sure what the vertical lines mean in the latter part of the equation
      Gauss window, σ=0.4; B=1.45
      - not sure what this part underneath is for?
      Nuttall window, continuous first derivative
      I've had a crack at this one, but i get a bit of a different window to the one described here http://en.wikipedia.org/wiki/Window_function
    • Apr 13 2009 | 10:08 pm
      Bartlett: [expr (($i2-1)/2 - abs($i1-($i2-1)*0.5))/(($i2-1)*0.5)]
      Gauss: [expr exp(-0.5*pow(($i1-(($i2-1)/2))/(0.4*(($i2-1)/2)),2))]
      Nuttall: [expr 0.35875-(0.48829*cos((2*3.1415925635*$i1)/($i2-1)))+(0.14128*cos((4*3.1415925635*$i1)/($i2-1)))-(0.01168*cos((6*3.1415925635*$i1)/($i2-1)))]
      Those should do the trick if you replace the [expr] in my previous patch with them. You could change the coefficients of the Nuttall equation to get the other curves on the wikipedia page. I always find it helpful to write the equation out on paper and then re-write it with breackets onto one line, it should then be in the form you need for use in [expr].
      lh
    • Nov 19 2009 | 6:48 am
      Hi,
      This might be useful - it's an abstraction for generating a bunch of typical window functions. Not perfect, and probably there are many important ones missing, but if you add more let me know and I'll put it on maxobjects.com.
      Here's the help:
      And here's the abstraction (save as window.maxpat):
      Best,
      Graham
    • Nov 19 2009 | 8:36 am
      >>"only going over half the buffer" ..
      expr exp(-.5*pow((($f1-($f2-1))/2)/(($f3* ($f2-1))/2)\,2));
      i had that experience also when building my first cosine and hanning buffer maker. you use uzi and counter, and it counts 1024, and it does not peek 1024 but only 511, and you think "wtf??"
      i found out that in my case it was the formula itself which was wrong because it simply had a max() or a *(x>y) at the wrong place so that the missing samples were actually samples of all 0. foat.
      -110
      oh, graham actually revived this thread from march -- i knew i´ve read something like that here before.
    • Nov 19 2009 | 10:19 am
      Back in Supercollider 1.x days I used to use Apgrain which had some nice properties. I was so perplexed by the different window types and why Apgrain sounded so good to my hears that i asked James McCartney about it and he said in 1997 (yikes!) about it:
      Apgrain gives a parabolic envelope. That is 1 - x*x evaluated between -1 and +1. This happens to be a very simple envelope to generate since it requires only a double integration (two adds). It has a shape more like a Welch envelope than a Hanning one. I actually prefer it because in the Hanning envelope the quiet tails on the end are really inaudible when mixed with other grains that mask it, so it is just wasted CPU to output it. A Welch envelope matches the curve of an equal power panning function, so it has good properties when overlapping fewer grains to get a smooth sound. This isn't exactly true of the parabola which is too 'hot' at the midpoint of the curve, but it suits my purposes fine.
      A hanning envelope shape is: .5 - .5 * cos(x); x = 0 to 2pi.
      A welch envelope shape is: sin(x); x = 0 to pi
      --
      Well, i miss that hot parabolic envelope! I always liked how that sounded for grains.
      (
      )