To understand the effect first consider the simple case of a one dimensional line of length TwoPi. Along that line we consider values of a simple cosine wave of unit amplitude and frequency. When we take the FT of the cosine signal that is spaced along the line, we get a value of 1 for the cosine coefficient of spatial frequency 1. The sine coefficient for spatial frequency 1, along with all other spatial frequency components, should remain zero. The phase vector for the fundamental frequency cosine wave will lie initially along the +x axis.
As the cosine wave is shifted sideways in space, the phase of the spatial frequency component will sweep in a circle from the +cosine through the +sine, then to -cosine, through -sine and back to +cosine. In effect the phasor rotates once each time the wave is moved sideways by one spatial period. The direction of spatial frequency vector rotation is decided by the direction of spatial movement. (This is the "fourier shift theorem" at work).
If the whole of a complex pattern moves sideways the phase of the fundamental will change at a rate proportional to the rate of image movement. Small movements may show up better in higher harmonics, but the highest harmonics will look like noise as the image content will change significantly with larger movements, (unless the panorama wraps around).
A small object that crosses a large fixed background will cause only a small difference in the real cos(1) and imaginary sin(1) coefficients. The point of the phase vectors will move in a small circle due to the small contribution of the part of the image that moves. If you plot all the phase vectors on an Argand diagram then as the image pans, you will see the entire constellation of phase vectors rotating about the centre. But if only a small object moves across the background you will see all the phase vectors rotate in small circles about the tips of their average background values. The rate of rotation will be proportional to the spatial frequency.
The principle of superposition does not usually apply to spatial images because an object that moves against the background does not sum to the background, it replaces background with an object. In effect the moving object removes other information temporarily while substituting it's own. Likewise, when a camera pans, information is lost on one side of the image as new information appears on the other.
So it is easy to detect a transverse movement through phase, but a rotating wheel is hard to detect using phase in a 2D spatial transform, unless it rolls across the image.
This is a windowing artifact.
The linked code pads out a 10,000 sample signal with zeroes so that the length is a power of two.
%% Author :- Embedded Laboratory
%%This Project shows how to apply FFT on a signal and its physical
% significance.
fSampling = 10000; %Sampling Frequency
tSampling = 1/fSampling; %Sampling Time
L = 10000; %Length of Signal
t = (0:L-1)*tSampling; %Time Vector
F = 100; %Frequency of Signal
%% Signal Without Noise
xsig = sin(2*pi*F*t);
...
%%Frequency Transform of above Signal
subplot(2,1,2)
NFFT = 2^nextpow2(L);
Xsig = fft(xsig,NFFT)/L;
...
Note that in the above code, the FFT is taken with the FFT size NFFT
which is the next power of 2 bigger than the signal length (in this case, 16,384.) From the Mathworks fft()
documentation:
Y = fft(X,n)
returns the n-point DFT. fft(X)
is equivalent to fft(X, n)
where n
is the size of X
in the first nonsingleton dimension. If the length of X
is less than n
, X
is padded with trailing zeros to length n
. If the length of X
is greater than n
, the sequence X
is truncated. When X
is a matrix, the length of the columns are adjusted in the same manner.
This means that you are not actually taking a FFT of a 'pure sine wave' - you are taking the FFT of a sine wave with a flat signal after it.
This is equivalent to taking the FFT of a sine wave multiplied with a square window function. The FFT spectrum is then the convolution of the sine wave frequency spectrum (an impulse function) with the square wave frequency spectrum (sinc(f).)
If you change L = 16,384
so that there is no zero-padding of the signal, you will observe a perfect
FFT.
Further search keywords: "Spectral Leakage", "Window Function", "Hamming Window".
Edit: I cleaned up some material I wrote on this topic back in university, which goes into substantially more detail. I've posted that on my blog.
Best Answer
First, you should realize that the FFT is just one particular algorithm for caluclating the discrete Fourier transform (DFT). None of what you asked depends on the details of the FFT algorithm, it all is generally applicable to the DFT, so I'll talk about that.
I'll answer your questions out of order.
You started with the actual wave, and calculated the DFT. That included getting the phase information. If you threw away the phase information, that was a mistake. The only way to get it back is to go back to the original time-domain data and re-calculate the DFT, but don't throw away the phase information this time.
You can recover the time-domain waveform using the inverse DFT (IDFT):
$$x_n = \frac{1}{N}\sum_{k=0}^{N-1}X_k e^{i2\pi{}kn/N}$$
However
This assumes you have the complex Fourier components, including phase information. Since you say you threw away the phase information, you don't actually know the \$X_k\$ values, only their magnitudes \$\left|X_k\right|\$, and you can't recover the waveform.
This just recovers the same waveform data you started with. It doesn't tell you "the formula" for the waveform unless you consider a decomposition into sinusoids (or complex exponentials) to be the same thing as "the formula".