You are on page 1of 21

Introduction to Matlab

Yu-Ting Kuo

VLSI Signal Processing Lab, NCTU


May. 29, 2007

*source: , Matlab ,
Outline

Introduction
Environment
Basic operations
Filter design
On-line resources
Introduction

Matlab = MATrix LABoratory


Cleve Moler
MathWorks 1984



toolbox



(
Environment
Environment (contd)

Command window
Type command here
Workspace window
Show variables
Current directory
Command history
Outline

Introduction
Environment
Basic operations
Filter design
On-line resources


MATLAB Command Window>>
Enter
>> (5*2+3.5)/5
ans =
2.7000
MATLAB ;

>> (5*2+3.5)/5;



31 MATLAB MATLAB 4
19
MATLAB Variable
Declaration double

MATLAB
N
>> s = [1 3 5 2];% []
>> t = 2*s+1
t = 3 7 11 5
N-by-M
A = [1 2 3 4; 5 6 7 8; 9 10 11 12]; % 34 A

A i j A(i, j)
i j SubscriptIndex
MATLAB
A(i, j) A(i+(j-1)*m) ~mA


Scalar

>>A = [12 34 56 20];
>>B = [1 3 2 4];
>>C = A + B; %C = 13 37 58 24
MATLAB

>> A = [1 2 3 2 1] + 5
A=6 7 8 7 6
(contd)


>> A = [123 , 442];
>> C = A/3; % C = 41.0000 147.3333
>> B = 2*A; % B = 246 884
Column
Dimension Row Dimension
A = [1; 2];
B = [3, 4, 5];
C = A*B; % C = 3 4 5
6 8 10

Operator MATLAB
Element-by-element

MATLAB
>> y = abs(x) % x
>> y = sin(x) % x
>> y = exp(x) % exp(x)
>> y = log(x) % ln(x)
MATLAB i j

>> y = min(x) % x
>> y = max(x) % x
>> y = mean(x)% x
>> y = sum(x) % x
>> y = sort(x) % x


zeros(m, n) mn 0
ones(m, n) mn 1
eye(n) n
n 1 0
pascal(m, n) m
n Pascal
vander(m, n) m
n Vandermonde
hilb(n) n
n Hilbert
rand(m, n) [0, 1] m
n
randn(m, n) = 0, = 1 m
n
magic(n) n
n
Outline

Introduction
Environment
Basic operations
Filter design
On-line resources
Filter Representation in Matlab

Digital filter representation


B(ejw) b(1) + b(2)e-jw + .... + b(m+1)e-jmw
H(ejw) = --------- = ------------------------------------------
A(ejw) a(1) + a(2)e-jw + .... + a(n+1)e-jnw

A filter is specified by the two vectore a and b


Filter Response Analysis

[H, W] = freqz(b, a, N)
returns the N-point complex frequency response vector H and the
N-point frequency vector W in radians/sample of the filter
Use plot command to plot the frequency response
Plot( w/pi, db(abs(H)) )
0
Axis([0 1 -150 10])

-50

-100

-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Filter Response Analysis (contd)

freqz(B,A,...) with no output arguments plots the resposne


Magnitude (dB) and Phase Responses
0.8436
4.6194

-16.171
-1.6577

-36.9614

Phase (radians)
Magnitude (dB)

-4.1589
-57.7518

-78.5423
-6.6602

-99.3327

-9.1615

-11.6628
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency ( rad/sample)
FDATool

Type fdatool in the command window


Choose filter type
Set constraints
Design filter
File > export
Outline

Introduction
Environment
Basic operations
Filter design
On-line resources
On-line Resources

MATLAB (),
http://www.cs.nthu.edu.tw/~jang/mlbook/
Matlab
http://libai.math.ncu.edu.tw/bcc16/B/matlab/
Matlab ,
http://ecaaser5.ecaa.ntu.edu.tw/weifang/matlab/index-matlab.htm