MATLAB Workshop Lecture 2
MATLAB Workshop Lecture 2
FOR EE 327
MWF 8:00-850 AM
August 26-30, 2002
WORKSHOP
WebPages
www.csee.wvu.edu/~jalali
CLS-MATLAB Files
Textbook MATLAB Files for Download :
http://www.csee.wvu.edu/~jalali
http://www.brookscole.com/engineering/ee/bookware.html
Macintosh and MS-Windows Versions
A For Answers of problems
E For Examples
F For Figures
P For Problems
Follows by a one or two-digit number 1 through 11 corresponding
to the chapter.
The final characters indicate the number of the appropriate answer.
(A8_16) Answer for problem 16 Chapter 8
(E7_4) Example 4 in chapter 7 (%E7_4 Filter outputs using convolution)
(F4_2) Figure 4 in Chapter 2
(P8_20) Problem 20 in Chapter 8
Unit Step Function (Figure 1.7a text)
%F1_7a Unit step function
t=-2:0.01:5; % make t a
vector of 701 points
q=size(t);
f=zeros(q(1),q(2)); % set f =
a vector of zeros
q=size(t(201:701));
f(201:701)=ones(q(1),q(2));%
set final 500 points of f to 1
plot(t,f),title('Fig.1.7a Unit
step function');
axis([-2,5,-1,2]); % sets
limits on axes
xlabel('time, t');
ylabel(' u(t)');
grid;
B if t t0
Bu (t t0 )
0 if t to .
Generic step
function
EE 327 fall 2002
%F1_7b Signal g(t) multiplied f(101:501)=2.5-
cos(5*t(101:501) by a pulse functions ([u(t+1)-u(t-3)]
MATLAB Code:
n=-10:1:20;
f=2*(n-10);
stem(n,f);
Composite sequence:
p(n) A(a) n u(n)
Multiplying point by
Point by the step sequence
MATLAB Code:
n=-10:1:10;
f =10*(.9).^n;
stem(n,f);
axis([-10 10 0 30]);
6. MATLAB Code:
7. n=-20:1:20;
8. f=5*[cos(n*pi/8+pi/4)];
9. stem(n,f);
2. Example: / 4.
3. A = 10, N = 16, a = 0.9
1. MATLAB Code:
2. n=-20:1:20;
3. f=10*[0.9 .^n];
4. g=[cos(2*n*pi/16+pi/4)];
5. h=f .*g;
6. stem(n,h);
7. axis([-20 20 -30 70]);
Lecture # 2
Wednesday August 28
MATLAB Basics
MATLAB Plots
MATLAB Examples
Lecture # 3
Friday August 30
MATLAB Fundation
Textbook Examples
Short Quiz
MATLAB WORKSHOP
Lecture # 2
Wednesday August 28
MATLAB Basics
MATLAB Plots
MATLAB Examples
MATLAB Basics
Contents
Numbers and Format
Command Line Help
Variables
Vectors and Matrices
Plotting Elementary Functions
Loading and Saving
M-Files
Loops and If Statements
User Defined Variable
MATLAB Basics
Numbers and Format:
>>help pi
PI 3.1415926535897....
PI = 4*atan(1) = imag(log(-1)) =
3.1415926535897....
>>help sin
SIN Sine.
SIN(X) is the sine of the elements of X.
MATLAB Basics
Variables:
Variables ans is assigned by MATLAB default.
For example, typing >>12+2.3*2 or >>12+2.3*2,
yields: ans = 16.6000
>>12+2.3*2; yields: blank
(but the result is saved on the variable "ans"
(write >>ans see the result of operation which is
16.6000).
Commas (,) tell MATLAB to display results
semicolons (; ) suppress printing.
MATLAB Basics
Variables:
End of Lecture # 2
MATLAB EE 327
Next time