fourier analysis - courses.physics.helsinki.fi · fourier analysis 5 - according to parseval s...

22
Scientific computing III 2013: 12. Fourier analysis 1 Fourier analysis • In many numerical problems methods based on Fourier transforms of a function of signal are needed: - Solving differential equations is in many cases easier in space: 1. Diffusion equation: , FT: . Initial condition: . 2. Elastic Green’s function of a point force. 3. Electronic structure calculations. . . - Signal and data processing: 1. Audio and video signal compression (perceptual coding): masking in the frequency domain. 2. Power spectrum of a signal . . - In this chapter we deal with numerical Fourier transformation of data and its implementation fast Fourier transform. k t c D c 2 = c ˜ kt cxte ikx x d = c ˜ kt t ----------------- Dk 2 c ˜ kt = c ˜ kt c ˜ 0 e Dk 2 t = cx 0 x = c ˜ k 0 1 = cxt 1 2 ------ e Dk 2 t e ikx k d 1 2 Dt ----------------- e x 2 4 Dt --------- = = Scientific computing III 2013: 12. Fourier analysis 2 Fourier analysis Fourier transform (FT) of a function is defined as . - Inverse Fourier transform (IFT) is respectively . - The above notation suggest that the original data is a function of time and that the transformation makes it a function of frequency. - The original data may also be e.g. a function of position and the transformed data a function of the wave number (or vec- tor). - Sometimes instead of the angular frequency is used: Hf ht Hf () ht () e 2 ift t d = ht () Hf () e 2 ift f d = f H( ) ht () e i t t d = ht () 1 2 ------ H( ) e i t d =

Upload: others

Post on 22-Jun-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 1

Fourier analysis

• In many numerical problems methods based on Fourier transforms of a function of signal are needed:

- Solving differential equations is in many cases easier in space:1. Diffusion equation:

, FT: .

Initial condition: .

2. Elastic Green’s function of a point force.

3. Electronic structure calculations. ..

- Signal and data processing:

1. Audio and video signal compression (perceptual coding): masking in the frequency domain.

2. Power spectrum of a signal..

- In this chapter we deal with numerical Fourier transformation of data and its implementation fast Fourier transform.

k

tc D c2= c̃ k t c x t e ikx– xd

= c̃ k tt

------------------ Dk2 c̃ k t–= c̃ k t c̃0e Dk2t–=

c x 0 x= c̃ k 0 1= c x t 12------ e Dk2t– eikx kd

12 Dt-----------------e

x2

4Dt---------–

= =

Scientific computing III 2013: 12. Fourier analysis 2

Fourier analysis

• Fourier transform (FT) of a function is defined as

.

- Inverse Fourier transform (IFT) is respectively

.

- The above notation suggest that the original data is a function of time and that the transformation makes it a function of frequency.

- The original data may also be e.g. a function of position and the transformed data a function of the wave number (or vec-tor).

- Sometimes instead of the angular frequency is used:

H f h t

H f( ) h t( )e2 ift td

=

h t( ) H f( )e 2– ift fd

=

f

H( ) h t( )ei t td

=

h t( ) 12------ H( )e i t– d

=

Page 2: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 3

Fourier analysis

- Symmetry and reality properties of the original function are reflected also to its FT:

1. real 2. imaginary 3. even even4. odd odd5. real and even real and even6. real and odd imaginary and odd7. imaginary and even imaginary and even8. imaginary and odd real and odd

- These symmetries can be utilized in speeding up FT algorithms.

- FT has also a couple of handy properties:

.

h t H f–( ) H f( ) *=

h t H f–( ) H f( ) *–=h t H f( )h t H fh t H fh t H fh t H fh t H f

h at( ) 1a

-----H fa---( )

1b

-----h tb---( ) H bf( )

h t t0–( ) H f( )e2 ift0

h t( )e 2 if0t– H f f0–( )

Scientific computing III 2013: 12. Fourier analysis 4

Fourier analysis

- Convolution of two functions and is defined as

.

- One can easily show that the FT of a convolution is the product of the FT’s of the individual functions and :

.

- Correlation function is defined as

.

- This essentially a convolution so that one can easily show that if and are real then

