tutorial - digital audio re sampling - julius smith

19

Click here to load reader

Upload: yonodio

Post on 21-Apr-2015

107 views

Category:

Documents


0 download

TRANSCRIPT

Digital Audio Resampling Home PageAbstractThis document describes digital audio sampling-rate conversion and related concepts. Open-source software is provided, and pointers are given to related projects and papers.Contents1 What is Bandlimited Interpolation? 22 Free Resampling Software 23 Theory of Operation 43.1 Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43.2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43.3 Theory of Ideal Bandlimited Interpolation . . . . . . . . . . . . . . . . . . . . . . . . 43.4 From Theory to Practice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.5 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.6 Quantization Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.6.1 Choice of Table Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.6.2 Linear Interpolation Error Bound . . . . . . . . . . . . . . . . . . . . . . . . . 123.6.3 Application to the Ideal Lowpass Filter . . . . . . . . . . . . . . . . . . . . . 133.6.4 Relation of Interpolation Error to Quantization Error . . . . . . . . . . . . . 133.6.5 Error in the Absence of Interpolation . . . . . . . . . . . . . . . . . . . . . . 143.6.6 Choice of Interpolation Resolution . . . . . . . . . . . . . . . . . . . . . . . . 143.6.7 Quantized Interpolation Error Bound . . . . . . . . . . . . . . . . . . . . . . 153.6.8 Ideal Lowpass Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.7 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153.8 Appendix: Periodic Sinc Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . 163.9 Appendix: Relation between Sinc and Lagrange Interpolation . . . . . . . . . . . . . 1611 What is Bandlimited Interpolation?Bandlimited interpolation of discrete-time signals is a basic tool having extensive application indigital signal processing. In general, the problem is to correctly compute signal values at arbitrarycontinuous times from a set of discrete-time samples of the signal amplitude. In other words,we must be able to interpolate the signal between samples. Since the original signal is alwaysassumed to be bandlimited to half the sampling rate, (otherwise aliasing distortion would occur uponsampling), Shannons sampling theorem tells us the signal can be exactly and uniquely reconstructedfor all time from its samples by bandlimited interpolation.There are many methods for interpolating discrete points. For example, Lagrange interpolationis the classical technique of nding an order N polynomial which passes through N+1 given points.The technique known as cubic splines ts a third-order polynomial through two points so asto achieve a certain slope at one of the points. (This allows for a smooth chain of third-orderpolynomial passing through a set of points.)You may also have heard of Bezier splines which interpolate a set of points using smooth curveswhich dont necessarily pass through the points. (Bezier curves are commonly used in graphics anddrawing programs, such as Adobe Illustrator.)The above methods are suitable for graphics and other uses, but they are not ideal for digitalaudio. In digital audio, what matters is the audibility of interpolation error between samples. SinceShannons sampling theorem says it is possible to restore an audio signal exactly from its samples,it makes sense that the best digital audio interpolators would be based on that theory. Such idealinterpolation is called bandlimited interpolation.A bandlimited interpolation algorithm designed along these lines is described in the theoryof operation tutorial.1There is also free open-source software2available in the C programminglanguage.2 Free Resampling Software Note: resample, libresample, and sndfile-resample (from libsamplerate) are alreadyincluded in the Planet CCRMA Distribution3. If you are running Red Hat Linux, check outthe Planet. resample-1.8.1.tar.gz4(502 Kbytes) (v1.8.1 released November 11, 2006)The resample software package contains free sampling-rate conversion and lter design util-ities written in C, including a stand-alone command-line sampling-rate conversion utilitycalled resample. The package compiles readily under Linux and most other UNIX operatingsystems. It is released under the GNU Lesser General Public License (LGPL). Older Version for NeXT Computers (49 Kbytes)5 Original 1983+ source for the PDP KL-106(Released under the Revised BSD License)1http://ccrma.stanford.edu/~jos/resample/Theory_Operation.html2http://ccrma.stanford.edu/~jos/resample/Available_Software.html3http://ccrma.stanford.edu/planetccrma/software/4http://ccrma.stanford.edu/~jos/gz/resample-1.8.1.tar.gz5http://ccrma.stanford.edu/~jos/gz/resample-1.2.tar.gz6./original-source.html2 libresample7(LGPL) (version 1.3 released Jan. 7, 2004) by Dominic Mazzoni is a real-timelibrary for sampling rate conversion providing several useful features relative to resample-1.7on which it is based: It should build out of the box on more platforms, including Linux, Solaris, and MacOS X (using the included configure script). There is also a Visual C++ project le forbuilding under Windows. Input and output signals are in memory (as opposed to sound les). Computations are in oating-point (instead of xed-point). Filter table increased by a factor of 32, yielding more accurate results, even withoutlinear interpolation (which also makes it faster). Data can be processed in small chunks, enabling time-varying resampling ratios (idealfor time-warping applications and supporting an external clock input in software). Easily applied to any number of simultaneous data channels libresample4j8is a Java port of libresample for real-time sampling-rate conversion bydnault-laszlo.9 Erik de Castro Lopos SecretRabbitCode libsamplerate10 Same basic algorithm Floating-point (resample is xed-pointsometimes needed on DSP chips) Congures for non-Linux platforms such as Mac OS X and Windows Includes the command-line program sndfile-resample which works like resample Uses Eriks libsndfile (resample uses Bill Schottstaedts sndlib) License is either GPL or commercial (resample is LGPL) The free Open Source Audio Library Project (OSALP)11(LGPL) contains a C++ class basedon resample. The Speex12speech coder/decoder (based on CELP) contains a variation of the resamplealgorithm in the le resample.c, is free and open-source, and is released under a BSD-stylelicense (i.e., free for both commercial and noncommercial uses). The code is characterized asworking, but its in a very early stage, so it may have artifacts ... the API isnt stable ....However, this appears to be the best BSD-licensed starting point. Website comparing various sampling-rate converters: http://src.infinitewave.ca/ Paper on optimal FIR interpolation lter design: (.pdf)13To report bugs, or contribute enhancements, please send email to jos ([email protected]).7http://ftp.debian.org/pool/main/libr/libresample/8https://github.com/dnault-laszlo/libresample4j9https://github.com/dnault-laszlo10http://www.mega-nerd.com/SRC/11http://sourceforge.net/projects/osalp/12http://www.speex.org13http://ccrma.stanford.edu/~jos/pdf/optfir.pdf33 Theory of Operation3.1 AbstractThis tutorial describes a technique for bandlimited interpolation of discrete-time signals whichsupports signal evaluation at an arbitrary time, and which performs well for smoothly changingsampling rates, such as needed for digital audio scrubbing. The method is based on interpolatedlook-up in a table of lter coecients, so as to make the lter impulse response available eectivelyin continuous-time form. A single pre-computed lter table handles all interpolation times andsampling-rate conversion ratios. Formulas are given for determining the look-up table size neededfor a given precision requirement. This tutorial is an expansion of the conference paper in [21].3.2 IntroductionBandlimited interpolation of discrete-time signals is a basic tool having extensive application indigital signal processing. In general, the problem is to correctly compute signal values at arbitrarycontinuous times from a set of discrete-time samples of the signal amplitude. In other words,we must be able to interpolate the signal between samples. Since the original signal is alwaysassumed to be bandlimited to half the sampling rate, (otherwise aliasing distortion would occur uponsampling), Shannons sampling theorem tells us the signal can be exactly and uniquely reconstructedfor all time from its samples by bandlimited interpolation.Considerable research has been devoted to the problem of interpolating discrete points. Acomprehensive survey of fractional delay lter design is provided in [10]. A comparison betweenclassical (e.g., Lagrange) and bandlimited interpolation is given in [18]. The book MultirateDigital Signal Processing [1] provides a comprehensive summary and review of classical signalprocessing techniques for sampling-rate conversion. In these techniques, the signal is rst interpo-lated by an integer factor L and then decimated by an integer factor M. This provides sampling-rateconversion by any rational factor L/M. The conversion requires a digital lowpass lter whose cutofrequency depends on max{L, M}. While suciently general, this formulation is less convenientwhen it is desired to resample the signal at arbitrary times or change the sampling-rate conversionfactor smoothly over time.In this tutorial, a public-domain resampling algorithm is described which will evaluate a signalat any time speciable by a xed-point number [21]. In addition, one lowpass lter is used re-gardless of the sampling-rate conversion factor. The algorithm eectively implements the analoginterpretation of rate conversion, as discussed in [1], in which a certain lowpass-lter impulse re-sponse must be available as a continuous function. Continuity of the impulse response is simulatedby linearly interpolating between samples of the impulse response stored in a table. Due to therelatively low cost of memory, the method is quite practical for hardware implementation.In section 2, the basic theory is presented, section 3 addresses practical issues, and implemen-tation details are discussed in section 4. Finally, section 5 discusses numerical requirements on thelength, width, and interpolation accuracy of the lter coecient table.3.3 Theory of Ideal Bandlimited InterpolationWe review briey the analog interpretation of sampling rate conversion [1] on which the presentmethod is based. Suppose we have samples x(nTs) of a continuous absolutely integrable signal x(t),where t is time in seconds (real), n ranges over the integers, and Ts is the sampling period. We4assume x(t) is bandlimited to Fs/2, where Fs = 1/Ts is the sampling rate. If X() denotes theFourier transform of x(t), i.e., X() =_x(t)ejtdt, then we assume X() = 0 for || Fs.Consequently, Shannons sampling theorem gives us that x(t) can be uniquely reconstructed fromthe samples x(nTs) via x(t) =

