4. 傅立葉轉換


Posted by 高肥 on 2022-07-16

4. 傅立葉轉換

傅立葉級數為法國數家傅立葉(Joseph Fourier)所提出的三角級數,可以將任何週期函數分解為 $\sin\left(\right)$ 與 $\cos\left(\right)$ 函數的集合,也就是對週期波進行分解,之後可透過傅立葉轉換(Fourier Transform)將函數轉換為另一個函數表現形式。

4.1 傅立葉級數定義(Fourier Series)

若函數 $x(t)$ 定義於時間區間$-L\leq t\leq L$
則傅立葉級數為:
$x(t)=a_0+\sum_{n=1}^\infty\lbrack a_n\cos\left(\frac{n\mathrm\pi}Lt\right)+b_n\sin\left(\frac{n\mathrm\pi}Lt\right)\rbrack$

其中:
$\begin{aligned}
a_0 & = \frac1{2L}\int_{-L}^Lx(t)\operatorname dt\\
a_n & = \frac1L\int_{-L}^Lx(t)\cos\left(\frac{n\mathrm{πt}}L\right)\operatorname dt\\
b_n & = \frac1L\int_{-L}^Lx(t)\sin\left(\frac{n\mathrm{πt}}L\right)\operatorname dt\\
n & = 1,\;2,\;\dots
\end{aligned}$

4.2 複數傅立葉級數(Complex Fourier Series)

參考Euler's Formula

$\begin{aligned}
e^{jt} & = \cos\left(t\right)+j\sin\left(t\right)\\
cos\left(t\right) & = \frac12\left(e^{jt}+e^{-jt}\right)\\
sin\left(t\right) & = \frac1{2j}\left(e^{jt}-e^{-jt}\right)
\end{aligned}$

則:
$
\begin{aligned}
x(t) & = \sum_{-\infty}^\infty c_ne^{jnt}\\
c_n & = \frac1{2\mathrm\pi}\int_{-\mathrm\pi}^{\mathrm\pi}x(t)e^{-jnt}\operatorname dt
\end{aligned}
$

範例

理想方波函數定義為
$
\delta\lbrack n \rbrack =
\begin{cases}
-1, & if\;-1<t<0 \\
1, & if\;0\leq t<1
\end{cases}
$
求函數的傅立葉級數

解法

$\begin{aligned}
a_0 & = \frac1{2L}\int_{-L}^Lx(t)\operatorname dt\\
& = \int_{-1}^1x(t)\operatorname dt\\
& = \int_{-1}^0(-1)\operatorname dt+\int_0^1(1)\operatorname dt\\
& = 0\\
a_n & = \frac1L\int_{-L}^Lx(t)\cdot\cos\left(\frac{n\mathrm{πt}}L\right)\operatorname dt\\
& = \int_{-1}^1x(t)\cdot\cos\left(n\mathrm{πt}\right)\operatorname dt\\
& = \int_{-1}^0(-1)\cdot\cos\left(n\mathrm{πt}\right)\operatorname dt+\int_0^1(1)\cdot\cos\left(n\mathrm{πt}\right)\operatorname dt\\
& = {\lbrack-\frac1{n\mathrm\pi}\sin\left(n\mathrm{πt}\right)\rbrack}_{-1}^0+{\lbrack\frac1{n\mathrm\pi}\sin\left(n\mathrm{πt}\right)\rbrack}_0^1\\
& = 0\\
b_n & = \frac1L\int_{-L}^Lx(t)\cdot\sin\left(\frac{n\mathrm{πt}}L\right)\operatorname dt=\int_{-1}^1x(t)\cdot\sin\left(n\mathrm{πt}\right)\operatorname dt\\
& = \int_{-1}^0(-1)\cdot\sin\left(n\mathrm{πt}\right)\operatorname dt+\int_0^1(1)\cdot\sin\left(n\mathrm{πt}\right)\operatorname dt\\
& = {\lbrack\frac1{n\mathrm\pi}\cos\left(n\mathrm{πt}\right)\rbrack}_{-1}^0+{\lbrack-\frac1{n\mathrm\pi}\cos\left(n\mathrm{πt}\right)\rbrack}_0^1\\
& = \frac2{n\mathrm\pi}-\frac2{n\mathrm\pi}\cos\left(n\mathrm\pi\right)\\
& = \frac2{n\mathrm\pi}\lbrack1-{(-1)}^n\rbrack
\end{aligned}$

因此理想方波的傅立葉級數為
$x(t)=\sum_{n=1}^\infty\frac2{n\mathrm\pi}\lbrack1-{(-1)}^n\rbrack\sin\left(n\mathrm{πt}\right)$

理想方波的傅立葉級數,若取出部分總和畫圖,可呈現如下圖的效果
下左圖取傅立葉級數前5項總和,下右圖取傅立葉級數前100項總和
可以看到在方波的波峰與波谷部分有跳動現象,稱為Gibbs現象

繪圖程式如下

import numpy as np
import matplotlib.pyplot as plt

N = eval( input( "Please enter number of terms for partial sum: " ) )

t = np.linspace( -1, 1, 1000 )  # 定義時間陣列    

