Walsh Function Primer

Neil Johnson Neil.Johnson at camcon.co.uk
Mon Aug 4 17:40:32 CEST 1997


     Hi list,
     
     Wow, my second posting!
     
     I've received a couple of requests for a simple introduction to what 
     Walsh functions are and how to use them in music synthesis.  I will 
     try and keep the maths as simple as possible (it can get very deep in 
     places) and steer these notes towards practical applications.  Here 
     goes...
     
     1. WALSH FUNCTIONS - What are they?
     
     Imagine a fruit cake - fruit, nuts, sugar, flour, butter, etc.  Now 
     imagine you have a tool that can not only analyse that fruit cake and 
     tell what how much of each component there is, but can also be 
     reversed to synthesize a new fruit cake.
     
     OK, Walsh functions (the tool) are a way of analysing and synthesising 
     waveforms (the fruit cake).  If you are familiar with Fourier analysis 
     and functions, you should be happy with this concept.  If not, eat a 
     piece of fruit cake and you'll feel better for it.
     
     Now, what we are really interested in here is creating new sounds - 
     synthesis.  Using the above synthesis method is known as additive 
     synthesis, since you start with the basic components and ADD then 
     together to create your sound.
     
     If you have seen or played with the new Kawai K5000 synth, or the 
     older K5, you should already have an idea of what additive synthesis 
     can do.  Those synths use sine waves (Fourier functions) as the basic 
     component, with up to 128 components to create the sound.
     
     Walsh functions can also be used to create sounds, as they exhibit 
     similar properties to Fourier functions - they are orthogonal (each 
     one is unique and cannot be created from any other, ie. there is no 
     redundancy)
     
     OK, we all know what Fourier functions look like - the humble sine 
     wave.  But what about Walsh functions?  Even simpler.  Imagine if you 
     will a rectangular waveform with an amplitude of 1.  This is a Walsh 
     function.
     
     2. CREATING WALSH FUNCTIONS
     
     So, Walsh functions are rectangular waves switching between +1 and -1. What 
     is their exact shape?  To define them mathematically would be a bit beyond 
     this introduction.  The description can be greatly simplified using the 
     hardware modulo-2 operator, the EXOR gate.
     
     A simple technique often used to generate Walsh functions is to use 
     Rademacher functions.  What the ****** hell are Rademacher functions?  Even 
     simpler than Walsh functions - they are square waves, forming a series of  
     harmonics following the rule 2^n, that is;
     
        f, 2f, 4f, 8f, 16f, 32f, 64f, ...
     
     Using R() to denote Rademacher functions,
     
        R(1) = f
        R(2) = 2f
        R(3) = 4f
        R(4) = 8f
        R(5) = 16f
     
        (BTW: R(0) = a constant)
     
     Now, there is a simple relationship between Rademacher functions and Walsh 
     functions, namely
     
        WAL(2^n-1) = R(n)
     
     so,
     
        WAL(1) = R(1)
        WAL(3) = R(2)
        WAL(7) = R(3)
        WAL(15) = R(4), etc
     
     So you can already see that some Walsh functions are nothing more than 
     square waves.
     
     To fill in the missing Walsh functions, we use the modulo-2 operator, 
     or the EXOR gate, with the following simple equation:
     
        WAL(n :+: m) = WAL(n) :+: WAL(m)
     
        where :+: stands for modulo-2 addition/multiplication - the EXOR 
     gate, thus:
     
        EXOR gate: 0 :+: 0 = 0
                   0 :+: 1 = 1
                   1 :+: 0 = 1
                   1 :+: 1 = 0
     
     So, to make WAL(2), feed WAL(1) and WAL(3) into an EXOR gate and 
     WAL(2) will appear at the output.
     
     For example (ASCII sketch follows)...
     
     
     WAL(1) =    ____----____----
     WAL(3) =    __--__--__--__--
      so,
     WAL(2) =    __----____----__
     
     
     Likewise, WAL(4) = WAL(7) :+: WAL(3), and so on.
     
     As for Rademacher functions, WAL(0) is a constant, so for an audio 
     synthesizer not much use.
     
     How do we do this in practice?  A handful of counters and a bag of 
     EXOR gates.
     
     Feed a clock signal into a binary counter.  The slowest output 
     (usually something like Q0 in my data books) is R(1).  The next output 
     (Q1) is R(2), etc.  These then become some of the Walsh functions as 
     explained earlier.
     
     Then use those EXOR gates to generate the remaining Walsh 
     functions, and before you can say "Hadamard Matrix" you've got 
     yourself a Walsh function generator.
     
     Now what?
     
     3. SYNTHESIZING WITH WALSH FUNCTIONS
     
     OK, so you've got a set of rectangular waveforms wibbling up and down 
     at various rates and duty cycles, what do you do with them?
     
     Continuing the fruit cake metaphor, we now have our ingredients.  All 
     we have to do is mix them together in the right proportions to create 
     our new fruit cake.
     
     To implement the mixing function you need a summing amplifier with 
     both +Ve and -Ve inputs (two opamps and some resistors will be 
     needed).  Give each Walsh function a level pot, and a switch to select 
     which input it feeds (so that you can change the sign of each Walsh 
     function).  The final output signal will be your fruit cake, err, 
     signal.
     
     To create your new waveshape, set the levels and signs of each Walsh 
     function.  This can then be fed into a VCA, or perhaps a VCF first for 
     adding an extra dimension to your synthesis.
     
     For example, a sine wave starts off with
     
     WAL(1) = 0.663
     WAL(2) = -0.026
     WAL(5) = 0.123
     WAL(6) = -0.013
     
     ... or something like that (my memory fails me at times)
     
     The pitch is determined by the frequency of the clock signal feeding 
     the counter.  Since the fundamental pitch is that of WAL(1), the clock 
     signal needs to be 2^n times higher, where n is the number of taps in 
     your counter.  For example, a four bit binary counter needs 16 clock 
     pulses per cycle, so the fundamental pitch is 1/16th of the clock 
     frequency.
     
     4. HINTS AND TIPS
     
     The quality of the final sound depends on how many Walsh functions you 
     have available.  You could think of a Walsh synth as mathematically 
     creating a set of sample points to create a waveform.  Obviously, the 
     more sample points you have, the finer the resolution and the smoother 
     the sound will be.
     
     To illustrate this, as you probably know from the classical Fourier 
     analysis, to completely synthesize a square wave requires an infinite 
     number of phase and frequency related sinewaves.  The converse is also 
     true for Walsh functions: to completely synthesize a sinewave requires 
     an infinite number of Walsh functions.
     
     However, from a musical perspective I think Walsh functions are 
     superior to sine waves.  With sine waves, you are literally starting 
     from the ground up when creating a sound.  Thus the result can sound a 
     bit dull, as you usually run out of functions for the higher 
     frequencies, making the sound "dull" like someone's turned the treble 
     down.
     
     Walsh functions approach the problem from the opposing end, so the 
     resulting sound may be a bit brighter than intended, but this can be 
     changed with the addition of a VCF, or perhaps a formant filter.
     
     Also, its a damn sight easier to build a board of counters and gates 
     to generate a full set of phase and frequency related Walsh functions, 
     rather than a bank of sinewave oscillators, drifting about all over 
     the place.  True, someone will say "why not do it digitally with phase 
     accumulators and look-up tables".  Sure you could, but I bet it would 
     be a lot bigger and expensive to build than a handful of EXOR gates!
     
     If anyone wants any further info, mail me.  However, I must say that my 
     work comes first, so I might not reply as fast I get mailed. If anyone 
     in the Cambridge, UK, area wants to talk about this further I'm partial 
     to a pint and pizza!
     
     
     5. FURTHER INFORMATION
     
     It seems that Walsh functions are the poor relation in the world of 
     signal processing, so information about them is hard to find.  They 
     did have a spurt of interest in the 60's and 70's, but now seem to 
     have gone into retirement.
     
     If you have access to a decent library do a search of old issues of 
     the IEEE journals, particularly the Instrumentation & Measurement 
     and the EMC Journals, where I found quite a few articles.  Also the 
     Journal of the Audio Engineering Society, where one Bernie Hutchins 
     published an article about a basic Walsh function synth, sometime 
     around 1973 if I recall (I may be wrong though...)
     
     Another author worth looking out for is K.G Beauchamp, who wrote a 
     couple of books on the subject.
     
     And finally, if anyone can find a copy of the 1923 Journal of the 
     American Mathematical Society, then issue 5, page 24 (I think) is 
     where J.L Walsh published his paper describing Walsh functions (OK, a 
     bit heavy going, but its sort of like the Holy Grail of Walsh 
     functions...)
     
     If anyone has further, different or correct information (this is all 
     of the top of my head) please add to what I have said.  If I'm wrong 
     anywhere, sorry.  Experiment, and discover the answer yourself.  
     Exploration is so much fun!
     
     
     Have fun!
     
     
     Neil
     ----
     
     +---------------------------+-----------------------------+
      Neil Johnson               * All thoughts and opinions 
      Cambridge Consultants Ltd  * expressed here are my own. 
      email: nj at camcon.co.uk     * Heck, even _I_ don't believe 
      http://www.camcon.co.uk    * what I say at times.....
     +---------------------------+-----------------------------+ 



More information about the Synth-diy mailing list