• Fourier Transform


    Fourier Transform

    基本的定义

    严格来说, 傅里叶变换是Schwartz space 上的一一映射, 对于(L^1), 即可积函数我们都可以找到其对应的傅里叶变换.

    符号 定义
    傅里叶变换: (hat{f}(u)) (int_{-infty}^{+infty} f(t) e^{-j2pi u t} mathrm{d}t)
    逆傅里叶变换: (check{F}(t)) (int_{-infty}^{+infty} F(u) e^{j2pi tu} mathrm{d}u)
    离散傅里叶变换: (F_m=hat{f}_m) (sum_{n=0}^{N-1} f_n e^{-j2pi nm/N})
    离散逆傅里叶变换: (f_n = check{F}_n) (frac{1}{N}sum_{m=0}^{N-1} F_m e^{j2pi mn /N})
    卷积: (f star g (t)) (int_{-infty}^{+infty} f( au) g(t- au) mathrm{d} au)
    correlation: (f ullet g(t)) (int_{-infty}^{+infty}f^*( au)g( au + t)mathrm{d} au)
    二元傅里叶变换: (hat{f}(u, v)) (int_{-infty}^{+infty}int_{-infty}^{+infty} f(t, z) e^{-j2pi ut} e^{-j2pi vz} mathrm{d}t mathrm{d}z)
    二元傅里叶逆变换: (check{F}(t, z)) (int_{-infty}^{+infty}int_{-infty}^{+infty} F(u, v) e^{j2pi tu} e^{-j2pi zv} mathrm{d}t mathrm{d}z)
    二元卷积: (f star g (t, z)) (int_{-infty}^{+infty}int_{-infty}^{+infty} f( au, omega) g(t - au, z - omega) mathrm{d} au mathrm{d}omega)
    共轭 (f^*(t) = [r(t) + j i(t)]^* = r(t) - ji(t), quad r(t), i(t) in mathbb{R})

    注: 不同版本的傅里叶变换的定义存在系数上的差异.

    性质

    (hat{}) (mathop{Leftrightarrow} limits^{mathcal{F}}) (check{})
    1 (f(t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(u))
    2 (f star g (t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(u) cdot G (u))
    3 (f ullet g(t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F^*(u) cdot G(u))
    4 $f(t) cdot g(t) $ (mathop{Leftrightarrow} limits^{mathcal{F}}) (F star G (u))
    5 (f(t) + g(t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(u) + G(u))
    6 (f(t + t_0)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (e^{j2pi t_0 u} F(u))
    7 (f(-t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(-u))
    8 (F(u)=hat{f}(u)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (f(-t) = hat{hat{f}}(t))
    以上 对于 离散 成立
    9 (f(at)) (mathop{Leftrightarrow} limits^{mathcal{F}}) $frac{1}{
    10 (f'(t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (j2pi u F(u))
    11 (-j2pi tf(t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F'(u))
    12 (f(R mathbf{t})), (R^TR=I) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(Rmathbf{u}))

    注: 虽然以上性质除11外都是用了标量, 但是实际上对于一般的傅里叶变换也是成立的.

    1. pass

    2. 卷积:

      [egin{array}{ll} (f star g)^{hat{}}(u) &= int f star g (t) e^{-j2pi u t} mathrm{d}t \ &= int int f(t- au) g ( au) mathrm{d} au e^{-j2pi u t} mathrm{d}t \ &= int int f(t- au) g ( au) e^{-j2pi u t} mathrm{d}t mathrm{d} au quad ightarrow mathrm{Fubini}\ &= int int f(t- au) e^{-j2pi u (t- au)} mathrm{d}t : g( au)e^{-j2pi u au} mathrm{d} au quad \ &= F(u) cdot G(u). end{array} ]

      (Leftarrow)是类似的证明.

    3. correlation:

      [egin{array}{ll} (f ullet g)^{hat{}}(u) &= int f*g(t) e^{-j2pi ut} mathrm{d}t \ &= int int f^*( au) g( au + t) mathrm{d} au e^{-j2pi ut} mathrm{d}t \ &= int f^*( au) int g( au + t) e^{-j2pi ut} mathrm{d}t mathrm{d} au \ &= G(u)int f^*( au) e^{j2pi u au} mathrm{d} au \ &= G(u)[int f( au) e^{-j2pi u au} mathrm{d} au]^* \ &= F^*(u)G(u) end{array} ]

    4. 乘积的证明和上面是一样的, 无非是作用于(check{})上.

    5. pass

    6. 平移:

      [(f(t+t_0))^{hat{}} = int f(t+t_0) e^{-j2pi ut} mathrm{d}t =e^{j2pi u t_0}int f(t+t_0) e^{-j2pi u(t+t_0)} mathrm{d}t = e^{j2pi t_0u} F(u). ]

    7. 逆:

      [(f(-t))^{hat{}} = int f(-t) e^{-j2pi u t} mathrm{d}t = int f(t) e^{j2pi u t} mathrm{d}t = F(-u). ]

    8. (hat{F}(t) = int F(u) e^{j2pi t u} mathrm{d}u = (F(-u))^{check{}}(t) = f(-t)).

    9. scaling:

      [(f(at))^{hat{}}(u) = int_{-infty}^{+infty} f(at) e^{-j2pi ut} mathrm{d}t = frac{1}{|a|}int_{-infty}^{+infty} f(z) e^{-j2pi frac{u}{a}z} dz = frac{1}{|a|} F(frac{u}{a}). ]

    10. 导函数:

      [egin{array}{ll} f'(t) &= frac{mathrm{d}}{mathrm{d}t} int_{-infty}^{+infty} F(u) e^{j2pi t u} mathrm{d}u \ &= int_{-infty}^{+infty} F(u) frac{mathrm{d}}{mathrm{d}t} e^{j2pi t u} mathrm{d}u \ &= int_{-infty}^{+infty} F(u) (j2pi u) e^{j2pi t u} mathrm{d}u \ &= (j2pi u F(u))^{check{}}. end{array} ]

    11. 同上

    12. 这个性质说明了, 对原图像加以旋转, 等价地在频域上加以同样的旋转.

      [egin{array}{ll} G(mathbf{u}) &=int f(Rmathbf{t}) e^{-j2 pi mathbf{u}^T mathbf{t}} mathrm{d}mathbf{t} \ &=int f(mathbf{x}) e^{-j2 pi (Rmathbf{u})^T mathbf{x}} |R^{-1}|mathrm{d}mathbf{x} \ &=int f(mathbf{x}) e^{-j2 pi (Rmathbf{u})^T mathbf{x}} mathrm{d}mathbf{x} \ &=F(Rmathbf{u}) end{array} ]

    对称性

    主要指的:

    1. 奇函数

      [f(x) = -f(-x). ]

    2. 偶函数

      [f(x) = f(-x). ]

    3. 共轭对称

      [f^*(x) = f(-x). ]

    考查(f(t)=r(t) + j i(t))(F(u) = R(u) + j I(u))之间的关系:

    (hat{ }) (Leftrightarrow) (check{ })
    1 (f(t) = r(t)) (Leftrightarrow) (F^*(u) = F(-u))
    2 (f(t)=r(t)) (Leftrightarrow) (R(u)=R(-u), I(u)=-I(-u))
    3 (f(t) = ji(t)) (Leftrightarrow) (F^*(-u) = -F(u))
    4 (f(t) = ji(t)) (Leftrightarrow) (R(u)=-R(-u), I(u)=I(-u))
    (hat{}) (mathop{Leftrightarrow} limits^{mathcal{F}}) (check{})
    5 (f(-t)in mathbb{R}) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F^*(u) in mathbb{C})
    6 (f(-t) in mathbb{C}) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(-u) in mathbb{C})
    7 (f^*(t) in mathbb{C}) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F^*(-u) in mathbb{C})
    8 (f(t) in mathbb{R}), 且(f(t) = f(-t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(u) in mathbb{R}), 且满足(F(u)=F(-u))
    9 (f(t) in mathbb{R}), 且(f(t) = -f(-t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(u) = jI(u) in mathbb{C}), 且(F(u)=-F(-u))
    10 (f(t) = ji(t) in mathbb{C}), 且(f(t) = f(-t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(u) = jI(u) in mathbb{C}), 且(F(u)=F(-u))
    11 (f(t)=ji(t) in mathbb{C}), 且(f(t)=-f(-t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(u) in mathbb{R}), 且满足(F(u)=-F(-u))
    12 (f(t) in mathbb{C}), 且(f(t) = f(-t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(u) in mathbb{C}), 且满足(F(u) = F(-u))
    13 (f(t) in mathbb{C}), 且(f(t) = -f(-t)) (mathop{Leftrightarrow} limits^{mathcal{F}}) (F(u) in mathbb{C}), 且满足(F(u) = -F(-u))
    1. real ->((Leftarrow)采用反证法即可)

      [egin{array}{ll} F^*(u) &=[int f(t) e^{-j2pi ut} mathrm{d}t]^* \ &=int f^*(t) e^{j2pi ut} mathrm{d}t \ &=int f(t) e^{-j2pi (-u)t} mathrm{d}t ightarrow f*(t) = r^*(t) = r(t)\ &=F(-u). end{array} ]

    2. 由1易证.

    3. imaginary ->

      [egin{array}{ll} F^*(-u) &=[int f(t) e^{j2pi ut} mathrm{d}t]^* \ &=int f^*(t) e^{-j2pi ut} mathrm{d}t \ &=int -f(t) e^{-j2pi ut} mathrm{d}t ightarrow f^*(t) = -ji(t)=-f(t) \ &=-F(u). end{array} ]

    4. 由3易证.

    5. 由性质6以及上述的对称性3可知((f(-t))^{hat{}}= F(-u) = F^*(u)).

    6. 由性质6可知((f(-t))^{hat{}} = F(-u)).

    7. [int f^*(t) e^{-j2pi ut} mathrm{d}t = [int f(t) e^{j2pi ut} mathrm{d}t]^* = F^*(-u). ]

    8. [F(u) = (f(t))^{hat{}} = (f(-t))^{hat{}} = F(-u) = F^*(u). ]

    9. [F(u) = (f(t))^{hat{}} = -(f(-t))^{hat{}} = -F(-u) = -F^*(u). ]

    10. [F(u) = (f(t))^{hat{}} = (f(-t))^{hat{}} = F(-u) = -F^*(u). ]

    11. [F(u) = (f(t))^{hat{}} = -(f(-t))^{hat{}} = -F(-u) = F^*(u). ]

    12. [F(u) = (f(t))^{hat{}} = (f(-t))^{hat{}} = F(-u). ]

    13. [F(u) = (f(t))^{hat{}} = -(f(-t))^{hat{}} = -F(-u). ]

    卷积

    这里特别说明离散卷积的一个重要性质:
    注意到

    [h star f (n) = sum_{k=0}^{N-1} h(n-k) f(k) = a^T_n f, \ a(n) = [h(0), h(n-1), cdots, h(n-N+1)], ]

    [A = [a_0, a_1, cdots, a_{N-1}] = left [ egin{array}{cccc} h(0) & h(1) &cdots & h(N-1) \ h(-1) & h(0) & cdots & h(N-2)\ vdots & vdots & ddots & vdots \ h(1-N) & h(2-N) & cdots & h(0), end{array} ight ] [h star f] = A^T f. ]

    定义

    [h'(n) = h(-n), ]

    则有

    [[h' star f] = Af. ]

    FFT

    考虑离散傅里叶变换:

    [F_m = sum_{n=0}^{N-1} f_n e^{-j2pi nm/N}, m=0,1,cdots, N-1. ]

    每次计算包含(N)个乘法, 故傅里叶变换的计算量是(N^2)级别的.

    下面假设(N = P * Q, P, Q in mathbb{N}^+), 则

    [m = uQ + v, quad u=0,1,cdots, P-1, v=0,1,cdots, Q-1, \ n = sP + t, quad s=0,1,cdots, Q-1, t=0,1,cdots, P-1. \ ]

    注意到:

    [nm = (sP + t)(uQ + v) = su N + svP + tm. ]

    此时, (m, n)与唯一的((u,v), (s, t))匹配, 则傅里叶变换可以表示为:

    [egin{align} F_m &= sum_{n=0}^{N-1}f_n e^{-j2pi nm / N} \ &= sum_{n=0}^{N-1}f_n e^{-j2pi (sP+t)(uP+v)/ N} \ &= sum_{n=0}^{N-1}f_n e^{-j2pi (suN + svP + tm)/ N} \ &= sum_{n=0}^{N-1}f_n e^{-j2pi (svP + tm)/ N} \ &= sum_{t=0}^{P-1}e^{-j2pi tm / N}sum_{s=0}^{Q-1} f_{sP+t} e^{-j2pi sv/ Q} \ end{align} ]

    [F_v^t := sum_{s=0}^{Q-1} f_{sP+t} e^{-j2pi sv /Q}, quad v = 0,1, cdots, Q-1, t=0,1,cdots, P-1. ]

    显然总共需要(QN)次乘法, 而

    [F_m = sum_{t=0}^{P-1} e^{-j2pi tm / N} F_v^t, quad m=0,1,cdots, N-1, \ F_{uQ+v} = sum_{t=0}^{P-1} e^{-j2pi tv /N}F_v^t e^{-j2pi tu / P} . ]

    总共有(PN)次乘法, 故总共有((P+Q) N)次乘法运算.
    由于每个(F^t)都是一个独立的傅里叶变换过程, 故倘若(Q)能够进一步分解, 计算量可以进一步降低.
    甚至, 若假设(N = P^J), 则可以证明最后的计算量可以分解为

    [PJN = P Nlog_P N, ]

    特别的, 常常(N=2^J), 则计算量是(Nlog_2 N)量级的.

    注: 卷积运算([fstar g]_n, n=0,cdots, N-1), 计算量也是(N^2)级别的, 但是通过FFT, 应当是((PNlog_P + 1)N)​乘法次数, 也是可以降低计算量的.

    逆傅里叶变换实际上就是

    [hat{F^*}^* = [sum_{m=0}^{N-1} F_m^* e^{-j2pi mn/N}]^*, ]

    虽然下面的代码我并没有采取这种策略.

    from typing import Iterable, Union
    import numpy as np
    
    
    
    def factorization(N: int):
        for P in range(2, N + 1):
            if N % P is 0:
                return P
    
    def dft(arr: Iterable, m: int):
        N = len(arr)
        basis = np.arange(N) * m * 2 * np.pi * 1j * -1
        basis = np.exp(basis / N)
        return arr @ basis
    
    def idft(arr: Iterable, m: int):
        N = len(arr)
        basis = np.arange(N) * m * 2 * np.pi * 1j
        basis = np.exp(basis / N) / N
        return arr @ basis
    
    def basis_dft(N: int):
        basis = np.outer(np.arange(N), np.arange(N))
        basis = basis * 2 * np.pi * 1j * -1
        return np.exp(basis / N)
    
    def basis_idft(N: int):
        basis = np.outer(np.arange(N), np.arange(N))
        basis = basis * 2 * np.pi * 1j
        return np.exp(basis / N) / N
    
    def fft(arr: Iterable) -> np.ndarray:
        N = len(arr)
        P = factorization(N)
        if P is N:
            return arr @ basis_dft(N)
        Q = N // P
        Fvt = np.array([fft(arr[t::P]) for t in range(P)]).T # Q x P
        dummy = np.outer(np.arange(Q), np.arange(P))
        dummy = np.exp((dummy * 2 * np.pi * 1j * -1) / N)
        Fvt_ext = Fvt * dummy
        return (Fvt_ext @ basis_dft(P)).T.flatten()
    
    def ifft(arr: Iterable) -> np.ndarray:
        N = len(arr)
        P = factorization(N)
        if P is N:
            return arr @ basis_idft(N)
        Q = N // P
        Fvt = np.array([ifft(arr[t::P]) for t in range(P)]).T # Q x P
        dummy = np.outer(np.arange(Q), np.arange(P))
        dummy = np.exp((dummy * 2 * np.pi * 1j) / N)
        Fvt_ext = Fvt * dummy
        return (Fvt_ext @ basis_idft(P)).T.flatten()
    
  • 相关阅读:
    Flask基础
    Scrapy框架(持久化,去重,深度控制,cookie)
    scrapy框架 简易整理
    BeautifulSoup 模块
    requests模块
    复习第三天
    在Django中使用原生Sql
    ajax跨域简单请求和复杂请求
    复习第二天
    IOS
  • 原文地址:https://www.cnblogs.com/MTandHJ/p/15183071.html
Copyright © 2020-2023  润新知