SlideShare una empresa de Scribd logo
1 de 5
Descargar para leer sin conexión
ECE 410 INTRODUCTION TO SIGNAL PROCESSING
Matlab Project I
Fall 2001
Issued: Monday, September 24, 2001 Due: Wednesday, October 17, 2001
The purpose of this project is to develop a thorough understanding of the Discrete Fourier Transform
(DFT) and how it is used to implement digital filters. Part 1 focuses on the circular convolution property
of the DFT. You will write and test Matlab functions that implement the circular flip, circular shift, and
circular convolution operations. In addition you will examine the relationship between linear convo-
lution and circular convolution. Part 2 considers the problem of using the DFT to implement linear,
time-invariant filtering operations on long signals. Specifically, you will write Matlab functions that
implement block convolution using the overlap-add and overlap-save strategies.
A list of guidelines for preparing the writeup of this project are given below. Failure to comply with
these guidelines will result in a grade of ZERO for the project.
• The report must be neatly handwritten or typed, and all pages must be numbered.
• All plots must be neatly annotated with x-axis and y-axis labels and a title.
• When referring to plots in the text, you should do at least one of the following:
– use figure numbers, e.g., “Figure 1 is a plot of the signal x[n].”
– cite the page number they are on, e.g., “The figure at the top of page 4 is a plot of x[n].”
• All Matlab code must be well-documented and should be included in an Appendix at the end of
the report.
1 CIRCULAR CONVOLUTION
The following exercises focus on the circular convolution property of the DFT. An N−point circular
convolution is defined as follows
y[n] = x[n] N h[n] =
N−1
m=0
x[m]h[(n − m)mod N]. (1)
Combining N-point vectors according to the circular convolution rule (Equation 1) is easy to visualize
with some experience, and Matlab provides the means to do the visualization. Circular convolution
requires that all indexing be done in a circular (or periodic) fashion. Thus a shifting operation becomes
a rotation. In the exercises below you will develop functions for circular flipping, circular shifting, and
then use those functions to implement circular convolution.
1.1 Circular Flip
The circular flipping operation is defined as
x[−n mod N] = x[N − n] for n = 0, 1, . . . , N − 1
(a) Write a Matlab function called cflip to implement the circular flipping operation.
(b) Define several test signals and use them to verify that your function is working. Include plots of a
few (two or three) test cases in your writeup, i.e., plots of both the original signal and the flipped
signal. You will probably want to use the subplot command to get these plots on the same
page.
1.2 Circular Shift
The circular shifting operation is defined as
x[(n − m) mod N]
(a) Write a function Matlab called cshift to implement the circular shifting operation.
Hint:
First write a short function that computes n mod N. Matlab’s rem function will be useful for
this task, but is not sufficient by itself because it will not handle the case where n is negative.
However, a simple modification that uses two calls to rem will guarantee an answer in the range
[0, N − 1]. Take advantage of the fact that (n + N) mod N = n mod N.
Once you have code to compute n mod N, writing the rest of the cshift function should be
easy.
(b) Define several test signals and use them to verify that your function is working. Include plots of
two or three of these test cases as documentation in your writeup. You should verify that your
function handles the case where m is negative and also the case where m is greater than N.
(c) We know that a circular shift corresponds to multiplying the DFT by complex exponential. Verify
the results of your test cases by
• Taking the DFT of the test signal: x[n] −→ X[k]
• Multiplying by a complex exponential: Xshift[k] = W−mk
N X[k]
• Computing the inverse DFT: Xshift[k] −→ xshift[n]
1.3 Circular Convolution
There are two ways to write a function for circular convolution: 1) in the transform domain and 2) in
the time domain. In this exercise you will develop a Matlab function, called cconv, that implements
both methods. The Matlab function will require four inputs: the signal vectors x[n] and h[n], the length
of the circular convolution, N, and a variable that indicates which method to use. The function returns
a single output y[n]. Include a comments section at the beginning of the m-file that is similar to the
following:
%% CCONV Computes N-point circular convolution of two vectors. The
%% user specifies whether to use a time or frequency-domain
%% implementation.
%%
%% Usage:
%% y=cconv(x,h,N,method)
%%
%% Variables:
%% x = signal vector x[n]
%% h = signal vector h[n]
%% N = number of points in the circular convolution
%% method = implementation of circular convolution
%% ’freq’ = Frequency-domain
%% ’time’ = Time-domain
%% y = result: N-point circular convolution of x and h
%%
%% File : cconv
%% Author : The DSP Wizard/Wizardess
%% Date : September 26, 2001
(a) The frequency-domain implementation uses the fact that the circular convolution of x[n] and h[n]
is equivalent to the multiplication of their DFT’s, i.e., X[k] · H[k]. Use this idea to implement the
frequency-domain method in cconv. This should require three calls to Matlab’s fft function.
Try (and plot!) the following simple tests for N = 16 and N = 21.
(i) An impulse at n = a convolved with an impulse at n = b, where a and b are integers. In
this case the output has only one nonzero value, so determine its location. Try with different
values of a and b.
(ii) Convolve two short pulses. Let x[n] be a pulse of length 5 and h[n] a pulse of length 8,
starting at n = 4. Verify that your function computes the correct output.
(iii) Two long pulses such that the output wraps around. Let x[n] be a pulse of length 11 and h[n]
a pulse of length 7, starting at n = 5. Compute the output and check its correctness versus a
hand calculation. Explain why the answer is different for the length-16 and length-21 cases.
(b) Implement the time-domain option for circular convolution in your cconv function, i.e., imple-
ment This can be done with for loops, but good Matlab programming style replaces for loops
with vector operations whenever possible. Since each output point in the circular convolution is
an inner product of x with a circularly-flipped and shifted version of h, only one for loop is
needed. Write a function called cconv2 based on this idea. Test your function using some of the
examples from part (a). Include several of the test cases in your writeup.
1.4 Relationship to Linear Convolution
The comparison of circular convolution output to a linear convolution output shows that they are not
always the same. Some values may be correct, while others are corrupted because of time aliasing. In
block convolution (overlap-save, in particular), it is often necessary to identify the good and bad points.
(a) Consider the circular convolution of the following signals:
x[n] =
(0.9)n 0 ≤ n ≤ 12
0 elsewhere
h[n] =
1 0 ≤ n ≤ 11
0 elsewhere
Let the length of the circular convolution be N = 21. Determine which values of the circular
convolution are the same as the linear convolution result. Plot the result and indicate the output
indices where the values are “bad”.
(b) Suppose the two signals are defined as
x[n] =
(0.9)n 0 ≤ n ≤ 12
0 elsewhere
h[n] =
1 9 ≤ n ≤ 20
0 elsewhere
Plot the results and indicate where the good and bad values are now that h[n] has leading zeroes.
(c) Consider the following example, which relates to the overlap-save situation.
x[n] =
1 0 ≤ n ≤ 16
0 elsewhere
h[n] =
sin(nπ/13) 0 ≤ n ≤ 99
0 elsewhere
Suppose that a 100-point circular convolution is performed. (There is no zero-padding of h[n].)
Plot the results and determine the indices of the good and bad points in the output.
2 BLOCK CONVOLUTION
While short signals provide useful illustrations of convolution, they are not typical of practical filtering
problems. In many applications the input x[n] is very long with respect to the filter impulse response
h[n]. It is often impractical to process the entire input signal at once. An alternative solution is to
break the input into blocks, filter each block separately and then combine the blocks appropriately to
obtain the output. There are two basic strategies for block processing, which are known as overlap-
add and overlap-save, respectively. Matlab’s fftfilt program uses the overlap-add approach. In the
following exercises you will develop your own Matlab implementations of overlap-add and overlap-save
block convolution.
2.1 Overlap-Add Implementation
The overlap-add method works by breaking the long input signal into small non-overlapping sections.
If the length of these sections is L and the length of the impulse response is P, then an N = L + P − 1
point DFT is used to implement the filter for each section. (The L + P − 1-point DFT avoids problems
with time-aliasing inherent in the circular convolution.) The result for each block overlaps with the
following block. These overlapping sections must be added together to compute the output.
(a) Write a Matlab function to implement overlap-add block convolution. The inputs to this function
should be the input signal vector x, the filter vector h, and the DFT size. Use the following as a
header for the m-file:
%% OLADD Filtering via overlap-add block convolution.
%%
%% Usage:
%% y=oladd(x,h,N)
%%
%% Variables:
%% x = signal vector x[n]
%% h = filter vector h[n]
%% N = DFT size (choose a power of 2 for fastest results)
%% y = Result: x[n]*h[n]
%%
%% File : oladd
%% Author : The DSP Wizard/Wizardess
%% Date : September 26, 2001
(b) Test your code using the signal and filter defined in the file projIdata.mat, available on the
course website. You can verify the results by comparing them to the result of convolving x and
h using the built-in conv function. Make sure that your function works for any reasonable DFT
length (i.e., longer than the filter).
2.2 Overlap-Save Implementation
The overlap-save method uses a different strategy to break up the input signal. If the length of the
circular convolution (i.e., the DFT length) is chosen to be N = L + P − 1, overlap-save uses input
segments of length N. The starting location of each input segment is skipped by an amount L, so there
is an overlap of P − 1 points with the previous section. Thus this method could also be called the
overlapped inputs method. The L “good” points resulting from the N-point circular convolution of
each section with the filter are retained. No additions are needed to create the output.
(a) Write a Matlab function called olsave to implement overlap-save block convolution. The inputs
to this function should be the input signal vector x, the filter vector h, and the DFT size. Use a
header for your function similar to the one for oladd.
(b) Test your code as you did the oladd function, i.e., using the data in projIdata.mat. Make
sure that your function works for any reasonable DFT-length (i.e., longer than the filter itself).

