[SciPy-User] fft convolutions

Sebastian Berg sebastian at sipsolutions.net
Thu Jun 30 08:26:44 EDT 2011


Hi,

I assume its *a inside the loop, but don't you have to conjugate one of
the two?
a = np.conj(np.fft2(A))
I did this once, and the scipy fftconvolve seemed to forget the
conjugation?
Also use np.fft.fftshift to undo the shifting introduced by the fft.

Regards,

Sebastian

On Thu, 2011-06-30 at 08:00 -0400, Alex Flint wrote:
> oops, I am actually using fft2/ifft2, I just forgot to write it in my
> pseudo code
> 
> On Thu, Jun 30, 2011 at 4:35 AM, Sturla Molden <sturla at molden.no>
> wrote:
>         Den 28.06.2011 20:17, skrev Alex Flint:
>         > I am trying to perform 2d convolutions between a large 2d
>         array A and
>         > a bunch of small 2d arrays B1...Bn. My approach is roughly:
>         >
>         > a = fft(A,size)
>         > for b in bs:
>         >    ans = ifft(fft(b,size)*A)
>         >    slow = convolve2d(A, b, 'same')
>         >
>         > However, as implemented above, ans is offset an inconsistent
>         amount
>         > from the answer produced by convolve2d, presumably because
>         convolve2d
>         > is treating b as if the origin is in the center whereas fft
>         treats b
>         > as if the origin is at the top left (but it doesn't seem to
>         be quite
>         > as simple as this). What am I missing?
>         
>         
>         You are not doing 2D convolution with the FFT. You want fft2
>         (or rfft2).
>         
>         Sturla
>         
>         
>         
>         _______________________________________________
>         SciPy-User mailing list
>         SciPy-User at scipy.org
>         http://mail.scipy.org/mailman/listinfo/scipy-user
> 
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user





More information about the SciPy-User mailing list