x = np.zeros( 1000 )            # 方波的傅立葉級數
for n in range( 1, N + 1 ):
    x += 2 / ( n * np.pi ) * ( 1 - np.power( -1, n ) ) * np.sin( n * np.pi * t ) 

plt.plot( t, x )                                
plt.xlabel( 't (second)' )
plt.ylabel( 'Amplitude' )

plt.show( )

4.3 連續時間傅立葉轉換

函數 $\mathrm x(\mathrm t)$
傅立葉轉換:$\mathrm X(\mathrm\omega)=\int_{-\infty}^\infty\mathrm x(\mathrm t)\mathrm e^{-\mathrm{jωt}}\operatorname d\mathrm t$
反傅立葉轉換:$\mathrm x(\mathrm t)=\frac1{2\mathrm\pi}\int_{-\infty}^\infty\mathrm X(\mathrm\omega)\mathrm e^{\mathrm{jωt}}\operatorname d\mathrm\omega$

範例

弦波定義
$x(t)=A\cos\left(\omega_0t\right)$
求傅立葉轉換?

解法

$\begin{aligned}
X(\omega) & = \int_{-\infty}^\infty x(t)e^{-j\omega t}\operatorname dt\\
& = \int_{-\infty}^\infty A\cos\left(\omega_0t\right)e^{-j\omega t}\operatorname dt\\
& = A\int_{-\infty}^\infty (\frac{e^{j\omega t}+e^{-j\omega t}}2)\cdot e^{-j\omega t}\operatorname dt\\
& = \frac A2\lbrack\mathcal F\{e^{j\omega t}\}+\mathcal F\{e^{-j\omega t}\}\rbrack\\
& = A\mathrm\pi\lbrack\mathrm\delta(\mathrm\omega-{\mathrm\omega}_0)+\mathrm\delta(\mathrm\omega+{\mathrm\omega}_0)\rbrack
\end{aligned}$
其中$\mathcal F\{\mathrm e^{\mathrm{jωt}}\}=2\mathrm{πδ}(\mathrm\omega-{\mathrm\omega}_0)$

上述的傅立葉轉換可畫出下圖
可以看到訊號經過傅立葉轉換後,在頻域會有共軛性
但是在實際應用中,我們並不理會負頻率

此特性要記住,在後續 [5. 頻譜分析]的章節 (待續),

會Demo透過Numpy的FFT計算出的結果也會有這個現象,
然後說明如何在程式中去除負頻率的部分。

4.4 傅立葉轉換性質

  1. 時間平移定理 (Time-Shifting Theorem

    若 $f$ 為時間函數,且 $\mathcal F$ 為傅立葉轉換
    則:$\mathcal F\{f(t-t_0)\}=F(\omega)\cdot e^{j\omega t_0}$
    其中 $t_0$ 為平移的時間,且 $t_0>0$

  2. 頻率平移定理 (Frequency-Shifting Theorem)

    若 $F$ 為頻率函數,且 $\mathcal F^{-1}$ 為反傅立葉轉換
    則:$\mathcal F^{-1}\{F(\omega-\omega_0)\}=f(t)\cdot e^{j\omega_0t}$
    其中 $\omega_0$ 為平移的時間,且 $\omega_0>0$

  3. 卷積定理

    若 $f$與$g$ 為時間函數,且 $\mathcal F$ 為傅立葉轉換
    則:$\mathcal F\{f\ast g\}=\mathcal F{f}\ast\mathcal F{g}$

4.5 離散傅立葉轉換 (Discrete Fourier Transform)

現實中在處理資料時型式通常為有限多點的狀況,是對取樣值而非函數來進行處理。在這種情況下我們可透過離散時間傅立葉轉換(DTFT)來處理資料。

若給定離散時間序列
則離散時間傅立葉轉換為:$X\lbrack k\rbrack=\sum_{n=0}^{N-1}x\lbrack n\rbrack\cdot e^{-j\frac{2\mathrm\pi}Nkn}$

反離散時間傅立葉轉換為:$x\lbrack n\rbrack=\frac1N\sum_{k=0}^{N-1}X\lbrack k\rbrack\cdot e^{j\frac{2\mathrm\pi}Nkn}$

範例

若數位訊號為:$x=\{1,\;2,\;3,\;4\},\;n=0,\;1,\;2,\;3$
其中$N=4$
求離散傅立葉轉換?

解法

透過離散傅立葉轉換公式
$X\lbrack k\rbrack=\sum_{n=0}^{N-1}x\lbrack n\rbrack\cdot e^{-j\frac{2\mathrm\pi}Nkn}$

可求得
$X={10,\;-3+j,\;0,\;-3-j}$

上述習題結果注意幾點

  • $X\lbrack0\rbrack$為訊號的直流分量 (DC Component)
  • $X\lbrack1\rbrack\;\sim\;X\lbrack3\rbrack$為訊號的交流分量 (AC Component)
  • $X\lbrack1\rbrack$ 與 $X\lbrack3\rbrack$互為共軛複數

Ref:


#Signal_Processing #DSP_Class







Related Posts

Day 95

Day 95

MTR04_1104

MTR04_1104

React(11) - class & function component 比較 & useRef

React(11) - class & function component 比較 & useRef


Comments