You are on page 1of 33

1

MATLAB

------------------------------------------------------------

1.1 MATLAB -----------------------------------------------

1.2 (operators) --------------------------------------------------------------------

13

1.3 MATLAB ------

15

1.4 , --------------------------------------------------------------

16

1.5 -------------------------------------------------------------------

17

1.6 ---------------------------------------------------------------

19

1 --------------------------------------------------------------------------------------

31

-----------------------------------------

34

2.1 ? ------------------------------------------------------------

34

2.2 ---------------------------------------------------

34

2.3 ------------------------------------------------------------------------

35

2.4 ---------------------------------------------------------------------

37

2.5 ------------------------------------------------------------------------

39

2.6 Aliasing ------------------------------------------------------------------------------

40

2.7 (quantization) A/D -------------------------------------------

41

2 --------------------------------------------------------------------------------------

43

---------------------------------------------------------

45

3.1 ---------------------------------------------------------

45

3.1.1 (Unit Impulse signal) --------------------------

45

3.1.2 (Unit Step signal) ---------------------------------

47

3.1.3 (Real exponential signal) ------------------------

48

3.1.4 (Complex exponential signal) -------------------

49

3.1.5 (Random signal) --------------------------------------------

50

3.2 -----------------------------------------------------------------

53

3.3 White Gaussian ---------------------------------------------------

54

3.4 ---------------------------

56

3 -------------------------------------------------------------------------------------

59

------------------------------------------------------------------

67

4.1 (Discrete System) --------------------------------------------------

67

4.2 (Convolution) (Correlation) --------------------------------

71

4.2.1 ------------------------------------------------------------------

71

4.2.2 (Correlation) ---------------------------------------------------------

78

4 -------------------------------------------------------------------------------------

82

---------------------------------

86

5.1 (Impulse Response) ------------------------------------------------

86

5.2 -----------------------------------------------

86

5.3 -----------------------------------------------------------------

88

5.4 ---------------------

89

5 -------------------------------------------------------------------------------------

91

z- (z-Transform)

------------------------------------------------------

94

6.1 z- ----------------------------------------------------------------------

94

6.1.1 DTFT ---------------------------------------

94

6.1.2 z- -----------------------------------------------------------

96

6.1.3 ------------------------------------------------

97

6.2 ------------------------------------------------------------------------

99

6.3 (Region of Convergence : ROC) ---------------------------------

101

6.4 ------------------------------------------------------------------------

105

6.5 z- (property) ----------------------------------------------------------

107

6.6 Z-(Inverse Z-Transform) ------------------------------------------------

109

6 -------------------------------------------------------------------------------------

113

(Discrete Fourier Transform)

--------------

121

7.1 --------------------------------------------------------------

121

7.2 -----------------------------------------------------------

122

7.3 (DTFT) -------------------------------------------------

122

7.4 (DFT) ---------------------------------------------------------

130

7.4.1 -----------------------------------------------

130

7.4.2 ------------------------------------------------

133

7.5 (high-density) (high-resolution)

134

7.6 ------------------------------------------------------

136

7.7 (Fast Fourier Transform : FFT) ------------------------

139

7.7.1 DIT ------------------------------------------------------------------

139

7 -------------------------------------------------------------------------------------

H/W

144

-------------------------------------------------

155

8.1 ---------------------

155

8.2 FIR ---------------------------------------------------------------------

156

8.2.1. (Direct Form) --------------------------------------------

157

8.2.2 (Transpose Form) ---------------------------------------

157

8.2.3 (Cascade Form) ------------------------------------

158

8.3 IIR -----------------------------------------------------------------------

159

8.3.1 I(Direct Form I) ---------------------------------------

159

8.3.2 II(Direct Form II) (Canonic Form)

160

8.3.3 (Cascade Form) ------------------------------------

161

8.3.4 (Parallel Form) -------------------------------------------

162

8 -------------------------------------------------------------------------------------

164

FIR

--------------------------------------------------------------

177

9.1 -----------------------------------------------------------

177

9.1.1 --------------------------------------------

178

9.1.2 FIR IIR ----------------------------------------

180