Más contenido relacionado

La actualidad más candente

Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
Ankit Katiyar
 
Dft and its applications
Dft and its applicationsDft and its applications
Dft and its applications
Agam Goel
 
Antenna & wave lab manual
Antenna & wave lab manualAntenna & wave lab manual
Antenna & wave lab manual
amanabr
 
Fourier transforms & fft algorithm (paul heckbert, 1998) by tantanoid
Fourier transforms & fft algorithm (paul heckbert, 1998) by tantanoidFourier transforms & fft algorithm (paul heckbert, 1998) by tantanoid
Fourier transforms & fft algorithm (paul heckbert, 1998) by tantanoid
Xavier Davias
 

La actualidad más candente (20)

DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)
DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)
DSP Lab Manual (10ECL57) - VTU Syllabus (KSSEM)
 
Digital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE studentsDigital Signal Processing Lab Manual ECE students
Digital Signal Processing Lab Manual ECE students
 
Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02Asymptotics 140510003721-phpapp02
Asymptotics 140510003721-phpapp02
 
Digital Signal Processing[ECEG-3171]-Ch1_L05
Digital Signal Processing[ECEG-3171]-Ch1_L05Digital Signal Processing[ECEG-3171]-Ch1_L05
Digital Signal Processing[ECEG-3171]-Ch1_L05
 