- Correlation of the function with itself is so called autocorrelation function

, .

g*h g t h t

g*h g( )h t –( )d

=

G f H f

g*h G f( )H f( )

Corr g h( ) g t+( )h( )d

=

g h

Corr g h( ) G f( )H* f( )

Corr g g( ) g t+( )g( )d

= Corr g g( ) G f( ) 2

Page 3: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 5

Fourier analysis

- According to Parseval’s theorem the total power of a signal is the same in the time and frequency domains:

.

- The power at the frequency interval is defined as (in this case positive and negative frequencies are often treated with equal footing)

, .

- When the original signal is real this becomes

.

Ptot h t( ) 2 td

H f( ) 2 fd

=

f f df+

Ph f( ) H f( ) 2 H f–( ) 2+ 0 f

Ph f( ) 2 H f( ) 2

Scientific computing III 2013: 12. Fourier analysis 6

Fourier analysis: discrete FT

• In practice the data is not continuous but is a set of discrete points placed on the time axis:

, .

- The inverse of the time step is called the sampling rate.

- The Nyquist critical frequency is defined as

.

- Assume we take samples from function with frequency .

- If the bandwidth of the function is restricted in such a way that for all frequencies ,

then the samples determine the signal completely.

- We can now express the function as

.

- We often do know that our data is bandwidth-limited. - In these cases it is enough to sample the data at a frequency which is twice the maximum frequency in the data.

hn

hn h n( )= n 3– 2– 1– 0 1 2 3=

fc1

2-------

h t 1

f fc H f 0=

hn

h t( ) hn2 fc t n–sin

t n–-------------------------------------------

n –=

=

Page 4: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 7

Fourier analysis: discrete FT

- If we sample the data with a too low frequency we observe that all frequencies outside the range is folded to this range. This phenomenon is called aliasing.

- For example signals and give the

same samples at an interval when the difference in the fre-quencies is a multiple of .

- In order to prevent aliasing one should make sure that the sig-nal does not contain too large frequencies (e.g. by a low-pass filter).

- It is easy check whether there is aliasing: if the FT goes to zero when approaching then the signal does not contain too hugh frequencies.

- With the discrete Fourier transformation (DFT1) one can approximate FT of a continuous function based on samples taken from it.

- Assume we have samples:

, , .

- Moreover, let be even.

1. Not to be mixed with another DFT, namely the density functional theory ;-)

fc– fc

aliasingaliasing

T

t

H f

f

f12-------– 1

2-------

2 if1texp 2 if2texp

f1 f2– 1

fc

N

hk h tk( ) tk k k 0 1 2 N 1–=

N

Scientific computing III 2013: 12. Fourier analysis 8

Fourier analysis: discrete FT

- We only have input data we only can obtain output data. - Because of this we compute DFT only for points

, .

- The limits and correspond to the Nyquist critical frequency .

- DFT is computed by approximating the integral by a sum:

.

- The last sum in the above expression is called the DFT. Let’s denote it as

.

- So the DFT can be depicted as a following transformation

N N

fnn

N-------- n N

2----– N

2----=

f N 2– fN 2 fc 1 2=

H fn( ) h t( )e2 ifnt td

hke2 ifntk

k 0=

N 1–hke2 ikn N

k 0=

N 1–= =

Hn hke2 ikn N

k 0=

N 1–

complex numbers N

hk

complex numbers N

Hn

Page 5: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 9

Fourier analysis: discrete FT

- Note that does not depend on any dimensional quantity (like ).

- The connection between the DFT and FT is

,

where the frequency is computed as .

- According to the definition of we assumed that the index is in the interval

- Now, when we look at the definition of we see that it is periodic with a period of . - This means that

for

- Because of this the index normally takes the values in the definition of the frequency: .

- In this case the positive frequencies are located at and the negative frequencies at .

- Value is the ‘DC component’. corresponds to both and .

Hn

H fn( ) Hn

fn n N

fn n N2----– N

2----

Hn N

H n– HN n–= n 1 2=

n n 0 1 2 N 1–= fn n N

n 1 2 N 2 1–=n N 2 1+ N 1–=