n=x(nTs)hs(t nTs) x(t), (1)wherehs(t) = sinc(Fst) = sin(Fst)Fst . (2)To resample x(t) at a new sampling rate Fs = 1/Ts, we need only evaluate Eq. (1) at integermultiples of Ts.When the new sampling rate Fs is less than the original rate Fs, the lowpass cuto must beplaced below half the new lower sampling rate. Thus, in the case of an ideal lowpass, hs(t) =min{1, Fs/Fs}sinc(min{Fs, Fs}t), where the scale factor maintains unity gain in the passband.A plot of the sinc function sinc(t) = sin(t)/(t) to the left and right of the origin t = 0 isshown in Fig. 1. Note that peak is at amplitude 1, and zero-crossings occur at all nonzero integers.The sinc function can be seen as a hyperbolically weighted sine function with its zero at the origincanceled out. The name sinc function derives from its classical name as the sine cardinal (orcardinal sine) function.-7 -6 -5 -4 -3 -2 -1 1 2 3 4 5 6 71. . .. . .. . .. . .Figure 1: The sinc function plotted for seven zero-crossings to the left and right.If denotes the convolution operation for digital signals, then the summation in Eq. (1) canbe written as (x hs)(t).Equation Eq. (1) can be interpreted as a superpositon of shifted and scaled sinc functions hs.A sinc function instance is translated to each signal sample and scaled by that sample, and theinstances are all added together. Note that zero-crossings of sinc(z) occur at all integers exceptz = 0. That means at time t = nTs, (i.e., on a sample instant), the only contribution to the sumis the single sample x(nTs). All other samples contribute sinc functions which have a zero-crossingat time t = nTs. Thus, the interpolation goes precisely through the existing samples, as it should.A plot indicating how sinc functions sum together to reconstruct bandlimited signals is shownin Fig. 2. The gure shows a superposition of ve sinc functions, each at unit amplitude, and dis-placed by one-sample intervals. These sinc functions would be used to reconstruct the bandlimitedinterpolation of the discrete-time signal x = [. . . , 0, 1, 1, 1, 1, 1, 0, . . .]. Note that at each samplinginstant t = nTs, the solid line passes exactly through the tip of the sinc function for that sample;5this is just a restatement of the fact that the interpolation passes through the existing samples.Since the nonzero samples of the digital signal are all 1, we might expect the interpolated signal tobe very close to 1 over the nonzero interval; however, this is far from being the case. The deviationfrom unity between samples can be thought of as overshoot or ringing of the lowpass lterwhich cuts o at half the sampling rate, or it can be considered a Gibbs phenomenon associatedwith bandlimiting.Figure 2: Bandlimited reconstruction of the signal The dots show the signal samples, the dashedlines show the component sinc functions, and the solid line shows the unique bandlimited recon-struction from the samples obtained by summing the component sinc functions.A second interpretation of Eq. (1) is as follows: to obtain the interpolation at time t, shift thesignal samples under one sinc function so that time t in the signal is translated under the peakof the sinc function, then create the output as a linear combination of signal samples where thecoecient of each signal sample is given by the value of the sinc function at the location of eachsample. That this interpretation is equivalent to the rst can be seen as a result of the fact thatconvolution is commutative; in the rst interpretation, all signal samples are used to form a linearcombination of shifted sinc functions, while in the second interpretation, samples from one sincfunction are used to form a linear combination of samples of the shifted input signal. The practicalbandlimited interpolation algorithm presented below is based on the second interpretation.3.4 From Theory to PracticeThe summation in Eq. (1) cannot be implemented in practice because the ideal lowpass lterimpulse response hs(t) actually extends from minus innity to innity. It is necessary in practiceto window the ideal impulse response so as to make it nite. This is the basis of the window methodfor digital lter design [3, 13]. While many other lter design techniques exist, the window methodis simple and robust, especially for very long impulse responses. In the case of the algorithmpresented below, the lter impulse response is very long because it is heavily oversampled. Anotherapproach is to design optimal decimated sub-phases of the lter impulse response, which are theninterpolated to provide the continuous impulse response needed for the algorithm [12].Figure 3 shows the frequency response of the ideal lowpass lter. This is just the Fouriertransform of hs(t).If we truncate hs(t) at the fth zero-crossing to the left and the right of the origin, we obtainthe frequency response shown in Fig. 4. Note that the stopband exhibits only slightly more than20 dB rejection.If we instead use the Kaiser window [8, 20] to taper hs(t) to zero by the fth zero-crossing to the6Ideal Lowpass Filter Frequency Response-0.4 -0.2 0 0.2 0.40.20.40.60.81Figure 3: Frequency response of the ideal lowpass lter.Frequency Response : Rectangular Window-400 -200 200 400-80-60-40-20Figure 4: Frequency response of the ideal lowpass lter after rectangularly windowing the ideal(sinc) impulse response at the fth zero crossing to the left and right of the time origin. Thevertical axis is in units of decibels (dB), and the horizontal axis is labeled in units of spectralsamples between plus and minus half the sampling rate.7left and the right of the origin, we obtain the frequency response shown in Fig. 5. Note that nowthe stopband starts out close to 80 dB. The Kaiser window has a single parameter which can beused to modify the stop-band attenuation, trading it against the transition width from pass-bandto stop-band.Frequency Response : Kaiser Window-400 -200 200 400-140-120-100-80-60-40-20Figure 5: Frequency response of the ideal lowpass lter Kaiser windowed at the fth zero crossingto the left and right.83.5 ImplementationThe implementation below provides signal evaluation at an arbitrary time, where time is speciedas an unsigned binary xed-point number in units of the input sampling period (assumed constant).Figure 6 shows the time register t, and Figure 7 shows an example conguration of the input signaland lowpass lter at a given time. The time register is divided into three elds: The leftmost eldgives the number n of samples into the input signal buer, the middle eld is an initial index linto the lter coecient table h(l), and the rightmost eld is interpreted as a number between 0and 1 for doing linear interpolation between samples l and l + 1 (initially) of the lter table. Theconcatenation of l and are called P [0, 1) which is interpreted as the position of the currenttime between samples n and n + 1 of the input signal.Let the three elds have nn, nl, and n bits, respectively. Then the input signal buer containsN = 2nnsamples, and the lter table contains L = 2nlsamples per zero-crossing. (The termzero-crossing is precise only for the case of the ideal lowpass; to cover practical cases we generalizezero-crossing to mean a multiple of time tc = 0.5/fc, where fc is the lowpass cuto frequencyin cycles per sample.) For example, to use the ideal lowpass lter, the table would contain h(l) =sinc(l/L).Our implementation stores only the right wing of a symmetric nite-impulse-response (FIR)lter (designed by the window method based on a Kaiser window [13]). Specically, if h(l), l =LNz, LNz + 1, . . . , 1, 0, 1, 2, . . . , LNz, denotes a symmetric nite impulse response, then theright wing of h is dened as the set of samples h(l) for l = 0, 1, 2, . . . , LNz. By symmetry, the leftwing can be reconstructed as h(l) = h(l), l = 1, 2, . . . , LNz.Our implementation also stores a table of dierences h(l) = h(l + 1) h(l) between successiveFIR sample values in order to speed up the linear interpolation. The length of each table isNh = LNz + 1, including the endpoint denition h(Nh) = 0.Consider a sampling-rate conversion by the factor = Fs/Fs. For each output sample, the basicinterpolation Eq. (1) is performed. The lter table is traversed twicerst to apply the left wingof the FIR lter, and second to apply the right wing. After each output sample is computed, thetime register is incremented by 2nl+n/ (i.e., time is incremented by 1/ in xed-point format).Suppose the time register t has just been updated, and an interpolated output y(t) is desired. For 1, output is computed viav h end

