Hari
Hari

Reputation: 197

Taking fourier transform after phase shift

I am trying to change the phase of an image and taking the Fourier transform of it. But this change in phase causes a leakage of power along x an y axis.

Suppose my image is a all ones matrix. If i take the Fourier transform i get Spectrum of all ones. See that all the power is at the center. In fact, unless you zoom, we cannot see it all.

Now suppose I multiply the matrix by a complex sinusoid. Ideally the power should just shift to the frequency of sinusoid. But this is what I get Spectra of phase multiplied image. Note the power that is leaked along the x and y axes..

Why does this occur? Is it because of the non continuous nature of signals?

Please see the python code below

import numpy as np
from matplotlib import pyplot as plt

# Init a all one array
base_image = np.ones([1024,1024])

#Generate a array so that we can make a sinusoid using it
x_cords = np.arange(base_image.shape[1]) - base_image.shape[1]/2
x_cords = np.transpose(x_cords)/512
x_cords = x_cords.astype(float)
x_cords = np.tile(x_cords, [base_image.shape[0], 1])
y_cords = np.transpose(x_cords)

#Generate the sinusoid
phase = np.exp(x_cords + y_cords)

#Apply this shift
new_image = base_image * phase

spec_base = np.fft.fftshift(np.fft.fft2(base_image))
spec_new = np.fft.fftshift(np.fft.fft2(new_image))

plt.imshow(np.log(np.abs(spec_base)))
plt.show()

plt.imshow(np.log(np.abs(spec_new)))
plt.show()

Thanks in advance for any answers

Upvotes: 3

Views: 977

Answers (2)

Brent Bradburn
Brent Bradburn

Reputation: 54859

If you plot your new_image, you see that it is not a sinusoid:enter image description here

Here's a brute-force approach to creating a sinusoid pattern without using complex numbers:

# create a sinusoid
F=4 ## select the frequency -- use an even integer to minimize spectral "leakage"
new_image = np.ones([X,Y])
for y in xrange(Y):
   for x in xrange(X):
      new_image[y][x] = sin(x/float(X)*pi*F)*sin(y/float(Y)*pi*F)

enter image description here

The power spectrum has minimal leakage, and if you zoom in you can see that the peak power is off-origin and that there are actually 4 peaks due to mirroring around DC.

enter image description here

Upvotes: 4

Warren Weckesser
Warren Weckesser

Reputation: 114781

A few points:

  • All 1s is a pretty special case--it is exactly periodic, so the FFT shows no spectral leakage.
  • xcords and ycords are real, which means phase is real--it is not a sinusoid. The argument to exp should be imaginary.
  • Even with a correct phase, unless you choose phase to be perfectly periodic on your domain, you'll get spectral leakage.

Upvotes: 3

Related Questions