Fourier Transform

이은상·2024년 10월 13일

How to Represent Signals?

Taylor series는 polynomials를 사용하여 모든 함수를 표현할 수 있음
f(x)=f(a)+f(a)(xa)+f(a)2!(xa)2+f(a)3!(xa)3+...f(x) = f(a)+f'(a)(x-a)+\frac{f''(a)}{2!}(x-a)^2 + \frac{f'''(a)}{3!}(x-a)^3+...

그러나

  • polynomials are not the best
    • unstable and not very physically meaningful
      computational cost가 높음
  • easier to talk about signals in terms of its frequencies(how fast/often signals change, etc)

Fourier Analysis

복잡한 time-series의 함수가 간단한 sinusoidal functions들의 합으로 표현될 수 있다는 전제에 기반

Sinusoidal function: A general term for periodic functions
주기 함수의 일반적 용어라는 뜻
보통 사인 함수를 뜻하는데, 사인과 코사인 함수를 포괄하는 용어로 사용되기도 함


이렇게 여러 주기함수가 합쳐지면서 target의 모양을 잡아감

Curve Fitting with Sinusoidal Functions

Periodic function

f(t)=f(t+T) whereT:periodf(t) = f(t+T)\quad\space where \quad T:period

A common example: Sinusoidal function

  • sine or cosine function
  • 주기 : π/2\pi/2

여기서는 cosine을 basis for explanations로 사용할 것임

Sinusoidal function

f(t)=A0+C1cos(w0t+θ)f(t) = A_0 + C_1\cos(w_0t+\theta)

  • Mean vlaue A0A_0
    horizontal axis를 따른 높이의 평균
  • Amplitude C1C_1
    oscillation의 height
  • Angular frequency w0w_0
    oscillation이 일어나는 주기
    • relationship between ordinary frequency and period T
       w0=2πf=2πT\space w_0 = 2\pi f = \frac{2\pi}{T}
  • Phase angle θ\theta
    the extent to which the sinusoidal wave is shifted horizontally

phase angle이 들어가면 곡선을 fitting하는 과정이 좀 복잡해짐
→ Trigonometric identity를 사용하여 해결

Trigonometric identity
cos(x+y)=cosxcosysinxsiny\cos(x+y) = \cos{x}\cos{y} - \sin{x}\sin{y}

Then,

C1cos(w0t+θ)=C1[cos(w0t)cos(θ)sin(w0t)sin(θ)]C_1\cos{(w_0t+\theta)} = C_1[\cos{(w_0t)}\cos{(\theta)} - \sin{(w_0t)}\sin{(\theta)}]
f(t)=A0+A1cos(w0t)+B1sin(w0t)\rightarrow f(t) = A_0+A_1\cos{(w_0t)} + B_1\sin{(w_0t)}
\quad Note: C1=A12+B12andθ=arctan(B1/A1)C_1 = \sqrt{A_1^2 + B_1^2}\quad and \quad \theta = arctan(-B_1/A_1)
 cos(θ)=C1A1\quad\space\cos(\theta) = \frac{C_1}{A_1}, sin(θ)=C1B1\sin(\theta) = -\frac{C_1}{B_1}, tan(θ)=A1B1\tan(\theta) = -\frac{A_1}{B_1}

Another example of a general linear regression model → can apply the least squares method
y=β0f0(x1,x2,...,xp)+β1f1(x1,x2,...,xp)+...+βmfm(x1,x2,...,xp)+ϵy = \beta_0\cdot f_0(x1,x_2,...,x_p) + \beta_1\cdot f_1(x_1,x_2,...,x_p) + ... + \beta_m\cdot f_m(x_1,x_2,...,x_p)+\epsilon

Sum of squared errors (SSE)

SSE=Ni=1{yi[A0+A1cos(w0t)+B1sin(w0t)]}2SS_E = \underset{i=1}{\overset{N}{\sum}}\{y_i - [A_0 + A_1\cos(w_0t) + B_1\sin(w_0t)]\}^2
그냥 real value에 estimated value를 뻰 값을 제곱한 거임

에러를 계산하는 거니까 당연히 작은 값이 나오도록 해야 됨

Normal equation


