• Aucun résultat trouvé

Other schemes

Dans le document Numerical Sound Synthesis (Page 66-72)

The oscillator

3.3 Other schemes

OTHER SCHEMES 55

3.2.7 Computational considerations

The computational requirements of scheme (3.12) are most easily seen through an examination of the Matlab code in Section A.1. In each updating cycle, the algorithm requires one multiplication and one addition. Interestingly, this is nearly the same amount of computation required to generate values of a sinusoid through table reading, as is common practice in sound synthesis applications [240], as mentioned in Section 1.1.3, but with the advantage of a much reduced cost in terms of memory, as mentioned below. The use of recursive structures as a generator of sinusoids has been discussed by Smith and Cook [335]. In fact, with a small amount of additional work, a scheme can be developed which calculates exact values of the sinusoid —see Section 3.3.4.

Though, for the sake of clarity of presentation, the algorithm in Section A.1 appears to make use of three memory locations, one for the current value of the computed solution and two for the previous two values, this may be reduced to two locations through overwriting. See Programming Exercise 3.1.

which has roots

z±=1± 1−

1+ω20k2/22

1+ω20k2/2

The solution will again evolve according to (3.16) whenz+andzare distinct.

In this case, however, it is not difficult to show that the rootsz± will be complex conjugates of unit magnitude for any choice ofk. Thusz±=e±j ωk, whereω, the frequency of the sinusoid generated by the scheme, is given by

ω=1 kcos1

1 1+ω20k2/2

Againω=ω0, but, in contrast to the case of scheme (3.12), one now has ω < ω0. The result is a well-behaved sinusoidal solution of the form of (3.18) for any value ofk; there is no stability condition of the form of (3.17). (This is typical of some types of implicit schemes for PDEs —see Section 6.3.2.) The energetic analysis mirrors this behavior. Multiplying (3.25) byδuand using identities (2.22a) and (2.22e) gives

u) (δt tu)+ω02u) (μu)=δt+

1

2t−u)2+ω20 2μt−

u2

=0 or

δt+h=0 with h=t+v and t= 1

2t−u)2 v=ω20

2 μt−u2 (3.28) Now, tandv, and as a resulth, are non-negative for any choice of k. A bound on solution size follows immediately. See Problem 3.6.

3.3.2 A second-order family of schemes

Though the stability condition inherent in scheme (3.12) has been circumvented in scheme (3.25), the problem of warped frequency persists. Using combination properties of the averaging operators (see Section 2.2.2), it is not difficult to see that any scheme of the form

δt tu= −ω02+(1α)μt·) u (3.29) will also be a second-order accurate approximation to (3.1), for any choice of the real parameterα.

In fact, it would be better to say “at least second-order accurate”— see Section 3.3.4 for more discussion. There is thus a one-parameter family of schemes for (3.1), all of which operate as two-step recursions: written out in full, the recursion has the form

un+1= 2−αω20k2

1+(1α)ω02k2/2unun−1

Schemes (3.12) and (3.25) are members of this family withα=1 and α=0, respectively. See Programming Exercise 3.2.

The stability condition for the family of schemes (3.29) is now dependent on the free parameter α. Using frequency domain techniques, it may be shown that this condition is

k < 2 ω0

2α−1 for α≥ 1

2, otherwise stable (3.30)

OTHER SCHEMES 57 The scheme (3.29) also possesses a conserved energy, i.e.,

δt+h=0 with h=t+v and t= 1

2tu)2 v= ω20 2

αuetu+(1α)μt(u2) (3.31) Finding a condition such that this energy is non-negative is again equivalent to the stability bound above obtained using frequency domain techniques. See Problem 3.7.

Frequency warping

It is interesting to examine the frequency warping characteristics of various members of this family, as a function ofω0, the reference frequency for the SHO. See Figure 3.5(a). Notice that for small values ofα, lower than aboutα=0.7, the difference scheme frequency is artificially low, and for values closer toα=1, artificially high. In fact, for high values of α, there is a certain “cutoff”