9.2 FIR ---------------------------------------------------------------------

181

9.2.1 --------------------------------------------------------

181

9.2.2 -----------------------------------------------------------------

183

9.2.3 ------------------------------

187

9 -------------------------------------------------------------------------------------

190

10

IIR

-------------------------------------------------------------

204

10.1 ------------------------------------------------------------

205

10.2 -----------------------

212

10.2.1 (impulse invariance transformation) --------

212

10.2.2 (bilinear transformation) ---------------------------

214

10.2.3 -----------------------------------------------------

215

10 -----------------------------------------------------------------------------------

217

11

(Adaptive Filter)

-------------------------------------------

238

11 -----------------------------------------------------------------------------------

12

241

---------------------------------------------

247

1 -------------------------------------------------------------------------------------

247

13

---------------------------------------------

250

2 -------------------------------------------------------------------------------------

250

14

---------------------------------------------

253

3 -------------------------------------------------------------------------------------

253

---------------------------------------------------------------------------------------

258

1 MATLAB
MATLAB .
MATLAB MATLAB
Toolbox .
MATLAB
MATLAB C C++
. ,
MATLAB C C++ , DSP
TMS320
Mathworks MATLAB
.
.
Mathworks

C++
2. TI TMS320C6000 Motolora M6800
3. Xilinx ALTERA EPLD(FPGA) HDL
4. x-PC MABLAB Emulation
1. C

Simulink
Labview MATLAB
.

MATLAB .
MATLAB ,

MATLAB .
MATLAB

1. Steven W. Smith, "The Scientist and Engineer's Guide to Digital Signal Processing"
2. Vinay K. Ingle, John G. Proakis, "Digital Signal Processing using the MATLAB"
3.

1.1 MATLAB


. 1-1


(matrix) (transpose) .
'
) a' , A'
.
' '
) title('Magnitude')
, .
[ ]
) a=[1 3 5 7]
, (function)
( )
.
) a(1,2), max(a)

;
.
) a=sqrt(2)+exp(3);
.
:
) t=[0:0.01:1];
.
.
) c=a.^2 , c=a./b
%
(comment line) .


.
. .
>>

(variable) = (expression)


. 1-2

pi

3.1415926535897...

), , , i j
(,
j
.
(infinity) .
inf
( nonzeros ) / 0
(Not-a-number) .
NaN
0 / 0 inf / inf


1)

>>A=[1 4 8 6]

A =
1

>>A=[1; 4; 8; 6;]

A =
1
4
8
6

>>a=[1:4:1]

4 1

% 1

a =
1

>>a=[9:-2:1]

1 -2

% 9

a =
9

2)

>>A=[1 1 1;1 2 3;1 3 6]

%
%

, .

>>A=
A =

3)

>> a=[1 2 3];

b=[4 5 6];

>> c= a.* b
c =
4

10

18

>> a=[1 -2 -3 6];

b=[-4 5 -6 2];

>> y=a.^2 + b.^2 - a + b


y =
12

36

42

36

>>A=[1 1 1;1 2 3;1 3 6];


>>sum(A) % sum(A)

ans =
3

4)

10

>> x=[-1 sqrt(3) 4/5]


x =
-1.0000

1.7321

0.8000

'x'

>>x(3)

'( )'

(subscript)

ans =
0.8000
>> a=[1 2 3; 4 5 6; 7 8 9]
a =
1

>> a(1,3)
ans =
3
>> a(2,2)
ans =
5
>> a(3,2)
ans =
8
>> a(1,:)

% 1

ans =
1
>> a(:,2)

% 2

ans =
2
5
8

2,3

>> a(3,2:3)

% 3

ans =
8

10

2,3

>> a(2:3,2)

% 2

ans =
5
8


, ... .
>> P=[1, 2, 4, 6, 8]+[pi, 4, exp(1), 0, -1]+...
[cos(0.1*pi), sin(pi/3), tan(3), atan(2), sqrt(pi)]
P =
5.0926

5)

6.8660

6.5757

7.1071

8.7725

>> a=[1 2 3 4 5; 2 4 6 8 10; 3 6 9 12 15]


