This** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
**Unformatted text preview: **Matlab Project 2 EB 228-O4 j gh‘ 4/7/06 The purposes of these team Matlab project assignments are to introduce the student to the use of
Matlab, to use Matlab as a tool to learn the theory presented in lecture and to analyze more
complicated systems than pencil and paper conveniently allow, and to introduce the student to
team project work. The BB 228 class is to form into two or three person teams for the Matlab
assignments; teams can be greater than three, but the larger teams will require the prior approval
of the instructor. For the submittal of each assignment, each team will submit one report, with
each team member providing one thoughtful, reﬂective paragraph discussing what they have
learned. All students are to read Chapter 21in their text. Matlab is available on computers in the
Digital Senior Project Lab (20-118) which should be open from 8:00am to 6:00pm Monday
through Friday, and from 9:00am to 1:00pm Saturday. The BB 368 lab (20-113) also has a copy
of Matlab installed on each of its machines. Access to the BB 368 lab will be limited to periods
outside scheduled lab times. Request access to the lab at the Senior Project window —— your name
should be on a list from the ER 228 class list. The team members are to learn the use of the
Matlab through the online documentation and/or the Matlab supplied tutorial and/or through the
use of the text material in Chapter 21. Before creating the m-ﬁle convprojm below, each team will have to create the Matlab function
trih. In addition to the m-ﬁles which are scripts of commands, there canbe m-ﬁles which are
deﬁned to be matlab functions. The name of the m-ﬁle and the function are the same. Below is
an example of a function which can be used to calculate your textbooks tri(t) function. The ﬁle is
named trih.m, and is to be saved in the work directory (which should be a directory accessed in
your local path environment). The function is named trih also. The format for the matlab function
code is given with the trih.m ﬁle as shown below: function y=trih(t) %TRIH triangle function centered at t=0 from t=-l to t=+1 with %trih(0)=1. % usage: % y = trih(t) % where: % t = input vector % y = output vector if (nargin==0 l nargin>l) %check that there is only one argument
error('only one input argument, a vector') %error output to user end x=abs(t); %two lines of code from Ambardar code for tri(x) y=(1-x).*(x<=l); %note logic x<=l is 1 if true and 0 if false Some things that'you should note are: _
1) the format of the ﬁrst command line and subsequent comment lines — these are shown if the command help trih is entered 2) the error check on the number of arguments and the output text for error explanation to the user
3) the use of the ; to inhibit the user output 4) the need to deﬁne the input vector t prior to the use of the function; also, the argument does not
have to be named t, but could be entered as z . 5) likewise, the output variable does not have to be named y, but could be entered as f. Note also that the name of the function is trih, which Will not conﬂict with the adsp function tri.
If you do not have the adsp functions available, then you can enter the function name as tri(t).
Note that you could still enter the function as tri(t), save it in your work directory, and there
would be no conﬂict. Enter the code for the m-ﬁle and save it in your work directory. Then execute the following
commands and observe the results:
help trih
= -2:0.01':2;
y = trih(t);
plow, y)
y = trih(x,t);
plot(t, 4*trih(2*t- l ))' .Now that the team has the function trih available in their work directory, the team is to enter the
following Matlab m-ﬁle code and execute it. The report is to consist of a commented version of
the m-ﬁle code with the added code for the annotation, a plot of the output with suitable
annotation for the title and axis, and the thoughtful, reﬂective individual paragraph from each of the team members discussing what they have learned from the experience. The report is due
Friday April 21, 2006. %script: convprij _ a % continuous convolution of x(t) with h(t), y(t) = x(t) * h(t), note that the output
% range must be determined explicitly, i.e., range of the time value for the output y(t)
ts=0 .0 1 ; tx=-1 :ts: 1; th=02ts:2; x=3 *cos(pi*tx/2); h=trih(th- l ); y=ts*conv(x,h); ty=-l :tsz3; plot(tx,x,th,h,ty,y); gtext('x(t)') gtext('h(t)') gtext('y<t)'> l
l
l
i
1
l
l
\
l ...

View
Full Document

- Spring '08
- HARRIS