Signals and Systems Laboratory Exercise 5 Fourier Spectra
Objective
The objective of this lab is to illustrate and understand the fundamental concepts of Fourier spectra, investigate their properties, and practical applications. The prelab should be done before the lab, and the answer sheet, not longer than one page, should be given to the demonstrator to sign before the lab starts. You will not be allowed to do the prelab during the Lab. Theoretical background is provided in the textbook references (check the website) and in the lecture notes. Fundamental formulas are mentioned in the introductory part of this handout. Your lab report should have a title, a short description of the purpose of the lab, and include the prelab report. For the experiments, include sketches or plots of the models (be sure that you label them and refer to them appropriately if necessary), relevant details of the experiment, and plots. The text part of the report, with answers, comments and conclusions, should not be more than 1 page long.
Introduction
1 Fourier Series
A continuous-time periodic signal with period T can be represented as an innite sum of complex exponentials, multiplied by appropriate Fourier coefcients:
+
x(t) =
Xk ejk T
(1)
where the coefcients Xk are calculated as: 1 T
+T/2
Xk =
x(t)ejk T t dt
T/2
(2)
Coefcient X0 is the mean value of the signal on one period (or its DC component). Coefcients with other indices represent higher harmonics of the signal. The signals spectrum can be viewed as a series of impulse functions in continuous frequency.
Fourier Transform
Fourier transform is used to represent spectra for signals that are continuous in time and aperiodic (which is the case for most practical signals). The Fourier transform of signal x is calculated as:
+
X() =
x(t)ejt dt
(3)
where = 2f is the angular frequency. The signal itself can be calculated from its frequency domain representation as: 1 x(t) = 2
+
X()ejt d
(4)
These relations can be seen as a limit case of Fourier series, when the period is allowed to approach innity, leading to a continuum of frequency components (1/T , which is the fundamental frequency converges to zero). The spectrum is a continuous function of frequency.
Discrete-Time Fourier Transform
When dealing with an aperiodic signal in discrete time, the discrete-time Fourier transform (DTFT) is used to represent the spectrum. This transform is expressed as:
+
X(e ) =
x[n]ejn
(5)
Brackets [ ] were used here to indicate a function that is discrete in time. = 2f is the Fs normalised angular frequency (Fs is the sampling frequency of the discrete-time signal). As you know from sampling theory, this spectrum is periodic in . It is also a continuous function of frequency. The signal can be reconstructed from its frequency domain representation as: 1 x[n] = 2
+
X(ej )ejn d
(6)
Discrete Fourier Transform
Discrete Fourier transform is used when the signal is discrete-time and periodic. In practice, it is used to calculate frequency domain representation of aperiodic signals in a given time interval, by assuming their periodic extension. DFT is calculated as:
N 1
X[k] =
n=0
x[n]ej
2k n N
(7)
The signal is reconstructed by using the inverse discrete Fourier transform (IDTFT): 1 x[n] = N WN =
N 1
X[k]ej
k=0
2n k N
(8)
The denition of DFT can also be written in matrix form X = WN x, where: 1 1 1 . . . 1 11 N 21 N . . .
(N 1)1
1 12 N 22 N . . . N
(N 1)2
1 N 2(N 1) N . . . N
(N 1)(N 1) 1(N 1)
, (N = ej N )
2
(9)
1 N
and x is a column-vector containing the signal values. The equation for signal reconstruction can analogously be written in matrix form. Since the signal is periodic in time, the spectrum is discrete in frequency, and because the signal is discrete in time the spectrum is also periodic in frequency. So in this case both the signal and the spectrum are discrete and periodic in their own domains. As the DFT of a signal is periodic, with period 2, the spectrum is calculated only on the interval [0, 2]. This interval corresponds to the interval [0, Fs ] in the physical frequency domain. The fact that the spectrum in this case only exists in discrete frequency points, means that frequency components of a signal that do not fall on those discrete frequency values cannot be accurately resolved. Their power will be distributed between adjacent frequency points. Assuming that the number of signal samples in one period is same as the number of frequency samples in DFT spectrum, the frequency resolution of a DFT spectrum is given as f = Fs/N . To improve resolution, we therefore need to increase N or reduce Fs. As mentioned above, DFT is often used to represent the spectrum of aperiodic signals, by picking a nite number of samples N, and assuming that those samples were taken from a periodic signal. This process is equivalent to multiplying the signal with a function that is non-zero only in a nite number of points (window function). This process of windowing and has a side-effect of transferring some of the components power to other frequencies known as spectral leakage, which reduces the ability to resolve individual frequency components, as well as the ability to accurately calculate their amplitudes. For instance the rectangular window, if not applied carefully, will introduce discontinuities in the waveform which will result in bad results in DFT. By choosing different window functions (like Hamming, Hann, Flattop etc.), things can be improved, but a trade-off between resolution and amplitude accuracy is always present. 3
Prelab
x(t)
A
t T
Figure 1: Ideal low-pass signal spectrum PQ.1 For the pulse train signal shown in Figure 1, complex Fourier coefcients (for k = 0) can be calculated as: sin(k) Xk = A k where = T is the duty cycle. For k = 0, X0 = A. Write Matlab code to calculate coefcients for the following cases (Assume A = 1): a) rst 60 coefcients with positive indices when T = 0.1 and = 0.05 b) rst 60 coefcients with positive indices when T = 0.1 and = 0.005 c) rst 300 coefcients with positive indices when T = 0.5 and = 0.005 d) rst 300 coefcients with positive indices when T = 0.5 and = 0.001 Plot coefcients for all these cases against frequency in one gure by using the subplot and stem commands. Extra marks will be awarded if you dont use the for loop to calculate coefcients themselves. PQ.2 For the spectrum shown in Figure 2, calculate its inverse Fourier transform. (Hint: use manipulations similar to those used in the reconstruction tutorial). Sketch the time domain signal.
X(w) 1
-W
Figure 2: Ideal low-pass signal spectrum PQ.3 In Matlab, create a 1 second time vector with N elements, where N = 64 (hint: check the linspace function), and a sinewave of frequency 25.2 Hz. Plot this signal against time. 4
Use fft command to calculate thr N point DFT of the signal you created. Measure how long it takes (use tic and toc commands). Create a WN vector as described above. It can be done in just one line of code, although you dont have to do it that way. (hint: Create a matrix of exponents use the colon operator and the fact that a n 1 column vector multiplied by a 1 n row vector produces a n n matrix; then use element-wise exponential function). Calculate the DFT of your signal by multiplying its transpose with WN matrix. (In fact the whole operation of calculating DFT can be done in one line of code). Check how long it takes to generate WN matrix and multiply it with the signal. Compare the speed with Matlabs fft routine. Note both times. Plot magnitudes of both calculated DFTs in one gure using the subplot command. estimate how different the two DFTs are by using the norm command on their difference. Note that you will need to transpose the result of the rst calculation to do this (use . operator for ordinary transpose). Plot both calculated spectra (for power spectral densities you will need to plot the squared magnitude of the DFT) in one gure by using the subplot command. Repeat the calculations for N = 128, 256, 512, 1024, note how the calculation times change. Plot the ratio of calculation times vs. the number of DFT points. What does it tell you?
Lab Work
LQ.1 Set the output of the function generator to high Z because the input impedance of the scope is 1 M. Generate a sinewave with frequency 1 kHz and amplitude 2 Vpp . Pres Autoset on the scope, and verify the parameters of the signal. Set the timebase to 200 s/div. In the math menu choose fft, and set windowing function to hanning. For this and all following tasks set readout to abs. Comment on what you see. Use the cursor to verify the frequency and the magnitude. LQ.2 Change the timebase to 5 ms/div and observe what happened. How did this affect the resolution? Why? (hint: the scope calculates a 512-point FFT of exactly what is on the screen, so we have a larger number of periods i.e. a larger time interval with the same number of samples). LQ.3 Change the windowing function to rectangle and set the timebase so that you see only one period of the signal on the screen. Observe the resulting FFT. Now change the sinewave frequency to 1.1 kHz so that a little more than one period is shown on the screen. How did the FFT change? Remember that the FFT is calculated for the periodic extension of the captured signal. In this case, is the FFT calculated for a sinusoidal wave? LQ.4 Set the modulation to FSK, with FSK rate of 10 Hz and FSK hop of 100 Hz. Set the timebase to 5 ms/div. Press Run/Stop to capture one screen of data. How many fre5
quencies are present in the captured signal? Determine the frequencies of the sinusoids from the time-domain display. Switch to FFT display and measure the frequencies of the components. Compare. LQ.5 Set the output to a square wave with frequency 1 kHz and amplitude 1 Vpp with a +0.5 V DC offset. Set the timebase on the scope to 500 s/div. Show the FFT of this signal on screen (you can turn of the time-domain display). Use the cursor to identify the frequencies of harmonics. Describe the spectrum. Can you compare it to any of the results from your prelab? LQ.6 Switch to a pulse output, and change the duty cycle from 50% to 10%. Observe the result. Was it expected? How does this relate to the prelab results? Change the timebase from 500 s/div to 200 s/div. What does the result remind you of? LQ.7 Change the generators output to a Sin(x)/x function, keeping the frequency at 1 kHz, and change the timebase to 200 s/div. Observe the FFT. Is this result expected? Why?
Report
Prelab
PQ.1 Submit your Matlab code. Attach the plot. PQ.2 Submit your calculation and hand sketch of the signal. PQ.3 Submit your Matlab code. Submit the plot of both power spectral densities for N=64. Submit the plot of the ratio of the calculation times. Comment on it.
Lab Exercise
In no more than one page, answer the lab questions. 75% of the grade will be awarded for correct answers, and up to 25% will be awarded for the quality of answers.