a =
1

10

12

15

3 -22.999

>> a(1,3)=22.999

% 1

a =
1.0000

2.0000

22.9990

4.0000

5.0000

2.0000

4.0000

6.0000

8.0000

10.0000

3.0000

6.0000

9.0000

12.0000

15.0000

>> a(2,6)=-88.999

6 -88.999
% 6 6 .
% 2

a =
1.0000

2.0000

22.9990

4.0000

2.0000

4.0000

6.0000

8.0000

3.0000

6.0000

9.0000

12.0000

>> a(3,5)=-55

5.0000

10.0000 -88.9990
15.0000

5 -55

% 3

a =
1.0000

2.0000

22.9990

4.0000

11

5.0000

2.0000

4.0000

6.0000

8.0000

3.0000

6.0000

9.0000

12.0000

>> b=2*a

% a

10.0000 -88.9990
-55.0000

b =

6)

2.0000

4.0000

45.9980

8.0000

10.0000

4.0000

8.0000

12.0000

16.0000

6.0000

12.0000

18.0000

24.0000 -110.0000

20.0000 -177.9980
0

(transpose : ij ji )
x " z' " (complex conjugate) .
x " z.' " .
" . (dot) " .

>>z=[1+2i 3+4i]

z =
1.0000 + 2.0000i
>>z'

3.0000 + 4.0000i

ans =
1.0000 - 2.0000i
3.0000 - 4.0000i
>>z.'

ans =
1.0000 + 2.0000i
3.0000 + 4.0000i

12

1.2
1)

(operators)

(Arithmetic Operators)

1. transpose( " .' " ), power ( " .^ " ),

power( " ^ " )

transpose( " ' " ),

2. unary plus( " + " ), unary minus( " - " )

( " * " ), ( " . / " ), ( " . \ " ), ( " *


" ), ( " / " ), ( " \ " )
4. ( " + " ), ( " - " )
5. colon ( " : " )
3.

>>A=[3 9 5];
>>B=[2 1 5];
>>C=A./B.^2
% B.^2
C =
0.7500
9.0000
0.2000

2)

, A./ .

(Relational operators)

(less), (not equal to)"


.
. 1-3


<
" (Less than)"
<=
" (Less than or equal to)"
>
" (Greater than)"
>=
" (Greater than or equal to)"
==
"(Equal to)"
~=
" (Not equal to)"
13

0 .
.123 .

>>A=[2 7 6;9 0 -1;3 .5 6]; % MATLAB


% , 0.123
>>B=[8 0.2 0;-3 2 5;4 -1 7];
>>C= A<B
C =
1
0
0
0
1
1
1
0
1

A B , A B (TRUE)
1 , (:FALSE) 0 .
, A B
.

.
, . ,
, , " find "
, .
" find "

>>A=magic(4) % magic
A =
16
2
3
13
5
11
10
8
9
7
6
12
4
14
15
1
>>index=find(A > 8);
>>A(index)=100
A =
100
2
3 100
5 100 100
8
100
7
6 100
4 100 100
1

14

3)

(Logical Operators)
"AND", "OR"

TRUE", "FALSE" .
. 1-4

1.3 MATLAB

&

AND

OR

NOT


sin(x) / cos(x) / tan(x) / asin(x) / acos(x) / atan(x) / exp(x) / log(x) / log10(x) /
sqrt(x) / abs(x) / phase(x) / real(x) / imag(x) / conj(x) / mean(x) / std(x) / sum(x)
/
max(x) / min(x) / ceil(x) / floor(x) / round(x) / rem(x,y) / fix(x) / length(x) /
size(x) / ones(rn,cn) / zeros(rn,cn) / eye(rn,cn) / linspace(sn,incn,en) / pi(=3.14159....)


x=3+3j or x=3+3i or x=3+3*j or x=3+3*i


clear all;
close all;
clc;
disp('DSP')

15

1.4

,
save

1) load

, save.m, load.m .
save.m *.mat file ,
load.m *.mat file .
MATLAB

>> x=eye(3); y='DSP'; z=2+2i;


>> save Data_file x y z

, x, y, z DataFile.mat file
.
>>clear all

