<<

Alias-Free Digital Synthesis of Classic Analog

Tim Stilson[email protected] rd.edu 

Julius Smith [email protected] u

CCRMA http://www-ccrma.stanford.edu/ Music Department, Stanford University

Abstract Techniques are reviewed and presented for alias-free digital synthesis of classical analog waveforms such as pulse train and sawtooth . Techniquesdescribed include summation of bandlim- ited primitive waveforms as well as table-lookup techniques. Bandlimited pulse and triangle waveforms are obtained by integrating the difference of two out-of- bandlimited impulse trains. Bandlimited impulse trains are generated as a superposition of windowed sinc functions. Methods for more general bandlimited synthesis are also reviewed. Methods are evaluated from the perspectives of sound quality, computational economy, and ease of control.

1 Introduction impulse train Any analog signal with a discontinuity in the - 1 form (such as pulse train or sawtooth) or in the wave- 0.8

form slope (such as ) must be bandlim- 0.6 ited to less than half the sampling rate before sampling 0.4 to obtain a corresponding discrete-time signal. Simple methods of generating these waveforms digitally con- 0.2 tain due to having to round off the discontinuity 0 0 5 10 15 20 time to the nearest available sampling instant. The sig- nals primarily addressed here are the impulse train, rect- Box Train, and Sample Positions angular pulse, and sawtooth waveforms. Because the 1 latter two signals can be derived from the ®rst by inte- 0.8 gration, only the algorithm for the impulse train is de- 0.6 veloped in detail. 0.4

0.2

2 Why Simple Discrete-Time Pulse 0 0 5 10 15 20 Trains are Aliased Rounded−Time Pulse Train

The ªobviousº way to generate a discrete-time ver- 1 sion of an impulse train is to approximate it by a unit- 0.8

δ  sample-pulse train. The unit sample pulse n is de- 0.6

®ned as  0.4 =

δ ∆ 1; n 0  =

n 0.2

j j = ; ; ;::: 0; n 1 2 3 0 The unit-sample pulse is only de®ned for integer n,so 0 5 10 15 20

we have a problem: Suppose the desired impulse-train =

is f1 = 1 T1, then the period in samples has to Figure 1: Rounded-Time Impulse Train as a Sampled Version

= = = = = be P = T1 Ts Fs f1,whereFs 1 Ts is the sampling of an Ideal Rectangular Pulse Train rate, and P is rarely an integer. Because pitch perception

Stilson and Smith 1 Alias-Free Synthesis ∞

is so accurate , it does not work to round M to the near- jωTs

 ∝ ω + π  Y e ∑ X k2 Fs

est integer, except at so low that the error is

∞ k =

on the order of a tenth of a percent (around 100 Hz or ∞

ω + π 

below for a 50 kHz sampling rate). Therefore, to make = ∑ P k2 Fs

∞ the pitch right, it is necessaryto compute the impulse ar- k = ∞

rival times very accurately and round each arrival time

δω + π ω   ∑ k2 F l

to the nearest sample instant. This process can be mod- s 1

∞ l = eled as pitch-period jitter which obviously adds noise to

the signal. It can also be modeled as a uniform sampling The desired pulse-train spectrum is only the k = 0term of a periodic sequence of rectangular pulses one sample above. Each nonzero k term contributes a string of wide (Figure 1): aliased of across the entire frequency band.

The amount of aliasing is highly signi®cant and audible,



j j =

∆ 1; t Ts2as can be predicted from looking at Fig. 6.

 =

pt

j j> = 0; tTs2The only frequency which does not suffer aliasing is DC since the sinc spectral envelope goes through zero The of this pulse is a sinc function at all multiples of the sampling rate. For this reason, the

Z ∞ aliasing is reduced at very low frequencies relative to the ∆ ω

j t

ω =   =   P p t e dt Ts sinc fTs sampling rate. This provides another explanation why ∞ the aliasing is not as objectionable for low fundamental π frequencies (where the nearest-integer roundoff is an in- where ω = 2 f ,and

signi®cant fraction of the period): The aliased frequen- π 

∆ sin x cies that would tend to be most noticeable (those near or

 = : sincx πx below the ) are most attenuated. The above analysis extends immediately to rectangle A periodic sequence of these rectangular pulses is con- waves. structed as ∞

∆ Trivial Sawtooth Trivial Square

 =  + 

xt ∑ p t lT1

∞ l = and its Fourier transform is, by the shift theorem and properties of delta functions,

∞ ∆

jωlT1

ω = ω

X  ∑ e P

∞ l = ∞

Saw. Spec. Sq. Spec.

ω δω ω  ∝ P ∑ l 1

0 0

l=



ω ; ω = ω P l l

∝ −20 −20

ω 6= ω ; 8 0; l l

δ ∆ −40 −40 ω ω = π where  denotes the delta function, and l 2 lF1. Thus, the rectangular-pulse train has an in®nite har- −60 −60 monic spectrum weighted by a sinc function having ze- 0 0.2 0.4 0 0.2 0.4 freq (norm) freq (norm) ros at multiples of the sampling rate Fs (because the original rectangular pulse was taken to be one sampling Figure 2: Spectra of Trivial Sawtooth and Square-Wave Sig- interval wide). Since the sinc function has a lot of en-

nals, Low Frequency  ergy above its ®rst zero crossing, sampling xt will cause aliasing of an in®nite number of harmonics whose

