fourier lab

Upload: azeem-iqbal

Post on 07-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Fourier Lab

    1/6

    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 youlabel 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 periodTcan be represented as an infinite sum of complex

    exponentials, multiplied by appropriate Fourier coefficients:

    x(t) =+

    Xkejk 2

    Tt (1)

    where the coefficients Xk are calculated as:

    Xk =1

    T

    +T/2

    T/2

    x(t)ejk2

    Ttdt (2)

    1

  • 8/3/2019 Fourier Lab

    2/6

    Coefficient X0 is the mean value of the signal on one period (or its DC component). Coeffi-cients with other indices represent higher harmonics of the signal. The signals spectrum can be

    viewed as a series of impulse functions in continuous frequency.

    2 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)ejtdt (3)

    where = 2f is the angular frequency. The signal itself can be calculated from its fre-quency domain representation as:

    x(t) =1

    2

    +

    X()ejtd (4)

    These relations can be seen as a limit case of Fourier series, when the period is allowed to ap-

    proach infinity, leading to a continuum of frequency components (1/T, which is the fundamentalfrequency converges to zero). The spectrum is a continuous function of frequency.

    3 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(ej) =+

    x[n]ejn (5)

    Brackets [ ] were used here to indicate a function that is discrete in time. = 2fFs

    is the

    normalised angular frequency (Fs is the sampling frequency of the discrete-time signal). As youknow from sampling theory, this spectrum is periodic in . It is also a continuous function offrequency. The signal can be reconstructed from its frequency domain representation as:

    x[n] =1

    2

    +

    X(ej)ejnd (6)

    2

  • 8/3/2019 Fourier Lab

    3/6

    4 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:

    X[k] =N1n=0

    x[n]ej2k

    Nn (7)

    The signal is reconstructed by using the inverse discrete Fourier transform (IDTFT):

    x[n] =1

    N

    N1k=0

    X[k]ej2n

    Nk (8)

    The definition of DFT can also be written in matrix form X= WN x, where:

    WN =

    1 1 1 1

    1 11N 12N

    1(N1)N

    1 21N 22N

    2(N1)N

    ......

    ......

    1 (N1)1N

    (N1)2N

    (N1)(N1)N

    , (N = e

    j 2N ) (9)

    and x is a column-vector containing the signal values. The equation for signal reconstructioncan analogously be written in matrix form.

    Since the signal is periodic in time, the spectrum is discrete in frequency, and because thesignal 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 intervalcorresponds to the interval [0, Fs] in the physical frequency domain. The fact that the spectrumin 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 ofaperiodic signals, by picking a finite 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 finite 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

  • 8/3/2019 Fourier Lab

    4/6

    Prelab

    A

    x(t)

    tT

    t

    Figure 1: Ideal low-pass signal spectrum

    PQ.1 For the pulse train signal shown in Figure 1, complex Fourier coefficients (for k = 0) canbe calculated as:

    Xk = Asin(k)

    k

    where = T

    is the duty cycle. For k = 0, X0 = A. Write Matlab code to calculatecoefficients for the following cases (Assume A = 1):

    a) first 60 coefficients with positive indices when T = 0.1 and = 0.05

    b) first 60 coefficients with positive indices when T = 0.1 and = 0.005

    c) first 300 coefficients with positive indices when T = 0.5 and = 0.005

    d) first 300 coefficients with positive indices when T = 0.5 and = 0.001

    Plot coefficients for all these cases against frequency in one figure by using the subplot

    and stem commands. Extra marks will be awarded if you dont use the for loop to

    calculate coefficients 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.

    1

    wW-W

    X( )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

  • 8/3/2019 Fourier Lab

    5/6

    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, althoughyou dont have to do it that way. (hint: Create a matrix of exponents use the colon op-

    erator and the fact that a n 1 column vector multiplied by a 1 n row vector producesa n n matrix; then use element-wise exponential function). Calculate the DFT of yoursignal by multiplying its transpose with WN matrix. (In fact the whole operation of cal-culating DFT can be done in one line of code). Check how long it takes to generate WNmatrix and multiply it with the signal. Compare the speed with Matlabs fft routine. Note

    both times.

    Plot magnitudes of both calculated DFTs in one figure using the subplot command. esti-

    mate 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 first 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 figure 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?

    1 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. PresAutoset 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 thisand 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 samenumber 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 fre-

    5

  • 8/3/2019 Fourier Lab

    6/6

    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 onscreen (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.

    6