Task 1

advertisement
1
Experiment 2.
Discrete Fourier Transform (DFT).
Methods of calculation and some basic applications.
Some useful Matlab procedures:
Discrete Fourier Transform:
Syntax
1.
Y = fft(X)
returns the discrete Fourier transform (DFT) of vector X, computed with a
fast Fourier transform (FFT) algorithm.
Y = fft(X,n)
returns the n-point DFT. 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.
Y = fft(X,[],dim),
Y = fft(X,n,dim)
applies the FFT operation across the dimension dim
.
.
The functions X = fft(x) and x = ifft(X) implement the transform and inverse transform pair
given for vectors of length N by:
2nk
N 1
j
N
X (k )   xn e
dla 0  k  N  1
n 0
1
x ( n) 
N
N 1
 X k e
j
2nk
N
dla 0  n  N  1
k 0
2. Some procedures operating on complex numbers:
a. complex c = complex(a,b) creates a complex output, c, from the two
real inputs, useful equivalent form for the following standard notations:
c  a  i * b or
c  a  j *b
b. imag returns imaginary part of the complex number (array),
c. real
returns real part of the complex number (array),
d. abs(X) returns the complex modulus (magnitude), which is the same as
sqrt(real(X).^2 + imag(X).^2)
e. angle returns the phase angles, in radians
f. conj returns the complex conjugate of the number (array).
2
3. Definition of the discrete convolution of two sequences:
x1 (n)  x2 n  

 x k  x n  k 
k  
1
2
4. Definition of the discrete convolution of two periodic sequences:
N 1
x1 (n)  x2 n    x1 k   x2 n  k 
k 0
.
TASKS
Task 1
Compute DFT of the sequence {xn}= …………………………………
using the definition (write m-file or m-function, use unique name for your m-file!)
Plot the amplitude and phase spectra of {Xn}.
Compare results obtained using your own m-file with the results calculated using
standard Matlab function fft. Describe briefly FFT.
Task 2
To illustrate the efficiency of the FFT compare the execution speed of the MATLAB
function fft with that created for Task 1. Use the commands tic and toc ( toc
measures the time elapsed from the execution of tic). Create an m-file that can be
used for the benchmarking test. Comment results.
Remarks:
a) compare DFT with FFT for N=110 , N=2048, N=4096
b) create the discrete time vector n=0:N-1; x=(-1)^n
c) exemplary code:
1. N=500;
2. n=0:N-1;
3. x=(-1).^n;
4. disp('my DFT');
5. tic
6. X=mydft(x);
7. toc
8. disp('FFT');
9. tic
10.X=fft(x);
11.toc
3
Task 3
Implement another benchmarking test for fft algorithm – the performance of FFT is
evaluated in relation to the value of N . Try N=2^20, N=950000, N=750000,
N=550000. Explain the results!
Remarks: Use the same test discrete-time function x=(-1)^n.
Task 4
Write m-file (or m-function) enabling us to compute IDFT (inverse transform) of the
sequence.
Insert proper code and check your solution using MATLAB built-in function ifft.
Task 5
Calculate discrete convolution of the following periodic sequences (N=4):
x1(n)=
x2(n)=
Apply:
a) Definition (use m-file from the previous experiment)
b) Built-in function conv
c) Periodic convolution theorem (or DFT of circular convolution) .Write new
m-file.
Task 6
Repeat Task 5 for non-periodic sequences x1(n) and x2(n),
Use again periodic convolution theorem. Give the assumptions enabling us to do it!
Task 7
Formulate and check the following properties of the DFT transform:
a) Linearity
b) DFT of a circularly shifted sequence (or shifted periodic sequence)
Download