昔の記事で、FFTでフーリエ変換する内容を紹介した。
koideforest.hatenadiary.com
koideforest.hatenadiary.com
そこから、フーリエ変換をパッと計算出来るヘルパー関数をまとめていなかったので、自分用にまとめる。
from scipy.fftpack import fft, fftfreq, fftshift, ifft def calc_FT(x,y): N=len(x) dx=x[1]-x[0] tilde_y=fftshift(fft(y)*dx) k =fftshift(fftfreq(N,dx)*2*np.pi) return k, tilde_y def calc_IFT(k,tilde_y): N=len(k) dk=k[1]-k[0] # timing of fftshift is different between x and y y=ifft(fftshift(tilde_y)) x=fftshift(fftfreq(N,dk/2/np.pi)) y/=x[1]-x[0] return x, y def calc_ILFT(k,tilde_y): x,y = calc_IFT(k,tilde_y) return x-x[0], y