i=0x(n i)_h(l + iL) + h(l + iL)_ (3)P 1 P (4)y(t) v +h end

i=0x(n + 1 + i)_h(l + iL) + h(l + iL)_, (5)where x(n) is the current input sample, and [0, 1) is the interpolation factor. When < 1,the initial P is replaced by P= P, 1 P becomes P= (1 P), and the step-size throughthe lter table is reduced to L instead of L; this lowers the lter cuto to avoid aliasing. Notethat is xed throughout the computation of an output sample when 1 but changes when < 1.9InputSignalIndex nn nlnnFilter TableInitialIndex lInterpolationFactor Binary Point [ ) P 1 , 0Figure 6: Time register format.. . . . . .. . . . . .Filter Coefficientsfor Current OutputCurrentOutput TimeLowpass FilterImpulse ResponseInput Signal Samples. . .. . .( ) n x( ) n x 1 ( ) h 0( ) l h( ) L l h +P( ) n x + 1P n +TimeFigure 7: Illustration of waveforms and parameters in the interpolator.When < 1, more input samples are required to reach the end of the lter table, thus pre-serving the ltering quality. The number of multiply-adds per second is approximately (2Nz +1) max{Fs, Fs}. Thus the higher sampling rate determines the work rate. Note that for < 1 theremust be NzFs/Fs extra input samples available before the initial conversion time and after thenal conversion time in the input buer. As 0, the required extra input data becomes innite,and some limit must be chosen, thus setting a minimum supported . For 1, only Nz extrainput samples are required on the left and right of the data to be resampled, and the upper boundfor is determined only by the xed-point number format, viz., max = 2nl+n.As shown below, if nc denotes the word-length of the stored impulse-response samples, thenone may choose nl = 1 + nc/2, and n = nc/2 to obtain nc 1 eective bits of precision in theinterpolated impulse response.Note that rational conversion factors of the form = L/M, where L = 2nland M is an arbitrary10positive integer, do not use the linear interpolation feature (because 0). In this case our methodreduces to the normal type of bandlimited interpolator [1]. With the availability of interpolatedlookup, however, the range of conversion factors is boosted to the order of 2nl+n/M. E.g., for 1, nl = 9, n = 8, this is about 5.1 decimal digits of accuracy in the conversion factor .Without interpolation, the number of signicant gures in is only about 2.7.The number Nz of zero-crossings stored in the table is an independent design parameter. For agiven quality specication in terms of aliasing rejection, a trade-o exists between Nz and sacricedbandwidth. The lost bandwidth is due to the so-called transition band of the lowpass lter [13].In general, for a given stop-band specication (such as 80 dB attenuation), lowpass lters needapproximately twice as many multiply-adds per sample for each halving of the transition bandwidth.As a practical design example, we use Nz = 13 in a system designed for high audio quality at20% oversampling. Thus, the eective FIR lter is 27 zero crossings long. The sampling rate inthis case would be 50 kHz.14In the most straightforward lter design, the lowpass lter pass-bandwould stop and the transition-band would begin at 20 kHz, and the stop-band would begin (andend) at 25 kHz. As a further renement, which reduces the lter design requirements, the transitionband is really designed to extend from 20 kHz to 30 kHz, so that the half of it between 25 and30 kHz aliases on top of the half between 20 and 25 kHz, thereby approximately halving the lterlength required. Since the entire transition band lies above the range of human hearing, aliasingwithin it is not audible.Using 512 samples per zero-crossing in the lter table for the above example (which is what weuse at CCRMA, and which is somewhat over designed) implies desiging a length 27 512 = 13824FIR lter having a cut-o frequency near /512. It turns out that optimal Chebyshev designprocedures such as the Remez multiple exchange algorithm used in the Parks-McLellan software[13] can only handle lter lengths up to a couple hundred or so. It is therefore necessary to usean FIR lter design method which works well at such very high orders, and the window methodemployed here is one such method.It is worth noting that a given percentage increase in the original sampling rate (oversampling)gives a larger percentage savings in lter computation time, for a given quality specication, becausethe added bandwidth is a larger percentage of the lter transition bandwidth than it is of theoriginal sampling rate. For example, given a cut-o frequency of 20 kHz, (ideal for audio work),the transition band available with a sampling rate of 44 kHz is about 2 kHz, while a 48 kHz samplingrate provides a 4 kHz transition band. Thus, a 10% increase in sampling rate halves the work persample in the digital lowpass lter.3.6 Quantization IssuesIn this section, we investigate the requirements on the sampling density L = 2nlof the lowpass-lter impulse response, and the number of bits n required in the interpolation factor . Thesequantities are determined by computing the worst-case error and comparing it to the lter coecientquantization error.14We arbitrarily dene the 20% guard band as a percentage of half the sampling rate actually used, not as 20% ofthe desired 20 kHz bandwidth which would call for a 48 kHz sampling rate.113.6.1 Choice of Table SizeIt is desirable that the stored lter impulse response be sampled suciently densely so that inter-polating linearly between samples does not introduce error greater than the quantization error. Wewill show that this condition is satised when the lter table contains at least L = 2nc/2entries perzero-crossing, where nc is the number of bits allocated to each table entry.3.6.2 Linear Interpolation Error BoundLet h(t) denote the lowpass lter impulse response, and assume it is twice continuously dierentiablefor all t. By Taylors theorem [6, p. 119], we haveh(t0 + ) = h(t0) + h(t0) + 122h(t0 + ), (6)for some [0, 1], where h(t0) denotes the time derivative of h(t) evaluated at t = t0, and h(t0)is the second derivative at t0.The linear interpolation error ise(t) = h(t) h(t), (7)where t = t0 + , t0 = t, = t t0, and h(t) is the interpolated value given byh(t) = h(t0) + h(t1), (8)where = 1 and t1= t0 + 1. Thus t0 and t1 are successive time instants for which samples ofh(t) are available, and [0, 1) is the linear interpolation factor.By denition, e(t0) = e(t1) = 0. That is, the interpolation error is zero at the known samples.Let te denote any point at which |e(t)| reaches a maximum over the interval (t0, t1). Then we have|e(te)| |e(t)|, t [t0, t1].Without loss of generality, assume te t0 + 1/2. (Otherwise, replace t0 with t1 in the following.)Since both h(t) and h(t) are twice dierentiable for all t (t0, t1), then so is e(t), and thereforee(te) = 0. Expressing e(t0) = 0 as a Taylor expansion of e(t) about t = te, we obtain0 = e(t0) = e(te) + (t0 te)e(te) + (t0 te)22! e() = e(te) + (t0 te)22 e()for some (t0, t1). Solving for e(te) givese(te) = (t0 te)22 e()DeningM2= maxth(t) = maxte(t),where the maximum is taken over t (t0, t1), and noting that |t0te| 1/2, we obtain the upperbound15|e(te)| M28 (9)15Thanks to Magnus Lundin for contributing this formulation, which sharpens the bound derived in [21].123.6.3 Application to the Ideal Lowpass FilterFor the ideal lowpass lter, we haveh(t) = sinc(Lt/) = sin(Lt)Lt = 1L_ L0cos(t), (10)where L = /L, and L = 2nlis the number of table entries per zero-crossing. Note that the right-most form in Eq. (10) is simply the inverse Fourier transform of the ideal lowpass-lter frequencyresponse. Twice dierentiating with respect to t, we obtainh(t) = 1L_ L02cos(t), (11)from which it follows that the maximum magnitude isM2 = 2L3 = 23L2. (12)Note that this bound is attained at t = 0. Substituting Eq. (12) into Eq. (9), we obtain the errorbound|e(te)| 224L2 < 0.412L2 = 0.412 22nl. (13)Thus for the ideal lowpass lter h(t) = sinc(t/L), the pointwise error in the interpolated lookup ofh(t) is bounded by 0.412/L2. This means that nl must be about half the coecient word-lengthnc used for the lter coecients. For example, if h(t) is quantized to 16 bits, L must be on theorder of 216/2= 256. In contrast, we will show that without linear interpolation, nl must increaseproportional to nc for nc-bit samples of h(t). In the 16-bit case, this gives L 216= 65536. Theuse of linear interpolation of the lter coecients reduces the memory requirements considerably.The error bounds obtained for the ideal lowpass lter are typically accurate also for lowpasslters used in practice. This is because the error bound is a function of M2, the maximum curvatureof the impulse response h(t), and most lowpass designs will have a value of M2 very close to thatof the ideal case. The maximum curvature is determined primarily by the bandwidth of the ltersince, generalizing equations Eq. (10) and Eq. (11),h(0) = 1_ 02H(),which is just the second moment of the lowpass-lter frequency response H() (which is real forsymmetric FIR lters obtained by symmetrically windowing the ideal sinc function [13]). A lowpass-lter design will move the cut-o frequency slightly below that of the ideal lowpass lter in order toprovide a transition band which allows the lter response to give sucient rejection at the idealcut-o frequency which is where aliasing begins. Therefore, in a well designed practical lowpasslter, the error bound M2 should be lower than in the ideal case.3.6.4 Relation of Interpolation Error to Quantization ErrorIf h(t) [1, 1 2nc] is approximated by hq(t) which is represented in twos complement xed-point arithmetic, thenhq(t0) = b0 +nc1

