18
17. Numerical Filtering

17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

17. Numerical Filtering

Page 2: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

� = 0 � = �

• Consider a signal �(�), such as velocity, varies in space � (or time �) between 0, � .

For example:

� � = 0.5 × sin (��) − 0.3 × cos (2��) + 0.7 × cos (12��) + 0.5 × sin (48��) − 0.6 × cos (64��)

• The fluctuating signal is decomposed into Fourier components with various wavenumbers:

0.5 × sin (��)

−0.3 × cos (2��)

0.7 × cos (12��)

0.5 × sin (48��)

−0.6 × cos (64��)

� = 0 � = �

Function in Physical Domain versus Spectrum in Wavenumber (or Frequency) Domain

� =2�

�� = �� = �2�

Page 3: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

� � = 0.5 × sin (��) − 0.3 × cos (2��) + 0.7 × cos (12��) + 0.5 × sin (48��) − 0.6 × cos (64��)

0.5 × sin (��)

0.5 × sin (��) − 0.3 × cos (2��)

0.5 × sin (��) − 0.3 × cos (2��) + 0.7 × cos (12��)

0.5 × sin (��) − 0.3 × cos (2��) + 0.7 × cos (12��) + 0.5 × sin (48��)

� = 0 � = �� =2�

Page 4: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

� = 0 � = �

� � = 0.5 × sin (��) − 0.3 × cos (2��) + 0.7 × cos (12��) + 0.5 × sin (48��) − 0.6 × cos (64��)

• Spectrum of � :

Sample the signal at discrete �� and expressed by discrete Fourier transform:

The largest ⇒ � = 128. Means � must be sampled at least on 128 grids.� = 6 4 =�

2

�� = � ���������

��

��

�� ���

= 0 − 0.25� ����� + 0 + 0.25� ������

+ −0.15 + 0� ������ + −0.15 − 0� �������

+ 0.35 + 0� ������� + 0.35 − 0� ��������

+ 0 − 0.25� ������� + 0 + 0.25� ��������

+ −0.3 + 0� ������� + −0.3 − 0� ��������

�� = �� = �2�

�� = � ��� ������

��

��

�� ���

= � ��� ������

��

��

��

�� ���

= � ��� ������

��

��

�� ���

� = 0, 1, 2, ⋯ , ��� =�

��

Page 5: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

����

What is the physical meaning of spectral density ����

?

�� = � ���������

��

��

�� ���

= 0 − 0.25� ����� + 0 + 0.25� ������

+ −0.15 + 0� ������ + −0.15 − 0� �������

+ 0.35 + 0� ������� + 0.35 − 0� ��������

+ 0 − 0.25� ������� + 0 + 0.25� ��������

+ −0.3 + 0� ������� + −0.3 − 0� ��������

� = 0 � = �

0.090.1

0.05

0.0225

0.0625

0.1225

0.0625

0.15

Page 6: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

� �� ⋅ ��∗

� ��

�� �

= � � ��� �����

� ��

�� �

⋅ � ���∗ ������

� ��

�� �

� ��

�� �

= � � ���

� ��

�� �

� ���∗ ��(���)��

� ��

�� �

� ��

�� �

= � ��� � ���∗ � ��(���)

���

� � ��

�� �

� ��

�� �

� ��

�� �

�� = � ��� �����

��

��

�� ���

= � ��������

� ��

�� �

��� =1

�� �� ������

� ��

�� �

discrete Fourier transform pair

� ���∗ ������

��

��

�� ���

= � ���∗������

� ��

�� �

= ��∗

1

�� ��

∗ �����

� ��

�� �

= ���∗

discrete Fourier transform pair of conjugate

� ��(���)���

� � ��

�� �

= � � if

� − �

� is an integer

0 otherwise

But,���

�= integer only happens only � = �.

Recall the orthogonality property of ����:

� �� ⋅ ��∗

� ��

�� �

= � � ��� ⋅ ���∗

