ar1, ar2 hilbert asig
An IIR implementation of a Hilbert transformer.
asig - input signal
ar1 - cosine output of asig
ar2 - sine output of asig
hilbert is an IIR filter based implementation of a broad-band 90 degree phase difference network. The input to hilbert is an audio signal, with a frequency range from 15 Hz to 15 kHz. The outputs of hilbert have an identical frequency response to the input (i.e. they sound the same), but the two outputs have a constant phase difference of 90 degrees, plus or minus some small amount of error, throughout the entire frequency range. The outputs are in quadrature.
hilbert is useful in the implementation of many digital signal processing techniques that require a signal in phase quadrature. ar1 corresponds to the cosine output of hilbert, while ar2 corresponds to the sine output. The two outputs have a constant phase difference throughout the audio range that corresponds to the phase relationship between cosine and sine waves.
Internally, hilbert is based on two parallel 6th-order allpass filters. Each allpass filter implements a phase lag that increases with frequency; the difference between the phase lags of the parallel allpass filters at any given point is approximately 90 degrees.
Unlike an FIR-based Hilbert transformer, the output of hilbert does not have a linear phase response. However, the IIR structure used in hilbert is far more efficient to compute, and the nonlinear phase response can be used in the creation of interesting audio effects, as in the second example below.
The first example implements frequency shifting, or single sideband amplitude modulation. Frequency shifting is similar to ring modulation, except the upper and lower sidebands are separated into individual outputs. By using only one of the outputs, the input signal can be "detuned," where the harmonic components of the signal are shifted out of harmonic alignment with each other, e.g. a signal with harmonics at 100, 200, 300, 400 and 500 Hz, shifted up by 50 Hz, will have harmonics at 150, 250, 350, 450, and 550 Hz.
sr = 44100 kr = 4410 ksmps = 10 nchnls = 2 instr 1 idur = p3 ibegshift = p4 ; initial amount of frequency shift - can be positive or negative iendshift = p5 ; final amount of frequency shift - can be positive or negative kfreq linseg ibegshift, idur, iendshift ; A simple envelope for determining the amount of frequency shift. ain soundin "supertest.wav" ; Use the sound of your choice. areal, aimag hilbert ain ; Phase quadrature output derived from input signal. asin oscili 1, kfreq, 1 ; Quadrature oscillator. acos oscili 1, kfreq, 1, .25 amod1 = areal * acos ; Trigonometric identity - see references for further details. amod2 = aimag * asin ; Both sum and difference frequencies can be output at once. aupshift = (amod1 + amod2) * 0.7 ; aupshift corresponds to the sum frequencies, while adownshift = (amod1 - amod2) * 0.7 ; adownshift corresponds to the difference frequencies. ; Notice that the adding of the two together is identical outs aupshift, aupshift ; to the output of ring modulation. endin ; a simple score f1 0 16384 10 1 ; sine table for quadrature oscillator i1 0 29 0 200 ; starting with no shift, ending with all ; frequencies shifted up by 200 Hz. i1 30 29 0 -200 ; starting with no shift, ending with all ; frequencies shifted up by 200 Hz. e
The second example is a variation of the first, but with the output being fed back into the input. With very small shift amounts (i.e. between 0 and +-6 Hz), the result is a sound that has been described as a "barberpole phaser" or "Shepard tone phase shifter." Several notches appear in the spectrum, and are constantly swept in the direction opposite that of the shift, producing a filtering effect that is reminiscent of Risset's "endless glissando."
sr = 44100 kr = 44100 ; kr MUST be set to sr for "barberpole" effect ksmps = 1 nchnls = 2 instr 2 afeedback init 0 ; initialization of feedback idur = p3 ibegshift = p4 ; initial amount of frequency shift - can be positive or negative iendshift = p5 ; final amount of frequency shift - can be positive or negative ifeed = p6 ; amount of feedback - the higher the number, the more pronounced ; the effect. Experiment to see at what point oscillation occurs ; (often a factor of 1.4 is the maximum feedback before oscillation). kfreq linseg ibegshift, idur, iendshift ain soundin "supertest.wav" areal, aimag hilbert ain asin oscili 1, kfreq, 1 acos oscili 1, kfreq, 1, .25 amod1 = areal * acos amod2 = aimag * asin aupshift = (amod1 + amod2) * 0.7 adownshift = (amod1 - amod2) * 0.7 afeedback = (amod1 - amod2) * .5 * ifeed ; feedback taken from downshift output outs aupshift, aupshift endin ; a simple score f1 0 16384 10 1 ; sine table for quadrature oscillator i2 0 29 -.3 -.3 1.4 ; upwards sweep, at a rate of .3 times a second, lots of feedback i2 30 30 .1 .1 1.4 ; downwards sweep, .3 times a second, lots of feedback i2 60 29 5 -5 1.4 ; sweep goes from .3 time a second, descending in pitch, ; to .3 times a second ascending in pitch, with a ; large amount of feedback. e
The use of phase-difference networks in frequency shifters was pioneered by Harald Bode.1 Bode and Bob Moog provide an excellent description of the implementation and use of a frequency shifter in the analog realm in;2 this would be an excellent first source for those that wish to explore the possibilities of single sideband modulation. Bernie Hutchins provides more applications of the frequency shifter, as well as a detailed technical analysis.3 A recent paper by Scott Wardle4 describes a digital implementation of a frequency shifter, as well as some unique applications.
Sean Costello
Seattle, Washington
1999
New in Csound Version 4.0