[Numpy-discussion] Interpolation via Fourier transform
Stéfan van der Walt
stefan at sun.ac.za
Fri Mar 6 12:30:49 EST 2009
Hi Nadav
You can also read the interesting discussion at
http://projects.scipy.org/numpy/ticket/748
which also contains some padding code.
I still disagree with the conclusion, but oh well :)
Cheers
Stéfan
2009/3/6 Nadav Horesh <nadavh at visionsense.com>:
> I found the solution I needed for my peculiar case after reading your email
> based of the following stages:
>
> I have a N x N frequency-domain matrix Z
>
> 1. Use fftshift to obtain a DC centered matrix
> Note: fftshift(fft(a)) replaces np.fft.fft(np.power(-1,np.arange(64))*a)
> Zs = np.fft.fftshift(Z)
> 2. pad Zs with zeros
> scale = int(ceil(float(N)/M))
> MM = scale*M
> Ztemp = np.zeros((MM,MM), dtype=complex)
> Ztemp[(MM-N)//2:(N-MM)//2,(MM-N)//2:(N-MM)//2] = Zs
> 3. Shift back to a "normal order"
> Ztemp = np.fft.ifftshift(Ztemp)
> 4. Transform to the "time domain" and sub-sample
> z = np.fft.ifft2(Ztemp)[::scale, ::scale]
>
> I went this was since I needed the aliasing, otherwise I could just truncate
> Zs to size MxM.
More information about the NumPy-Discussion
mailing list