% base workspace

>>load Data_file

, Data_file.mat file x, y, z base


workspace .

>> save output_filename variables (xxx.mat

>> load data_filename.mat


ASCII

>> save output_filename.dat variables -ascii(

>> load data_filename.txt

.
2) Low_level file I/O

fclose.m
.
fopen.m

16

/ascii

: ascii

fscanf.m
, .
fprintf.m

3) input

input

a= ')
a= 6
>> a=input('
a =
6
>> x=a+a.^2;
>> x
x =
42

1.5

1) FOR

for i = 1:10

end

x=0;
for i = 1:10
x=x+i;
end
x
x =
55

2) IF

if (

)
;

elseif

;
17

else

end

x=0; y=0; z=0;


for k=0:1:100;
if (2*round(k/2)==k)
x=x+1;
elseif (3*round(k/3)==k)
y=y+1;
else
z=z+1;
end
end
x
y
z
x =
51
y =
17
z =
33

3) WHILE

while (

end

n=1;
while (prod(1:n)<1000)
n=n+1;
end
n
n =
7

18

4) SWITCH


case 1,
;
case 2,
;
switch

.....
otherwise

case

end

x=input('

x=')

y=rem(x,2);
switch y
case 1,
disp('
case 2,
disp('

')
')

end

x=45
x =
45


1.6

MATLAB

19

.
.
MATLAB

PLOT
1)

>> t=[0:0.1:2*pi];
>> y=sin(t);
>> plot(t,y)

20

"plot"

stem"

21

2)
>> t=[0:0.1:2*pi];
>> y=sin(t);
>> z=cos(t);
>> plot(t,y,t,z)

3) hold


>> hold on

, hold on
>> hold off

22

>>
>>
>>
>>
>>
>>

x=0:.1:2*pi;
y=sin(x);
plot(x,y)
grid on
hold on
plot(x,exp(-2*x),'r:*')

STEM
>> n=[0:0.2:2*pi];
>> y=sin(n);
>> stem(n,y)
>> stem(n,y,'filled')

23

log


x, y log ,

.

>>w=logspace(-2,2,1000);
>>H=1./(1+w.^2).^0.5;
>>subplot(1,3,1),semilogx(w,H);
>>subplot(1,3,2),semilogy(w,H);
>>subplot(1,3,3),loglog(w,H);



, , )

subplot(

>>
>>
>>
>>
>>

subplot(2,2,1),
x = 0:.1:2*pi;
subplot(2,2,2),
subplot(2,2,3),
subplot(2,2,4),

plot(1:10)
plot(x,sin(x))
plot(x,exp(-x),'r')
plot(x+sin(x)+exp(-x),'k')

24



'option' .
>> plot(x,y,'option')

>> x = 0:.1:2*pi;
>> plot(x,sin(x),'r--d')

25

. 1-5 option
option
option option

blue

point

solid

green

circle

dotted

red

x-mark

-.

dashdot

cyan

plus

--

dashed

magenta

star

yellow

square

black

diamond
triangle

(down)

triangle(up)

<

triangle(left)

>

triangle(right)

pentagram

hexagram

26


>>
>>
>>
>>
>>

x = 0:.1:2*pi;
plot(x,sin(x),'r--d');
xlabel('Frequency(w)');
ylabel('Amplitude[V]');
title('SIN function');


1)

>> xlabel('^ {super } and _ {sub }')


2)

>> ylabel('Some \bfboldface\rm and some \it {italics }')


3)

>> text(3.5, 20, 'y = e^ { \alphax}sin( \betax)')

27

. 1-6.

28

Property Editor
1) Figure Property

2) Axes Property

29

30

1
MATLAB .
1.


MATLAB

2.


MATLAB
MATLAB
MATLAB
MATLAB ,

3.

(1)

MATLAB meditor .
.

(2) MATLAB
(3)

31

1]
. , .
[

2] sin cos
. y1 y2 .
[

32

3] sin cos
save ASCII . load
,
. "o" .
[

4] "input" a,b,c,d,e
log c) d) e)
a) b)
MATLAB . .
[

33

You might also like