digital signal processing with examples in m atlab ® chap 1 introduction ming-hong shih, aug 25,...
Post on 20-Dec-2015
215 views
TRANSCRIPT
Digital Signal Processingwith Examples in MATLAB®
Chap 1 Introduction
Ming-Hong Shih, Aug 25, 2003
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
2
Introduction to MATLAB
Why is MATLAB in use by a large fraction of
the DSP community?
(1)The user do most DSP operations
with very simple lines of code.
(2)MATLAB’s graphics support.
(3)Don’t to be an expert in MATLAB.
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
3
Variables, Vectors, Matrices, and Arrays
1. Variable: 一個單獨的元素 ( 整數、實數、複數 ) 。
2. 向量 (Vector): 一維的矩陣,可分為 Column Vectors 及 Row Vectors 。
3. 矩陣 (Matrices): 二維的陣列,一維向量為其特例。
4. 陣列 (Arrays): Using array as an inclusive term to designate a vector or a matrix.
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
4
Variables, Vectors, Matrices, and Arrays
──→ Variable
──→ Vector
──→ Matrix
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
5
Indexing a matrix
A=[1 2; 3 4]; A(1,1)=1; % the index starts from 1 A(1,2)=2; A(2,1)=3; A(2,2)=4;
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
6
Array Operation - Sum(+) and Difference(-)
The sum or difference of two array is obtained simply by adding or subtracting the individual element.
122
211
143
021
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
7
Array Operation - Sum(+) and Difference(-) (cont.)
Dimensions must be the same
unless one variable is a scalar.
矩陣與純量可以直接進行加減,MATLAB 會直接將加減應用到每一個元素。
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
8
Array Operation - Product(*)
純量對矩陣的乘或除,可比照一般寫法。
矩陣與純量可以直接進行乘法,MATLAB 會直接將乘法應用到每一個元素。
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
9
Array Operation - Product(*) (cont.)
進行矩陣相乘,必需確認第一個矩陣的直行數目 (Column Dimension) 必需等於第二個矩陣的橫列數目 (Row Dimension),否則其乘法無從定義, MATLAB 會產生錯誤訊息。
72
32
11
21
10
*243
021
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
10
Array Operation - Exponentiation(^)
矩陣的次方運算,可由「 ^ 」來達成,但矩陣必需是方矩陣,其次方運算才有意義。
2227
1831
43
25
43
25
43
252
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
11
Array Operation - Product(.*) and Exponentiation(.^)
83
610
21
32
43
25
若在「 * 」及「 ^ 」之前加上一個句點, MATLAB 將會執行矩陣內「元素對元素」(Element-by-element) 的運算
163
825
21
32^
43
25
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
12
Array Operation - Transpose( ′ and . ′)
654
321a
63
52
41
ca
若處理的是實數,那麼 ‘ 和 .‘ 後的結果是一樣的。
63
52
41
da
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
13
Array Operation - Transpose( ′ and . ′) (cont.)
jjb 4321
j
jeb
43
21若處理的是複數,那麼 ′和 .′ 後的結果是不一樣的。所以,若不希望conjugation 出現,就要用 .′ 。
j
jfb
43
21
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
14
Example – M-file
% ex1.mA=[1 2 3 4 2; 3 4 2 1 2; 4 2 1 2 3; 1 2 3 4 2];map=[0 0 0; 85/255 85/255 85/255; 170/255 170/255 170/255; 1 1 1]; image(A); colormap(map); colorbar;
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
15
Example – M-file(cont.)
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
16
Matlab functions
Matlab has lot of toolboxes, which contain many functions
help function-name On-line help for a function
lookfor keyword Search for functions that are related to this key
word
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
17
Loop
Example:
for i=1:1:10
a(i) = i;
end;
Ming-Hong Shih Digital Signal Processing with Example in MATLAB
18
Laboratory exercise #1 Read and show an image:
> I=double(imread(‘swim.bmp’));
> imshow(I, []);
Perform the following operation to matrix I:
1 2 3 4
2 2 3 4
3 4 3 2
1 3 2 4
1 2 3 4
2 2.55
3
1