i=1bi2i,13where bi {0, 1} is the ith bit, and the worst-case rounding error is|h(t) hq(t)| 2nc.Letting hq(ti) = h(ti) + i, where |i| 2nc, the interpolated look-up becomeshq(t0 + ) = hq(t0) + hq(t1) = h(t0 + ) + 0 + 1.Thus the error in the interpolated lookup between quantized lter coecients is bounded by|eq(t)| M28 + 2nc,which, in the case of h(t) = sinc(t/L), can be written|eq(t)| < 0.412L2 + 2nc= 0.412 22nl+ 2nc.If L = 2nc/2, then |eq(t)| < 1.5 2nc.3.6.5 Error in the Absence of InterpolationFor comparison purposes, we derive the error incurred when no interpolation of the lter table isperformed. In this case, assuming rounding to the nearest table entry, we havet = t0 + , || 12h(t) = h(t0)e(t) = h(t) h(t0)= h(t0) + 122h(t0 + )|e(t)| M12 + M28 ,where M1= maxt|h(t)|. For the ideal lowpass, we haveh(t) = 1L_ L0 sin(t)d = Lt cos(Lt) sin(Lt)Lt2 .Note that h(L) = 1/L and |h(t)| < L/2 = /2L. Thus M1 = a/L where 1 a < /2. Theno-interpolation error bound is thenh(t) a2L + 224L2 < 0.7854L + 0.4113L2 .3.6.6 Choice of Interpolation ResolutionWe now consider the error due to nite precision in the linear interpolation between stored ltercoecients. We will nd that the number of bits n in the interpolation factor should be abouthalf the lter coecient word-length nc.143.6.7 Quantized Interpolation Error BoundThe quantized interpolation factor and its complement are representable asq = + q = where, since , are unsigned, || 2(n+1). The interpolated coecient look-up then giveshqq(t) = ( )[h(t0) + 0] + ( + )[h(t1) + 1]= h(t) + 0 + 1 + [h(t1) h(t0)],where second-order errors 0 and 1 are dropped. Since |h(t1) h(t0)| M1, we obtain the errorbound|eqq(t)| 2nc+ 2(n+1)M1 + 18M2. (14)The three terms in Eq. (14) are caused by coecient quantization, interpolation quantization, andlinear-approximation error, respectively.3.6.8 Ideal Lowpass FilterFor the ideal lowpass, the error bound is|eqq(t)| 2nc+ a2(nl+n+1)+ 28 2nl.Let nl = 1 + nc/2 and require that the added error is at most 122nc. Then we arrive at therequirementn nc2 .3.7 ConclusionsA digital resampling method has been described which is convenient for bandlimited interpolationat arbitrary times and for smoothly varying sampling rates, and which is attractive for hardwareimplementation. We have presented the case which assumes uniform sampling of the input signal;however, extensions to variable sampling rates and isolated-point evaluation are straightforward.A quantization error analysis led to the conclusion that for nc-bit lter coecients, the numberof impulse-response samples stored in the lter lookup table should be on the order of 2nc/2timesthe number of zero-crossings in the impulse response, and the number of bits in the interpolationbetween impulse-response samples should be about nc/2. With these choices, the linear interpola-tion error and the error due to quantized interpolation factors are each about equal to the coecientquantization error. A signal resampler designed according to these rules will typically be limitedprimarily by the lowpass lter design, rather than by quantization eects.We note that the error analysis presented here is pessimistic in the sense that it assumes worst-case input signal conditions (e.g., a sinusoid at half the sampling rate or white noise). A dierenttype of error analysis is possible by treating the lter coecients as exact but subject to time jitter.In this approach, the error can be expressed in terms of the input signal Taylor series expansion,15and consequently in terms of the input signal bandwidth (or maximum slope). Such an analysisreveals that for most practical signals, the quantization error is considerably less than the levelsderived here.3.8 Appendix: Periodic Sinc InterpolationIt is interesting to note that all periodic sampled signals can be sinc-interpolated exactly using thefollowing formula [19]:x(t) = sin(t)2NM1

n=Lxn(1)n_(1)N+1tan_t n2N_ + cot_t n2N__, N = L + Mwhere the sampling rate is normalized to be T = 1, and the period is N = L + M samples.The rst step in the derivation is the exact general formulax(t) =

n=xnsin[(t n)](t n) (15)= sin(t)

n=xn(1)nt n (16)which follows immediately from the identity sin[(t n)] = (1)nsin(t). This form can be used todevelop a table-based sinc interpolation algorithm in which the function 1/t is sampled, windowed,and stored in a table over a small range of t. (Reverting to the weighted sinc table is advisablenear an argument of zero where there is a pole-zero cancellation in the denition of sinc, i.e., when|t n| 1.) Note that when t crosses 2, the 1/t table can be implemented as (1/2)(1/(t/2)). Inother words, the table between t = 2 and t = 4 can be computed from the table between t = 1 andt = 2 using a simple one-bit right-shift on the table address and the table output. If this trick isused, the table window must be applied separately, but there ways to synthesize simple windows(e.g., the Hanning or Hamming windows which consist of a single sinusoidal component) usingwaveform synthesis techniques, avoiding a separate table for the interpolated window function.3.9 Appendix: Relation between Sinc and Lagrange InterpolationLagrange interpolation is a well known, classical technique for interpolation [7]. It is also calledWaring-Lagrange interpolation, since Waring actually published it 16 years before Lagrange [11, p.323]. Given a set of n+1 known samples f(xk), k = 0, 1, 2, . . . , n, the problem is to nd the uniqueorder n polynomial y(x) which interpolates the samples. The solution can be expressed as a linearcombination of elementary nth order polynomials:y(x) =n

