EET 357 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

EET 357

Description:

EET 357. Lab 1: Introduction to Matlab. Matlab ... There are several ways to create a vector. First, we can do it element by element: ... Lab 1 Excercise ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 16
Provided by: PeteGo2
Category:
Tags: eet | excercise

less

Transcript and Presenter's Notes

Title: EET 357


1
EET 357
  • Lab 1
  • Introduction to Matlab

2
Matlab basics
  • First steps
  • Launch Matlab (or Octave)
  • Go to the Command Window
  • Type 2 3, return
  • Now, type
  • a 2
  • b 3
  • c a b

3
Vectors
There are several ways to create a vector.
First, we can do it element by element x 0
1 2 3 4 5 6 7 8 9 Second, we can create a
similar array like this y (09)
4
Vectors
If we want the elements to be incremented by,
say, 0.1 instead of 1 z(00.19) z We can
look at individual elements of a vector by using
the index z(0 10 20 30)
5
Vectors
We can generate a vector of indices, and use it
to access the elements we want i
(11091) z(i) Or, we can do both in one
step z(11091)
6
Vectors
If we want the elements to be incremented by,
say, 0.1 instead of 1 z(00.19) z We can
look at individual elements of a vector by using
the index z(0 10 20 30)
7
Vectors
We can concatenate two arrays. Remember x and y?
Theyre still there x y Now we concatenate
them w x y
8
Vectors
We can add two vectors of the same size w x
y We can add a scalar to a vector w 1
x We can multiply or divide a vector by a
scalar w x pi w w / pi
9
Vectors
We can perform most functions with a vector
argument and a vector result t linspace(0, 1,
101) f 2 w sin(2 pi f t) plot(t,
w) title(2 Hz Cosine Wave) xlabel(t
(seconds)) ylabel(w(t))
10
M-Files
  • We can place the commands we just used to
    generate a sine wave in an m-file, to automate
    the process. If youre using Octave, you can
    create this file using whatever text editor you
    like (I use EMACS). In the Matlab command
    window, select File -gt New -gt M-File. This will
    bring up the Matlab editor/debugger. Type in the
    sequence of commands on the previous slide (which
    will be repeated in a moment).

11
M-Files
t linspace(0, 1, 101) f 2 w sin(2 pi
f t) plot(t, w) title(2 Hz Cosine
Wave) xlabel(t (seconds)) ylabel(w(t))
12
M-Files
Save the script as cosine.m. Return to the
command window, and type cosine at the prompt.
This will run the script. If youre one of those
who has to miss the lab sections because of a
conflict, you may turn in m-files which
demonstrate the goals of the lab exercises.
These may be emailed to me. The rest of you may
also do this, or can demonstrate them to me in
the lab.
13
Lab 1 Exercise
1. Generate a vector representing 2 seconds of
time, sampled at 100 samples per second. Note
that this will be a vector of 201 samples,
starting at t0 and ending at t 2 seconds.
This is very similar to the generation of t in
the M-File example.
14
Lab 1 Excercise
2. Use the time vector to generate another
vector representing the impulse response of an
single pole RC filter with t 0.2 seconds
In Matlab, use exp(x) for
Plot h(t)
15
Lab 1 Exercise
  • Generate an impulse to drive the filter. An
    impulse is one sample, of amplitude 1. No
    zero-padding is necessary, so you can just use x
    1. Convolve this with the impulse response
    vector h using the conv function y
    conv(x, h) Plot y(t)
Write a Comment
User Comments (0)
About PowerShow.com