digital signal-processing-lab-manual
digital signal-processing-lab-manualdigital signal-processing-lab-manual
digital signal-processing-lab-manual
 
Digital Signal Processing[ECEG-3171]-Ch1_L06
Digital Signal Processing[ECEG-3171]-Ch1_L06Digital Signal Processing[ECEG-3171]-Ch1_L06
Digital Signal Processing[ECEG-3171]-Ch1_L06
 
DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)
DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)
DSP_FOEHU - MATLAB 04 - The Discrete Fourier Transform (DFT)
 
no U-turn sampler, a discussion of Hoffman & Gelman NUTS algorithm
no U-turn sampler, a discussion of Hoffman & Gelman NUTS algorithmno U-turn sampler, a discussion of Hoffman & Gelman NUTS algorithm
no U-turn sampler, a discussion of Hoffman & Gelman NUTS algorithm
 
DSP_FOEHU - Lec 08 - The Discrete Fourier Transform
DSP_FOEHU - Lec 08 - The Discrete Fourier TransformDSP_FOEHU - Lec 08 - The Discrete Fourier Transform
DSP_FOEHU - Lec 08 - The Discrete Fourier Transform
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
Digital Signal Processing[ECEG-3171]-Ch1_L02
Digital Signal Processing[ECEG-3171]-Ch1_L02Digital Signal Processing[ECEG-3171]-Ch1_L02
Digital Signal Processing[ECEG-3171]-Ch1_L02
 