� ��

�� �

∴ � ���

� ��

�� �

= � � ����

� ��

�� �

or

Parseval’s Theorem of Discrete Fourier Transform0 1 2� = ��−1�

�� =2�

��

Page 7: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

• Parseval’s theorem for Fourier transform of continuous function:

� � � ⋅ �∗ � ���

��

= � �� � ⋅ ��∗ � ���

��

� � � � ���

��

= � �� ��

���

��or

� �� ⋅ ��∗

� ��

�� �

= � � ��� ⋅ ���∗

� ��

�� �

� ���

� ��

�� �

= � � ����

� ��

�� �

or

• Parseval’s theorem for discrete Fourier transform:

• If � is the velocity, the left-hand side of the equality represents the total kinetic energy.

Parseval’s theorem can then be interpreted as :

The total energy is the summation of energies contributed by all spectral components ���(or �� � ).

• The contribution of the spectral component of wavenumber � (or �) is proportional to ����

(or �� ��

).

• Therefore, we can interpret ����

(or �� ��

) as the energy per unit wavenumber of the

spectral component.

In other word, ����

(or �� ��

) is the energy spectral density of �.

Page 8: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

Averaging and Filtering

�̅ � =1

�� � � ��

����

����

• The averaged function �̅ � depends on the averaging interval � employed.

The larger � will result in smoother �̅ � .

• In analyzing the fluctuating function �(�), it is desirable to decompose � � into a averaged

(smoothed) part �̅ � plus a fluctuation �′(�), i.e., � � = �̅ � + �′(�)

• This corresponds to filtered out the fluctuation �′ from �, or find the smoothed counterpart �.̅

• The most straightforward smoothing scheme is to use the vicinal mean at �:

�� ��

original function � averaged function �̅ with �� averaged function �̅ with ��

Page 9: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

• Thus, a more general way which leads to smoothing is to employ a filter function � � − � :

�̅ � = � � � � � − � ���

��

• The vicinal-mean smoothing can be represented in term of a filter function:

�̅ � =1

�� � � ��

����

����

= � � �1

���

����

����

≡ � � � � � − � ���

��

� � − � =1

� where � − � <

2

� � � ���

��

= 1

� � =6

� 1

� exp −

6

� �

• A commonly used Gaussian filter function � � :

0 10 20−10−20

� = 8

� = 16

0.2

0.1

0

Page 10: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

• Discrete form of filtering:

�̅ � = � � � � � − � ���

��

��̅ = � �� ����

� ��

�� �

= �� ∙ �� +�� ∙ ���� + ⋯ + ���� ∙ �� +�� ∙ �� +���� ∙ ��� + ⋯ + �� �� ∙ ���� �� +�� �� ∙ ���� ��

1 2�= 0 ��−1

��

��

���� ����

������� �� �� ���� ���� ������ ��� �� ������� ��

�� ���� �� ��

• Filtering of a continuous function �:

Page 11: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

Filtering in Physical versus Wavenumber (or Frequency) Domain

� ∗ � � = � � � � � − � ���

��

= � � � − � � � ���

��

�̅ � = � � � � � − � ���

��

• Filtering carried out in physical domain:

• This suggests that the filtering can be done by:

• Convolution of two functions:

� � ∗ � = 2� � � ⋅ � �

• Fourier transform of a convolution (convolution theorem):

This is the form of filtering.

�̅ � = (� ∗ �)(�) = ��� � � ∗ � = ��� 2� � � ⋅ � �

�� � =1

2�� � � �������

��

≡ � �

� � = � �� � �������

��

≡ ��� ��

Fourier transform pair

Page 12: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

• Convolution of discrete functions:

• Discrete Fourier transform of a convolution:

��� =1

�� �� �����

���

� ��

�� �

= � ��

�� = � ��� �������

��

��

�� ���

= � ��� �������

� ��

�� �

= ���(���)

discrete Fourier transform pair

