Вы находитесь на странице: 1из 8

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

October 26, 2015

1 Foreword
Given a set of experimental points

(xi , yi ),

one wants to nd a cut-o Fourier series (i.e. its coecients

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

an and bn coecients. The second point concerns an even number


(xi , yi ). The formula 1 naturally contains an odd number of parameters: they come in pairs in the sum,
plus the stand-alone a0 coecient. The number of free parameters should match the number of points, in the case of an
even number of points one has to nd an ad hoc approach to cut-o the series. Here I present the symmetric cut-o with
aN = bN = w. Then I also discuss a generalization of this approach. Finally, I provide a SciLab code to perform the

I provide here a detailed calculation leading to the


of point pairs

trigonometric (and polynomial) interpolation.

2 Detailed calculation
The condition that coecients need to fulll is

a0
+
[bn sin (nxi ) + an cos (nxi )] .
2
n=1
N

yi =

This condition can be transformed as follows:

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

of Physics, Bratislava, Slovak Academy of Sciences

]
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

We have a power series, however with negative powers. Multiplying by

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

one can get a polynomial:

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.

Let me repeat, the procedure with

2N + 1

Take the

xi

values and compute

zi eixi .

Take the

yi

values and compute

Yi ziN yi .

Compute interpolation-polynomial coecients

Rename the coecients

Compute the original coecients

experimental points is:

for the points

(zi , Yi ).

cnN n , ck k+N
an = 2Re (cn ) = 2Re (cn ) , bn = 2Im (cn ) = 2Im (cn ).

(Is

b0 automatically

zero? Yes, it is!)

Construct the function

a0
2

N
n=1

[bn sin (nxi ) + an cos (nxi )]

(do not forget to divide by

in the case of

a0 ).

3 Even number of data points: symmetric cut-o


In this case an

ad hoc

choice must be made to reconciliate the number of parameters with the number of data points:

Cut the highest-frequency cosine?

Cut the highest-frequency sine?

Cut

a0 ?

I want to cut high-frequencies, so I do not want to cut the

a0 ,

I want to be symmetric, so I introduce the term

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 )

and I will place it correctly so that

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

data points. The condition

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

So that the polynomial looks like:

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

that keeps the interpolation property of

for

2N

points. We want to construct

and, in addition, goes through the point

(x2N +1 , y2N +1 ).

can be written as:

= P + K (x x1 ) (x x2 ) (x x2N )
where the constant

is responsible for tting the

They look like (p0 comes from

(x2N +1 , y2N +1 )

point. How do the

x0

and

x2N +1

terms of

look like?

P ):

[p0 Kx1 x2 x2N ] + + [K] x2N

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

This needs to be a real number.


Let me repeat the procedure for case of

Take the

xi

2N

values and compute

zi e

values and compute

Yi

ixi

Take the

Determine the interpolation polynomial

Extract the absolute term

K=

1
2

yi

p0

of

P.

points:
.

ziN yi .
P

for the points

Compute

(zi , Yi ).

q = (x1 ) (x2 ) . . . (x2N ).

Then compute

(w iw).

Construct a new polynomial

Treat the polynomial

2p0
1+iq+iq and

= P + K (x x1 ) (x x2 ) (x x2N ).

as the interpolation polynomial for (2N

its coecients (n ) compute

w=

an

and

bn .

Automatically one gets

+ 1 points) from
aN = bN = w .

the previous (odd) case. From

4 Even number of data points: general aN /bN cut-o


The approach from the previous paragraph can be straightforwardly generalized to any

aN /bN

cut-o. The algorithm is

as follows:

Formulate the constraints on the coecients

Find the corresponding constraints on

Build polynomial

P.

Take the coecients

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 condition reads:

The coecients

One has immediately:

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)

can be built and its coecients read-out.

5 Ecient approach for non-minimal series


An ecient alternative approach is achieved by interpolating the data with a complex exponential sum

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

= (n + in ) (cos nx + i sin nx)


= n cos nx + in sin nx + in cos nx n sin nx
= [Re (qn ) cos nx Im (qn ) sin nx] + i [Re (qn ) sin nx + Im (qn ) cos nx] .
5

The second bracket is vanishing for purely real

yi ,

thus the trigonometric interpolation is fully given by the rst one. One

immediately gets the coecients

an
bn
where the coecient

a0

is

not

= Re (qn ) ,
= Im (qn ) ,

divided by two

yi = a0 +

[bn sin (nxi ) + an cos (nxi )]

n=1
and the coecient

b0

is irrelevant.

standard approach (2N

In this approach, however, the series is (approximately) twice as long as in the

terms in total for

experimental points). But still, it is a valid Fourier series.

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

data points (standard approach):

// 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

modulo ( nDat ,2)==1

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)

// SPECIAL TRATMENT IN THE CASE OF EVEN NUMBER OF POINTS


if

modulo ( nDat ,2)==0


p0 =

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 , ' ')

Вам также может понравиться