Download The MATLAB Notebook v1.5.2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CHAPTER 3: NUMERICAL ALGORITHMS WITH MATLAB
Lecture 3.4: Trigonometric interpolation
General properties of trigonometric series:
Any function y = f(x) that is continuous and periodic function of x with period L can be replaced by the
trigonometric (Fourier) series (infinite sum of cosines and sines):
f(x) =
1
a0 +
2


aj cos(2  jx/L) + bj sin(2  jx/L),
0 x L
j 1
where (aj,bj) are Fourier coefficients computed from the function f(x) by means of integrals:
2
aj =
L
L

f(x) cos(2  jx/L) dx, j = 0,1,2,…, 
0
and
bj =
2
L
L

f(x) sin(2  jx/L) dx, j = 1,2,…, 
0
Example: f(x) = sign(x), -1 < x < 1 ; f(x + 2) = f(x), L = 2.
Trigonometric series for sign-function:

f(x) =

k 1
4
sin  (2k - 1) x
 (2k  1)
Trigonometric interpolation:
Problem: Given a set of (n+1) data points:
(x1,y1); (x2,y2); …; (xn,yn); (xn+1,yn+1) ,
such that the values of x are equally spaced on the interval x  [0,L] and the values of y are periodic with
period of L, i.e. yn+1 = y1. Find a finite sum of cosines and sines y = f(x) that connects all (n+1) data points.
Example: Consider interpolation of the Runge function y = 1/(1 + 25 x2). The polynomial interpolation (on
the left) does not produce any good approximation of the Runge function because of the polynomial wiggle.
The trigonometric interpolation (on the right) reproduces the Runge function on the interval -1 < x < 1 with
sufficiently small error.
Methods:
 Linear systems for Fourier coefficients
 Summation formulas for Fourier coefficients
 Discrete Fourier Tranform
Linear systems for Fourier coefficients:
The interval x  [0,L] has the equally-spaced partition at the values of x:
xi = (i-1)L/n, i=1,2,…,n
The trigonometric interpolation y = f(x) should have n coefficients [aj,bj], which are to be found from n
equations: yi = f(xi). If n is even, i.e. n = 2m, the trigonometric interpolant y = f(x) takes the form:
f(x) =
1
a0 +
2
m 1
 
aj cos(2  jx/L) + bj sin(2  jx/L)
 + am cos(2  mx/L)
j 1
The Fourier coefficients are to be found from the linear system:
yi =
1
a0 +
2
m
 
aj cos(2  j xi / L) + bj sin(2  j xi / L)
 + am cos(2  mxi/L)
j 1
x = -1 : 0.1 : 1; % equally-spaced partition of the interval: –1 < x < 1
y = 1./(1 + 25*x.^2); % values of the Runge function
n = length(x)-1; m = n/2; L = 2;
xx = [x(m+1:n),x(1:m)]'; yy = [y(m+1:n),y(1:m)]';
% continuation of data to the positive interval for x in [0,L]
A = 0.5*ones(n,1); % building the coefficient matrix for linear system
for j = 1 : (m-1)
A = [ A, cos(2*pi*j*xx/L), sin(2*pi*j*xx/L) ];
end
A = [ A, cos(2*pi*m*xx/L) ];
c = A\yy; % computations of Fourier coefficients in a special order
a = [ c(1); c(2:2:n) ]; b = [0; c(3:2:n)]; % coefficients are column vectors
a',b', xInt = -1: 0.01 : 1; % interpolation partition on the same interval
yInt = 0.5*a(1)*ones(1,length(xInt));
for j = 1 : (m-1)
yInt = yInt + a(1+j)*cos(2*pi*j*xInt/L) + b(1+j)*sin(2*pi*j*xInt/L);
end
yInt = yInt + a(m+1)*cos(2*pi*m*xInt/L);
plot(x,y,'*g',xInt,yInt,'b');
ans =
0.5492
0.3442
0.1756
0.0970
0.0499
0.0279
0.0140
0.0084
0.0041
0.0032
0.0010
ans = 1.0e-016 *
0.1228
0.1459
0.0789
0.0692
0.0106
-0.3902
0.1272
0.1426
0.0627
1.2
1
0.8
0.6
0.4
0.2
0
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Summation formulas for Fourier coefficients:
When the partition of the interval x  [0,L] is equally spaced, the Fourier coefficients [aj,bj] can be computed
from direct summation formulas:
aj =
2
n
n

yi cos(2  jxi /L),
j = 0,1,2,…,m
i 1
and
bj =
2
n
n

