%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()