frequency ω0, for which the difference scheme becomes unstable—this is readily visible in the figure. In the middle range of values ofα (between aboutα=0.7 and α=0.8), the difference scheme yields a good approximation over nearly the entire range of frequencies ω0 up to the Nyquist limit. It is useful, from a musical point of view, to plot the frequency deviation in terms of cents, defined as

deviation in cents=1200 log2 ω

ω0

(3.32) A deviation of 100 cents corresponds to a musical interval of a semitone. See Figure 3.5(b). For α=0.7, the maximum detuning is approximately two semitones and, if the sample rate is chosen sufficiently high, occurs in a region of the spectrum for which frequency discrimination in humans may not be of great importance [421]. See Programming Exercise 3.3. Note also the limited range of frequencies which can be simulated, for larger values ofα, reflecting increased strictness of the stability condition for the family of schemes, from (3.30). See also Problem 3.8.

As mentioned earlier, the effect of frequency warping in discrete-time simulations of lumped systems generalizes to the issue of numerical dispersion and thus inharmonicity in schemes for PDEs. Though, as will be seen shortly, in Section 3.3.4, the problem may be dealt with neatly in the case of the oscillator in isolation, in general the only cure is through the use of more carefully designed schemes, such as those presented in this section.

−1500

−1000

−500 0 1 0.9 0.8 500

0.7 0.5

0

1 0.9

0.8 0.7 0.5 0 00

2k p k p

k

p 0

2k p

k p

(a) (b)

w0 w0

1200 log2ww0

2k p w

Figure 3.5 (a) Frequencyωof the parameterized difference scheme (3.29) for the SHO, plotted againstω0∈[0, π/ k] as dotted lines, for various values of the free parameterα(indicated in the figure). The reference frequency is plotted as a solid black line. (b) Deviation in cents ofωfromω0

for the same members of the family, as a function ofω0∈[0, π/ k]. Zero deviation is plotted as a solid black line. Successive deviations of a musical semitone are indicated by grey horizontal lines.

3.3.3 Wave digital filters

Because scattering methods have played such a dominant role in physical modeling sound synthesis for the past 20 years, it is worth making a short detour at this point to see how they fit into the standard framework of numerical methods. Wave digital filters, developed by Fettweis [127, 126], were the first such methods to appear, though not, admittedly, in the context of musical sound synthesis —see Section 1.2.4 for some comments on the history of such methods. Though based on ideas from circuit and network theory, in the end they can be rather simply viewed as finite difference schemes. Consider a parallel combination of an inductor and a capacitor, orLC circuit, as shown in Figure 3.6(a). An electrical network theorist would describe this system in the following way: supposing that the voltage across and current through the inductor (of inductance L) are u1 and i1, and the voltage across and current through the capacitor (of capacitance C) are u2 and i2, then the following four equations describe the dynamics of the parallel combination:

u1=Ldi1

dt i2=Cdu2

dt u1=u2 i1+i2=0 (3.33)

The first two equations describe the internal behavior of the circuit elements themselves, and the last two are Kirchhoff’s connection rules for a parallel combination of two circuit elements. The above system (3.33) of four equations in four unknowns can be reduced to the SHO (3.1) with ω0=1/√

LC, with a dependent variable which is any of u1, u2, i1, ori2. (The analogy of the electrical network with an acoustical system such as that which might arise in a musical instrument model is direct: replacing currents with velocities, voltages with forces, and the inductance and capacitance with mass and the inverse of stiffness respectively, one arrives immediately at a simple mass – spring system.)

The wave digital discretization procedure relies on essentially two manipulations. The first is the discrete approximation of the first two of (3.33) through the trapezoid rule (see page 37); in terms of the difference operators that have been defined in this book, these discretized equations may be written as

μt+u1=t+i1 μt+i2=t+u2 (3.34) or, expanding out this notation and introducing a time indexn,

un1+1+un1=2L k

i1n+1i1n

in2+1+in2 =2C k

un2+1un2

(3.35) The connection rules are assumed to hold instantaneously in discrete time. The second manipulation is the introduction of wave variables:

a1=u1+R1i1 2√

R1

b1= u1R1i1 2√

R1

a2= u2+R2i2 2√