time intervals t\bigtriangleup t들이 uniform하고 N observations with T=(N1)tT=(N-1)\bigtriangleup t가 있다면 계산이 간단해지고 parameter (A0,A1,B1)(A_0,A_1,B_1)을 구하기 쉬워짐


이렇게 구할 수 있게됨!

따라서
sinusoidal function: f(t)=A0+A1cos(w0t)+B1sin(w0t)f(t) = A_0+A_1\cos{(w_0t)} + B_1\sin{(w_0t)}

  • A0=yNA_0 = \frac{\sum y}{N}
  • A1=2Nycos(w0t)A_1 = \frac{2}{N}\sum y\cos(w_0t)
  • B1=2Nysin(w0t)B_1 = \frac{2}{N}\sum y\sin(w_0t)

General model

더 자세히 표현할 경우
f(t)=A0+A1cos(w0t)+B1sin(w0t)+A2cos(2w0t)+B2(2w0t)+...+Amcos(mw0t)+Bmsin(mw0t)f(t) = A_0 + A_1\cos(w_0t)+B_1\sin(w_0t)+A_2\cos(2w_0t)+B_2(2w_0t)+...+A_m\cos(mw_0t)+B_m\sin(mw_0t)

  • A0=yNA_0 = \frac{\sum y}{N}
  • Aj=2Nycos(jw0t)A_j = \frac{2}{N}\sum y\cos(jw_0t)
  • Bj=2Nysin(jw0t)B_j = \frac{2}{N}\sum y\sin(jw_0t)
    j=1,2,...,mj=1,2,...,m

Continuous Fourier Series

fourier는 모든 주기 함수는 infinite series of sinusoidal functions로 표현될 수 있다는 것을 증명함

  • function with period T에 따라 Fourier series는 다음과 같이 표현됨
    f(t)=a0+a1cos(w0t)+b1sin(w0t)+a2cos(2w0t)+b2sin(2w0t)+...f(t) = a_0 + a_1\cos(w_0t)+b_1\sin(w_0t)+a_2\cos(2w_0t)+b_2\sin(2w_0t)+...
    =a0+k=1[akcos(kw0t)+bksin(kw0t)]\quad\quad= a_0 + \underset{k=1}{\overset{\infty}{\sum}}[a_k\cos(kw_0t)+b_k\sin(kw_0t)]
    whereak=2T0Tf(t)cos(kw0t)dt   bk=2T0Tf(t)sin(kw0t)dt   a0=1T0Tf(t)dt\quad\quad where \quad a_k = \frac{2}{T}\int_0^T f(t)\cos(kw_0t)dt\\ \quad\quad\quad\quad\quad\space\space\space b_k=\frac{2}{T}\int_0^T f(t)\sin(kw_0t)dt\\ \quad\quad\quad \quad \quad \space \space \space a_0 = \frac{1}{T}\int_0^T f(t)dt

    • w0w_0 : Fundamental frequency
    • 2w0,3w0,...2w_0,3w_0,... : Harmonics

Euler's formula

e±ix=cosx±isinxe^{\pm ix} = \cos x \pm i\sin x

이 공식을 사용해서 Fourier series를 더 compact하게 표현할 수 있음

f(t)=k=c~keikw0tf(t) = \underset{k=-\infty}{\overset{\infty}{\sum}}\tilde{c}_ke^{ikw_0t}
c~k=1TT2T2f(t)eikw0tdt\tilde{c}_k = \frac{1}{T}\int_{-\frac{T}{2}}^{\frac{T}{2}}f(t)e^{ikw_0t}dt

Euler's formula에서 얻은 정보

  • cosx=eix+eix2\cos x = \frac{e^{ix}+e^{-ix}}{2}
  • sinx=eixeix2i\sin x = \frac{e^{ix}-e^{-ix}}{2i}

Frequency and Time Domains

위에서의 Fourier analysis는 시간 domain으로 제한이 되어 있음
Fourier analysis는 frequency domain으로도 해석될 수 있음

예시
f(t)=C1cos(t+π2)f(t) = C_1\cos(t+\frac{\pi}{2})

  • (b) : projection of the curve onto the time plane
  • (c) : projection of the curve onto the frequency plane
  • (d) : projection of the curve onto the phase angle plane

Fourier series와 같은 complex cases의 경우에는

