EE 328 Signals and Systems Laboratory

Similar documents
Lab 1. The Fourier Transform

SGN-1158 Introduction to Signal Processing Test. Solutions

Frequency Response of FIR Filters

Euler s Method and Functions

Signal Processing First Lab 01: Introduction to MATLAB. 3. Learn a little about advanced programming techniques for MATLAB, i.e., vectorization.

How long is the vector? >> length(x) >> d=size(x) % What are the entries in the matrix d?

PYKC Jan Lecture 1 Slide 1

The Algorithms of Speech Recognition, Programming and Simulating in MATLAB


AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

Curve Fitting, Loglog Plots, and Semilog Plots 1

Beginner s Matlab Tutorial

MATLAB Functions. function [Out_1,Out_2,,Out_N] = function_name(in_1,in_2,,in_m)

Computational Foundations of Cognitive Science

Sampling and Interpolation. Yao Wang Polytechnic University, Brooklyn, NY11201

u = [ 2 4 5] has one row with three components (a 3 v = [2 4 5] has three rows separated by semicolons (a 3 w = 2:5 generates the row vector w = [ 2 3

B3. Short Time Fourier Transform (STFT)

6 Scalar, Stochastic, Discrete Dynamic Systems

CHAPTER 11: Flip Flops

UNIVERSITY OF CALIFORNIA, SAN DIEGO Electrical & Computer Engineering Department ECE Fall 2009 Linear Systems Fundamentals

FFT Algorithms. Chapter 6. Contents 6.1

MATLAB Workshop 14 - Plotting Data in MATLAB

Summary of important mathematical operations and formulas (from first tutorial):

Section 10.4 Vectors

Probability and Random Variables. Generation of random variables (r.v.)

CD-ROM Appendix E: Matlab

MATHEMATICAL SURVEY AND APPLICATION OF THE CROSS-AMBIGUITY FUNCTION

Lecture 8 ELE 301: Signals and Systems

1.4 Fast Fourier Transform (FFT) Algorithm

10 Discrete-Time Fourier Series

Excel Tutorial. Bio 150B Excel Tutorial 1

1.1 Discrete-Time Fourier Transform

Elements of a graph. Click on the links below to jump directly to the relevant section

3 Signals and Systems: Part II

EE 402 RECITATION #13 REPORT

PLOTTING IN SCILAB.

6 Systems Represented by Differential and Difference Equations

Final Year Project Progress Report. Frequency-Domain Adaptive Filtering. Myles Friel. Supervisor: Dr.Edward Jones

How To Draw A Circle Of Radius 1 On A Computer (For A Computer)

0 Introduction to Data Analysis Using an Excel Spreadsheet

DIODE CIRCUITS LABORATORY. Fig. 8.1a Fig 8.1b

Lecture 2 Mathcad Basics

Chapter 8 - Power Density Spectrum

MATLAB Programming. Problem 1: Sequential

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

The Z transform (3) 1

Department of Electrical and Computer Engineering Ben-Gurion University of the Negev. LAB 1 - Introduction to USRP

Infrared Spectroscopy: Theory

AP PHYSICS C Mechanics - SUMMER ASSIGNMENT FOR

Experiment 3: Double Sideband Modulation (DSB)

The continuous and discrete Fourier transforms

Em bedded DSP : I ntroduction to Digital Filters

AP Physics - Vector Algrebra Tutorial

Reflection and Refraction

Solving ODEs in Matlab. BP205 M.Tremont

Financial Econometrics MFE MATLAB Introduction. Kevin Sheppard University of Oxford

An Introduction to Using Simulink

CMPT 468: Matlab Tutorial 3: Analysis with the Fast Fourier Transform (FFT)

Understanding CIC Compensation Filters

Copyright 2007 by Laura Schultz. All rights reserved. Page 1 of 5

Lecture 1-6: Noise and Filters

UNIVERSITY OF CALIFORNIA, SAN DIEGO Electrical & Computer Engineering Department ECE Fall 2010 Linear Systems Fundamentals

2+2 Just type and press enter and the answer comes up ans = 4

ANALYTICAL METHODS FOR ENGINEERS

Tutorial Program. 1. Basics

How To Understand The Nyquist Sampling Theorem

Experiment 5. Lasers and laser mode structure

Correlation in Random Variables

Immunophenotyping Flow Cytometry Tutorial. Contents. Experimental Requirements...1. Data Storage...2. Voltage Adjustments...3. Compensation...

Interactive Web-based Calculus Projects at Hollins University: Student Solutions

by the matrix A results in a vector which is a reflection of the given

Vector Algebra II: Scalar and Vector Products

EE 179 April 21, 2014 Digital and Analog Communication Systems Handout #16 Homework #2 Solutions

Part 1: Background - Graphing

Programming Your Calculator Casio fx-7400g PLUS

Analysis of System Performance IN2072 Chapter M Matlab Tutorial

The purposes of this experiment are to test Faraday's Law qualitatively and to test Lenz's Law.

Signal Detection C H A P T E R SIGNAL DETECTION AS HYPOTHESIS TESTING

Absorbance Spectrophotometry: Analysis of FD&C Red Food Dye #40 Calibration Curve Procedure

23 Identification of a Response Amplitude Operator from Data

TEACHING AUTOMATIC CONTROL IN NON-SPECIALIST ENGINEERING SCHOOLS

2 Signals and Systems: Part I

9 Fourier Transform Properties

The Basics of FEA Procedure

EDEXCEL NATIONAL CERTIFICATE/DIPLOMA MECHANICAL PRINCIPLES AND APPLICATIONS NQF LEVEL 3 OUTCOME 1 - LOADING SYSTEMS

Having read this workbook you should be able to: recognise the arrangement of NAND gates used to form an S-R flip-flop.

Design of Efficient Digital Interpolation Filters for Integer Upsampling. Daniel B. Turek

Physics 202 Problems - Week 8 Worked Problems Chapter 25: 7, 23, 36, 62, 72

= V peak 2 = 0.707V peak

ECE 3510 Final given: Spring 11

TWO-DIMENSIONAL TRANSFORMATION

Quantitative vs. Categorical Data: A Difference Worth Knowing Stephen Few April 2005

Computer exercise 2: Least Mean Square (LMS)

Analog and Digital Signals, Time and Frequency Representation of Signals

RLC Series Resonance

To launch the Microsoft Excel program, locate the Microsoft Excel icon, and double click.

Armstrong Atlantic State University Engineering Studies MATLAB Marina Image Processing Primer

Linear Algebra and TI 89

Simple Programming in MATLAB. Plotting a graph using MATLAB involves three steps:

Basics of STATA. 1 Data les. 2 Loading data into STATA

Transcription:

EE 328 Signals and Systems Laboratory Spring 2011 Experiment 3: Time Domain Convolution Introduction: This assignment emphasizes how MATLAB can be used to represent continuous-time signals and to approximate continuous-time convolution. In particular, we are going to use MATLAB to rework the Signals and Systems Workbook chapter 1's problem 4, parts (b) and (c). Although you have already been exposed somewhat to MATLAB, we will assume here that you don't have much experience using it (so bear with us if you do). All you have to do is follow along with the tutorial and turn in the specified plots.before you begin, here are some conventions that we will be using: Things that you need to turn in are in bold. Equations and theoretical expressions are in red. Don't enter these directly into MATLAB (it may choke if you try). The actual expressions you need to type into MATLAB are in blue. Objectives: 1) Represent continuous time signals in MATLAB. 2) Use MATLAB to perform basic transformations on continuous time signals. 3) Use MATLAB to perform convolution in time domain. Procedure: This LAB has three parts. In part 1, we will learn how to represent a continuous time signal in MATLAB. In part 2, we will perform some basic operations on continuous time signal, again using MATLAB and finally in part 3, we will perform time domain convolution of continuous time signals. Part 1: Creating a rectangular pulse in MATLAB Consider the rectangular pulse studied in class, which has the following definition: x(t) = 1 for -0.5 sec <= t < 0.5 sec = 0 elsewhere We would like to represent this continuous-time signal in MATLAB. However, digital computers in general (and MATLAB in particular) don't have the ability to cope with continuous-time signals... they can only work on samples of the signal. Thus, we must sample the signal to make it discrete-time. The first thing we must decide is what sample frequency we want to use. A high sample frequency

gives a more faithful reproduction of the signal but requires more computer memory to store it (and also more CPU cycles to process it). For our purposes, a sample frequency of f_s = 100 Hz is sufficient. Begin by entering the sample frequency into MATLAB: f_s = 100 If you want your rectangular pulses to have sharper edges, try using f_s = 1000 (although this will make the convolution operation much slower). Another important parameter is the sample period, which is just T_s = 1/f_s, and entered into MATLAB using: T_s = 1/f_s Another thing to consider is that MATLAB can only handle a finite number of samples at a time. Thus we must restrict the time axis to a limited range. I suggest that we only consider the signal in the range -5<= t <= 5 seconds. Now we must create a time axis. This will be a vector containing all the sample instants beginning at t = -5 sec and continuing to t = 5sec. These sample instants are all T_s seconds apart. The time axis is created in MATLAB as follows: t = [-5:T_s:5] The above command generates a vector containing all integer multiples of T_s = 0.01 between -5 and +5 (i.e. -5.00, -4.99, -4.98,...,4.99, 5.00). If you don't want MATLAB to echo this long vector onto the screen, simply terminate the command with a semicolon: t = [-5:T_s:5]; Now we must generate our rectangular pulse. While MATLAB has built in functions to generate a wide range of signals (such as cos, sin, and exp) it does not have a function to create the rectangular pulse. Thus, one has been created for you. Build the rect.m function from the appendix into your working directory (to find out which directory you are in type pwd and you can use cd to move to a different directory). To learn how to use the rect function type: help rect Also, you should open the file and read through the function. This will give you an idea about how to make your own functions, how to make a for loop, and how to do conditional branching with the if statement. You can open the file by using: edit rect Now let's generate a rectangular pulse: x1 = rect(t); Once it is generated we would like to plot it: plot(t,x1);

Note that you always want your time axis to come first. A problem with the plot is that the y-axis only shows values from 0 to 1, and thus you really can't see the pulse very clearly. You can change the field of view of the plot by using the axis command: The first two numbers specify the starting and ending times of the plot (the x-axis), while the last two numbers specify the range of the signal values (y-axis). A plot without labels doesn't give us much information, so next we need to label the axis. You do that as follows: ylabel( 'x_1(t)' ) Finally, let's put a title on the plot: title ('Plot 1: A rectangular pulse') Turn in a copy of this plot with your report. Don t need to include the code. Part 2: Elementary signal operations Now let's try to do some elementary signal operations, such as time-delay, time-scaling, and time-reversal. First let's create and plot the time-delayed signal x2(t) = rect(t-1) x2 = rect(t-1); plot(t,x2) Now let's try to make the time-scaled signal x3(t) = rect(t/2) x3 = rect(t/2); plot(t,x3) We can create a more interesting signal x4(t) = rect(t)+(1/2)rect(t-1) ( Finish the code by yourself similar to the above code) Now let's perform a time-reversal on this signal by forming the new signal x5(t) = x4(-t) = rect(-t)+(1/2)rect(-t-1) Finally, let's create the signal x6(t) = x4(1-t) = rect(1-t)+(1/2)rect(-t) Now, instead of turning in 5 new plots, let's try to save some space by putting all these plots on the same page. You can do that with the subplot command. Enter the following into MATLAB to get a single plot with the proper labels (you might want to cut and paste this): subplot(3,2,1) plot(t,x1)

ylabel('x_1(t) = rect(t)') subplot(3,2,3) plot(t,x2) ylabel('x_2(t) = x_1(t-1)') subplot(3,2,5) plot(t,x3) ylabel('x_3(t) = x_1(t/2)') subplot(3,2,2) plot(t,x4) ylabel('x_4(t)') subplot(3,2,4) plot(t,x5) ylabel('x_5(t) = x_4(-t)') subplot(3,2,6) plot(t,x6) ylabel('x_6(t) = x_4(1-t)') You might need to maximize the plot to its fullest size (otherwise you may not be able to read the x-axis label). Turn in this plot with you report. Although you need to write code to generate the x4(t),x5(t) and x6(t), don t include all the code in your report. Part 3: Convolution We can use MATLAB to approximate continuous-time convolution by using the conv function. Take for example, the convolution of two rectangular pulses (using the same time axis t and pulse x1 from part 1):

y = conv(x1,x1); Now try plotting y (first use the close statement to close the plot that's already displayed): close all plot ( t, y) Notice what just happened? MATLAB complained because the size of y is now different than the size of t. Check the size of y and t: length(y) length(t) You will notice that length(y) = 2*length(t)-1. What has happened is that MATLAB has given you the signal y(t) over the range -10 sec <= t <= 10 sec, instead of the range -5 sec <= t <= 5 sec used by x1(t). Thus, we need to create a separate time axis for the signal y: t_y = -10:T_s:10; Now we can plot: plot( t_y, y) Now what's wrong with this plot? As expected, we got a triangular pulse. However, the peak of this triangle is f_s = 1000... but it should have been at 1. This is because the discrete-time convolution used by MATLAB is slightly different from the continuous-time convolution we have studied in class. In general, when you use MATLAB to perform a continuous-time convolution, the result will be off by a factor of the sample frequency f_s. We can account for this discrepancy as follows: y1 = T_s*conv(x1,x1); Now our plot gives the correct answer: plot(t_y, y1) axis( [-2 2-1 2] ) xlabel( 'time (sec)') ylabel('y_1(t)') title('figure 3: y_1(t) = x_1(t)*x_1(t)') Turn in this plot with your report. Don t include the code. Problems (turn in all the codes and plots with your lab report): 1) Here you will perform convolution on discrete time signals using MATLAB: (1) x(n) = { 1,2,4 }, h(n) = {1,1,1,1,1} (2) x(n) = { 1,2,3,4,5 }, h(n) = {1} (3) x(n) = { 1,2,0,2,1}, h(n) = x(n). Use the Matlab function conv. For each set of signals, plot x(n), h(n) and y(n) as subplots in the same figure.

2) Consider a system with an impulse response Determine the input x (n) that will generate the output sequence y(n) = {1, 2, 2.5, 3, 3, 3, 2, 1,0...}. Plot x (n), y (n) and h (n) in one figure. Hint: Use the MATLAB function deconv. 3) Determine the cross-correlation sequence r r xy (n) of the sequences x (n) = {..., 0, 0, 2, -1, 3, 7, 1, 2, -3, 0, 0,...} y(n) = {..., 0, 0, 1, -1, 2, -2, 4, 1, -2, 5, 0, 0,...} Plot x(n), y(n) and r xy (n) in one figure. Hint: Use the MATLAB function xcorr.

Appendix function x = rect( t ) RECT rectangular pulse Usage: x = rect(t) This functions takes in a vector t of sample instants and outputs the corresponding rectangular pulse contained in the function x Written by Matthew Valenti For EE 329 Spring 2002 determine the size of the input matrix [m,n] = size(t); make sure the input matrix is actually a vector check_vector = min(m,n); if (check_vector ~= 1) error( 'Input to rect must be a vector' ); end determine the dimensionality K of the input vector K = max(m,n); initialize the output to all zeros x = zeros(m,n); loop through the time vector and assign the output to be equal to one whenever -0.5 <= t < 0.5 for i=1:k if ( ( t(i) >= -0.5)&( t(i) < 0.5) ) x(i) = 1; end end all done... exit function return