R2

b2= u2R2i2 2√

R2

Inductor Capacitor

L C k k

−1 Parallel

connection

Parallel adaptor WD one-port

inductor

WD one-port capacitor u1

i1

u2 i2

R1=2L

k R2 =2Ck

(a) (b)

Figure 3.6 TheLCcircuit: (a) a parallel connection of an inductor of inductanceLand a capacitor of capacitanceC; and (b) the corresponding wave digital network.

OTHER SCHEMES 59 Here, two positive constants,R1 andR2, called port resistances have been assigned to the induc-tor and capaciinduc-tor, respectively. Under the special choices of R1=2L/ k and R2=k/(2C), the recursions (3.35) reduce to

bn+11 = −a1n bn+12 =a2n (3.36) These are the defining equations of the wave digital inductor and capacitor, respectively —notice that they involve only shifting operations (with sign inversion in the case of the inductor), and are thus strictly causal. They do, however, act in isolation, and must be connected through the equations which result from the substitution of wave variables into the connection rules:

an1 an2

⎦=

⎣−1+R2R1+R22 2R1R+R1R22

2 R1R2

R1+R2 −1+R12R+R12

bn1 bn2

⎦ (3.37)

This operation, called scattering, is at the heart of wave digital filtering, and is viewed as a two-port element in its own right, called an adaptor. Notice that the matrix operation above is orthogonal, preserving the “energy” orl2norm of wave variables through the scattering operation.2 The scattering formulation may be extended to the connection of as many elements as desired, all the while maintaining this property of orthogonality, or losslessness. The wave digital discretization of the parallel inductor/capacitor combination is complete, and is illustrated in Figure 3.6(b); in each step in the recursion that the structure implies, there will occur a scattering step (at a wave digital adaptor), and a shifting of data. Such a mode of operation is also characteristic of digital waveguide networks.

One of the nice features of wave digital networks is that the energetic properties are funda-mentally built in to the scattering and shifting operations. For example, using the orthogonality of the scattering matrix, in (3.37) and the simple shifting operations above in (3.36), it is simple to show, in this case, that

a1n+1

2

+ a2n+1

2

= bn+1 1

2

+ bn+2 1

2

= an12

+ a2n2

or

an12

+ a2n2

=constant (3.38)

implying losslessness, using wave variables. This should come as no surprise—combining the two recursions in (3.34) leads immediately to the difference scheme (in, say,u=u1=u2)

δt tu= −ω20μt tu

which is a member of the family (3.29) of schemes for the SHO, withα=1/2 andω02=1/(LC).

See also Programming Exercise 3.4. As was shown earlier, this scheme possesses a conserved energy, given in (3.31); this is in fact identical to the conserved quantity for the wave digital network, from (3.38). (Notice, however, that scheme (3.29) with α=0.5 behaves quite poorly with regard to frequency warping, as illustrated in Figure 3.5.)

2Though power-normalized waves, which give rise to orthogonal scattering matrices, have been used here, it is by no means necessary to use such wave variables. Simple “voltage waves” are in fact the norm in most applications of wave digital filters, including sound synthesis. In this case, scattering matrices are no longer orthogonal, but rather orthogonal with respect to a weighting of the port resistances —energy conservation holds in this case as well. For nonlinear networks, however, power-normalized waves are necessary in order to ensure passivity. See, for example, [128, 129, 41].

Energy conservation and the good stability properties that follow from it have been a primary selling point of wave digital filtering methods; another is the manner in which a complex system may be broken down into modular components, which behave strictly causally, leading to fully explicit methods. But, as has been seen throughout this chapter, at least in the case of the SHO, energy conservation follows from the simplest imaginable difference schemes; one need not restrict oneself to the use of a particular numerical integration method (such as the trapezoid rule) in order to obtain this property. Indeed, the entire apparatus of network theory and scattering is not necessary to show such conservation properties, or numerical stability. The modularity argument is also somewhat misleading: though for certain circuit networks, it is indeed possible to arrive at fully explicit methods using wave digital discretization principles, there are many (such as those involving nonlinearities) for which this is rather strenuous —a delicate juggling of port resistances, through the use of so-called reflection-free ports [130], will be necessary. This approach has been taken by some in sound synthesis applications —see Section 1.2.4 on hybrid methods. Often, however, simple finite difference schemes are explicit, such as those for the SHO. In short, wave digital filters are intuitively appealing but somewhat restrictive, and perhaps overly complicated, and do not lead to any real gains in terms of efficiency or ease of analysis, at least for simulation purposes. On the other hand, if one is making use of digital waveguides, which are genuinely more efficient than finite difference schemes for a certain range of applications, then wave digital filters are an excellent match when used in order to model, say, waveguide terminations, or connections with lumped elements.