Signal Prosessing Lab Mannual
Signal Prosessing Lab Mannual Signal Prosessing Lab Mannual
Signal Prosessing Lab Mannual
 
Computer Vision: Feature matching with RANSAC Algorithm
Computer Vision: Feature matching with RANSAC AlgorithmComputer Vision: Feature matching with RANSAC Algorithm
Computer Vision: Feature matching with RANSAC Algorithm
 
Dft,fft,windowing
Dft,fft,windowingDft,fft,windowing
Dft,fft,windowing
 
Preemptive RANSAC by David Nister.
Preemptive RANSAC by David Nister.Preemptive RANSAC by David Nister.
Preemptive RANSAC by David Nister.
 
Dft and its applications
Dft and its applicationsDft and its applications
Dft and its applications
 
Analysis of Algorithm
Analysis of AlgorithmAnalysis of Algorithm
Analysis of Algorithm
 
Symbolic Execution as DPLL Modulo Theories
Symbolic Execution as DPLL Modulo TheoriesSymbolic Execution as DPLL Modulo Theories
Symbolic Execution as DPLL Modulo Theories
 
Antenna & wave lab manual
Antenna & wave lab manualAntenna & wave lab manual
Antenna & wave lab manual
 
Fourier transforms & fft algorithm (paul heckbert, 1998) by tantanoid
Fourier transforms & fft algorithm (paul heckbert, 1998) by tantanoidFourier transforms & fft algorithm (paul heckbert, 1998) by tantanoid
Fourier transforms & fft algorithm (paul heckbert, 1998) by tantanoid
 

Similar a Mlab i

Lossless image compression via by lifting scheme
Lossless image compression via by lifting schemeLossless image compression via by lifting scheme
Lossless image compression via by lifting scheme
Subhashini Subramanian
 
FINITE ELEMENT FORMULATION FOR CONVECTIVE-DIFFUSIVE PROBLEMS WITH SHARP GRADI...
FINITE ELEMENT FORMULATION FOR CONVECTIVE-DIFFUSIVE PROBLEMS WITH SHARP GRADI...FINITE ELEMENT FORMULATION FOR CONVECTIVE-DIFFUSIVE PROBLEMS WITH SHARP GRADI...
FINITE ELEMENT FORMULATION FOR CONVECTIVE-DIFFUSIVE PROBLEMS WITH SHARP GRADI...
Aleix Valls
 
Presentation for Numerical Field Theory
Presentation for Numerical Field TheoryPresentation for Numerical Field Theory
Presentation for Numerical Field Theory
Indraneel Pole
 
EE 567ProjectDue Tuesday, December 3, 2019 at 640 p.m..docx
EE 567ProjectDue Tuesday, December 3, 2019 at 640 p.m..docxEE 567ProjectDue Tuesday, December 3, 2019 at 640 p.m..docx
EE 567ProjectDue Tuesday, December 3, 2019 at 640 p.m..docx
gidmanmary
 

Similar a Mlab i (20)

DSP_Lab_MAnual_-_Final_Edition.pdf
DSP_Lab_MAnual_-_Final_Edition.pdfDSP_Lab_MAnual_-_Final_Edition.pdf
DSP_Lab_MAnual_-_Final_Edition.pdf
 
DSP_Lab_MAnual_-_Final_Edition[1].docx
DSP_Lab_MAnual_-_Final_Edition[1].docxDSP_Lab_MAnual_-_Final_Edition[1].docx
DSP_Lab_MAnual_-_Final_Edition[1].docx
 
Introducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlowIntroducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlow
 