이렇게 복잡한 waveforms를 이해하는 것에 도움을 줌

Fourier Integral and Transform

reality에는 non-repetitive(non-periodic)한 waveforms도 많음

Fourier Integral

transition from periodic to non-periodic functions can be achieved by letting the period T approach infinity
T를 무한대로 설정하면 주기함수를 non-periodic 함수로 변환할 수 있음

T가 infinite가 되면 function은 다시 반복하지 않게 됨 → 주기가 없어짐

{f(t)=12πF(iw0)eiw0tdw0Inverse Fourier Transform (IFT)F(iw0)=f(t)eiw0tdtFourier Transform (FT)\begin{cases} f(t) = \frac{1}{2\pi}\int_{-\infty}^{\infty} F(iw_0)e^{iw_0t}dw_0 & \text{Inverse Fourier Transform (IFT)}\\ F(iw_0) = \int_{-\infty}^{\infty}f(t)e^{-iw_0t}dt & \text{Fourier Transform (FT)} \end{cases}
밑의 식을 위로 변환하면 IFT, 위의 식을 아래로 변환하면 FT라는 뜻임

IFT, FT에 따른 결과는 이런 식으로 됨↓

복기 : 주기가 있는 경우
{f(t)=k=c~keikw0tInverse Fourier Transform (IFT)c~k=1TT/2T/2f(t)ekw0tdtFourier Transform (FT)\begin{cases}f(t) = \underset{k=-\infty}{\overset{\infty}{\sum}}\tilde{c}_k e^{ikw_0t} & \text{Inverse Fourier Transform (IFT)}\\ \tilde{c}_k = \frac{1}{T}\int_{-T/2}^{T/2}f(t)e^{-kw_0t}dt & \text{Fourier Transform (FT)}\end{cases}

Discrete Fourier Transform (DFT)

일반적으로, 데이터는 discrete values로 수집됨
0에서 T까지, there are n evenly spaced data points with a width of T/n\bigtriangleup T/n

Discrete Fourier Transform (DFT)

Fk=N1n=0fneikw0nfor k=0 to N-1F_k = \underset{n=0}{\overset{N-1}{\sum}}f_ne^{ikw_0n}\quad \quad\quad\text{for k=0 to N-1}
적분을 급수함수로 변경한 임

Inverse Discrete Fourier Transform (IDFT)

fn=1NN1k=0Fkeikw0nfor n=0 to N-1f_n = \frac{1}{N}\underset{k=0}{\overset{N-1}{\sum}}F_ke^{ikw_0n} \quad\quad\text{for n=0 to N-1}

Fast Fourier Transform (FFT)

DFT는 n2n^2 operations가 필요 → 계산적으로 비쌈

FFT는 DFT를 더 효율적으로 계산할 수 있도록 만들어진 알고리즘
Fk=N1n=0fneikw0nF_k = \underset{n=0}{\overset{N-1}{\sum}}f_ne^{-ikw_0n}

  • 이전 계산 결과를 재사용함으로써 계산량을 줄임
  • in particular, it leverages the periodicity and symmetry of trigonometric functions
  • O(n2)O(nlogn)O(n^2)\rightarrow O(n\log n)

근데 요즘은 DFT, FFT 구분 잘 안한다고 함

Power Spectrum

electrical engineering에서 power는 일반적으로 proportional to the square of the voltage or current함

this concept is extended to Fourier analysis, where power is calculated as the sum of the squares (or the integral) of the Fourier coefficietns

Pk=c~k2orP(w)=F(w)2P_k = \lvert\tilde{c}_k\rvert^2 \quad \text{or} \quad P(w)=\lvert F(w)\rvert^2

Other Frequency Spectrums

여기에 나오는 식들에서 R: realvalue(실수부), I: imaginal value(허수부)

Complex spectrum

F(u,v)=R(u,v)+iI(u,v)F(u,v) = R(u,v)+iI(u,v)

Magnitude spectrum

F(u,v)=R2(u,v)+I2(u,v)\lvert F(u,v)\rvert = \sqrt{R^2(u,v) + I^2(u,v)}

Phase spectrum

ϕ(u,v)=tan1(I(u,v)/R(u,v))\phi (u,v) = \tan^{-1}(I(u,v)/R(u,v))

Power spectrum

일반적으로 사용
P(u,v)=F(u,v)2=R2(u,v)+I2(u,v)P(u,v) = \lvert F(u,v)\rvert^2 = R^2(u,v) + I^2(u,v)

Fourier Transform Pairs

Cosine function with frequency

f(x)=cos(w0x)F(u)=π2(δ(u+w0)+δ(uw0))f(x) = \cos(w_0x) \quad\quad F(u) = \sqrt{\frac{\pi}{2}}\cdot (\delta(u+w_0)+\delta(u-w_0))

e.g. w0=3w_0 = 3


오른쪽 그래프의 y축 : power or magnitude spectrum

Sine function with frequency

f(x)=sin(w0x)F(u)=iπ2(δ(u+w0)δ(uw0))f(x) = \sin(w_0x) \quad\quad F(u) = i\sqrt{\frac{\pi}{2}}\cdot (\delta(u+w_0)-\delta(u-w_0))

e.g. w0=5w_0 = 5

Rectangular pulse

f(x)=Πb(x)={1for |x|b0otherwiseF(u)=π2(δ(u+w0)+δ(uw0))f(x)=\Pi_b(x) = \begin{cases} 1 & \text{for |x|}\leq b \\ 0 & \text{otherwise} \end{cases} \quad\quad F(u) = \sqrt{\frac{\pi}{2}}(\delta(u+w_0)+\delta(u-w_0))

e.g. b=2b=2

Gaussian function

f(x)=1σexp(x22σ2)F(u)=exp(σ2u22)f(x) = \frac{1}{\sigma}\exp(-\frac{x^2}{2\sigma^2}) \quad\quad F(u)=\exp(-\frac{\sigma^2u^2}{2})

e.g. σ=3\sigma=3

Fourier Transform and Convolution


이렇게 식을 전개하면, 결과값은 두 component의 곱으로 표현이 된다는 것을 알 수 있음
Convolution in spatial domainMultiplication in frequency domain\text{Convolution in spatial domain} \longleftrightarrow \text{Multiplication in frequency domain}

따라서, g(x)g(x)를 Fourier transform을 통해 구할 수 있음

  • 각각 f, h에 FT 실행
  • 두 값 곱하기
  • 곱한 값 IFT 취하기

convolution 연산량이 많은 경우 이렇게 계산하는 것을 통해 연산량을 줄일 수 있음

Example use: Smoothing/Blurring

  • f(x)f(x)의 smoothed function을 구하고자 함
    g(x)=f(x)h(x)\quad \quad g(x) = f(x)*h(x)
  • 가우시안 커널을 사용할 것임
    h(x)=12πσexp[12(2πu)2σ2]\quad\quad h(x)=\frac{1}{\sqrt{2\pi}\sigma}\exp\big[-\frac{1}{2}(2\pi u)^2\sigma^2\big]
  • Then,

H(u)=exp12(2πu)2σ2\quad\quad H(u) = \exp\lfloor -\frac{1}{2}(2\pi u)^2\sigma^2\rfloor
G(u)=F(u)H(u)\quad\quad G(u) = F(u)H(u)

H(u)H(u)F(u)F(u)의 고주파를 attenuate함
→ low frequency만 통과시키는 Low-pass Filter

2-D Fourier Transform

별 다른 거 없음..

u,v는 각각 x,y

2D의 경우, 1D에 없었던 방향이 생김

Image and Fourier Transform

spatial function f(x,y)f(x,y)

f(x,y)=F(u,v)ei2π(xu+yv)dudvf(x,y) = \int_{-\infty}^{\infty}\int_{-\infty}^{\infty}F(u,v)e^{i2\pi(xu+yv)}dudv
는 decomposed into a weighted sum of 2D orthogonal basis functions

Image Processing in the Fourier Domain

RGB의 경우는 각각 chanel에 적용 후 평균을 구하는 식으로 진행함

Convolution is Mulfiplication in Fourier Domain

Low-Pass Filtering


고주파를 제거하면 blur 효과가 일어남

High-Pass Filtering


저주파를 제거하면 large strucres가 사라지고 edge와 같은 부분만 남게됨

Most Information at Low Frequencies

Fun with Fourier Spectra

0개의 댓글