3.3.4 An exact solution

For this very special case of the SHO, there is in fact a two-step recursion which generates the exact solution to (3.1), at timest=nk. It is simply given by

un+1−2 cos(ω0k)un+un−1=0 (3.39) This recursion may be more familiar to electrical and audio engineers as a two-pole filter operating under transient conditions. Thez transformation analysis reveals

z−2 cos(ω0k)+z−1=0 which has solutions

z±=cos(ω0k)±jsin(ω0k)=e±j ω0k −→ ω=ω0

Thus the oscillation frequency ω of recursion (3.39) is exactly ω0, the frequency of the continuous-time oscillator (3.1). In a sense, then, all the preceding analysis of difference schemes is pointless, at least in the case of (3.1). On the other hand, the SHO is pathological; more complex systems, especially when nonlinear, rarely allow for exact numerical solutions. One other case of interest, however, and the main reason for dwelling on this point here, is the 1D wave equation, to be introduced in Chapter 6, which is of extreme practical importance in models of musical instruments which are essentially 1D, such as strings and acoustic tubes. Numerical methods which are exact also exist in this case, and have been exploited with great success as digital waveguides [334].

Another question which arises here is that of accuracy. Consider again the one-parameter family of two-step difference schemes given by (3.29). Using identity (2.7a) relatingμt·toδt t, it may be rewritten as

δt tu= −ω20 1+ω20(1α)k2

2 u

LUMPED MASS–SPRING NETWORKS 61 Under the special choice of

α= 2

ω20 − cos(ω0k)

1−cos(ω0k) (3.40)

the difference scheme becomes exactly (3.39), or

δt t+ 2

k2(1−cos(ω0k))

P

u=0 (3.41)

Consider the action of the operatorP as defined above on a continuous function. Expanding the operatorδt t and the function cos(ω0k)in Taylor series leads to

P =

l=1

2k2(l−1) (2l)!

d2l

dt2l +(−1)l−102lk2(l1) (2l)! =

l=1

2k2(l−1) (2l)!

d2l

dt2l+(−1)l−1ω2l0

The various terms of the form d2l

dt2l +(−1)l−1ω2l0

(3.42) all possess a factor ofd2/dt2+ω02. Thus (3.41) may be rewritten as

1+O(k2) d2 dt2+ω20

u=0

which shows that the solutionuindeed solves the equation of the SHO exactly.

This property of accuracy of a difference scheme beyond that of the constituent operators, under very special choices of the scheme parameters, is indeed a very delicate one. In the distributed setting, it has been exploited in the construction of so-called modified equation methods [181, 323, 259, 260, 98] and compact spectral-like schemes [222, 419, 203, 227].

3.3.5 Further methods

In this book, relatively simple difference strategies will be employed whenever possible. On the other hand, sometimes more accurate methods are necessary, especially when one is interested in more delicate modeling of musical instrument physics. There are a large variety of time differencing methods which are in use for the solutions of ODEs; normally, these are framed in terms of a first-order system, and so do not fit well into the main development here. Some of the better known are Adams –Bashforth, Adams –Moulton, and Runge–Kutta methods.

There do exist, however, some families of methods which have been developed directly for use with second-order systems, generally for application to problems in structural dynamics, such as those which occur in musical acoustics —among these are the Newmark family of schemes [256], as well as those proposed by Hilber, Hughes, and Taylor [168].

Dans le document Numerical Sound Synthesis (Page 66-72)