4.2. 从DFT到DTFT

[1]:
%matplotlib inline
from numpy import *
from matplotlib.pyplot import *

N = 32
n = arange(0,N)
xn = exp(-0.2*n)

Xk = fft.fft(xn)

# 定义插值函数
def phi(w,k):
    return (sin(N*(w-2*pi*k/N)/2)/N/sin((w-2*pi*k/N)/2) * exp(-1j*(N-1)/2*(w-2*pi*k/N)))
# 频域插值方法
w = arange(-2*pi,2*pi,0.001)
Xw = zeros([len(w),])
for k in range(0,N):
    Xw = Xw + phi(w,k)*Xk[k]

plot(w,abs(Xw),label='Interpolation in Freq.')

# 时域补零方法
w = linspace(0,2*pi,len(w))
plot(w,abs(fft.fft(xn,len(w))),'--r',label='Zero-padding in Time')

w = linspace(0,2*pi*(1-1/len(Xk)),len(Xk))
plot(w,abs(Xk),'-o',label='N-Point DFT')

legend(loc='best')

xlabel('omega')

show()
/Users/mac/anaconda3/lib/python3.7/site-packages/mkl_fft/_numpy_fft.py:158: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  output = mkl_fft.fft(a, n, axis)
../_images/experiments_dft2dtft_1_1.png
[ ]: