Short Notice On (Exact) Trigonometric Interpolation
Short Notice On (Exact) Trigonometric Interpolation
Short Notice On (Exact) Trigonometric Interpolation
1) detailed calculation
2) symmetric cut-o for even number of points
3) general approach to aN /bN cut-o for even number of points
4) SciLab code
Andrej Liptaj
1 Foreword
Given a set of experimental points
(xi , yi ),
a0
+
[bn sin (nx) + an cos (nx)]
2
n=1
an
and
bn )
y=
that exactly passes through
all
(1)
points. This problem has been (of course) solved and the solution can be found on many
dierent places (on internet). This notice covers some points related to the trigonometric interpolation. First, it seems
to me, that existing descriptions I have found are not detailed enough, or somewhat messy (my personal opinion). So
2 Detailed calculation
The condition that coecients need to fulll is
a0
+
[bn sin (nxi ) + an cos (nxi )] .
2
n=1
N
yi =
a0
+
[bn sin (nxi ) + an cos (nxi )]
2
n=1
]
N [
einxi einxi
einxi + einxi
a0
+
bn
+ an
2
2i
2
n=1
]
N [
a0 bn inxi bn inxi an inxi an inxi
+
e
e
+
e
+
e
2
2i
2i
2
2
n=1
)
(
)
]
N [(
bn
an
an
bn
a0
+
+
einxi +
einxi
2
2i
2
2
2i
n=1
N
yi
=
Institute
]
N [
a0 1
1
inxi
inxi
+
(an ibn ) e
+ (an + ibn ) e
2
2
2
n=1
N
N
a0
1
1
+
(an ibn ) einxi +
(an + ibn ) einxi
2
2 n=1
2 n=1
N
N
a0
1
1
+
(an ibn ) einxi +
(ak + ibk ) eikxi
2
2 n=1
2
k=1
r = k
k = r
=
N
N
a0
1
1
inxi
+
(an ibn ) e
+
(ar + ibr ) eirxi
2
2 n=1
2 r=1
N
N
1
a0
1
+
(an ibn ) einxi +
(ar + ibr ) eirxi
2
2 n=1
2 r=1
N
N
1
a0
1
+
(an ibn ) einxi +
(an + ibn ) einxi
2
2 n=1
2 n=1
[N
]
N
a0
1 inxi
inxi
+
e
(an ibn ) +
e
(an + ibn )
2
2 n=1
n=1
{
[N
]}
N
1
inxi
inxi
a0 +
e
(an ibn ) +
e
(an + ibn )
2
n=1
n=1
1
(an ibn )
2
1
cn<0 = (an + ibn ) = cn
2
1
c0 = a0
2
N
=
cn einxi
cn>0 =
n=N
(
)n
cn eixi
n=N
yi
zi eixi
N
=
cn zin
n=N
yi
ziN ,
cn zin
n=N
ziN yi
= ziN
cn zin
n=N
Yi ziN yi
Yi
cn ziN +n
n=N
Yi
k =n+N
n=kN
2N
=
ckN ziN +kN
k=0
k ckN
Yi
2N
k zik
k=0
Yi
2N
n zin
n=0
Next, one uses some standard interpolation procedure for the polynomial interpolation, interpolating the (complex) points
(zi , Yi )
by a (complex) polynomial.
2N + 1
Take the
xi
zi eixi .
Take the
yi
Yi ziN yi .
(zi , Yi ).
cnN n , ck k+N
an = 2Re (cn ) = 2Re (cn ) , bn = 2Im (cn ) = 2Im (cn ).
(Is
b0 automatically
a0
2
N
n=1
in the case of
a0 ).
ad hoc
choice must be made to reconciliate the number of parameters with the number of data points:
Cut
a0 ?
a0 ,
w sin (N xi ) + w cos (N xi ) .
2N . In order
w = aN = bN .
With this choice the things become little bit more complex. The number of data points is even, let me note it
to solve the coecients, I introduce a new data point
(x2N +1 , y2N +1 )
With this point the situation looks similar to the odd case:
a0
+
[bn sin (nxi ) + an cos (nxi )]
2
n=1
N
yi =
and corresponds to
2N + 1
w sin (N xi ) + w cos (N xi ) =
=
=
w = aN = bN
implies:
1
1
(w iw) eiN xi + (w + iw) eiN xi
2
2
M = N
N = M
1
1
(w iw) eiN xi + (w + iw) eiM xi
2
2
1
1
(w + iw) ei(|N |)xi + (w iw) ei|N |xi
2
2
yi =
n=N
cn zin
where
cN >n>0
cN <n<0
cN
cN
c0
1
(an ibn )
2
1
(an + ibn ) = cn
2
1
(w + iw)
2
1
(w iw) = cN
2
1
a0
2
After renaming the indices (as in the odd case), we want to get to the polynomial interpolation
Yi =
2N
n zin .
n=0
Now comes the reasoning: Imagine we have already the interpolation polynomial
a new polynomial
for
2N
(x2N +1 , y2N +1 ).
= P + K (x x1 ) (x x2 ) (x x2N )
where the constant
(x2N +1 , y2N +1 )
x0
and
x2N +1
terms of
look like?
P ):
q x1 x2 x2N
[p0 + qK] + + [K] x2N
Coecients of these two terms are just shifted coecients
K
1
p0 + q (w iw)
2
2p0 + q (w iw)
2p0 + qw iqw
cN
and
1
(w iw)
2
cN ,
so one requires:
1
(w + iw)
2
w + iw
w + iw
2p0
w + iw qw + iqw
2p0
(1 + i q + iq) w
p0
1 + i q + iq
Take the
xi
2N
zi e
Yi
ixi
Take the
K=
1
2
yi
p0
of
P.
points:
.
ziN yi .
P
Compute
(zi , Yi ).
Then compute
(w iw).
2p0
1+iq+iq and
= P + K (x x1 ) (x x2 ) (x x2N ).
w=
an
and
bn .
+ 1 points) from
aN = bN = w .
aN /bN
as follows:
Build polynomial
P.
cN
aN
and
and
bN .
cN .
Find the appropriate equation which follows from the constraints, solve it, and build
of
and treat them same as in the odd case, compute from them the coecients
an
and
bn .
I give here the example of the highest-sine cut-o.
The coecients
Polynomial
cN
bN = 0.
then look like
cN =
aN
2
aN
p0 + q
2
p0
p0
aN
= P + K (x x1 ) (x x2 ) (x x2N )
aN
2
aN
2
aN
aN
q
2
2
aN
(1 q)
2
2p0
(1 q)
p0
(1 q)
yi =
qn einxi .
n=0
One proceeds analogically
yi
(
)n
qn eixi
n=0
zi = eixi
N
=
qn zin .
n=0
One constructs the interpolation polynomial for (yi , zi ) and nds the coecients qn . However qn can be complex. If yi
N
n
is real, then
n=0 qn zi needs also to be real. Because a real part of a sum is sum of real parts, one can focus on an
individual term
qn einxi
yi ,
thus the trigonometric interpolation is fully given by the rst one. One
an
bn
where the coecient
a0
is
not
= Re (qn ) ,
= Im (qn ) ,
divided by two
yi = a0 +
n=1
and the coecient
b0
is irrelevant.
6 SciLab code
Here is a SciLab code for the polynomial (works also for complex data points) and the trigonometric interpolation (works
for real-valued data points only) passing (in both cases) through
cutOffType = 0
all
// s y m m e t r i c
// h i g h s i n e
// c u t O f f T y p e = 1
/ / INTERPOLATING POLYNOMIAL
function
[ f ]
= interpolation_poly (x , y)
nData = l e n g t h ( x )
atom ( 1 ) = p o l y ( 1 , " x " , " c o e f f " )
for
i =2: nData
atom ( i ) = atom ( i
1) p o l y ( x ( i 1 ) , " x " )
end
poly_interpol = poly (0 ," x " ," c o e f f ")
for
i =1: nData
const = (
y( i )
horner ( poly_interpol , x ( i ) )
) / h o r n e r ( atom ( i ) , x ( i ) )
p o l y _ i n t e r p o l = p o l y _ i n t e r p o l + c o n s t atom ( i )
end
f = poly_interpol
endfunction
/ / INTERPOLATING FOURIER SERIES
/ / COMPUTING COEFFICIENTS
function
[ a , b ,N]
= trigo_cfs (x , y)
nDat = l e n g t h ( x )
if
then
N = r o u n d ( ( nDat 1 ) / 2 )
// I f
nDat
I S ODD
else
N = r o u n d ( ( nDat ) / 2 )
// I f
nDat
I S EVEN
end
for
i =1: nDat
z ( i )=
e x p ( %i
x ( i
))
Y( i ) = ( z ( i ) ) ^N y ( i )
end
z _ p o l y n o m i a l = i n t e r p o l a t i o n _ p o l y ( z , Y)
then
c o e f f ( z_polynomial , 0 )
q = 1
for
i =1: nDat
q = q ( z ( i ) )
end
if
c u t O f f T y p e==0 t h e n
// c u t t i n g
w = 2 p0 / ( 1 + %i
K = ( 1 / 2 ) (w
q
%i w)
+ %i
symmetrically
q )
end
if
c u t O f f T y p e==1 t h e n
//
cutting
K = p0 /(1 q )
h i g h f r e q u e n c y
sine
end
polyToAdd = K p o l y ( z , " x " )
z _ p o l y n o m i a l = z _ p o l y n o m i a l + polyToAdd
end
cfs
c o e f f ( z_polynomial )
i =N : N
for
if
i <0 t h e n
continue
end
coef =
c f s ( i +N+1)
a ( i +1)=2 r e a l ( c o e f )
b ( i +1)=2 imag ( c o e f )
// m p r i n t f ( " a%i
= %f ,
b%i
= %f
\n " ,
i +1 , a ( i + 1 ) , i +1 , b ( i + 1 ) )
end
endfunction
/ / COMPUTING TRIGONOMETRIC INTERPOLATION
function
[ f ]
= i n t e r p o l a t i o n _ t r i g o ( x , a , b , N)
f = a (1)/2
for
i =1:N
f = f + b ( i +1) s i n ( i
x )
+ a ( i +1) c o s ( i
end
endfunction
/ / START OF THE PROGRAM FLOW
dataSet = read (" t r i g o D a t a . dat " , 1 ,2)
nDat = l e n g t h ( d a t a S e t ) / 2
for
i =1: nDat
x ( i ) = dataSet ( i , 1 )
y ( i ) = dataSet ( i , 2 )
end
[ a_cfs , b_cfs ,N]
= trigo_cfs (x , y)
d e l t a = x ( nDat) x ( 1 )
margin = d e l t a /10
x_ax =
[ x (1) m a r g i n : 0 . 0 1 : x ( nDat)+ m a r g i n ]
x )
p l o t ( x_ax , i n t e r p o l a t i o n _ t r i g o ( x_ax , a _ c f s , b _ c f s , N) )
plot (x , y , ' ')