• Discrete form of filtering: ��̅ = � �� ����

� ��

�� �

�� ∗ �� ≡ � �� ����

� ��

�� �

= � � ��� �������

� ��

�� �

� ��ℓ ����ℓ ���

� ��

ℓ� �

� ��

�� �

= � ��� � ��ℓ

� ��

ℓ� �

� �������

� ��

�� �

����ℓ ���

� ��

�� �

= � ��� � ��ℓ

� ��

ℓ� �

����ℓ�� � ����

(��ℓ)��

� ��

�� �

� ��

�� �

= � ��� � ��ℓ

� ��

ℓ� �

����ℓ�� � ∙ �(� − ℓ)

� ��

�� �

= � ∙ � ��� ∙ ��� �������

� ��

�� �

= � ∙ ���(��� ∙ ���)

� �� ∗ �� = � � ���(��� ∙ ���) = � ∙ ��� ∙ ��� = � ∙ � �� ∙ � ��

• Again, this suggests that the filtering can be done by:

��̅ = �� ∗ �� = ��� � �� ∗ �� = ��� � ∙ � �� ⋅ � ��

Page 13: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

• Computing discrete filtering using FFT:

��̅ = � �� ����

� ��

�� �

= �� ∗ �� = ��� � �� ∗ �� = ��� � ∙ � �� ⋅ � ��

� �

������ ���� �� ���� �� ��

��̅��̅�� ��̅�� ��̅ ����̅ ��̅ ��̅

• In general, the transformed filtered function

ℑ �� can be derived analytically.

• So only one forward and one backward transform are needed to be computed.

• Since an FFT only requires � log�� operations, while filtering in physical domain requires ��

operations; filtering in wavenumber domain is far more efficient than doing in physical domain.

� � � = ����

� � � = ����

0 0.5 1 1.5 2 2.5 3

�� =2�

��

spec

tral

den

sity

Page 14: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

� � = �1

� for � <

20 otherwise

• Top-Hat Filter Function:

� � =sin ��

σ2

��σ2

0 50 100 150 200

0.4

-0.4

0

��

��̅

��̅

2= 4

σ

2= 8

0 10 20−10−20�

0.2

0.1

0

�� = �� = �2�

��Δ = �2�

�= 2�

σ

2= 4

σ

2= 8

0

1

0 1 2 3��Δ

σ

2= 4

σ

2= 8

Page 15: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

� � = ����

����

� � =6

1

Δ�

��

��

• Gaussian Filter Function

0 50 100 150 200

0.4

-0.4

0

��

��̅

��̅

0 1 2 3

0

1

� = 8

� = 16

��Δ = 2��

0 10 20−10−20

σ = 8

σ = 16

0.2

0.1

0

Page 16: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

� �(�) = �1 for �� < ��

0 otherwise• Sharp-cutoff Filter Function

�� =�

�� � =

sin(���)

��

0 50 100 150 200

0.4

-0.4

0

��

��̅

��̅

�� =2�

16

0

1

0 1 2 3

�� =2�

8

0.2

0

0 10 20−10−20�

�� =2�

16

�� =2�

8

��Δ = 2��

cutoff wavenumber

Page 17: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)

0

1

1

� � =sin ��

σ2

��σ2

Top-hat

0

1

� = 8

� = 16

� � = ����

����

Gaussian

�� =2�

16

0

1

0 1 2 3

�� =2�

8

��Δ = 2��

� �(�) = �1 for �� < ��

0 otherwise

Sharp-cutoff

0 50 100 150 200

�� ��̅��̅

σ = 8

σ = 16

Page 18: 17. Numerical Filteringhomepage.ntu.edu.tw/~wttsai/fortran/ppt/17.Numerical_Filtering.pdf · = 0.5×sin()−0.3×cos(2)+0.7×cos(12)+0.5×sin(48)−0.6×cos(64) 0.5×sin() 0.5×sin()−0.3×cos(2)