20115ee102_1_hw3_matlab_soln - 1 EE102 Systems and Signals...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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 discrete-time convolution of two discrete-time 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 m-file. 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 m-file. 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 m-files 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 m-file 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 m-file can also call it. From then on, it will appear as though this function was actually a built-in component of matlab. In fact, many of the functions in matlab are function m-files....
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.

Page1 / 9

20115ee102_1_hw3_matlab_soln - 1 EE102 Systems and Signals...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online