n 0= n N 2= fc– fc

Scientific computing III 2013: 12. Fourier analysis 10

Fourier analysis: discrete FT

- If this sounds complicated the figure below should clarify the issue.

- The same symmetry properties as for the continuous FT apply also to DFT. - For example changing the sign of the argument corresponds to a shift by : .

- The discrete inverse FT is defined as

.

N 2– N 2 N 1–

n

Hn2

N f– N n–

hk1N---- Hne 2 ikn N–

n 0=

N 1–=

Page 6: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 11

Fourier analysis: discrete FT

- Discrete version of the Parseval’s theorem is

.hk2

k 0=

N 1–1N---- Hn

2

n 0=

N 1–=

Scientific computing III 2013: 12. Fourier analysis 12

Fourier analysis: FFT

• The computation time of a DFT behaves as .

- This can justified as follows:

Define a complex number .Definition of DFT can now be written in the form

.

In other words a -vector is multiplied by a matrix,

the elements of which are powers of a complex number .

Matrix multiplication scales as .

- In the mid-60’s John Tukey and John Cooley published an article describing an algorithm for DFT that scales as .

- The algorithm is called fast Fourier transform (FFT)1.

O N2

W e2 i N

Hn hke2 ikn N

k 0=

N 1–hkWnk

k 0=

N 1–= =

N hk N N

W

O N2

O Nlog2N

Page 7: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 13

Fourier analysis: FFT

