









Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!










September 7, 2000
Any discussion of finite Fourier transforms and MATLAB immediately encoun- ters a notational issue – we have to be careful about whether the subscripts start at zero or one. The usual notation for finite Fourier transforms uses subscripts j and k that run from 0 to n − 1. MATLAB uses notation derived from matrix theory where the subscripts run from 1 to n, so we will use yj+1 for mathemat- ical quantities that will also occur in MATLAB code. We will reserve i for the complex unit,
The finite, or discrete, Fourier transform of a complex vector y with n ele- ments yj+1, j = 0,... n − 1 is another complex vector Y with n elements
Yk+1 =
n∑− 1
j=
yj+1e−^2 ijkπ/n, k = 0,... , n − 1
The exponentials are all complex n-th roots of unity, i.e. they are all powers of
ω = e−^2 πi/n^ = cos δ − i sin δ
where δ = 2π/n. The transform can also be expressed with matrix-vector notation Y = F y
where the finite Fourier transform matrix F has elements
fk+1,j+1 = ωjk
It turns out that F is nearly its own inverse. More precisely, the complex conjugate transpose of F satisfies
F H^ F = nI
so
F −^1 =
n
This allows us to invert the Fourier transform.
y =
n
Hence
yj+1 =
n
n∑− 1
k=
Yk+1e^2 ijkπ/n, j = 0,... , n − 1
We should point out that this is not the only notation for finite Fourier transform in common use. The minus sign in the complex exponentials in the first equation, and in the definiton of ω, sometimes occurs in the inverse trans- pose instead. And the 1/n scaling factor in the inverse transform is sometimes replaced by 1/
n scaling factors in both transforms. In MATLAB, the Fourier matrix F could be generated for any given n by
omega = exp(-2pii/n); j = 0:n-1; k = j’ F = omega.^(k*j)
The quantity k*j is an outer product, an n-by-n matrix whose elements are the products of the elements of two vectors. However, the built-in function fft takes the finite Fourier transform of each column of a matrix argument, so an easier, and quicker, way to generate F is
F = fft(eye(n))
The function fft uses a fast algorithm to compute the finite Fourier trans- form. The first ”f” stands for both ”fast” and ”finite”. A more accurate name might be ffft, but nobody wants to use that. We will discuss the fast aspect of the algorithm in a later section.
The GUI fftshow allows you to investigate properties of the finite Fourier trans- form. If y is a vector containing a few dozen elements.
fftshow(y)
produces four plots
real(y) imag(y) real(fft(y)) imag(fft(y))
You can use the mouse to move any of the points in any of the plots and the points in the other plots will respond. Please run fftshow and try the following examples. Each illustrates some property of the Fourier transform. When you start with no arguments
fftshow
all four plots are initialized to zeros(1,32). Click your mouse in the upper left hand corner of the upper left hand plot. You will be taking the fft of the first unit vector, with one in the first component and zeros elsewhere. This should produce
real(y) imag(y)
real(fft(y)) imag(fft(y))
You are seeing the graph of
Yk+1 = 0 + 1 · e−^2 ikπ/n^ + 0 + · · · + 0
Using δ = 2π/n,
real(Yk+1) = cos kδ, imag(Yk+1) = − sin kδ
for k = 0, · · · , n − 1. We have sampled two trig functions at n equally spaced points in the interval 0 ≤ x < 2 π. The first sample point is x = 0 and the last sample point is x = 2π − δ. Now set y 3 = 1 and vary y 5 with the mouse. One snapshot is
real(y) imag(y)
real(fft(y)) imag(fft(y))
We have graphs of
cos 2kδ + η cos 4kδ, and − sin 2kδ − η sin 4kδ
for various values of η = y 5 The point just to the right of the center of these graphs is particularly important. We will call it the Nyquist point. With the points numbered from 1 to n for even n, it’s the point with index n 2 + 1. When n = 32, it’s point number 17, just under the left parenthesis in the title. Here is fftshow with a unit vector at the Nyquist point.
of length n and Y = fft(y), then
real(Y 1 ) =
yj imag(Y 1 ) = 0 real(Y2+j ) = real(Yn−j ), j = 0, · · · , n/ 2 − 1 imag(Y2+j ) = −imag(Yn−j ), j = 0, · · · (^) , n/ 2 − 1
This section is an expansion of MATLAB’s sunspots demo. For centuries people have noted that the face of the sun is not constant or uniform in appearance, but that darker regions appear at random locations on a cyclical basis. This activity is correlated with weather and other eco- nomically significant terrestrial phenomena. In 1848, Rudolf Wolfer proposed a rule that combined the number and size of these sunspots into a single index. Using archival records, astronomers have applied Wolfer’s rule to determine sunspot activity back to the year 1700. Today the sunspot index is measured by many astronomers and the worldwide distribution of the data is coordinated by the Sunspot Index Data Center at the Royal Observatory of Belgium. (See http://www.astro.oma.be/SIDC/index.html) The text file sunspot.dat in MATLAB’s demos directory has two columns of numbers. The first column is the years from 1700 to 1987 and the second column is the average Wolfer sunspot number for each year.
load sunspot.dat t = sunspot(:,1)’; wolfer = sunspot(:,2)’; n = length(wolfer)
There is a slight upward trend to the data. A least squares fit gives the trend line.
c = polyfit(t,wolfer,1); trend = polyval(c,t); plot(t,[wolfer; trend],’-’,t,wolfer,’k.’) xlabel(’year’) ylabel(’Wolfer index’) title(’Sunspot index with linear trend’)
17000 1750 1800 1850 1900 1950 2000
20
40
60
80
100
120
140
160
180
200
year
Wolfer index
Sunspot activity
You can definitely see the cyclic nature of the phenomenon. The peaks and valleys are a little more than 10 years apart. Now, subtract off the linear trend and take the finite Fourier transform.
y = wolfer - trend; Y = fft(y);
The first Fourier coefficient, Y(1), can be deleted because subtracting the linear trend insures that Y(1) = sum(y) is zero.
Y(1) = [];
The complex magnitude squared of Y is called the power and a plot of power versus frequency is a ”periodogram”. The frequency is the array index scaled by n, the number of data points. Since the time increment is one year, the frequency units are cycles per year.
pow = abs(Y(1:n/2)).^2; pmax = 20e6; f = (1:n/2)/n; plot([f; f],[0*pow; pow],’c-’, f,pow,’b.’, ... ’linewidth’,2,’markersize’,16) axis([0 .5 0 pmax]) xlabel(’cycles/year’) ylabel(’power’) title(’Periodogram’)
(^0) 144.0 72.0 48.0 36.0 28.8 24.0 20.6 18.0 16.0 14.4 13.1 12.0 11.1 10.3 9.6 9.0 8.5 8.
1
2 x 10
7
years/cycle
power
Periodogram
As expected, there is a very prominent cycle with a length of about 11 years. This shows that over the last 300 years, the period of the sunspot cycle has been slightly over 11 years.
We all use FFTs everyday without even knowing it. Cell phones, disc drives, DVD’s and JPEG’s all involve finite Fourier transforms. One-dimensional tran- forms with a million points and two-dimensional 1000-by-1000 transforms are common. The key to modern signal and image processing is the ability to do these computations rapidly. Direct application of the definition
Yk+1 =
n∑− 1
j=
ωjkyj+1, k = 0,... , n − 1
requires n multiplications and n additions for each of the n components of Y for a total of 2n^2 floating point operations. And that does not count the generation of the powers of ω. A computer capable of doing one multiplication and addition every microsecond would require a million seconds, or about 11.5 days, to do a million point FFT. Several people discovered fast FFT algorithms independently and many peo- ple have since contributed to their development, but it was a 1965 paper by John Tukey of Princeton University and John Cooley of IBM Research that is gener- ally credited as the starting point for the modern usage of the FFT.
Modern fast FFT algorithms have computational complexity O(n log 2 n) in- stead of O(n^2 ). When n is a power of 2, a one-dimensional FFT of length n requires less than 3n log 2 n floating point operations. For n = 2^20 , that’s a fac- tor of almost 35,000 faster than 2n^2. Even when n = 1024 = 2^10 , the factor is about 70. With MATLAB 5.3 and a 266 MHz Pentium laptop, the time required for fft(x) when length(x) is 2^20 = 1048576 is about 5 seconds. MATLAB 6. is still in development in February, 2000, but its new FFT code is available for testing. With the new code, a length 2^20 fft takes less than half a second. The new code is based on FFTW, ”The Fastest Fourier Transform in the West”, developed at MIT and available from http://www.fftw.org. The key to the fast FFT algorithms is the double angle formula for trig functions. Using complex notation and
ω = ωn = e−^2 πi/n^ = cos δ − i sin δ
we have ω^22 n = ωn
Written out in terms of separate real and imaginary parts, this is
cos 2δ = cos^2 δ − sin^2 δ sin 2δ = 2 cos δ sin δ
Start with the basic definition.
Yk+1 =
n∑− 1
j=
ωjkyj+1, k = 0,... , n − 1
Assume that n is even and that k ≤ n/ 2 − 1 Divide the sum into terms with even subscripts and terms with odd subscripts.
Yk+1 =
evenj
ωjkyj+1 +
oddj
ωjkyj+
n/ ∑ 2 − 1
j=
ω^2 jky 2 j+1 + ωk
n/ ∑ 2 − 1
j=
ω^2 jky 2 j+
The two sums on the right are components of the FFTs of length n/2 of the portions of y with even and odd subscripts. In order to get the entire FFT of length n, we have to do two FFTs of length n/2, multiply one of these by powers of ω, and concatenate the results. The relationship between an FFT of length n and two FFTs of length n/ 2 can be expressed compactly in MATLAB. If n = length(y) is even,
omega = exp(-2pii/n); k = (0:n/2-1)’;
if rem(n,2) == 0 % Recursive divide and conquer k = (0:n/2-1)’; w = omega .^ k; u = ffttx(x(1:2:n-1)); v = w.ffttx(x(2:2:n)); y = [u+v; u-v]; else % The Fourier matrix. j = 0:n-1; k = j’; F = omega .^ (kj); y = F*x; end
The Fourier integral transform converts one complex function into another. The transform is F (μ) =
−∞
f (t)e−^2 πiμtdt
The inverse transform is
f (t) =
−∞
F (μ)e+2πiμtdμ
The variables t and μ run over the entire real line. If t has units of seconds, then μ has units of radians per second. Both functions f (t) and F (μ) are complex valued, but in most applications the imaginary part of f (t) is zero. Alternative units use ν = 2πμ, which has units of cycles or revolutions per second. With this change of variable, there are no factors of 2π in the exponen- tials, but there are factors of 1/
2 π in front of the integrals, or a single factor of 1/(2π) in the inverse transform. Maple and MATLAB’s Symbolic Toolbox use this alternative notation with the single factor in the inverse transform.
A Fourier series converts a periodic function into an infinite sequence of Fourier coefficients. Let f (t) be the periodic function and let L be its period, so
f (t + L) = f (t) for all t
The Fourier coefficients are given by integrals over the period
cj =
−L/ 2
f (t)e−^2 πijtdt, j =... , − 1 , 0 , 1 ,...
With these coefficients, the complex form of the Fourier series is
f (t) =
j=−∞
cj e^2 πijt/L
A discrete time Fourier transform converts an infinite sequence of data values into a periodic function. Let xk be the sequence, with the index k taking on all integer values, positive and negative. The discrete time Fourier transform is the complex valued periodic function
X(eiω^ ) =
k=−∞
xkeikω
The sequence can then be represented
xk =
2 π
∫ (^) π
−π
X(eiω^ )e−ikω^ dω, k =... , − 1 , 0 , 1 ,...
The finite Fourier transform converts one finite sequence of coefficients into another sequence of the same length, n. The transform is
Yk+1 =
n∑− 1
j=
yj+1e−^2 ijkπ/n, k = 0,... , n − 1
The inverse transform is
yj+1 =
n
n∑− 1
k=
Yk+1e^2 ijkπ/n, j = 0,... , n − 1
The Fourier integral transform involves only integrals. The finite Fourier trans- form involves only finite sums of coefficients. Fourier series and the discrete time Fourier transform involve both integrals and sequences. It is possible to ”morph” any of the systems into any of the others by taking limits or restricting domains. Start with Fourier series. Let L, the length of the period, become infinite and let j/L, the coefficient index scaled by the period length, become a continuous variable, μ. Then the Fourier coefficients, cj , become the Fourier transform, F (μ).
integers. For example, one of the frequencies of 5/3 times another. The fre- quences that are integer multiples of other frequencies are ”overtones”. How many of the peaks are fundamental frequencies and how many are overtones?