A similar argument applies to explain why sawtooth  amplitudes fall off at 6 dB per octave (since sinc fTs signals alias: If the unit-amplitude sawtooth is gener-

falls off as 1 = f ). (Harmonics under the outer half of the

main lobe of the sinc function also alias.) Sampling, we ated by

=   get sn f1nTs mod1 where f1 is the desired frequency, then it can be shown

 =   $ yn x nTs to be simply a sampling of a continuous-time (ªanalogº)

Stilson and Smith 2 Alias-Free Synthesis Trivial Sawtooth Trivial Square it appears not to be done in practice.

3 Bandlimited Synthesis

In this section, various preexisting methods for syn- thesis of bandlimited waveforms will be reviewed.

Saw. Spec. Sq. Spec. 0 0 3.1 Additive synthesis is trivially bandlimited simply by not −20 −20 generating harmonics higher than Fs =2; typically this also presents a computational savings. Additive synthe- −40 −40 sis systems that use the inverse FFT to compute the os- cillators are bandlimited by de®nition because the in- −60 −60 0 0.2 0.4 0 0.2 0.4 verse FFT only generates frequencies up to Fs =2. In freq (norm) freq (norm) inverse-FFT synthesis, time-aliasing becomes the error to minimize. Figure 3: Spectra of Trivial Sawtooth and Square-Wave Sig- nals, High Frequency 3.2 Wavetable Synthesis One of the very earliest synthesis techniques used sawtooth of equivalent slope. Since the analog sawtooth in computer music was periodic wavetable synthesis is not bandlimited, the sampled version will be aliased. [Mathews 1969] (not to be confused with sample play- This is slightly different from a rounded-time retrig- back synthesis which is also called wavetable synthe- gered sawtooth which is better described as the convolu- sis these days). In this technique, a wavetable contains tion of a single cycle of a sawtooth wave with a rounded- only one period of the desired tone, sampled at a high

time impulse train, which was just shown to be aliased rate, such as N = 512 samples per period. Playing out as well. Since a single cycle of a sawtooth has a Fourier the table repeatedly generates a periodic waveform with

transform which falls off at 6 dB per octave (all dis- fundamental frequency Fs =N,whereFs is the sampling continuous waveforms have spectral fall-offs no faster rate. Skipping every other sample on playback yields a

than 6 dB per octave [Papoulis 1991]), it follows that fundamental frequency of 2Fs =N and so on. Intermedi-

the spectrum of the rounded-time retriggered sawtooth ate frequencies f0 are obtained using a non-integer skip- = also falls off at 6 dB per octave. Therefore, sampling it factor, or ªphase increment,º given by Inc = Nf0 Fs;in causes aliasing in an amount similar to that in the sam- such cases, the wavetable address has a fractional part pled rectangular pulse train. which is often either discarded or used to round to the By convolving the rounded-time impulse train (sam- nearest integer (reasonable for very large N and/or heav- pled rectangular pulse train, with pulses of width ily oversampled waveforms), or it is used to determine Ts) with an arbitrary ®xed ®lter, formant synthesis an interpolated table value. By far the most common such as VOSIM [Kaegi and and S. Tempelaars 1978], interpolation technique is linear interpolation. How- Chant [Rodet et al. 1989] (see also [Roads 1996]) is de- ever, higher order interpolation methods, especially La- scribed. By multiplying the rounded-time impulse train grange [Schafer and Rabiner 1973] and bandlimited in- by a periodic amplitude envelope and convolving it with terpolation [Smith and Gossett 1984], have been used a Blackman FFT window, window-function synthesis commercially. is described [Goeddel and Bass 1984] (summarized in Interpolated wavetable synthesis is not guaranteed to [Roads 1996]). In all these cases, a pitch-period is as- be bandlimited when the phase increment is larger than sociated with the impulse response of the formant ®lter one sample. In these cases, one is performing the equiv- (or lowpass ®lter in the case of window-function syn- alent of a decimation of the waveform, with the decima- thesis), perhaps overlapping with those of other periods, tion factor being equal to the phase increment in sam- and the impulse-responsestart times are quantized to the ples. Therefore, for nonsinusoidal wavetables, an upper nearest sample, thus causing pitch-period jitter. Elim- bound is imposed on the phase increment by the high-

inating this jitter requires resampling the ®lter impulse est of the signal in the wavetable (max(Inc) =

  response each period which would be very expensive, so Nf0= Fsnh ,wherenh is the harmonic number of the

Stilson and Smith 3 Alias-Free Synthesis highest harmonic.). If the restriction on exact bandlim- 3.4 Exact Wavetable Interpolation iting is relaxed, then the phase increment can have a For best results using interpolated periodic wavetable higher bound, based on the highest harmonic whose am- synthesis, sinc interpolation is ideal as always. Since the plitude is large enoughto be objectionable when aliased. signal is periodic, Eq. (2) can be collapsed to a ®nite sum Interpolated wavetable synthesisis equivalentin prin- over one period, thus making it implementable in ideal ciple to additive synthesis employing a digital sinusoidal form [Schanze 1995]:

oscillator on every harmonic. In practice, wavetables



are generally computed as a weighted sum of harmon- M 1

π 

sin t n t n

=    π ics up to some maximum harmonic number. Thus, we xt ∑ x n 1 cot

2N 2N