Lossless image compression via by lifting scheme
Lossless image compression via by lifting schemeLossless image compression via by lifting scheme
Lossless image compression via by lifting scheme
 
Implementation of Energy Efficient Scalar Point Multiplication Techniques for...
Implementation of Energy Efficient Scalar Point Multiplication Techniques for...Implementation of Energy Efficient Scalar Point Multiplication Techniques for...
Implementation of Energy Efficient Scalar Point Multiplication Techniques for...
 
Subquad multi ff
Subquad multi ffSubquad multi ff
Subquad multi ff
 
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsDSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
 
FINITE ELEMENT FORMULATION FOR CONVECTIVE-DIFFUSIVE PROBLEMS WITH SHARP GRADI...
FINITE ELEMENT FORMULATION FOR CONVECTIVE-DIFFUSIVE PROBLEMS WITH SHARP GRADI...FINITE ELEMENT FORMULATION FOR CONVECTIVE-DIFFUSIVE PROBLEMS WITH SHARP GRADI...
FINITE ELEMENT FORMULATION FOR CONVECTIVE-DIFFUSIVE PROBLEMS WITH SHARP GRADI...
 
Loop parallelization & pipelining
Loop parallelization & pipeliningLoop parallelization & pipelining
Loop parallelization & pipelining
 
Reconstruction
ReconstructionReconstruction
Reconstruction
 
Presentation for Numerical Field Theory
Presentation for Numerical Field TheoryPresentation for Numerical Field Theory
Presentation for Numerical Field Theory
 
Optimization Techniques
Optimization TechniquesOptimization Techniques
Optimization Techniques
 
EE 567ProjectDue Tuesday, December 3, 2019 at 640 p.m..docx
EE 567ProjectDue Tuesday, December 3, 2019 at 640 p.m..docxEE 567ProjectDue Tuesday, December 3, 2019 at 640 p.m..docx
EE 567ProjectDue Tuesday, December 3, 2019 at 640 p.m..docx
 
Newton cotes integration method
Newton cotes integration  methodNewton cotes integration  method
Newton cotes integration method
 
Chap12 slides
Chap12 slidesChap12 slides
Chap12 slides
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
 
lecture_09.pptx
lecture_09.pptxlecture_09.pptx
lecture_09.pptx
 
A partial linearization method for the traffic assignment problem.pdf
A partial linearization method for the traffic assignment problem.pdfA partial linearization method for the traffic assignment problem.pdf
A partial linearization method for the traffic assignment problem.pdf
 
Analysis_molf
Analysis_molfAnalysis_molf
Analysis_molf
 
Dsp file
Dsp fileDsp file
Dsp file
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 