k=0lk(x)f(xk) (17)wherelk(x) = (x x0) (x xk1)(x xk+1) (x xn)(xk x0) (xk xk1)(xk xk+1) (xk xn) (18)16From the numerator of the above denition, we see that lk(x) is an order n polynomial having zerosat all of the samples except the kth. The denominator is simply the constant which normalizes itsvalue to 1 at xk. Thus, we havelk(xj) = kj=_ 1, j = k0, j = k (19)In other words, the polynomial lk is the kth basis polynomial for constructing a polynomial inter-polation of order n over the n + 1 sample points xk.In the case of an innite number of equally spaced samples, with spacing xk+1 xk = , theLagrangian basis polynomials converge to shifts of the sinc function, i.e.,lk(x) = sinc_x k_, k = . . . , 2, 1, 0, 1, 2, . . . (20)wheresinc(x) = sin(x)xA simple argument is based on the fact that any analytic function is determined by its zeros andits value at one point. Since sinc(x) is zero on all the integers except 0, and since sinc(0) = 1, itmust coincide with the innite-order Lagrangian basis polynomial for the sample at x = 0 whichalso has its zeros on the nonzero integers and equals 1 at x = 0.The equivalence of sinc interpolation to Lagrange interpolation was apparently rst publishedby the mathematician Borel in 1899, and has been rediscovered many times since [11, p. 325].A direct proof can be based on the equivalance between Lagrange interpolation and windowed-sinc interpolation using a scaled binomial window [9, 23]. That is, for a fractional sample delayof D samples, multiply the shifted-by-D, sampled, sinc functionhs(n) = sinc(n D) = sin[(n D)](n D)by a binomial windoww(n) =_ Nn_, n = 0, 1, 2, . . . Nand normalize by [23]C(D) = (1)N (N + 1)sin(D)_ DN + 1_,which scales the interpolating lter to have a unit L2 norm, to obtain the Nth-order Lagrangeinterpolating lterhD(n) = C(D)w(n)hs(n), n = 0, 1, 2, . . . , NSince the binomial window converges to the Gaussian window as N , and since the windowgets wider and wider, approaching a unit constant in the limit, the convergence of Lagrange to sincinterpolation can be seen.A more recent alternate proof appears in [24].17References[1] R. Crochiere and L. R. Rabiner, Multirate Digital Signal Processing, Englewood Clis, NJ:Prentice-Hall, 1983.[2] L. de Soras, The quest for the perfect resampler, June 20, 2003,http://ldesoras.free.fr/doc/articles/resampler.pdf.[3] DSP Committee, ed., Programs for Digital Signal Processing, New York: IEEE Press, 1979.[4] DSP Committee, ed., Programs for Digital Signal Processing II, New York: IEEE Press,1979.[5] J. A. Fessler and B. P. Sutton, Nonuniform fast Fourier transforms using min-maxinterpolation, IEEE Transactions on Signal Processing, vol. 51, pp. 560574, Feb. 2003.[6] A. A. Goldstein, Constructive Real Analysis, New York: Harper and Row, 1967.[7] F. B. Hildebrand, Introduction to Numerical Analysis, New York: Dover, 1974, Secondedition.[8] J. F. Kaiser, Using the I0 sinh window function, IEEE Transactions on Circuits andSystemsI: Fundamental Theory and Applications, pp. 2023, April 2225 1974, Reprintedin [4], pp. 123126.[9] P. J. Kootsookos and R. C. Williamson, FIR approximation of fractional sample delaysystems, IEEE Transactions on Circuits and SystemsII: Analog and Digital SignalProcessing, vol. 43, pp. 4048, Feb 1996.[10] T. I. Laakso, V. V alimaki, M. Karjalainen, and U. K. Laine, Splitting the UnitDelayTools for Fractional Delay Filter Design, IEEE Signal Processing Magazine, vol. 13,pp. 3060, Jan. 1996.[11] E. Meijering, A chronology of interpolation: From ancient astronomy to modern signal andimage processing, Proceedings of the IEEE, vol. 90, pp. 319342, Mar. 2002.[12] W. Putnam and J. O. Smith, Design of fractional delay lters using convex optimization,in Proceedings of the IEEE Workshop on Applications of Signal Processing to Audio andAcoustics, New Paltz, NY, (New York), IEEE Press, Oct. 1997,http://ccrma.stanford.edu/~jos/resample/optfir.pdf.[13] L. R. Rabiner and B. Gold, Theory and Application of Digital Signal Processing,Prentice-Hall, 1975.[14] T. A. Ramstad, Digital methods for conversion between arbitrary sampling frequencies,IEEE Transactions on Acoustics, Speech, Signal Processing, vol. ASSP-32, pp. 577591, June1984.[15] D. Rossum, Constraint based audio interpolators, Proceedings of the IEEE Workshop onApplications of Signal Processing to Audio and Acoustics, New Paltz, NY, 1993.18[16] A. J. Russel, Ecient rational sampling rate alteration using iir lters, IEEE SignalProcessing Letters, vol. 7, pp. 67, Jan. 2000.[17] A. J. Russel and P. E. Beckmann, Ecient arbitrary sampling rate conversion withrecursive calculation of coecients, IEEE Transactions on Signal Processing, vol. 50,pp. 854865, Apr. 2002.[18] R. W. Schafer and L. R. Rabiner, A digital signal processing approach to interpolation,Proceedings of the IEEE, vol. 61, pp. 692702, June 1973.[19] T. Schanze, Sinc interpolation of discrete periodic signals, IEEE Transactions on SignalProcessing, vol. 43, pp. 15021503, June 1995.[20] J. O. Smith, The window method for digital lter design, Winter 1992, Mathematicanotebook for Music 420 (EE 367A),URL:ftp://ccrma-ftp.stanford.edu/pub/DSP/Tutorials/Kaiser.ma.Z.[21] J. O. Smith and P. Gossett, A exible sampling-rate conversion method, in Proceedings ofthe International Conference on Acoustics, Speech, and Signal Processing, San Diego, vol. 2,(New York), pp. 19.4.119.4.2, IEEE Press, Mar. 1984, expanded tutorial and associated freesoftware available at the Digital Audio Resampling Home Page:http://ccrma.stanford.edu/~jos/resample/.[22] P. P. Vaidyanathan, Multirate Systems and Filter Banks, Prentice-Hall, 1993.[23] V. V alimaki, Discrete-Time Modeling of Acoustic Tubes Using Fractional Delay Filters, PhDthesis, Report no. 37, Helsinki University of Technology, Faculty of Electrical Engineering,Laboratory of Acoustic and Audio Signal Processing, Espoo, Finland, Dec. 1995,http://www.acoustics.hut.fi/~vpv/publications/vesa phd.html.[24] M. M. J. Yekta, Equivalence of the Lagrange interpolator for uniformly sampled signals andthe scaled binomially windowed shifted sinc function, Digital Signal Processing, vol. 19,pp. 838842, Sept. 2009.19