may either add the outputs of N oscillators together, or n= L



t n

we may add their effective wavetables together with the N +1

+ π 1  tan same weightings to obtain a single wavetable oscilla- 2N tor. If the highest harmonic frequency is well below

where the sampling interval is normalized to be T = 1,

half the sampling rate, and/or if the harmonic ampli- + and the period isN = L M samples. Intuitively, this tudes decrease rapidly with harmonic number, as nor- can be understood as a time aliasing of Eq. (2) over one

mally happens in natural waveforms, inexpensive in-  period of xt , i.e., it can be shown that terpolation techniques such as linear interpolation give

high quality results.

=   [  ]   xt ∑x nTs SincN Fs t nTs CN n (2) period 3.3 Bandlimited Interpolation

where

  For a general discrete-time signal xnTs which has been

∆ 1 ; N odd

 =

uniformly sampled at twice its highest frequency, exact CN n

π  = ; cos F t n N N even bandlimited interpolation, which we call sinc interpola- s

tion, is carried out as and π  ∆ sin t

 =

SincN t

π = 

N sin t N

=    

xt ∑xnTs hs t nTs (1)

n=  can be recognized as sinct time-aliased on a block

∞ n

π    ω

sin Fst 1 of N samples. The form NSincN N arises often as

  = ∑ x nTs

πF t nT the Discrete-Time Fourier Transform (DTFT) of the N-

∞ s n= s sample pulse (N successive unit samples preceded and

where followed by zeros). The present occurrence is sim- π 

∆ ∆ sin Fst

 

 =   = :  ply the dual: Sinc F t is the N-periodic continuous- hs t sinc Fst π N s

Fst time signal given by the inverse expansion

0 0

 = = =

To resample x t at a new sampling rate Fs 1 Ts ,we of a uniform bank of N harmonics at amplitude 1 N, 0

need only evaluate Eq. (2) at integer multiples of Ts . centered about and including DC, and extending from

= = The summation in Eq. (2) cannot be implemented Fs 2toFs 2.

in practice because the ªideal lowpass ®lterº impulse Unifying with the previous section, each of the N 

response hs t actually extends from minus in®nity samples of a periodic signal contributes a copy of  to in®nity. It is necessary in practice to window SincN Fst to the interpolation output (for odd N), while

the ideal impulse response so as to make it ®nite. each sample of a general discrete-time signal con-  This is the basis of the window method for digital tributes a copy of sincFst to the interpolation output. ®lter design [Rabiner and Gold 1975]. (See also the A dif®culty with ªSincN Synthesisº is that the

fir1 function in Matlab.) While many other ®l- wavetable contents must be changed with frequency. ter design techniques exist (e.g., [Bellanger 1996]), Since frequency is constantly varying due to vibrato, the window method is simple and robust, especially onset skew, etc., the wavetable must be recomputed for very long impulse responses. The ®lter impulse on the ¯y or else stored for all pitches. One way to response is very long because it is heavily oversam- accomplish this is to have an ef®cient means for real-

pled. Interpolation techniques of this nature which time generation of SincN , and synthesize an arbitrary approximate sinc interpolation in the frequency N-periodic signal as a sum of N SincN oscillators. domain are generally referred to as bandlimited in- However, the end result is no different from summing terpolation techniques [Schafer and Rabiner 1973, N sinusoidal oscillators, so ordinary additive synthesis Crochiere and Rabiner 1983, Smith and Gossett 1984]. would be preferable.

Stilson and Smith 4 Alias-Free Synthesis 3.5 DSF Synthesis 3.6 Bandlimited Impulse Train (BLIT) Synthesis In [Moorer 1975] (partially summarized in [Dodge and Jerse 1985, pp. 149±154] and [Roads 1996, Some of the previously mentioned techniques can be pp. 260±261]), Discrete-Summation Formulae (DSF) used to generate BLITs, but can also generate other are proposed for synthesizing bandlimited periodic waveforms. Now we will discuss techniques designed signals based on the identity especially to generate BLITs, without consideration for extension to other waveforms (although it may be pos-

N 1 sible in some cases). By restricting to a single spe-

k 1

θ + β= 

∑ a sin k 2ci®c waveform, these methods can often be much more

β+ 12acos a k =0 ef®cient than the other methods. These also bene®t

N

