傅里葉變換(FT)[1]
傅里葉變換的目的是可將時域(即時間域)上的信號轉變?yōu)轭l域(即頻率域)上的信號殖卑,隨著域的不同,對同一個事物的了解角度也就隨之改變麸折,因此在時域中某些不好處理的地方,在頻域就可以較為簡單的處理。
傅里葉變換公式:
(w代表頻率码耐,t代表時間,e^-iwt為復變函數)
其中:糖儡,
傅里葉逆變換:
傅里葉變換認為一個周期函數(信號)包含多個頻率分量伐坏,任意函數(信號)f(t)可通過多個周期函數(基函數)相加而合成怔匣。
從物理角度理解傅里葉變換是以一組特殊的函數(三角函數)為正交基握联,對原函數進行線性變換,物理意義便是原函數在各組基函數的投影每瞒。
以下是代碼:
import numpy as np
from numpy import linalg
import matplotlib.pyplot as plt
import math
#時間長度
t_len = 3.14*4
#分割時間
t = np.linspace(0, t_len, 1000)
#傅里葉變換原函數g_t(t)
g_t = []
for i in range(len(t)):
? ? #測試函數
? ? temp = 2*math.sin(t[i])+math.sin(2*t[i]+3)
? ? g_t.append(temp)
#頻率范圍
f_len = 2
#分割頻率
f = np.linspace(0, f_len, 1000)
#傅里葉變換函數實軸函數g_cos(f)金闽,x軸函數
g_cos = []
#傅里葉變換函數虛軸函數g_sin(f),y軸函數
g_sin = []
#傅里葉變換 復數模 函數g_f(f)剿骨,偏離中心距離函數
g_f = []
#傅里葉函數虛軸和實軸存在的意義在于區(qū)分振動中不同方向的增益效果
#所謂虛函數只是一種區(qū)分方向的方式代芜,不讓cos()與sin()在積分前混合
#傅里葉變換,時間進行積分
for c_f in range(len(f)):
? ? sinsum = 0
? ? cossum = 0
? ? for c_t in range(len(t)):
? ? ? ? tempsin = g_t[c_t] * math.sin(f[c_f] * t[c_t] * (-2 * math.pi))
? ? ? ? tempcos = g_t[c_t] * math.cos(f[c_f] * t[c_t] * (-2 * math.pi))? ? ?
? ? ? ? sinsum = sinsum + tempsin
? ? ? ? cossum = cossum + tempcos
? ? g_f.append(math.sqrt((cossum/len(t))**2 + (sinsum/len(t))**2))
? ? g_sin.append(sinsum/len(t))
? ? g_cos.append(cossum/len(t))
#逆傅里葉變換還原后函數f_g(t)
f_g = []
#傅里葉變換浓利,頻率進行積分
for c_t in range(len(t)):
? ? sinsum = 0
? ? cossum = 0
? ? for c_f in range(len(f)):
? ? ? ? tempsin = g_sin[c_f] * math.sin(f[c_f] * t[c_t] * (-2 * math.pi))
? ? ? ? tempcos = g_cos[c_f] * math.cos(f[c_f] * t[c_t] * (-2 * math.pi))
? ? ? ? sinsum = sinsum + tempsin
? ? ? ? cossum = cossum + tempcos
? ? f_g.append(2*f_len*t_len*sinsum/len(f) + 2*f_len*t_len*cossum/len(f))
plt.figure("傅里葉變換",figsize=(6, 6))
plt.subplot(2,2,1)
#原函數g_t(t)
plt.scatter(t, g_t, s = 1, color='red')
plt.title("Original Function g_t(t)")
plt.subplot(2,2,2)
#傅里葉變換虛軸函數g_sin(f)
plt.scatter(f, g_sin, s = 1, color='red')
plt.title("Fourier(sin) g_sin(f)")
plt.subplot(2,2,3)
#傅里葉變換 復數模 函數g_f(f)
plt.scatter(f, g_f, s = 1, color='blue')
plt.title("Fourier(module) g_f(f)")
plt.subplot(2,2,4)
#逆傅里葉變換還原后的函數f_g(t)
plt.scatter(t, f_g, s = 1, color='red')
plt.title("restore f_g(t)")
plt.show()
[1] 傅里葉變換概念及公式推導 https://blog.csdn.net/lzzdflg/article/details/78254381