• A sidenote: Remember the list of top ten algorithms of the 20th century (http://www.siam.org/siamnews/05-00/current.htm)

1. Metropolis Monte Carlo. von Neumann et al., 1946

2. Simplex linear programming method (optimization). Dantzig, 1947

3. Krylov subspace iteration method (solving for large matrices). Hestenes et al., 1950

4. Decompositional approach to matrix computations. Householder, 1951

5. Fortran optimizing compiler. Backus, 1957

6. QR algorithm for eigenvalue problems. Francis, 1959-61

7. Quicksort. Hoare, 1962

8. Fast Fourier transform. Cooley and Tukey, 1965

9. Integer relation detection algorithm. Ferguson and Forcade, 1977

10.Fast multipole algorithm. Greengard and Rokhlin, 1987

1. For a historical background of FFT see D. Kahaner, C. Moler, S. Nash: Numerical Methods and Software, Prentice-Hall, London, 1989, sec. 11.14.

Ax b=

Scientific computing III 2013: 12. Fourier analysis 14

Fourier analysis: FFT

• FFT is based on the fact that the DFT of samples can be expressed in terms of

two DFTs of data sets with samples. - One of the DTFs consists of samples with even indices and the other of samples with odd indices1:

.

- Here the constant is as above, i.e. .- is the th element of the DFT computed from the even samples of the original data.

- is correspondingly computed from the odd samples.

1. Note that now is not a frequency but the sample of the data set.

N fiN 2

fj j

Fk fje2 ijk N

j 0=

N 1–

f2je2 i 2j k N

j 0=

N 2 1–f2j 1+ e2 i 2j 1+ k N

j 0=

N 2 1–+

f2je2 ijk N 2

j 0=

N 2 1–Wk f2j 1+ e2 ijk N 2

j 0=

N 2 1–+

Fke WkFk

o+

=

=

=

=

W W e2 i N=

Fke k

Fko

Page 8: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 15

Fourier analysis: FFT

- The idea of FFT is to apply this kind of division recursively:

Divide into two parts and each of which is a DFT of data sets of length .

- Assuming that is a power of two ( ) we can continue the division process until we have a DFT of length one, which is nothing more than an identity operation.

- So, for all different combinations of symbols and with length we can find a DFT of length one:

.

- The problem is now to find out the value of that corresponds to a particular string ‘ ‘.

- The first division is based on the least significant bit of :If it is 0 then is even and the element belongs to term ,

otherwise to term .- In the next division we examine the second least significant bit and so on.- The index of the element is obtained by the reversing the string ‘ ‘

and interpreting it as a binary number such that

.

Fke Fk

ee Fkeo N 4

N N 2m=

o e log2N

Fkeooeoeoeeeeoo...oeoee fn=

n eooeoeoeeeeoo...oeoee

n

n Fke

Fko

n eooeoeoeeeeoo...oeoee

e 0o 1

Scientific computing III 2013: 12. Fourier analysis 16

Fourier analysis: FFT

- As a figure for :N 16=

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

0

2

4

6

8

10

12

14

1

3

5

7

9

11

13

15

0

4

8

12

2

6

10

14

1

5

9

13

3

7

11

15

0

8

4

12

2

10

6

14

1

9

5

13

3

11

7

15

0000

1000

0100

1100

0010

1010

0110

1110

0001

1001

0101

1101

0011

1011

0111

1111

N N 2 N 4 N 8 N 16

Page 9: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 17

Fourier analysis: FFT

- We see that in the last column the data is in the bit reversed order and it consists of one-element DFTs.

- The FT of length is then obtained by successively combining adjacent elements in this bit reversed array by applying the formula

- So, the FFT algorithm consists of two steps:

1. Sort the data table in bit reversed order.

2. Recursively combine adjacent elements in this array to obtain the final FT.

- Combination of the elements takes time as , and this is done times so that the algorithm behaves as

. (Assuming that the initial sorting of the array does not take more time than .)

- The algorithm can further speeded up by restricting the calls to trigonometric functions to outer loops.

N

Fk Fke WkFk

o+=

O N O log2N

O Nlog2N O N

Scientific computing III 2013: 12. Fourier analysis 18

Fourier analysis: FFT

• There is no lack of FFT implementations

MATLAB: FFT(x), also 2D FFT: FFT2(x)

GSL: gsl_fft_complex_radix2_forward, gsl_fft_complex_radix2_backward,gsl_fft_real_radix2_transform,. . .

SLATEC: RFFTF (only single precision). . .

FFTW: A C library for FFT (http://www.fftw.org/)

FFTPACK: A Fortran library for FFT (http://www.netlib.org/fftpack/)

- When using a particular implementation of FFT be careful to store your data in the right format.- Especially in C because there is no complex data type in the language.

Page 10: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 19

Fourier analysis: FFT

- Example of using GSL FFT routine gsl_fft_complex_radix2_forward:

#include <stdio.h>#include <stdlib.h>#include <math.h>#include <gsl/gsl_errno.h>#include <gsl/gsl_fft_complex.h> #define DR(z,i) ((z)[2*(i)]) /* Real part */#define DI(z,i) ((z)[2*(i)+1]) /* Imag. part */double gasdev(int *); int main (int argc, char **argv){ int i,np,np2; double per1,per2,std,*data,sr,si; int seed;

np=atoi(*++argv); per1=atof(*++argv); per2=atof(*++argv); std=atof(*++argv); seed=atol(*++argv); np2=2*np; data=(double *) malloc((size_t)((2*np)*sizeof(double)));

for (i=0;i<np;i++) { DR(data,i)=cos(2.0*M_PI*(i-1)/per1)+ cos(2.0*M_PI*(i-1)/per2)+ std*gasdev(&seed); DI(data,i)=0.0; }

for (i=0;i<np;i++) { printf ("ORIG: %d %e %e\n", i,DR(data,i),DI(data,i)); } printf ("\n"); gsl_fft_complex_radix2_forward(data,1,np); for (i=0;i<np;i++) { sr=DR(data,i)*DR(data,i)/np; si=DI(data,i)*DI(data,i)/np; printf ("FFT: %d %g \n",i,sr+si); } return 0;}

/*

Program uses the routine gasdev to generate Gaussian random numbers.

Only the absolute value of the FT is printed.That’s for plotting purposes.

*/

Scientific computing III 2013: 12. Fourier analysis 20

Fourier analysis: FFT

- The program transforms the function

,

where and are the periods of the signal and is a random number

with Gaussian distribution ( , ).

- Compilation and run:

2 tP1--------cos 2 t

P2--------cos nr+ +

P1 P2 r

r 0= r 1=

gsl> gcc -o gsl_fft gsl_fft.c -lgsl -lgslcblas -lmgsl> ./gsl_fft 16 3 5 0.3 34535ORIG: 0 -4.420391e-01 0.000000e+00ORIG: 1 1.948316e+00 0.000000e+00ORIG: 2 -1.348478e-01 0.000000e+00ORIG: 3 -8.243850e-01 0.000000e+00ORIG: 4 1.379508e-01 0.000000e+00ORIG: 5 4.960397e-03 0.000000e+00ORIG: 6 3.360909e-01 0.000000e+00ORIG: 7 1.367261e+00 0.000000e+00ORIG: 8 -1.031304e+00 0.000000e+00ORIG: 9 -9.477208e-01 0.000000e+00ORIG: 10 1.768183e+00 0.000000e+00ORIG: 11 9.333204e-02 0.000000e+00ORIG: 12 -1.755363e-01 0.000000e+00ORIG: 13 4.970365e-01 0.000000e+00ORIG: 14 -1.676865e+00 0.000000e+00ORIG: 15 2.156618e-02 0.000000e+00

FFT: 0 0.0554601FFT: 1 0.0834737FFT: 2 0.219583FFT: 3 2.29423FFT: 4 0.247893FFT: 5 1.72874FFT: 6 1.73657FFT: 7 0.743871FFT: 8 0.71349FFT: 9 0.743871FFT: 10 1.73657FFT: 11 1.72874FFT: 12 0.247893FFT: 13 2.29423FFT: 14 0.219583FFT: 15 0.0834737

Page 11: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 21

Fourier analysis: FFT

- The figures below were computed with

, , , .P1 20= P2 50= n 0.3= N 512=

k5000

Scientific computing III 2013: 12. Fourier analysis 22

Fourier analysis: FFT

- Aliasing can be illustrated by using the same function and by varying the period .

- In the figure on the right the period is varied as .

- Note that in this case, because the Nyquist critical frequency is

.

- Other parameters are

.

- We see that when the peak of the corresponding signal appears in a wrong place.

• FT can easily be generalized to more than one dimension:

.

P1

P1 1.4 10.0=

1=

fc12---=

P2 30=

n 0.1=

N 256=

P1 2

H n1 nLkL 0=

NL 1– 2 ikLnLNL

---------------------–exp2 ik1n1

N1--------------------–exp

k1 0=

N1 1–

=

Page 12: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 23

Fourier analysis: FFT

• Note that above we assumed that the size of the data set is a power of two. - If this not the case we can add zeros to our data to increase the size up to the nearest power (zero padding).- Figures below demonstrate how this affects the power spectrum of a signal.

- Other that radix-2 FFT algorithms are used when the data size is something else than a power of two. - For example the GSL library allow one to ise so called mixed radix algorithms where the data decomposition is based on

the factorization of the size of the data set in terms of 2, 3, 4, 5, 6 and 7. The fraction of data that can not be factored is computed by the DFT.

>> x=[0:0.01:40.95];>> y0=sin(pi*x);>> y1=y0;>> y1(2048:4095)=0;>> y2=y0;>> y2(1024:4095)=0;

Signal abs(FFT)

O N2

Scientific computing III 2013: 12. Fourier analysis 24

Fourier analysis: windowed FT

• In Fourier analysis in principle only the frequency information is obtained.

- Time information can be obtained by using windowed Fourier transform (WFT).

,

where is so called window function.

- For example let’s transform the so called chirp signal

.

- As a windows function we take

H f t h u g u t– e2 ifu ud

=

g u t–

h t t2sin=

g u 1 ucos+ 1– u 10 otherwise

=

Page 13: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 25

Fourier analysis: windowed FT

- Below the signal and its WFT (at different times )t

H f 3

H f 7

h t g t 3–

h t g t 7–

h t

H f

- In the last exercise you will become acquainted with different windows functions and their effect on the power spectrum.

Scientific computing III 2013: 12. Fourier analysis 26

Fourier analysis: spectral applications of FT

• As shown in the beginning of the chapter convolution and correlation functions can be easily computed by using FT.

- Convolution: .

- When convoluting nonperiodic data one has to keep in mind the wrap-around problem which can be cured by zero-padding:1

1. Numerical Recipes, Figures 13.1.3 and 13.1.4.

sj k– rkk N 2– 1+=

N 2SnRn

Page 14: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 27

Fourier analysis: spectral applications of FT

- Correlation: and autocorrelation - Example: Exercise 10, problem 1:

Corr g h j GkHk* Corr g g j GkGk

* G 2=

Matlab:

>> ac1=ifft((abs(fft(y1))).^2);>> ac2=ifft((abs(fft(y2))).^2);

plot(y2,’-b’); hold on; plot(y1,’-r’)

n=100;clf;plot(ac1(1:n),’-ro’);hold on; plot(ac2(1:n),’-b*’)

Scientific computing III 2013: 12. Fourier analysis 28

Fourier analysis: spectral applications of FT

• Digital filters are often used to smoothing or filtering data.

- A general linear filter transforms the input signal to output :

.

- The coefficients and determine the filter behavior.

- If all are zero then the filter is called nonrecursive or finite impulse response (FIR) filter. Otherwise it is called recursive or infinite impulse response (IIR) filter.

- Impulse response is the output of the filter when the input is a delta peak: .

- Impulse response of a FIR is

and as the name says: finite.- For IIR the response is so straightforward to calculate. Let’s take an example:

.- This gives the following filtered data

, , . . .- Solving this recursively gives

showing an exponential decay.

xt yt

yt asyt s–s 1=

pxt bsxt s–

s 1=

q–+=

as bsas

xt t t0=

ytt t0

bt t0–– 1 t t0– q

t t0 otherwise

=

yt ayt 1– xt+=

y1 x1= y2 ay1 x2+=

yt xt axt 1– a2xt 2– at 1– x1+ + + +=

Page 15: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 29

Fourier analysis: spectral applications of FT

- The frequency response of the filter is defined as1

,

where and are the Fourier transforms of the output and input , respectively, and

,

.

- This means that if we know the coefficients , we can immediately calculate the frequency response of the filter. - In practice it is the other way around: we know the desired response and want to build a corresponding filter.

- For nonrecursive filters the frequency response is , from which we can by inverse FT get the coefficients. - This is roughly done such that initially you take a rather large number of coefficients (large ) and compute their values

from the known . Then you zero all except the first and last coefficients (and cyclically shift the last coefficients to the beginning of the array to get rid of negative lags). If the response computed from this set is not satisfactory then you can e.g. increase the number of non-zero coefficients.

- This is only one way to design filters and recursive filters are more complicated to handle. There is a vast literature dealing with the subject.

1. R.H.Shumway, Applied Statistical Time Series Analysis, Prentice-Hall, 1988; Section 2.9.

Y f B f 2

A f 2----------------X f=

Y f X f yt xt

A f 1 ase 2 ifs–

s 1=

p–=

B f 1 bse 2 ifs–

s 1=

q–=

as bs

B fq

B f K

Scientific computing III 2013: 12. Fourier analysis 30

Fourier analysis: spectral applications of FT

- Note that a simple rolling average is also a linear filter:

.

and its frequency response function can be calculated as

.

- A simple example:

.

- Now a demo.

yt1N---- xt s–

s 0=

N 1–=

B f 2 1N2------ e 2 ifs–

s 0=

N 1– 21

N2------ 2 fscos

s 0=

N 1– 22 fssin

s 0=

N 1– 2+= =

N 2=

yt12---xt

12---xt 1–+=

B f 2 14--- 1 e 2 if–+ 1 e2 if+ 1

4--- 2 e2 if e 2 if–+ + 1

2--- 1 2 fcos+= = =

Page 16: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 31

Wavelet transforms

• In Fourier transform one can not at the same time get an accurate picture of the original signal both on the frequency and time axis.

- Uncertainty principle: In order to determine the frequency accurately one has to take a long (in time) sample.

Signal .

Window

h t 5 tsin=

g u1 a ucos+ 1

a---– u 1

a---

0 otherwise=

a 1=

a 1 2=

H f

H f

Scientific computing III 2013: 12. Fourier analysis 32

Wavelet transforms

• In order to get accurate description of data in the time axis (locality) we need many FT basis functions (because the are not localized at all).

- Using the windowed FT we can get some localization but the scale is set to the width of the window :

Features with time scales shorter than are produced in frequency domain.Features with time scales longer than are produced in time domain.

- In Wavelet transformation (WF) the basis functions (wavelets) are derived from so called mother wavelet

- This function is scaled and translated so that we get basis functions that ‘probe’ the original signal at different times ( ) and scales ( ):

- In order to be a wavelet the function must be more or less localized and satisfy the admissibility condition:

,

; is the FT of the wavelet.

- This implies that i.e. wavelet acts as a band-pass filter.

T

TT

u

ts

s t u s 1 2– u t–s

----------

u

u ud

0= u 2 ud

1=

cˆ 2

2-------------------d

= ˆ

ˆ0= 0=

Page 17: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 33

Wavelet transforms

- An example: the Haar wavelet

.

.

- FT of the mother wavelet is

,

.

u1 0 t 1 21– 1 2 u 10 otherwise

=

jk u 2j 2/ 2jx k–=

ˆ ie i 2– 4 sinc 4sin2

---------------------------------------------------------------------=

sinc x xsinx

--------------=

c 2 2ln=

Scientific computing III 2013: 12. Fourier analysis 34

Wavelet transforms

- The wavelet transform of function is defined as

.

- The signal can be reconstructed from the WT by the inverse wavelet transform (IWT)

.

- WT and IWT can be computed based on these equations by utilizing Fourier transforms.

- In addition to actual wavelets usually on adds to the function basis so called scaling functions that take care of the fact that the wavelets can not well describe a constant function (DC component).

- The most common and fastest way to compute the WT is the discrete wavelet transformation (DWT).

f u

f̃ s t c 1 2/– s 1 2– f u s t u ud

=

f u c 1 2/– s 1 2–

s2---------------- u t–

s---------- f̃ s t sd td=

u

Page 18: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 35

Wavelet transforms

- In a way there is redundancy in the CWT.

- In DWT we produce wavelet coefficients from original data points.

- This is usually accomplished by only considering a certain subset of scales.

- Assume the number of data points is a power of two: - We compute the coefficients only for scales , - For scale there are wavelet coefficients and the ‘times’ (or arguments) associated with these points

are ,

N N

N 2J=

2j j 0 J 1–=

2j 1– Nj N 2j=

2n 1+ 2j 1– 1 2– n 0 Nj 1–=

Scientific computing III 2013: 12. Fourier analysis 36

Wavelet transforms

- A simple example:- Our original data is , .- CWT by using the Haar wavelet in matrix form:

- A few examples of the colum vectors of

Scale1

2

4

816

j 0 15WT

X Xi= i 0 15=

Y WX=W

W0 jT 1

2-------– 1

2------- 0 0=

W8 jT 1

2---– 1

2---– 1

2--- 1

2--- 0 0=

W14 jT 1

4---– 1

4---– 1

4--- 1

4---=

W15 jT 1

4--- 1

4---=

Page 19: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 37

Wavelet transforms

- To put it another way the output of the CWT gives us the following

- CWT gives information of the variation of the original data in different length scales.

Y

Y0

Y7Y8

Y11Y12Y13Y14Y15

12

------- X1 X0–

12

------- X15 X14–

12--- X3 X2 X1– X0–+

12--- X15 X14 X13– X12–+

18

------- X7 X4 X3– – X0–+ +

18

------- X15 X12 X11– – X8–+ +

14--- X15 X8 X7– – X0–+ +

14--- X15 X0+ +

= =

Scientific computing III 2013: 12. Fourier analysis 38

Wavelet transforms

• Algorithms performing DWT can be viewed as digital filters.

- Let’s take a simple example of the Haar wavelet.

- Now the basis functions are

,

- The sequence of expansion functions is

, ,

- Each of these functions is supported on the interval .

- The scaling function added to this set is

, .

u 1 0 u 1=

u1 0 u 1 21– 1 2 u 10 otherwise

=

n 2j k+= j 0 0 k 2j

n u 2j 2/ 2ju k–=

In k2 j– k 1+ 2 j–=

u 0 u 1= u 0 1

Page 20: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 39

Wavelet transforms

- We want to describe our data in the wavelet basis:

.

- The coefficients can be obtained from .

- The basis functions for the Haar wavelet can now be written as

.

x t

x t i ii

=

i i i x t=

2k t 1 2 n 2k 2k 1+=0 otherwise

=

2k 1+ t1 2 n 2k=

1– 2 n 2k 1+=0 otherwise

=

Scientific computing III 2013: 12. Fourier analysis 40

Wavelet transforms

- In matrix form this can be written as

, .

- The vectors and can be seen as the time series of even and odd Haar wavelets.

- So, we generated from one data set of length (say) two sets of length .

- One contains the smoothed information and the other the ‘detail’ information of the original signal.

- The Haar expansion can now be applied to the smoothed data set and this gives new sets of length .

- If our original data set length is we can continue the process until we end up with two data sets of of length 1.- One contains the average of the whole set and the other the difference

between the averages of the first and second halves of the set.- This is called the pyramid algorithm.

1

2

3

4

5

6

y1 0

y2 0

y1 2

y2 2

y1 4

y2 4

a a a a– a a a a– a a a a–

x 0x 1x 2x 3x 4x 5

= = a 12

-------–=

y1 y2

N N 2

N 4

N 2m=

Page 21: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 41

Wavelet transforms

- Graphically:

- The inverse WT is obtained by applying the above procedure in the opposite direction and using the inverse of the coef-ficient matrix.

x0x1x2x3x4x5x6x7x8x9x10x11x12x13x14x15

s0d0s1d1s2d2s3d3s4d4s5d5s6d6s7d7

s0s1s2s3s4s5s6s7d0d1d2d3d4d5d6d7

S0D0S1D1S2D2S3D3d0d1d2d3d4d5d6d7

S0S1S2S3D0D1D2D3d0d1d2d3d4d5d6d7

S0D0S1D1D0D1D2D3d0d1d2d3d4d5d6d7

S0S1D0D1D0D1D2D3d0d1d2d3d4d5d6d7

S0D1D0D1D0D1D2D3d0d1d2d3d4d5d6d7

Filter Permute Filter Permute Filter Permute Filter

Scientific computing III 2013: 12. Fourier analysis 42

Wavelet transforms

• The DWT can be viewed as a digital filter:

- What wavelet one uses is determined by the filter coefficients in the transformation matrix.- These coefficients must fulfill various conditions:

1. In order to compute the IWT easily the filter matrix is made orthogonal.2. The sequence of coefficients must a certain number of vanishing moments.

- For example so called DAUB4 wavelets are ‘generated’ by the matrix

xn ckxn k–k 1=

M=

ck

c0 c1 c2 c3

c3 c2– c1 c0–

c0 c1 c2 c3

c3 c2– c1 c0–

c0 c1 c2 c3

c3 c2 – c1 c0–

. . -

Page 22: Fourier analysis - courses.physics.helsinki.fi · Fourier analysis 5 - According to Parseval s theorem the total power of a signal is the same in the time and frequency domains: -

Scientific computing III 2013: 12. Fourier analysis 43

Wavelet transforms

- The coefficients are obtained from equations

, , , .

- Graphically (from NR, Fig. 13.10.1)

c02 c1

2 c22 c3

3+ + + 1=

c2c0 c3c1+ 0=

c3 c2– c1 c0–+ 0=

0c3 1c2– 2c1 3c0–+ 0=

c01 3+

4 2----------------= c1

3 3+4 2

----------------= c23 3–4 2

----------------= c31 3–4 2

----------------=

Scientific computing III 2013: 12. Fourier analysis 44

Wavelet transforms

• Wavelet routines can be found in

GSL: gsl_wavelet_transform_forward(w,data,1,n,work);gsl_wavelet_transform_inverse(w,data,1,n,work);

Matlab: Wavelet Toolbox (from Mathworks; costs money)Various free toolboxes (or collections of routines):

http://www-stat.stanford.edu/~wavelab/http://taco.poly.edu/WaveletSoftware/

• Wavelets have been applied (among other things) in data compression, noise reduction and linear algebra.

- FBI uses wavelets to compress its fingerprint image database.

- The JPEG2000 standard uses wavelets.