yi sin(2  jxi / L),
j = 1,2,…,m-1
i 1
These formulas represent the discrete Fourier transform defined at the given set of data points (xi,yi).
P = A'*A; % summation formulas follows from the fact that A'*A is diagonal
P(1:6,1:6)
% the discrete cosines and sines are orthogonal with respect to sums!
ans =
5.0000
0.0000
-0.0000
0.0000
-0.0000
0.0000
0.0000
10.0000
-0.0000
0.0000
0
-0.0000
-0.0000
-0.0000
10.0000
-0.0000
-0.0000
0.0000
0.0000
0.0000
-0.0000
10.0000
0.0000
0.0000
-0.0000
0
-0.0000
0.0000
10.0000
-0.0000
0.0000
-0.0000
0.0000
0.0000
-0.0000
10.0000
x = -1 : 0.1 : 1; y = 1./(1 + 25*x.^2);
n = length(x)-1; m = n/2; L = 2;
xx = [x(m+1:n),x(1:m)]'; yy = [y(m+1:n),y(1:m)]';
for j = 0 : m
a(j+1) = 2*yy'*cos(2*pi*j*xx/L)/n;
b(j+1) = 2*yy'*sin(2*pi*j*xx/L)/n;
% inner (dot) product is used for computations
% b(1) = b(m+1) = 0
end
a',b', xInt = -1: 0.01 : 1;
yInt = 0.5*a(1)*ones(1,length(xInt));
for j = 1 : (m-1)
yInt = yInt + a(1+j)*cos(2*pi*j*xInt/L) + b(1+j)*sin(2*pi*j*xInt/L);
end
yInt = yInt + a(m+1)*cos(2*pi*m*xInt/L);
plot(x,y,'*g',xInt,yInt,'b');
ans =
0.5492
0.3442
0.1756
0.0970
0.0499
0.0279
0.0140
0.0084
0.0041
0.0032
0.0020
ans = 1.0e-016 *
0
-0.0833
-0.2220
0
0.1110
0
0.1110
-0.1110
0.0555
-0.0278
0.0471
1.4
1.2
1
0.8
0.6
0.4
0.2
0
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Discrete Fourier Transform:
The trigonometric sum can be rewritten as a complex Fourier sum:
f(x) =
1
n
m

cj exp( 2  i*
j  m
jx
),
L
i=
1 , 0  x  L
(1)
where cj = n (aj - ibj) / 2 and c-j = n (aj + ibj ) / 2. The complex Fourier coefficients cj are found from the
summation formulas:
n
cj =

k 1
yk exp(-2  i*
jxk
),
L
j = 0,  1,  2 ,…,  m
(2)
Given data points (xk,yk) for k = 1,…,n and n = 2m, formulas (2) are usually referred to as the discrete Fourier
transform (DFT), while formulas (1) at the points (xk,yk) are referred to as the inverse discrete Fourier
transform (IDFT). We use a simple observation:
c-j = exp(2  i*
jxk
j (k  1)
( j  n)( k  1)
) = exp(2  i*
) = exp(2  i*
) = cn-j
n
n
L
Then, the discrete and inverse discrete Fourier transforms can be regrouped for positive indices:
n
cj =

yk exp(-2  i*
k 1
jxk
),
L
j = 0,1,2,…,n-1
and
yk =
1
n
n 1

cj exp( 2  i*
j 0
jxk
).
L
These formulas are valid only at the discrete data points (xk,yk). In order to actually interpolate the function y
= f(x) beyond the data points (xk,yk), we would need to use the formula for trigonometric interpolation with:
aj =
2
2
Re(cj); bj = - Im(cj); j = 0,1,…,m,
n
n
where m = n/2.


fft: computes the discrete Fourier transform
ifft: computes the inverse discrete Fourier transform
x = -1 : 0.5 : 1; y = 1./(1 + 25*x.^2); % data points
n = length(x)-1; m = n/2; L = 2;
xx = [x(m+1:n),x(1:m)]'; yy = [y(m+1:n),y(1:m)], yy = yy';
for j = 0 : m
a(j+1) = 2*yy'*cos(2*pi*j*xx/L)/n;
b(j+1) = 2*yy'*sin(2*pi*j*xx/L)/n;
end
a =a, b =b
% Fourier coefficients of trigonometric series
c = fft(yy); c = c'
aF = 2*real(c(1:m+1))/n; bF = -2*imag(c(1:m+1))/n;
aF = aF, bF = bF % Fourier coefficients derived from FFT
yF = ifft(c)
% the same function y is recovered, i.e. yF = ifft(fft(y)) = y
yy =
1.0000
0.1379
0.0385
a =
0.6572
0.4808
0.3813
b = 1.0e-017 *
0
0
0.4710
c =
1.3143
0.9615
0.7626
aF =
0.6572
0.4808
0.3813
bF =
0
0
0
yF =
1.0000
0.1379
0.0385
0.1379
0.9615
0.1379
The function y = f(x) can be computed at data points which are different from (xk,yk) from trigonometric sum:
f(x) =
1
a0 +
2
m 1
 
j 1
aj cos(2  jx/L) + bj sin(2  jx/L)
 + am cos(2  mx/L)
Related documents