This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 1 EE102 Systems and Signals Fall Quarter 2011 Jin Hyung Lee Matlab Assignment #2 Solution This laboratory will be concerned with numerically evaluating continuous time convolution integrals. Matlab provides a function conv() that performs a discretetime convolution of two discretetime sequences. We will add a new function to matlab that uses conv() to numerically integrate the continuous time convolution. To do this, we’ll need to learn about how to define new functions in matlab. Matlab provides two ways of executing commands that you have programmed in a file. Both are stored in a ”.m” file or mfile. This first is a script . Invoking the script at the command line causes the file to be treated as terminal input in your current matlab environment. Most of the examples in the book are matlab scripts. Variables created in the script are visible when it completes, and the script has access to all of the variables that have been defined in your work space. Because it can modify your workspace, this is not a good way to implement extentions to matlab. The second option is to define a function in the mfile. In this case, the function operates in its own local context. It doesn’t have access to variables in your workspace, only to the function arguments which are are passed by value. Only the returned values are available to the calling function, and these are also passed by value. Hence, function mfiles are a much more robust way to encapsulate repeated operations. As an example, lets say you want to be able to compute the average value of some vector. A function mfile that does this is function a = avg(v) % % Anything you type here is printed when you enter "help avg" % at the matlab prompt. Good things to put here are a description % what the function does, the calling arguments and the % return values. % % a = avg(v) % Inputs: % v  vector % outputs: % a  average value of the elements in v % % at last, the actual code % compute the mean 2 a = sum(v)/length(v); Store this in a file ”avg.m” either in your current directory, or somewhere in your matlab path (”help path” and ”help addpath” for more information). Any time you enter avg() at the com mand prompt, this function will be invoked. Any other mfile can also call it. From then on, it will appear as though this function was actually a builtin component of matlab. In fact, many of the functions in matlab are function mfiles....
View
Full
Document
This note was uploaded on 03/30/2012 for the course ELEC ENGR 102 taught by Professor Lee during the Fall '11 term at UCLA.
 Fall '11
 lee

Click to edit the document details