[ θ θ β θ + β

sin asin a sin N strongly from the fact that the signal to be generated is 

N +1 an impulse train, which is mathematically much simpler

[θ + β + a sin n1 than most other waveforms.1

The above closed-form expression is derived in a = straightforward manner using the identity 2 j sinx 3.7 Sum of Sincs and SincM

jx jx

e e on the left-hand side, and applying the closed- The standard operation before sampling is to apply an form expression for a geometric series: anti-aliasing ®lter. The ideal anti-aliasing ®lter has a continuous-time impulse response that is a sinc function

N 1 N k 1 z with a zero-crossing interval of one sample: ∑ z =

1 z

k =0 π 

∆ ∆ sin Fst

 =   = : h t sinc F t s s πF t By setting θ and β to various values, a wide class of s bandlimited waveforms can be generated. Bandlimiting The ideal unit-amplitude impulse train with period T1

is achieved by controlling N such that the highest fre- seconds is given by

θ = β =

quency generated is less than Fs =2 (for 0and ∞

 = δ + 

= b = c

f1t; N 1 Fs 2f1 ). This also easily generalizes to x t ∑tlT1

∞ l= lower bandlimit frequencies. Note that Csound's buzz

and gbuzz unit generators implement this method. Applying the anti-aliasing ®lter hs to this signal gives ∞

 =   = +  Group: 1 2 3 x t xht ∑htlT

{ { { { 4 { 56{ f ss1

∞ l= Log ∞

Amp

 = + 

= ∑ sinc t Ts lP

l= = where P = T1 Ts is the period in samples (not an inte- 0 F1 F2 F3

Frequency ger). Since x f is bandlimited to the frequency interval

= ; =   Fs 2 Fs 2 , it can now be sampled without aliasing to obtain ∞

Figure 4: Use of six DSF tables to synthesis voice. ∆

 =  =  + 

yn x f nTs ∑sinc n lP

∞ l=

As an example, voice synthesis using three vocal for-  mants can be carried out using DSF in a manner similar As before, the above expression for yn can be inter- to FM voice synthesis [Chowning 1989]. In this tech- preted as a time aliasing of the sinc function about an nique, a row of exponentially rising or falling harmon- interval of P samples. It can be shown that the time- ics is used to approximate the harmonics falling under aliased sinc becomes

half a formant, as shown in Fig. 4. For K formants, we

=  =  [ =  ] y n MPSinc M P n (3) need 2K DSF units. In the three-formant case, we have M

six partial groups. Moorer also describes a variant of 1The basic operation to be simulated is

ulseTrain   sinc ]  DSF that generates two-sided harmonic series. In this Sample[Imp t t ,whereªº denotes convolution. Since ImpulseTrain is just impulses, the convolution scheme, only three groups would be necessary (as long is almost trivial. This operation would be much more dif®cult to as the fall-off rate were the same for both sides). calculate for more complex waveforms

Stilson and Smith 5 Alias-Free Synthesis

where of human hearing and half the sampling rate. This re- π 

∆ sin x duces the window length required.

 =

SincM x

π =  M sin x M This function provides a closed-form expression for the Number of Harmonics vs. Sinc Overlap sampled bandlimited impulse train (BLIT), and it can be used directly for synthesis in a manner similar to DSF. Number of Harmonics < f / 2 Number of Required Pulse Generators While P is the period in samples, M is the number of s 2 5 4 harmonics. It is always odd because an impulse train 3 6 3 1 4 5 7 2 has one ªharmonicº at DC, and an even number of non- 6 zero harmonics, provided no harmonic is allowed at ex- 8 1 actly half the sampling rate (which we enforce). Note

that M =P is always close to 1. When P is an odd integer,

    P = M,andy n is simply SincM n .AsPdeparts from M, Eq. (3) implements a time scaling along with a com- pensating amplitude scaling. We can relate the number Figure 5: Comparing number of harmonics to number of

of harmonics M to the period P of the impulse train as overlapped pulse instances for a pulse 8 samples long.

b = c + M = 2 P 2 1 A further optimization comes from comparing the num- ber of sincs that must be overlapped in the BLIT-SWS i.e., M is the largest odd integer not exceedingthe period method to the number of harmonics of the BLIT that P in samples.

land below Fs =2. At very high frequencies, the number  The above expression for yn can also be derived via of bandlimited harmonics becomes quite small. Indeed, Discrete-Summation Formulae and Eq. (2). DSF is of- in the top octave, only the fundamental is in band. Thus ten used with a constant number of harmonics, rather for a large percentage of the frequency range, it is quite

than harmonics that go all way out to Fs =2. This pro- likely that it may be more ef®cient to generate a BLIT duces a slightly different result. (I think it is the same (or any other harmonic waveform) by simple summa- as the above equation for y, except that M is a constant.) tion of sines. At lower frequencies, we can again revert to the BLIT-SWS method because it is obviously more 3.8 Sum of Windowed Sincs (BLIT-SWS) ef®cient at low frequencies, where the number of har- monics is very large. A more ef®cient method for synthesizing digital Precisely where the tradeoff occurs depends on the impulse trains may be based on the windowed- system in which the algorithm is to be implemented. For

sinc method for general bandlimited interpolation an extreme example, in an FFT1 system the tradeoff fre-

  [Smith and Gossett 1984]. The technique is equiva- quency moves all the way down to Fs = 2N , because the lent conceptually to bandlimited periodic wavetable system implements summed sines so ef®ciently. On the synthesis of an impulse train, as mentioned earlier: other hand, in a system where sine generation is signif- Bandlimited interpolation is used to convert the sam- icantly more expensive (say in a system where mem- pling rate of a discrete-time unit sample pulse train ory accesses are expensive enough to make even table from a pitch which divides the sampling rate (so that lookup mildly expensive), the tradeoff frequency can

the period is an integer) to the desired pitch. The easily be on the order of Fs =8. Of course, the amount

δ 

rate conversion causes each unit sample pulse n to of accuracy desired in the BLIT-SWS algorithm also af-

   be replaced by a windowed sinc function wt hs t fects the tradeoff, because it will affect the choice of the sampled at some phase which generally varies each window length, thus affecting the number overlapping period. sincs at a given frequency.

Harmonic (aliasing) fall-off rate vs. number of zero Exact BL vs. some fall-off rate crossings In practice, the BLIT-SWS method has demonstrated Because the windowing imposes a ®nite fall-off rate in another advantage over other, more exact bandlimited the harmonics, some aliasing is inevitable. We can, BLIT algorithms. In cases where the frequency is however, control this by our choice of window. It is also sweeping, such as vibrato or portamento, high harmon- helpful to helpful to have an oversampling factor so that ics of the signal will disappear or appear (depending on there is a good sized guard band between the upper limit the direction of the frequency sweep) during the sweep.

Stilson and Smith 6 Alias-Free Synthesis In an exactly bandlimited system, the highest harmonic transitions between full amplitude and zero amplitude in the period of one sample. This causes an audible tran- Rounded−Time Impulse Train (NIIT) sient, especially at low sampling rates, where Fs =2is 0 well within the audible region. These transients are usu- −30 ally unwanted and distracting. Like additive synthesis and bandlimited wavetable −60 synthesis, and unlike DSF, in BLIT-SWS synthesis the Amp (dB) −90 highest harmonic need not audibly ªpopº in or out as it −120 comes down from or gets up to half the sampling rate, 0 0.1 0.2 0.3 0.4 0.5 since the window function can be chosen to exhibit any normalized frequency

amount of attenuation at Fs =2. This effect has not been a historical problem in Figure 6: Spectrum of rounded-time impulse train with a line recorded digital music because of the use of non-ideal drawn connecting the peaks of both the desired harmonics anti-aliasing ®lters. The ®nite fall-off rate of these ®l- and the ®rst string of aliased harmonics (ªNIITº stands for ters allows harmonics to die out more slowly in up- ªNearest-Integer Impulse Trainº). ward sweeps (and appear more slowly in downward sweep), which avoids the above-mentioned transients. The BLIT-SWS method ends up implementing slower fall-off rates as an artifact of the windowing, and there- fore gets this effect for free. Some of the above-mentionedBLIT generation meth- Linear Interpolation ods cannot easily implement a slower fallof. DSF, for 0 example, has control only over the existence (or lack −30 thereof) of harmonics via N, so it can only implement −60 abrupt transitions in the number of active harmonics. DSF can implement a harmonic fall-off via the param- Amp (dB) −90 eter a, but this fall-off must start at the ®rst harmonic −120 0 0.1 0.2 0.3 0.4 0.5 and increase through all the harmonics, rather than be- normalized frequency ginning only at the last few harmonics. (SincM synthe- sis has a similar lack of control over fall-off rate; in fact, Figure 7: Spectrum of linearly interpolated impulse train there is no fall-off control at all without additional ®lter- with a line drawn connecting the peaks of desired harmonics ing). A few hacks can be used to overcome this. For ex- and aliased harmonics. ample, a second DSF group of harmonics can be placed at the top few harmonics with a small a to implement the fall-off rate. Another hack places a post- ®lter after the DSF to implement the high-frequency fall-off. This hack may have problems handling the harmonics' on-off transients, however. 8 zero crossings within window (Blackman) 0

Example Spectra −30 Figure 6 shows the spectrum of a rounded-time impulse −60 train. Here unit samples are put out at the sample time Amp (dB) −90 nearest the ideal time, and there is massive aliasing. −120 Figure 7 shows the spectrum of a discrete-time im- 0 0.1 0.2 0.3 0.4 0.5 pulse train using linear interpolation to interpolate the normalized frequency unit sample pulse locations. The aliasing is reduced, but it is still very strong. Figure 8: Spectrum of windowed-sinc interpolated impulse Figure 8 shows the spectrum of a bandlimited impulse train, the window spanning 8 zero-crossings of the sinc func- train generated using the BLIT-SWS method with 8 sinc tion. zero-crossings under a Blackman window. While there is still considerable aliasing at high frequencies, at low

Stilson and Smith 7 Alias-Free Synthesis frequencies it is down 90 dB or so. Corner at 0.9*Fs/2, 32 ZC in window 0

16 zero crossings within window (Blackman) −30 0 −60 −30

Amp (dB) −90 −60 −120 Amp (dB) −90 0 0.1 0.2 0.3 0.4 0.5 normalized frequency −120 0 0.1 0.2 0.3 0.4 0.5 normalized frequency Figure 11: Spectrum of windowed-sinc interpolated impulse train, the window spanning 32 zero-crossings of the sinc func- Figure 9: Spectrum of windowed-sinc interpolated impulse tion, and the sinc function dilated so as to lower its cut-off fre- train, the window spanning 16 zero-crossings of the sinc func- quency below half the sampling rate. tion.

Figure 9 shows the same thing as Fig. 8 with the num- The next major class of analog waveforms are Square 2 ber of zero crossings raised from 8 to 16. This roughly waves and Sawtooth waves. We will show how to eas- halves the transition bandwidth of the window trans- ily derive these from a BLIT via integrations which are form, and as a result, the aliasing is down 90 dB over linear transforms (that can be implemented with trivial approximately 60% of the spectrum. ®lters), so that they preserve the bandlimited nature of the BLIT. 32 zero crossings within window (Blackman) 0 4.1 Successive Integration of BLIT −30 Sawtooth −60 A sawtooth function can be generated as follows: Amp (dB) −90 Z t

−120 = τ τ 0 0.1 0.2 0.3 0.4 0.5 SawCTS t CIT C1 d

normalized frequency 0 τ where CIT  is a continuous-time impulse train, and

R T

τ τ Spectrum of windowed-sinc interpolated impulse = Figure 10: C1 0 CIT d , the DC component of the impulse train, the window spanning 32 zero-crossings of the sinc func- train. This converts directly to discrete-time (via the tion. impulse-invariant transform):

Figure 10 shows the same thing again with the num- n

=   Sawn ∑BLIT k C ber of zero crossings doubled again from 16 to 32. 2

k=0

Again the transition width is halved, and now only the z

 =      upper 20% of the spectrum is heavily aliased. , Saw z BLIT z Z C2 z1 Finally Fig. 11 shows the previous case (32 zero crossings) with the cut-off frequency of the sinc func- Which is trivally impementable with a single sum and tion lowered below half the sampling rate. This means one-pole digital ®lter. The offet C2 is the average value the transition band of the window transform is folded in of BLIT, which should be subtracted off to keep the in- half as it falls into half the sampling rate and re¯ects. tegration from ramping off to in®nity (or saturating). C2 The result is another halving of the aliased region to is a function of frequency. Depending on the initial con- about 10% of the highest frequencies. If the limit of ditions of the integrator, there will be a DC offset on the human hearing is 20 kHz, this means we need a 2 kHz output of the integrator. guard band, so the sampling rate should be at least 44 2To avoid confusion, we will use the following naming convention: kHz. A ªsquare waveº is a rectangle wave with 50% duty cycle (i.e., ªrect- angle waveº means a wave that can have other duty cycles). A ªtrian- gle waveº can have asymmetric up/down slopes (including the 50% duty-cycle version), and a ªsawtoothº wave must have in®nite-slope 4 Square- and Sawtooth-Wave transitions (either up or down). Thus a sawtooth wave is a triangle Generation wave with either 0% or 100% duty cycle. All waves can have unipo- lar, bipolar, or arbitrary-offset versions.

Stilson and Smith 8 Alias-Free Synthesis BLIT(n) Rect(n) BLIT(n) z Saw(n) z-1 amp BP-BLIT(n) amp frequency: f Tri(n) z g(f,d) z BP-BLIT z-1 z-1 amp C2 duty-cycle: d C4 C6

Figure 12: Direct Sawtooth Generation Figure 13: Rectangle and Triangle Generation

Rectangle

= + the rectangle wave: C6 = k0 Period C7 . C7 is a

A rectangle wave can be computed as:  function of BLIT 0 , the initial condition of the inte-

Ztgration. To get appropriate amplitude on the triangle

= τ τ  τ RectCTS t CIT CIT t0 C3 d wave (so that its extrema are the same size as those of 0the BLIT and Rectangle wave), a frequency- and duty- Which discretizes to: cycle-dependant scaling must be performed on the Tri- n

angle integration:

=     Rect n ∑BLIT k BLIT k k0 C4

k=0

n

  = n

∑ BP-BLITk0 k C4

 = ;     k =0 Tri n ∑gfdRect k C6

zk=0

 =      , Saw z BP-BLITk0 z Z C4

z12f

; =

g f d

 d1d Where BP-BLIT is a ªBiPolarº BLIT, whose pulses alternate sign. See Section 5 for discussion on hacks for

ef®ciently generating BP-BLIT. It turns out that a bipo- Where f is the frequency in units of (cycles/sample),

[ ; ]

lar impulse train has a DC component of zero, which and d is the duty cycle (d 2 0 1 ). = means that C3 = 0 (and subsequentlyC4 0). The rect- angle width is controlled with k0, which can be varied to give PWM (pulse-width modulation). The range of k0 in Why Rectangle and Triangle? these equations is [0,Period]. Depending on the imple- mentation of the BLIT, the PWM control may also be in These particular waveforms were chosen especially be- the range [0,1]. Depending on the initial conditions of cause they can be easily generated from BLITs, which the integrator, there will be a DC offset on the output. as explaied earlier are special in their ease of calcula- tion. We were just lucky that they were also popular analogwaveforms(oris it morethancoincidence...?) Triangle A triangle wave can be generated as:

Z t 4.2 Can DSF do it?

= τ τ TriCTS t RectCTS C5 d 0 One may wonder if DSF can be used to directly gener-

Where C5 is the DC component of the rectangle wave: ate rectangle or triangle waves via appropriate settings

R T

τ τ = of the a parameter. The answer is no, because (as can C5 0 RectCTS d . This discretizes to: be shown from the integrations) the square-wave's har- n

monics' amplitudes fall of as 1= f (or, equivalently, as

=   Trin ∑Rect k C6 1 =n,wherenis the harmonic number), and the trian- k=02 k

zgle'sas1= f . The DSF harmonics fall off as a .This

 =      , Tri z Rect z Z C6 keeps the DSF from generating exact rectangle or trian-

z1 gle waves, but depending on the circumstance (i.e. the The offsets C5 and C6 are functions of the rectangle signal not being used as a control signal, etc), ®tting an

k 2 = wave duty cycle and of a DC offset that arises from a fall-off rate to approximate 1=n or 1 n may be close the initial conditions of the integration that produces enough (perceptually, for example).

Stilson and Smith 9 Alias-Free Synthesis 4.3 Appropriate Scalings/Offsets and where the exact shape of the signal is important, Non-Steady-State Fixups this can be a big problem.

In order to keep the integrators from ramping their out- 2. In steady-state, the outputs of the integrators will puts to in®nity (or at least beyond the capabilities of the have no DC component (because BP-BLIT has number system or the DACs), any DC offset in the in- none), regardless of initial conditions, since the put to the integrator must be avoided. As already noted, leaky integrators eventually forget them. Thus, if BP-BLIT has no DC offset, so there need be no spe- one can live with occasional transient DC offsets cial offsets for the square-wave integration. The initial (which decay at the leak rate), then just the pres- conditions of the ®rst integrator, however, can produce ence of the leaky integrators can handle all offset 4 a DC offset on the output that must be canceled before cases . the second integration. The value of this offset is also If one still requires the absence of any DC offset, dependant on the duty-cycle of the signal3, so that the transient or not, then the presense of the leaky integra- correct initial condition will change based on: (1) de- tors makes the problem of computing appropriate off- sired phase, and (2) desired duty cycle. There is also sets much more dif®cult. a frequency-dependant scaling necessary for the second integration (because the triangle slopes are proportional to frequency), whose effects must be accounted for dur- Defs of Amplitude ing frequency changes. It is important to remember that Moore presents a discussion of amplitude compensation the old state (right before the change) acts as a new ªini- in his DSF paper. Similar compensation is necessary in tial conditionº for the integrator when the parameters BLIT generation. The compensation to be used depends are changed. on how one de®nes amplitude, which depends on how the signal is to be used. If the signal is to be used as an audio signal, signal power or some psychoacoustic Leaky Integrators loudness measure is appropriate, but if the signal is to The use of pure integrators can present problems in the be used as a control signal, a maximum-value (Cheby- presence of numerical errors, such as roundoff. These chev) measure is more appropriate. errors accumulate in the integrators, causing unwanted (and unpredicatble) offsets in the signals, which can de- stroy the ability to create the desired waveforms, espe- 5 Generating Bipolar BLITs in cially in the second integration. Therefore, we move DSF the poles of the ®lters that implement the integration slightly in from the unit circle. These ªleakyº integra- The above sections describing the generation of rect- tors slowly forget bad initial conditions and numerical angle waves and triangle waves from BLITs did not errors, so that they don't continue the build up forever. prescribe which method need be used to generate the The impulse response of a leaky integrator is an expo- BLITs. This is because it doesn't matter which tech- nential that slowly decays to zero. This has two more nique is used (to within numerical accuracy differ- effects: ences). It does turn out, however, that there are one or two interesting methods that can be employed in gener- 1. The decay rate places an effective lower bound on ating the bipolar BLITs necessary to generate rectangle frequency(especially in caseswhere the signal is to waves. be used as a control signal), when the period gets Difference of BLITs The standard (straight-forward) on the order of the decay time, the `held' output method of generating the bipolar BLITs is simply to take (as in a rectangle wave), is no longer even close to the difference to two BLITs, one shifted relative to the being constant over its portion of the cycle. In au- other. This is the technique used in BLIT-SWS. dio signals, this is probably not a problem (it just DSF method In cases where DSF is acceptable attenuates the lowest-frequency harmonics, which (ef®ciency-wise), a few re®nements to the algorithm can may not be audible anyway), but in control signals, be put to good use to directly generate bipolar BLITs.

3Any amplitude dependance can be avoided by assuming unit am- 4The transient DC offsets can be reduced by temporarily increas- plitude in all the integrations and simply post-scaling the outputs. ing the integrators' leak rate at times when transients are expected.

Thus the scaling gains are: on input of ®rst integrator, 1.0; on input of This causes the integrators to `center' themselves faster (at the expense

   2 [ ; ] second integrator 2 = Td 1 d where d is the duty cycle ( 0 1 ) of low frequencies), and then return to the desired steady-state leak and T is the period in samples. rate after DC has been ®xed.

Stilson and Smith 10 Alias-Free Synthesis First, we note that BLITs can be generated via DSF DSF BLIT can be generated almost as ef®ciently as a by replacing the sin by cos in the DSF formulas (this single DSF BLIT. ends up essentially replacing sin by cos in the numera- tor of the original DSF equation, the denominator stays y = sum(.99^k cos(0 + 3 k t)), N=20 the same). See Figure 14. 20 10 y = sum(.99^k cos(0 + 3 k t)), N=20

20 y 0

10 −10 y −20 0 0 0.5 1 1.5 2 y = 2*.99*sum((.99^2)^k cos(3 + 6 k t)), N=10 20 −10 0 0.5 1 1.5 2 10 t/pi

y 0 Figure 14: Using cosine-DSF to generate BLIT −10

50% duty cycle: First, it can be shown that using −20

N k 0 0.5 1 1.5 2

+  anegativeain the DSF formula ∑ a sin0 kf t k =1 1 t/pi produces a signal that is shifted from the positive-a sig- nal by exactly half a cycle (Figure 15), this gives a Figure 16: 50% duty-cycle BP-BLIT using DSF slightly more ef®cient (or elegant...) way of produc- ing the shifted BLIT than offsetting t. This can lead to PWM: For other duty cycles, there is another varia- showing that: tion on DSF that is of interest. Let a be complex and take either the real or imaginary part of the DSF, this

y = sum(.99^k cos(0 + 3 k t)), N=20

6

  20 imposes a sink a (or cosine) amplitude envelope onto the harmonics, which is equivalent to a comb ®l- 10 tering, which in turn is equivalent to summing a real

y 0 DSF with a shifted version of itself (possibly with a sign ¯ip), all of which can be shown mathematically. See −10 Figure 17. This method implements BP-BLIT in essen- −20 tially the same complexity as evaluating the difference 0 0.5 1 1.5 2 y = sum((−.99)^k cos(0 + 3 k t)), N=20 of two real DSF BLITs, but with a bit more elegance. 20 10 References y 0 [Bellanger 1996] Bellanger, M. 1996. ªImproved Design of −10 Long FIR Filters using the Frequency Masking Technique.º −20 In: Proc. Int. Conf. Acoustics, Speech, and Signal Process- 0 0.5 1 1.5 2 t/pi ing, Atlanta. New York: IEEE Press. Paper DSP1.1. [Chowning 1989] Chowning, J. M. 1989. ªFrequency Mod- Figure 15: DSF: half-cycle shift ulation Sythesis of the Singing Voice.º. Pages 57±63 of: Mathews, M. V., and J. R. Pierce (eds), Current Directions in Computer Music Research. Cambridge, MA: MIT Press. N N

k k [Committee 1979] Committee, D. S. P. (ed). 1979. Programs

+     + 

∑ a sina bk ∑ a sin a bk for Digital Signal Processing. New York: IEEE Press. = k =1 k 1

N =2 [Crochiere and Rabiner 1983] Crochiere, R., and L. R. Ra-

2 k

   + +  = 2a ∑ a sin ab2bk biner. 1983. Multirate Digital Signal Processing. Engle-

k =1 wood Cliffs, NJ: Prentice-Hall, Inc. The same applies to the sum-of-cosines DSF, which [Dodge and Jerse 1985] Dodge, C., and T. A. Jerse. 1985. is shown in Figure 16. Thus a 50% duty-cycle bipolar Computer Music. New York: Schirmer.

Stilson and Smith 11 Alias-Free Synthesis y = Re[sum((.99*exp(j pi/4))^k cos(0 + 3 k t))], N=20 [Smith and Gossett 1984] Smith, J. O., and P. Gos- 10 sett. 1984. ªA Flexible Sampling-Rate Conversion 5 Method.º Pages 19.4.1±19.4.2 of: Proc. Int. Conf. Acoustics, Speech, and Signal Processing, San Diego, y 0 vol. 2. New York: IEEE Press (An expanded tuto- rial based on this paper is available in the directory −5

ftp://ccrma-ftp.stanford.edu/p ub/DSP /Tutori als/, −10 ®le BandlimitedInterpolation.eps.Z, as is C code 0 0.5 1 1.5 2 for implementing the technique in directory y = Im[sum((.99*exp(j pi/4))^k sin(0 + 3 k t))], N=20 10 ftp://ccrma-ftp.stanford.edu/p ub/NeX T/,®le resample-n.m.tar.Z, where n.m denotes the latest version 5 number. Note that the C source code is included so it is easy to port it to any platform supporting the C language. y 0 The tutorial can be browsed online with any Web browser

−5 at http://www-ccrma.stanford.e du/~jos /).

−10 0 0.5 1 1.5 2

t/pi This paper can be found online at http://www-ccrma.stanford.edu /~stil ti/pape rs Figure 17: Using a complex multiplier in DSF to generate BP-BLIT

[Goeddel and Bass 1984] Goeddel, T. E., and S. C. Bass. 1984. ªHigh Quality Synthesis of Musical Voices in Dis- crete Time.º IEEE Trans. Acoustics, Speech, Signal Pro- cessing, 32(3):623±633. [Kaegi and and S. Tempelaars 1978] Kaegi, and W. a S. Tem- pelaars. 1978. ªVOSIMÐA New Sound Synthesis Sys- tem.º J. Audio Eng. Soc., 26(6):418±24. [Mathews 1969] Mathews, M. V. 1969. The Technology of Computer Music. Cambridge, MA: MIT Press. [Moorer 1975] Moorer, J. A. 1975. ªThe Synthesis of Com- plex Audio Spectra by Means of Discrete Summation For- mulae.º J. Audio Eng. Soc., 24(Dec.):717±727 (Also svail- able as CCRMA Report No. STAN-M-5). [Papoulis 1991] Papoulis, A. 1991. Probability, Random Variables, and Stochastic Processes, 3rd Edition.New York, NY: McGraw-Hill, Inc. [Rabiner and Gold 1975] Rabiner, L. R., and B. Gold. 1975. Theory and Application of Digital Signal Processing. Englewood Cliffs, NJ: Prentice-Hall, Inc. [Roads 1996] Roads, C. 1996. Computer Music Tutorial. Cambridge, MA: MIT Press. [Rodet et al. 1989] Rodet, X., Y. Potard, and J. BarriÁere. 1989. ªThe CHANT Project: From the Synthesis of the Singing Voice to Synthesis in General.º. Pages 449±465 of: Roads, C. (ed), The Music Machine. Cambridge, MA: MIT Press. [Schafer and Rabiner 1973] Schafer, R. W., and L. R. Ra- biner. 1973. ªA Digital Signal Processing Approach to In- terpolation.º Proc. IEEE, 61(June):692±702. [Schanze 1995] Schanze, T. 1995. ªSinc Interpolation of Dis- crete Periodic Signals.º IEEE Trans. Signal Processing, 43(6):1502±1503.

Stilson and Smith 12 Alias-Free Synthesis