Interpolation
2.3 Trigonometric Interpolation
EXAMPLE [taken from Bulirsch and Rutishauser (1968)]. For the function f(x) = cot x the values cot 1 0, cot 2°, ... have been tabulated. The problem is to determine an approximate value for cot 2°30'.
Polynomial interpolation of order 4, using the formulas (2.1.2.4), yields the tableau
Xi /; = cot (Xi) 1° 57.28996163
14.30939911
2° 28.63625328 21.47137102
23.85869499 22.36661762
3° 19.08113669 23.26186421 22.63519158
21.47137190 23.08281486
4° 14.30066626 22.18756808
18.60658719 5° 11.43005230
Rational interpolation with (j.l, v) = (2, 2) using the formulas (2.2.3.8) in contrast gives
1° 57.28996163
22.90760673
2° 28.63625328 22.90341624
22.90201805 22.90369573
3° 19.08113669 22.90411487 22.9037655J.
22.91041916 22.90384141
4° 14.30066626 22.90201975
22.94418151 5° 11.43005230
The exact value is cot 2°30' = 22.903 765 5484 ... ; incorrect digits are underlined.
A similar situation is encountered in extrapolation methods (see Sections 3.4,3.5, 7.2.3, 7.2.14). Here a function T{h) of the step length h is interpolated at small positive values of h.
(2.3.1.1b) A M-l A
\}I(x)
= T +
h~l (Ah cos hx+
Bh sin hx)+
2M cos Mx of, respectively, N = 2M+
1 or N = 2M support points (Xk'he),
k = 0, ... , N - 1. Interpolation by such expressions is suitable for data which are periodic of known period. Indeed, the expressions \}I(x) in (2.3.1.1) represent periodic functions of x with the period 2n.lConsiderable conceptual and algebraic simplifications are achieved by using complex numbers and invoking De Moivre's formula
ekix
=
cos kx+
i sin kx.Here and in what follows, i denotes the imaginary unit. If c
=
a+
ib, a, b real, thenc
= a - ib is its co~lex con' u ate, a is the real part of c, bits imaginary part, andI
cI =
.j cc=
a2+
b2 its absolute value.Particularly important are uniform partitions of the interval [0, 2n]
Xk
=
2nkjN, k=
0, ... , N-1to which we now restrict our attention. For such partitions, the trigonomet- ric interpolation problem can be transformed into the problem of finding a phase polynomial
(2.3.1.2)
with complex coefficients
P
j such thatk
=
0, ... , N - 1.Indeed
and therefore (2.3.1.3)
Making these substitutions in expressions (2.3.1.1) for \}I(x) and then collect- ing the powers of eixt produces a phase polynomial p(x), (2.3.1.2), with
1 If sin u and cos u have to be both evaluated for the same argument u, then it may be advantageous to evaluate t = tan(u/2) and to express sin u and cos u in terms of t:
. 2t
sm u = 1 + t2 ' cosu=1+t1 - t2 2 '
This procedure is numerically stable for 0 ,,;; u ,,;; 1[/4, and the problem can always be trans- formed so that the argument falls into that range.
coefficients
P
j ,j=
0, ... , N - 1 which are related to the coefficients Ah , Bh of 'P(x) as follows:(2.3.1.4)
(a) If N is odd, then N = 2M
+
1 andPO=2'
Ao Ao=
2Po,(b) If N is even, then N = 2M and
Po =
Ao2'
Pj=
t(Aj - iBj), PN-j=
t(Aj+
iBj ), j=
1, ... , M - 1,PM=T;
AMAo
=
2Po, Ah=
Ph+
PN-h, Bh=
i(Ph - PN-h), h=
1, ... , M - 1, AM=
2PM.The trigonometric expression 'P(x) and its corresponding phase polyno- mial p(x) agree for all support arguments Xk = 2nk/N of an equidistant partition of the interval [0, 2n]:
k = 0, 1, ... , N - 1.
However, 'P(x) = p(x) need not hold at intermediate points x+-Xk. The two interpolation problems are equivalent only insofar as a solution to one problem will produce a solution to the other via the coefficient relations (2.3.1.4).
The phase polynomials p(x) in (2.3.1.2) are structurally simpler than the trigonometric expressions 'P(x) in (2.3.1.1). Upon abbreviating
and since W j +-Wk for j +- k,
°
~ j, k ~ N - 1, it becomes clear that we are faced with just a standard polynomial interpolation problem in disguise:find the (complex) algebraic polynomial P of degree less than N with k
=
0, ... , N - 1.The uniqueness of polynomial interpolation immediately gives the following
(2.3.1.5) Theorem. For any support points (Xk,
h),
k = 0, ... , N - 1, withh
complex and Xk
=
2nk/ N, there exists a unique phase polynomial p(x)=
Po+
Pl e ix+ ... +
PN-l e(N-l)ixwith
for k = 0, 1, ... , N - 1.
The coefficients
Pi
of the interpolating phase polynomial can be expressed in closed form. To this end, we note that, for 0 ::;;; j, h ::;;; N - 1(2.3.1.6)
More importantly, however, we have for 0 ::;;; j, h ::;;; N - 1 (2.3.1.7) N - l .
L
w{.W;h = {N for j = h,k = 0 0 for j =F h.
PROOF. Wj-h is a root of the polynomial
N-l w N - 1 = (w -1)
L
w k,k=O
from which either Wj-h = 1, and therefore j = h, or
N-l N-l N-l
"" ,.,; W- h -L. UlJc: k - "" ,.,;- h -L. UlJc: - "" L. wk j-h -- 0 .
o
k=O k=O k=O
Introducing the N-vectors
W(h) = (1, w~, ... , W~_dT, h = 0, ... , N - 1,
we see that the sums in (2.3.1.7) are the complex scalar products of the vectors w(j) and W(h):
N-l
(2.3.1.8)
L
evi,w;h=
WU)TW(h)=
[w(j), W(hl].k=O
This definition of the scalar product of two complex vectors is standard;
it implies that [w. w] =
2;;J IWh
12 ~ 0 for each complex vector w.Thus the vectors W(h) are seen to form an ortho onal basis of the complex space
eN.
Note that the vectors are of length [W(h), w( )] =jN
instead of length 1, however.From the orthogonality of the vectors W(h) follows:
(2.3.1.9) Theorem. The phase polynomial p(x) = L7~Ol Pjeiix satisfies P(Xk) =
h ,
k = 0, 1, ... , N - 1,for j,. complex and Xk
=
2nk/N,if
and onlyif
I N - 1 I N - 1
f3j=-
L
j,.w;j=-L
j,.e-21tijk/N,N k=O N k=O j
=
0, 1, ... , N - 1.PROOF. With the vector notation f
=
(fo, fl' ... ,fN _ 1 )T,1 N-l . 1 . 1 .
N k~O j,.w;J
=
N[f, w(})]=
N[f3o w(O)+ ... +
f3N_1W(N-l), w(})]=
f3j. 0 For phase polynomials q(x) of degree at most s, s ~ N - 1 given, it is in general not possible to make all residualsk
=
0, ... , N - 1,vanish~ as they would for the interpolating phase polynomial. In this context, the s-segments
Ps{x)
= 130 +
f31eiX+ ... +
f3se'iXof the interpolating polynomial p(x) have an interesting best-approximation property:
(2.3.1.10) Theorem. The s-segment Ps(x),
°
~ s < N, of the interpolating phase polynomial p(x) minimizes the sumN-l
S(q) =
L
1he -
q(Xk) 12k=O
[note that S(p) = 0] of the squared absolute values of the residuals over all phase polynomials
q(x)
=
Yo+
1'1 eix+ ... +
yse'iX.The phase polynomial Ps(x) is uniquely determined by this minimum property.
PROOF. We introduce the vectors
P. = (P.(xo), ... , Ps(xN-tlf, q
=
(q(xo), ... , q(XN-1W and use the scalar product (2.3.1.8) to writeS(q)
=
[J - q,f - q].By Theorem (2.3.1.9), f3j == (I/N)[f, w(j)] for j
=
0, ... , N - 1. For j ~ s,~
[J - Ps' w(j)]= ~
[f -htlhW(h),
w(j)]=
f3j - f3j=
0,and
[J - p., Ps - q] =
L •
[J - p., (f3j - Yj)w(j)] =o.
j=O
But then we have
S{q) = [f - q,f - q]
=
[f - Ps+
Ps - q,f -
Ps+
Ps - q]=
[f - Ps,f -
Ps]+
[Ps - q, Ps - q]~ [f - Ps,f - Ps]
=
S{Ps).Equality holds only if [Ps - q, Ps - q]
=
0, i.e., if the vectors Ps and q are equal. Then the phase polynomials Ps(x) and q(x) are identical by theuniqueness theorem (2.3.1.5). 0
Returning to the original trigonometric expressions (2.3.1.1), we note that Theorems (2.3.1.5) and (2.3.1.9) translate into the following:
(2.3.1.11) Theorem. The trigonometric expressions 'I'{x)
= ~O + h~O
(Ah cos hx+
Bh sin hx)A M-l A
'I'{x) =
i +
h~O (Ah cos hx+
Bh sin hx)+
2M cos Mx, where N = 2M+
1 and N = 2M, respectively, satisfy'I'{Xk)
=
fb k=
0,1, ... , N - 1,for Xk = 2nk/N
if
and onlyif
the coefficients of'l'(x) are given by2 N - 1 2 N - 1 2nhk
Ah
=
NL
fk cos hXk=
NL he
cos -N 'k=O k=O
2 N - 1 2 N - 1 2nhk
Bh = N
L he
sin hXk = NL he
sin -N .k=O k=O
PROOF. Only the expressions for Ah, Bh remain to be verified. For by (2.3.1.4)
. N-l
Bh
=
i{Ph - PN-h)=
~L
he{e- hixk - e-(N-h)ixk), N k=Oand the substitutions (2.3.1.3) yield the desired expressions.
o
Note that if the support ordinates
he
are real, then so are the coefficients Ah, Bh in (2.3.1.11).2.3.2 Fast Fourier Transforms
The interpolation of equidistant support points (Xk' f,,), Xk = 2nk/ N, k = 0, ... , N - 1, by a phase polynomial p(x) = L7~Ol
P
jei
ix leads to expressions of the form [Theorem (2.3.1.9)]1 N-l
P
j = NL
f"e-21tijk/N,k=O
(2.3.2.1 ) j = 0, ... , N - 1.
The evaluation of such expressions is of prime importance in Fourier analysis. The expressions occur also as discrete approximations-for N equidistant arguments s-to the Fourier transform
H(s):=
f
+00 f(t)e-21tist dt,-00
which pervades many areas of applied mathematics. However, the numerical evaluation of expressions (2.3.2.1) had long appeared to require on the order of N2 multiplications, putting it out of reach for even high-speed electronic computers for those large values of N necessary for a sufficiently accurate discrete representation of the above integrals. The discovery [Cooley and Tukey (1965)] of a method for rapidly evaluating (on the order of N log N multiplications) all expressions (2.3.2.1) for large special values of N has therefore opened up vast new areas of applications. This method and its variations are called fast Fourier transforms. For a detailed treatment see Brigham (1974) and Bloomfield (1976).
There arc two main approaches, the original Coo ley- Tukey method and one described by Gentleman and Sande (1966), commonly called the Sande- Tukey method. Both approaches rely on an integer factorization of Nand decompose the problem accordingly into subproblems of lower degree.
These decompositions are then carried out recursively. This works best when
N= 2n, n >
°
integer.We restrict our presentation to this most important and most straightfor- ward case, although analogous techniques will clearly work for the more general case N = N 1 N 2 ... N n' N m integer.
The Cooley-Tukey approach is best understood in terms of the interpola- tion problem described in the previous section (2.3.1). Suppose N = 2M and consider the two interpolating phase polynomials q(x) and r(x) with
q(X2h) = f2h' r(x2h) = f2h+ b h = 0, ... , M - 1.
The phase polynomial q(x) interpolates all support points of even index, whereas the phase polynomial r(x) = r(x - 2n/N) = r(x - n/M) interpo- lates all those of odd index. Since
eMixk _ e21tiMk/N _ e1tik _ - - - I 1+1,
\ -1,
keven, k odd,
the complete interpolating phase polynomial p(x) is now readily expressed in terms of the two lower-degree phase polynomials q(x) and r(x):
(2.3.2.2) p(x) = q(x) ( 1
+
2 eMiX)+
r(x - 1t/M)(1 _
2 eMiX) .This suggests the following n step recursive scheme. For m ~ n, let M = 2m -1 and R = 2n - m•
Step m then consists of determining R phase polynomials P(m) = a(m)
+
a(m)eix+ ... +
a(m) e(2M - l)ixr PrO Prl Pr,2M-l , r = 0, ... , R - 1,
from 2R phase polynomials p~m-l)(x), r = 0, ... , 2R - 1, using the recursion (2.3.2.2):
This relation gives rise to the following recursive relationship between the coefficients of the above phase polynomials:
(2.3.2.3) =
j3(~-I) rj
+
j3(m-1)B j R+r,j m I r2j3(m) r,M+j . = j3(~-rj 1) _ j3(m- 1)'B j R+r,j I ~ m /
r = 0, ... , R - 1, j = 0, ... , M - 1, where
m=O, ... , n.
The recursion is initiated by putting
a(0) := {' k
°
N 1PkO Jb =, ... , - ,
and terminates with
j = 0, ... , N - 1.
This recursion typifies the Cooley-Tukey method.
The Sande-Tukey approach chooses a clever sequence of additions in the sums L~~l he e-jiXk. Again with M = N/2, we assign to each termhe e-jiXk an opposite term fk+Me-jiXk+M. Summing respective opposite terms in (2.3.2.1) produces N sums of M = N/2 terms each. Splitting those N sums into two sets, one for even indices j = 2h and one for odd indices j = 2h
+
1, will lead to two problems of evaluating expressions of the form (2.3.2.1), each prob- lem being of reduced degree M = N/2.Using the abbreviation
again, we can write the expressions (2.3.2.1) in the form 1 N-l
j3j = N
L
heB~k,k;O j = 0, ... , N - 1.
Here n is such that N = 2n. Distinguishing between even and odd values ofj and combining opposite terms gives
1 N - 1 1 M- 1 1 M- 1
P2h
=
NL
f,.c;hk=
NL
(f,.+
f,.+M)C="--1=
NL
fleC="--1k=O k=O k=O
1 N - 1 1 M- 1 1 M- 1
P 2h+ 1 -_ ~ N k~O " Jkcn # (2h+ 1)k _ _ "(( - N k~O Jk Jk+M c# _ # ) k) hk n cn-1 -- _ " f" hk N k~O kCn-1 for h =
° ... ,
M - 1 and M:= N/2, since c; = Cn-1' c';; = -1. Herefie
=
f,.+
f,.+MI
f~ =
(f,. - f,.+M)C:~
k=
0, ... , M - 1.In order to iterate this process for m
=
n, n - 1, ... , 0, we let M := 2m -1,R := 2n- m and introduce the notation
f~k)' r
=
0, ... , R - 1, k=
0, ... , 2M - 1,with f~~ = f,., k = 0, ... , N - 1. f~k-1) and 11k- 1) represent the quantities fk and f~
,
respectively, which were introduced above. In general we have, with M = 2m -1 and R = 2n - m,1 2M-1 (2.3.2.4) PjR+r = -
L
f~k)cf::,N k=O r = 0, ... , R - 1, j = 0, ... , 2M - 1, with the quantities f~k) satisfying the recursions:
I
m= n, ... ,1,f~k-1) = f~k)
+
f~~k+MI
I ; r = 0, ... , R - 1, f~~R~l = (f~k) - f~~~+M)C~ ~
I I
k=
0, ... , M - 1.(2.3.2.5)
PROOF. Suppose (2.3.2.4) is correct for some m:::; n, and let M':= M/2
=
2m - 2 , R' :=2R=
2n - m+1• For j=
2h and j=
2h+
1, respec- tively, we find by combining opposite terms1M-1 1 2M'-1
PhR'+r
=
PjR+r=
NL
(f~~~+
f~~~+M)cf::=
NL
f~~k-1)c::;"_1'k=O k=O
1 M-1
PhR'+r+R
=
PjR+r=
NL
(f~~~ - f~~~+M)ci,:k=O
1 M-1 1 2M'-1
= N
L
(f~~~ - f~~~+M)C~C::;"-1 = NL
f~~I/lc::;"-1'k=O k=O
where r
=
0, ... , R - 1, j=
0, ... , 2M - 1.o
The recursion (2.3.2.5) typefies the Sande-Tukey method. It is initiated by putting
f
(n):=# Ok Jk, k=
0, ... , N - 1,and terminates with
P
, N :=_/(0) 1,0,
r = 0, ... , N - 1.Returning to the Cooley-Tukey method for a more detailed algorithmic formulation, we are faced with the problem of arranging the quantities f3';.j) in an array:
I(
=
0, ... , N - 1.Among suitable maps I( = I((m, r, j), the following is the most straightforward:
m
=
0, ... , n, r=
0, ... , 2n - m - 1, j=
0, ... , 2m - 1.It has the advantage, that the final results are automatically in the correct order. However, two arrays
PT ], P[ ]
are necessary to accommodate the left- and right-hand sides of the recursion (2.3.2.3).We can make do with only one array
P[ ]
if we execute the transforma- tions "in place," that,is,
if we let each pair of quantities f3';.j), f3';.~k + i occupy the same positions in P[ ] as the pair of quantitiesf3';.j-l), P<;;/},
from w~ich the former are computed. In this case, however, the entries in the array P[ ]are being permuted, and the maps which assign the positions in
P[ ]
as afunction of the integers m, r, j become more complicated. Let r = r(m, r,j)
be a map with the above mentioned replacement properties, namely
p[r]
= f3';.j) withr(m, r, j)
=
r{m - 1, r, j)(2.3.2.6) .,
r(m, r,j
+
2m-1 ) = r(m - 1, r+
2n-m,j)~~m=l, ... ,n,
i r
=
0, ... , 2n - m - 1,I
j ='0, ... , 2m -1 - 1, and(2.3.2.7) r(n, 0, j) = j, j
=
0, ... , N - 1.The last condition means that the final result
Pi
will be found in positionj in the arrayP[ ]: Pi
=PU].
The conditions (2.3.2.6) and (2.3.2.7) define the map r recursively. It remains to determine it explicitly. To this end, let
rt.p = 0, 1 for p = 0, ... , n - 1, be a binary representation of an integer t, 0 :::; t < 2n. Then putting (2.3.2.8) p(t) :=rt.n-1
+
rt.n-2 ·2+ ... +
rt.o ·2n-1defines a permutation of the integers t
=
0, ... , 2n - 1 called bit reversal. The bit-reversal permutation is symmetric, i.e. p(p(t»=
t.With the help of the bit-reversal permutation p, we can express r(m, r,j) explicitly:
(2.3.2.9) r(m, r, j) = p(r)
+
j,m = 0, ... , n, r = 0, ... , 2n - m - 1, j = 0, ... , 2m - 1.
PROOF. If again
t
=
(Xo+
(Xl • 2+ ... +
(Xn-l • 2n-1,
(Xp=
0, 1 for p=
0, ... , n - 1, then by (2.3.2.6) and (2.3.2.7)_ ( ° ) _
{r(n - 1, 0, t) if (Xn-l= °
t - r n, ,t - r ( n - , 1 1 ,t - 2n - 1)·f 1 (Xn-l
= .
1 Thust
=
r(n, 0, t)=
r(n - 1, (Xn- b (Xo+ ... +
(Xn-2 ·2n - 2 ),and, more generally,
t = r(n, 0, t) = r(m, (Xn-l
+ ... +
(Xm· 2n - m - 1, (Xo+ ... +
(Xm-l ·2m -1 )for m
=
0, ... , n - 1. For r=
(Xn-l+ ... +
(Xm· 2n - m - 1, we find p(r) = (Xm • 2m+ ... +
(Xn-l • 2n - 1and t = p(r)
+
j.By the symmetry of bit reversal,
r(m, p(r), j) = r
+
j,D
where
r
is a multiple of 2m,°
~r
< 2n, and°
~ j < 2m. Observe that if°
~ j < 2m - 1, thent = r(m, p(r), j) = r(m - 1, p(r), j) = r
+
j,t
= r(m, p(r), j+
2m - 1 ) = r(m - 1, p(r)+
2n - m, j) = r+
j+
2m - 1 mark a pair of positions inP[ ]
which contain quantities connected by the Cooley-Tukey recursions (2.3.2.3).In the following pseUdO-ALGOL formulation of the classical Cooley- Tukey method, we assume that the array
P[ ]
is initialized by puttingP[P(k)] :=fb k = 0, ... , N - 1,
where p is the bit-reversal permutation (2.3.2.8). This" scrambling" of the initial values can also be carried out "in place," because the bit-reversal permutation is symmetric and consists, therefore, of a sequence of pairwise interchanges or "transpositions." In addition, we have deleted the factor 2 which is carried along in the formulas (2.3.2.3), so that finally
P
j := N 1 -PU],
j = 0, ... , N - 1.The algorithm then takes the form for m := 1 step! until n do
begin for j :=
°
step 1 until 2m - 1 - 1 do begin e :=e!..;
end
end;
for
r
:=°
step 2m until 2" - 1 dobegin u :=
p[r +
j]; V :=p[r +
j+
2m -1] X e;p[r +
j] := U+
v;p[r +
j+
2m - 1] := U - Vend
If the Sande-Tukey recursions (2.3.2.5) are used, there is again no prob- lem if two arrays of length N are available for new and old values, respec- tively. However, if the recursions are to be carried out" in place" in a single array
J[ ],
then we must again map index triples m, r, j into single indices r.This index map has to satisfy the relations r(m - 1, r, k)
=
r(m, r, k), r(m - 1, r+
2"-m, k) = r(m, r, k+
2m-1 )for m
=
n, n - 1, ... ,1, r=
0,1, ... , 2"-m - 1, k=
0,1, ... , 2m-1 - 1. If we assumer(n, 0, k) = k for k = 0, ... , N - 1,
that is, if we start out with the natural order, then these conditions are precisely the conditions (2.3.2.6) and (2.3.2.7) written in reverse. Thus r
=
r(m, r, k) is identical to the index map r considered for the Cooley- Tukey method.In the following pseUdO-ALGOL formulation of the Sande-Tukey method, we assume that the array ][ ] has been initialized directly with the values fk :
J[k] :=
h,
k = 0, 1, ... , N - 2.However, the final results have to be "unscrambled" using bit reversal, 1 _
Pj := N [J[pU)], j
=
0, ... , N - 1:for m := n step - 1 until 1 do
begin for k :=
°
step 1 until 2m - 1 - 1 do begin e:= t:~;for
r
:=°
step 2m until 2" - 1 dobegin u :=
IF +
k]; V :=J[r +
k+
2m - I];J[r +
k] :=u+
V;J[r
+k+
2m - I ] :=(u - V) X e endend
end;
If all values
h,
k = 0, ... , N - 1 are real and N = 2M is even, then the problem of evaluating the expressions (2.3.2.1) can be reduced in size by puttinggh = i2h
+
if2h+ band evaluating the expressions 1 M-l ..
Y . = _ ~ g e- 2'tlJh/M
J M L... h ,
h=O
h = 0, ... , M - 1,
j = 0, ... , M - 1.
The desired values
p
j , j = 0, ... , N - 1, can be expressed in terms of the values Yj,j = 0, ... , M - 1. Indeed, one has with YM :=yo(2.3.2.10)
P _
1 ( _ )+
~( _ - ) -
27tij/Nj -
4.
Yj+
YM - j 4i Yj YM - j e ,j=o, ...
,M,PN -
j =P
j , j = 1, ... , M - 1.PROOF. It is readily verified that
1 1 M-l
-4(Yj
+
1M-j) = NI
i2he-27tij2h/N, h=O1 1 M-l
_(y._y- .)=_ ~ r e- 27tij(2h+l)/N+27tij/N
4 · J M-J N L... J2h+l •
I h=O D
In many cases, particularly if all values f,. are real, one is actually in- terested in the expressions
2 N-l 2njk Aj
=
N I i k cos -N 'k=O
2 N-l . 2njk Bj=N k=O
Ih
sm -N 'which occur, for instance, in Theorem (2.3.1.11). The values A j ' Bj are con- nected with the corresponding values for
P
j via the relations (2.3.1.4).2.3.3 The Algorithms of Goertzel and Reinsch
The problem of evaluating phase polynomials p(x) from (2.3.1.2) or trigo- nometricexpressions 'P(x) from (2.3.1.1) for some arbitrary argument x = ~ is called Fourier synthesis. For phase polynomials, there are Horner-type eval- uation schemes, as there are for expressions (2.3.l.1a) when written in the form 'P(x) =
If= _
M pje jix. The numerical behavior of such evaluation schemes, however, should be examined carefully.For example, Goertzel (1958) proposed an algorithm for a problem closely related to Fourier synthesis, namely, for simultaneously evaluating the two sums
N-l N-l
I
Yk cos k~,I
Yk sin k~k=O k=l
for a given argument ~ and given values Yk, k = 0, ... , N - 1. This algorithm is not numerically stable unless it is suitably modified. The algorithm is based on the following:
(2.3.3.1) Theorem. For ~ =1= nt, r = 0, ± 1, ±2, ... , define the quantities 1 N-1
Uj:=~ LYksin(k-j+1g, j=0,1, ... ,N-1,
SIll .. k=j UN:= UN+1 :=0.
These quantities satisfy the recursions
(2.3.3.1 a) Uj
=
Y + 2Uj+ 1 cos ~ - Uj+ 2, j=
N - 1, N - 2, ... , O.I n particular
N-1
(2.3.3.1b)
L
Yk sin k~=
U 1 sin ~, k=1N-1
(2.3.3.1c) L Yk cos k~
=
Yo + U 1 cos ~ - U 2 .k=O
PROOF. For 0 ~j ~ N - 1, let
A:=Yj+2Uj+1COS~- Uj+2.
By the definition of Uj+ b Uj+2 ,
1 { N - 1 N-1 }
A = Yj + -. -" .2(cos
0
L Yk sin(k - j)~ ~ L Yk sin(k - j - 1)~SIll .. k=j+1 k=j+2
1 N-1
= Yj + ~.
I
Yk[2 cos ~ sin(k - jg - sin(k - j - 19].SIll.. k=j+1 Now
2 cos ~ sin(k - jg
=
sin(k - j + 1)~ + sin(k - j - 19.Hence
1 [ N - 1 ]
A=~ Yjsin~+
L
y"sin(k-j+1g =Uj •SIll .. k=j+1
This proves (2.3.3.1 a ). (2.3.3.1 b) restates the definition of U l' To verify (2.3.3.1c), note that
1 N-1 1 N-1
U 2
=
~.L
y" sin(k - 1 g=
~.L
y" sin(k - 1 )~,. SIll..
,,=
2 SIll.. k=
1and
sin(k -
19 =
cos ~ sin k~ - sin ~ cos k~.o
Goertzel's algorithm applies the recursions (2.3.3.1) directly:
U[N]:= U[N
+
1] :=0; C :=cos(~); cc :=2 x c;for j := N - 1 step - 1 until 1 do
UU]:= yU]
+
cc x UU+
1] - UU+
2];s1:= y[O]
+
C x U[1] - U[2];s2:= U[1] x sin(~);
to find the desired results s1
= L;:J
Yk cos k~, s2= L;:l
Yk sin k~.This algorithm is unfortunately not numerically stable for small absolute values of~,
I
~I
~ 1. Indeed, having calculated c=
cos ~, the quantity s1 =L;:J
Yk cos k~ will depend solely on c and the values Yk' We can write s1=
<p(c, Yo, ... , YN-1)' whereN-1
<p(c, Yo, ... , YN-
d = L
Yk cos k(arccos c).k=O
As in Section 1.2, we denote by eps the machine precision. The roundoff error Ac = eeC' leel ~ eps, which occurs during the calculation of c, causes an absolute error A.s1 in s1, which in first-order approximation amounts to
A 1 . O<p A _ Ee cos ~ N~1k . kJ:
OeS = ; ) oC - . J: L. Yk sm ..
uC sm.. k=O
= Ee(Cot~) N-1
L
kYk sin k~.k=O
An error A~
=
E~~,I
E~I
~ eps in ~, on the other hand, causes only the errora
{N -1 }A~sl == o~ k~/k cos k~ . A~
= -E~~ N-1
L
kYk sin k~k=O
in s1. Now cot ~ ::::; 1/~ for small
I
~I.
The influence ofthe roundoff error in c is consequently an order of magnitude more serious than that of a corre- sponding error in ~. In other words, the algorithm is not numerically stable.In order to overcome these numerical difficulties, Reinsch has modified Goertzel's algorithm [see Bulirsch and Stoer (1968)]. He distinguishes the two cases cos ~ > 0 and cos ~ ~ O.
Case (a): cos ~ > O. The recursion (2.3.3.la) yields for the difference bUj := Uj - Uj+1
the relation
bUj
=
Uj - Uj+1=
Yj+
(2 cos ~ - 2)Uj+1+
Uj+1 - Uj+2= Yj
+
;"Uj+ 1+
bUj+ 1,where
A. :=2(cos ~ - 1) = -4 sin2(~/2).
This suggests the algorithm A.:= -4 sin2(~/2);
U[N
+
1] :=bU[N] :=0;for j:= N - 1 step -1 until 0 do
begin U[j
+
1] :=bUU+
1]+
UU+
2];bUU] :=A. x UU
+
1]+
bU[j+
1]+
yU]end;
sl :=bU[O] - A.12 x U[1];
s2:= U[I] x sin(~);
This algorithm is well behaved as far as the propagation of the error L\A.
=
c).A., I c).1 ~ eps in A. is concerned. The latter causes only the following error L\).sl in sl:osl osl lOA.
L\).sl ==
8I
L\A. = c).A. .a[
o~sin2(~/2)
N-l .
= - c).
sin(~/2) cos(~/2)
.k~O
kYk smk~
(
~)N-l= -c). tan:2 k~O kYk sin k~.
and tan(~/2) is small for small
I
~I.
Besides,I
tan(~/2)I
< 1 for cos ~ > O.Case (b): cos ~ ~ O. Here we put
bUj:= Uj
+
Uj+ 1and find
bUj = Uj
+
Uj+1 = Yj+
(2 cos ~+
2)Uj+1 - Uj+1 - Uj+2=Yj+A.Uj+1 -bUj+b
where now
A.:= 2(cos ~
+
1)=
4 cos2(~/2).This leads to the following algorithm:
A. := 4 cos2(~/2);
U[N
+
1] :=bU[N] :=0;for j:= N - 1 step - 1 until 0 do
begin UU
+
1] :=bUU+
1] - UU+
2];bUU] :=A. x UU
+
1] - bUU+
1]+
yU]end;
sl :=bU[O] - U[I] x A.12;
s2:= U[I] x sin(~);
It is readily confirmed that a roundoff error AA =
8;.
A,18;.1 ::::;
eps, in A causes an error of at most(
~)N-lA;.s1 == 8;. cot
2
k~O kYk sin k~in s1, and
I
cot(~/2)I ::::;
1 for cos ~ ::::; O. The algorithm is therefore well behaved as far as the propagation of the error AA is concerned.2.3.4 The Calculation of Fourier Coefficients.
Attenuation Factors
Let ~ be the set of all absolutely continuous2 real functionsJ: ~ --+ ~ which are periodic with period 2n. It is well known [see for instance Achieser (1956)] that every function
J
E ~ can be expanded into a Fourier series (2.3.4.1 ) J(x)= " c·ei
L..J 00 J ix 'j= -00
which converges towardsJ(x) for every x E ~. The coefficients Cj
=
cj(f) of this series are given by1 f21t ..
(2.3.4.2) Cj
=
Cj(f):= 2n 0 J(x)e-JIX dx, j = 0,±
1,±
2, ....In practice, frequently all one knows of a functionJare its values./k := J(Xk) at equidistant arguments xk:= 2nk/N, where N is a given fixed positive integer. The problem then is to find, under these circumstances, reasonable approximate values for the Fourier coefficients cAf). We will show how the methods of trigonometric interpolation can be applied to this problem.
By Theorem (2.3.1.9), the coefficients
P
j of the interpolating phase polynomialwith
2 A real function f: [a, b] -+ IR is absolutely continuous on the interval [a, b] if for every e > 0 there exists b > 0 such that
L; I
f(b;} - f(a;}I
< e for every finite set of intervals [a;, bJ with a ,,; a I < b I < ... < an < bn ,,; bandL; I
b; - a;I
< b. If the function f is differentiable every- where on the closed interval [a, b] or, more generally, if it satisfies a .. Lipschitz condition"I f(xl } - f(x2 } I ,,;
e
I Xl - x21 on [a, b], then f is absolutely continuous, but not conversely:there are absolutely continuous functions with unbounded derivatives. If the function is abso- lutely continuous, then it is continuous and its derivative f' exists almost everywhere.
Moreover,f(x} = f(a} + J= f'(t} dt for X E [a, b]. The absolute continuity of the functionsf, g in an integral of the form J~ f(t}g'(t} dt also ensures that integration by parts can be carried out safely.
for k
=
0, ± 1, ±2, ... , are given by 1 N-lPj
=
NL
fke- jixk,k=O
j=0,1, ... ,N-1.
Since
fo = fN,
the quantitiesP
j can be thought of as a "trapezoidal sum"[compare (3.1.7)]
P
.=![fo
+!e-jiXl+ ... + I" e-jiXN-l+fNe-iiXN]J N 2 1 IN-l 2
approximating the integral (2.3.4.2), so that one might think of using the sums
(2.3.4.3 )
for all integers j
=
0,±
1,±
2, ... as approximate values to the desired Fourier coefficients cj(f). This approach appears attractive, since fast Four- ier transforms can be utilized to calculate the quantities pj(f) efficiently.However, for large indices j the value
PAf)
is a very poor approximation to cj(f). Indeed, Pj+kN=
Pj holds for all integers k, j, while on the other handlimlil~oo Cj = 0. [This follows immediately from the convergence of the Four- ier series (2.3.4.1) for the argument x
=
0.] A closer look also reveals that the asymptotic behavior of the Fourier coefficientscAf)
depends on the degree of differentiability off:(2.3.4.4) Theorem. If the 2n-periodic function f has an absolutely continuous
r th derivative prl, then
PROOF. Successive integration by parts yields 1 2" ..
c· J
= -f
2n 0 f(x)e-J1X dx1 2" ..
= - ..
2nJIf
f'(x)e-JIX dx0
1 2" ..
= -.-.
2n(JIY f
Prl(X)e-JIX dx0
1 2"
= 2n(jiY+
f
e- jix dprl(x).1 0
in view of the periodicity off This proves the proposition.