Mlab i

  • 1. ECE 410 INTRODUCTION TO SIGNAL PROCESSING Matlab Project I Fall 2001 Issued: Monday, September 24, 2001 Due: Wednesday, October 17, 2001 The purpose of this project is to develop a thorough understanding of the Discrete Fourier Transform (DFT) and how it is used to implement digital filters. Part 1 focuses on the circular convolution property of the DFT. You will write and test Matlab functions that implement the circular flip, circular shift, and circular convolution operations. In addition you will examine the relationship between linear convo- lution and circular convolution. Part 2 considers the problem of using the DFT to implement linear, time-invariant filtering operations on long signals. Specifically, you will write Matlab functions that implement block convolution using the overlap-add and overlap-save strategies. A list of guidelines for preparing the writeup of this project are given below. Failure to comply with these guidelines will result in a grade of ZERO for the project. • The report must be neatly handwritten or typed, and all pages must be numbered. • All plots must be neatly annotated with x-axis and y-axis labels and a title. • When referring to plots in the text, you should do at least one of the following: – use figure numbers, e.g., “Figure 1 is a plot of the signal x[n].” – cite the page number they are on, e.g., “The figure at the top of page 4 is a plot of x[n].” • All Matlab code must be well-documented and should be included in an Appendix at the end of the report. 1 CIRCULAR CONVOLUTION The following exercises focus on the circular convolution property of the DFT. An N−point circular convolution is defined as follows y[n] = x[n] N h[n] = N−1 m=0 x[m]h[(n − m)mod N]. (1) Combining N-point vectors according to the circular convolution rule (Equation 1) is easy to visualize with some experience, and Matlab provides the means to do the visualization. Circular convolution requires that all indexing be done in a circular (or periodic) fashion. Thus a shifting operation becomes a rotation. In the exercises below you will develop functions for circular flipping, circular shifting, and then use those functions to implement circular convolution. 1.1 Circular Flip The circular flipping operation is defined as x[−n mod N] = x[N − n] for n = 0, 1, . . . , N − 1
  • 2. (a) Write a Matlab function called cflip to implement the circular flipping operation. (b) Define several test signals and use them to verify that your function is working. Include plots of a few (two or three) test cases in your writeup, i.e., plots of both the original signal and the flipped signal. You will probably want to use the subplot command to get these plots on the same page. 1.2 Circular Shift The circular shifting operation is defined as x[(n − m) mod N] (a) Write a function Matlab called cshift to implement the circular shifting operation. Hint: First write a short function that computes n mod N. Matlab’s rem function will be useful for this task, but is not sufficient by itself because it will not handle the case where n is negative. However, a simple modification that uses two calls to rem will guarantee an answer in the range [0, N − 1]. Take advantage of the fact that (n + N) mod N = n mod N. Once you have code to compute n mod N, writing the rest of the cshift function should be easy. (b) Define several test signals and use them to verify that your function is working. Include plots of two or three of these test cases as documentation in your writeup. You should verify that your function handles the case where m is negative and also the case where m is greater than N. (c) We know that a circular shift corresponds to multiplying the DFT by complex exponential. Verify the results of your test cases by • Taking the DFT of the test signal: x[n] −→ X[k] • Multiplying by a complex exponential: Xshift[k] = W−mk N X[k] • Computing the inverse DFT: Xshift[k] −→ xshift[n] 1.3 Circular Convolution There are two ways to write a function for circular convolution: 1) in the transform domain and 2) in the time domain. In this exercise you will develop a Matlab function, called cconv, that implements both methods. The Matlab function will require four inputs: the signal vectors x[n] and h[n], the length of the circular convolution, N, and a variable that indicates which method to use. The function returns a single output y[n]. Include a comments section at the beginning of the m-file that is similar to the following: %% CCONV Computes N-point circular convolution of two vectors. The %% user specifies whether to use a time or frequency-domain %% implementation. %% %% Usage:
  • 3. %% y=cconv(x,h,N,method) %% %% Variables: %% x = signal vector x[n] %% h = signal vector h[n] %% N = number of points in the circular convolution %% method = implementation of circular convolution %% ’freq’ = Frequency-domain %% ’time’ = Time-domain %% y = result: N-point circular convolution of x and h %% %% File : cconv %% Author : The DSP Wizard/Wizardess %% Date : September 26, 2001 (a) The frequency-domain implementation uses the fact that the circular convolution of x[n] and h[n] is equivalent to the multiplication of their DFT’s, i.e., X[k] · H[k]. Use this idea to implement the frequency-domain method in cconv. This should require three calls to Matlab’s fft function. Try (and plot!) the following simple tests for N = 16 and N = 21. (i) An impulse at n = a convolved with an impulse at n = b, where a and b are integers. In this case the output has only one nonzero value, so determine its location. Try with different values of a and b. (ii) Convolve two short pulses. Let x[n] be a pulse of length 5 and h[n] a pulse of length 8, starting at n = 4. Verify that your function computes the correct output. (iii) Two long pulses such that the output wraps around. Let x[n] be a pulse of length 11 and h[n] a pulse of length 7, starting at n = 5. Compute the output and check its correctness versus a hand calculation. Explain why the answer is different for the length-16 and length-21 cases. (b) Implement the time-domain option for circular convolution in your cconv function, i.e., imple- ment This can be done with for loops, but good Matlab programming style replaces for loops with vector operations whenever possible. Since each output point in the circular convolution is an inner product of x with a circularly-flipped and shifted version of h, only one for loop is needed. Write a function called cconv2 based on this idea. Test your function using some of the examples from part (a). Include several of the test cases in your writeup. 1.4 Relationship to Linear Convolution The comparison of circular convolution output to a linear convolution output shows that they are not always the same. Some values may be correct, while others are corrupted because of time aliasing. In block convolution (overlap-save, in particular), it is often necessary to identify the good and bad points. (a) Consider the circular convolution of the following signals: x[n] = (0.9)n 0 ≤ n ≤ 12 0 elsewhere
  • 4. h[n] = 1 0 ≤ n ≤ 11 0 elsewhere Let the length of the circular convolution be N = 21. Determine which values of the circular convolution are the same as the linear convolution result. Plot the result and indicate the output indices where the values are “bad”. (b) Suppose the two signals are defined as x[n] = (0.9)n 0 ≤ n ≤ 12 0 elsewhere h[n] = 1 9 ≤ n ≤ 20 0 elsewhere Plot the results and indicate where the good and bad values are now that h[n] has leading zeroes. (c) Consider the following example, which relates to the overlap-save situation. x[n] = 1 0 ≤ n ≤ 16 0 elsewhere h[n] = sin(nπ/13) 0 ≤ n ≤ 99 0 elsewhere Suppose that a 100-point circular convolution is performed. (There is no zero-padding of h[n].) Plot the results and determine the indices of the good and bad points in the output. 2 BLOCK CONVOLUTION While short signals provide useful illustrations of convolution, they are not typical of practical filtering problems. In many applications the input x[n] is very long with respect to the filter impulse response h[n]. It is often impractical to process the entire input signal at once. An alternative solution is to break the input into blocks, filter each block separately and then combine the blocks appropriately to obtain the output. There are two basic strategies for block processing, which are known as overlap- add and overlap-save, respectively. Matlab’s fftfilt program uses the overlap-add approach. In the following exercises you will develop your own Matlab implementations of overlap-add and overlap-save block convolution. 2.1 Overlap-Add Implementation The overlap-add method works by breaking the long input signal into small non-overlapping sections. If the length of these sections is L and the length of the impulse response is P, then an N = L + P − 1 point DFT is used to implement the filter for each section. (The L + P − 1-point DFT avoids problems with time-aliasing inherent in the circular convolution.) The result for each block overlaps with the following block. These overlapping sections must be added together to compute the output. (a) Write a Matlab function to implement overlap-add block convolution. The inputs to this function should be the input signal vector x, the filter vector h, and the DFT size. Use the following as a header for the m-file:
  • 5. %% OLADD Filtering via overlap-add block convolution. %% %% Usage: %% y=oladd(x,h,N) %% %% Variables: %% x = signal vector x[n] %% h = filter vector h[n] %% N = DFT size (choose a power of 2 for fastest results) %% y = Result: x[n]*h[n] %% %% File : oladd %% Author : The DSP Wizard/Wizardess %% Date : September 26, 2001 (b) Test your code using the signal and filter defined in the file projIdata.mat, available on the course website. You can verify the results by comparing them to the result of convolving x and h using the built-in conv function. Make sure that your function works for any reasonable DFT length (i.e., longer than the filter). 2.2 Overlap-Save Implementation The overlap-save method uses a different strategy to break up the input signal. If the length of the circular convolution (i.e., the DFT length) is chosen to be N = L + P − 1, overlap-save uses input segments of length N. The starting location of each input segment is skipped by an amount L, so there is an overlap of P − 1 points with the previous section. Thus this method could also be called the overlapped inputs method. The L “good” points resulting from the N-point circular convolution of each section with the filter are retained. No additions are needed to create the output. (a) Write a Matlab function called olsave to implement overlap-save block convolution. The inputs to this function should be the input signal vector x, the filter vector h, and the DFT size. Use a header for your function similar to the one for oladd. (b) Test your code as you did the oladd function, i.e., using the data in projIdata.mat. Make sure that your function works for any reasonable DFT-length (i.e., longer than the filter itself).