50
MTH -343 Mathematics for Electrical and Computer Engineers MATLAB Project II The Discrete Fourier Transform Ruihua Liu, Ph.d., Temesguen Messay University of Dayton - Department of Electrical and Computer Engineering - Spring 2009

MTH -343 Mathematics for Electrical and Computer Engineers MATLAB Project II The Discrete Fourier Transform Ruihua Liu, Ph.d., Temesguen Messay University

Embed Size (px)

Citation preview

  • MTH -343 Mathematics for Electrical and Computer Engineers

    MATLAB Project II

    The Discrete Fourier Transform

    Ruihua Liu, Ph.d.,Temesguen Messay

    University of Dayton - Department of Electrical and Computer Engineering - Spring 2009

  • OutlineDiscussion about CTFT, DTFT and DFT/fftSection I (Mandatory 100pts)The DFT/fftCommunication (Problem I)Signal Processing (Problem II)Discussion about CSFT, DSFT and 2-D DFT/fft2Section II ( Optional, Extra Credit 60pts)The 2D-DFT FFT2Spatial Frequency Spectrum (Part a)Image Processing (Part b)Optical Engineering (Part c)Z-Domain (part d)History and functionality of the Fast Fourier Transform algorithm (part e)

  • The Continuous Time Fourier Transform (CTFT) and its inverse transform (iCTFT)Continuous Time Fourier Transform (CTFT)

    Analog frequencies

    in

    F in

    Inverse Continuous Time Fourier Transform (iCTFT) xc(t)

  • The notion of sampling/discretizingLet x(n) be a sampled version of the continuous-time signal xc(t),sampled at regular interval Ts:

    Sampling period

    Sampling frequency

    We do so by multiplying xc(t) by an impulse train function, s(t) (Dirac Deltas)

    Dirac Delta : xc(t)s(t)xc(t)s(t)

  • Discrete Time Fourier Transform (DTFT)Nyquist criterion A MUST !!!!!The NyquistShannon sampling theorem The minimum sampling rate required to avoid aliasing,Signal must be sampled twice the highest frequency contained within the signal.

    From CTFT to Discrete Time Fourier Transform (DTFT)

  • The DTFT and its periodicityDTFT: Introducing/Switching to digital frequency

    Digital frequencies:

    in Note:

    in

    DTFT of x(n) (i.e., X( )) is continuous and2-periodic in frequency !!!Inverse DTFT (iDTFT)

  • DTFT periodicityIn digital frequenciesSpectrum of x(n) is periodic in w with period 2p.Spectrum of x(n) is also periodic in f with unity period (i.e., 1 cycle/sample).In analog frequenciesSpectrum of x(n) is periodic in W with period ( 2p ) / Ts.Spectrum of x(n) is also periodic in F with period Fs.Due to periodicity Xs(W) and Xs(w) are the summation of scaled and shifted copies of Xc(W), i.e. Xc(w) .Mathematically;Digital

    Analog

  • From DTFT to Discrete Fourier Transform (DFT) The DFT is the Fast Fourier Transform (fft)!!The digital frequencies( and f ) are in turn discretized in one period [0-2 and 0-1] by introducing k

    DFT - Take transform of these discrete frequencies

    Proper interpretation of the spacing of the DFT samples Digital (Normalized) Spacing Analog Spacing

    Inverse DFT (iDFT)DFT Analog frequencies

  • Interpretation of DFT Frequencies

    Hence, for an 8 point fft transformk =01234567Fk =fk =Bin numberDigital or Normalized frequencyAnalogue frequency(Hz)

  • Section IProblem ICommunication

    Amplitude Modulation (AM)Simulating a primitive method of transmitting a signal

  • AM A radio contains anantenna to detect the transmitted signal, a tuner to pick out the desired frequency, a decoder to extract the original electrical wave from the transmitted signal and a speaker to reproduce the sound waveConcept of Communication SystemsA sound wave is produced (a disturbance travelling through a medium : air )The sound wave is equivalent to a pressure wave traveling through air A microphone converts the sound wave (pressure wave) into an electrical wave

    The signal is then transmitted by a radio broadcast tower or antennaThe electrical wave traveling through the microphone wire is analogous to the original sound wave FM [Encoder/Converter]The electrical wave (signal) is used to convert (encode) the sound waves into high frequency waves in the radio frequency range (electromagnetic waves )

  • Generating the message signal - m(t)

  • Examining the FFT of the generated message signal (the frequency domain) M(f)

  • The carrier SignalTime DomainFrequency Domain

  • Amplitude Modulation - TransmissionTime DomainFrequency Domain?

  • Examining AM message signal spectrum using MATLAB built-in functionsPERIODOGRAM(X,WINDOW,NFFT,Fs)SPECTROGRAM(X,WINDOW,NOVERLAP,NFFT,Fs)

  • Signal Processing

    Designing and implementing a graphic equalizer Frequency sampling designSection IProblem II

  • An audio signal (Sound wave)[ Y, FS ]=WAVREAD(FILE)SOUND(Y,FS)Y = Y( : , 1 ) ; (conversion from stereo to mono)Frequency DomainTime DomainMATLAB = fftshift(fft())Ts = 1/fs (secs) fs/2 fs = 44.1KHz -fs/2MATLAB = fft())CD sampling rate = 44.1KHz 0 fs

  • Graphic EqualizerBank of sliders for boosting and attenuating/cutting different bands (i.e., range of frequencies)

  • Geq : 3 FiltersWoofer/sub-woofer (LPF)~ 0 ~300 Hz (cut-off)Mid-Range (BPF)~ 300Hz - ~5KHzTweeter (HPF)~ 5KHz 22.05KHz

    Frequency DomainIdeal continuous Frequency Response of the filtersNote : frequency response in Hz Effective cont frequency response -fs/2 fs/2

  • Frequency Sampling filter designExample : Woofer ~ 0 - 300Hz (LPF)N = 151 samples (filter length in freq. domain)Samples of ideal cont. freq. resp. of filter for frequencies ranging from -fs/2 to fs/2 from -22.05KHz to 22.05KHz Frequency response is symmetric75 samples for positive frequencies75 samples for negative frequencies1 sample for f = 0 Hz ( DC value )Need to sample only half of ideal frequency response of LPF filterSamples of continuous and ideal frequency response of filter for frequencies 0 Hz ( i.e., for positive frequencies & DC value) ( N + 1 ) / 2 = 76 samples from 0 to 22.05KHz Sampling Rate fs / N = 290.13 Hz / sample Take a sample every ~ 290 Hz (Total of 76 samples)(i.e., define array consisting of 76 ones and zeros representing samples every 290Hz of the ideal frequency response of filterstarting from f = 0Hz up to f = 22.05KHz )

    Note : Zoomed in

  • Need to sample the other half of the cont. ideal frequency response (i.e., negative frequencies )Flip the samples of the ideal frequency response for the positive frequencies ( i.e., defined array consisting of 76 samples) starting from the 2nd sample 75 samples for neg. freq rangeTake conjugate Concatenate the samples of both half responses(i.e., negative and positive frequencies respectively)Result range: - fs/2 to fs/2 = -22.05KHz to 22.05KHz

    Circularly shift result/samplesifftshift()Result range: 0 to 2 (rads/sample)Result range: 0 to 44.1 (Khz)Compatible with ifft

    Frequency Sampling filter designExample : Woofer ~ 0 - 300Hz (LPF)

  • Frequency Sampling filter designExample : Woofer ~ 0 - 300Hz (LPF)Inverse Fourier Transform (ifft) to get samples of the Impulse Response of filter in time domain.

    Check actual, effective and continuous frequency response of filter (High resolution transform, N =1024)

    fftshift(ifft())fftshift(fft())

  • Effective frequency responses of the three filtersTime DomainFrequency Domainfftshift(fft())fftshift(fft())fftshift(fft())

  • Combining the filters in the time domain using the specified weights to get impulse response of GeqWoofer/sub-woofer (LPF)W1 = 1/4Mid-Range (BPF)W2 = 1/2Tweeter (HPF)W3 = 1Ideal Goal in Frequency DomainTime Domainh_LPFW1W2W3h_BPFh_HPFh_Eq

  • Implementing graphic Eqfftshift(fft())CONVTime DomainFrequency Domain?fftshift(fft())Note: use conv2(same)

  • Operational Fourier Properties (p251)*Convolution :

    Time Domain (t)Frequency Domain ()Functions involvedf(t), g(t), y(t)F(w), G(w), Y(w)Linearity

    Modulation Frequency Translation OperationMultiplication

    Convolution *

    OperationConvolution *Multiplication

    Reversibility

  • Section II (2-D DFT)Discussion about 2-D DFT/fft2Section II ( Optional, Extra Credit 60pts)The 2D-DFT FFT2Spatial Frequency Spectrum (Part a)Image Processing (Part b)Optical Engineering (Part c)Z-Domain (part d)History and functionality of the Fast Fourier Transform algorithm (part e)

  • Continuous Space Fourier Transform (CSFT)

    Forward

    Reverse

    Units (continuous)x, y: spatial position (in mm)U, V: spatial frequency (in cycles/mm)

    f(x, y)F(U, V)

  • Forward

    Reverse

    Forward

    Reverse

    Discrete Space Fourier Transform (DSFT)

    nx,ny discrete in sample #, u,v continuous in cycles/sample(repeats period 1)nx,ny discrete in sample #, x, y continuous in rads/sample(repeats period 2)

  • 2-D DFT ( = fft2)Discretized/normalized (Digital) spatial frequencies:

    Forward

    Reverse

    FYI : KEYu,v in cycles/sampleDivide by pixel spacing to get U,V in cycles/mm

  • 2-D circular shift (fftshift)

  • Generating images ( Vertical and Horizontal strips)Repeat/Duplicate the message and carrier signals (i.e., arrays) in problem I horizontally and vertically to form matrices (i.e., images)Use 129 samples instead of the original 201Use repmat() to duplicate the signals 129 times in the desired orientation.Use imagesc() followed by colormap(gray) to display imageImages (slow intensity variation)Images (High intensity variation)Spatial Domain

  • Spatial frequency spectrum (fft2)Spatial DomainSpatial frequency DomainFourier Domainfftshift(fft2())

  • Reading a Natural Image

  • Analyzing spatial frequency spectrum of natural imageSpatial DomainSpatial frequency DomainFourier DomainNote : - Convert to double() before fft2() - Magnitude is clipped @10,000 to obtain a decent plot

  • 2-D Low pass spatial filter

    Spatial DomainSpatial frequency DomainFourier Domainfftshift(fft2())

  • 2-D convolutionContinuous extension

    Discrete extension

  • Implement 2-D low pass filter Spatial DomainCONV2()Spatial frequency DomainFourier Domain

  • 2-D High Pass spatial filterusing fspecial(unsharp)

    Spatial DomainSpatial frequency DomainFourier Domainfftshift(fft2()) Note : Not entirely true

  • Implement 2-D High pass filter Spatial DomainCONV2()Spatial frequency DomainFourier Domain

  • 2-D motion blur filterusing fspecial(motion)

    Spatial DomainSpatial frequency DomainFourier Domainfftshift(fft2())

  • Implement 2-D motion blur filter Spatial DomainCONV2()Spatial frequency DomainFourier Domain

  • Diffraction Pattern (Fresnel / Fraunhofer approximation)After several computational derivation steps ...

  • Diffraction pattern simulation in MATLABfftshift(fft2())Note: true image

  • Magnitude surface plot of a complex function f(z)Given function:

    where

  • Magnitude of unit circle overlaid on magnitude surface plot

  • Phase angle of unit circle overlaid on Phase angle surface plot

  • **********