HK231 CO2036 Lab02 2053321 NgoChanPhong

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

VIET NAM NATIONAL UNIVERSITY HO CHI MINH CITY

HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY


FACULTY OF COMPUTER SCIENCE AND ENGINEERING

DIGITAL SIGNAL PROCESSING

LAB 02

Student name: Ngo Chan Phong


Student ID: 2053321

Semester 231, AY 2023-2024


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

1 Exercise 1

plot2d3() is the same as plot2d, but the curves are plotted by using vertical bars. For example:
1 consider x =[0:0.1:2*% pi ] ;
2 Single plot : plot2d3 ( sin ( x ) )
3 Multiple plot : plot2d3 (x , [ sin ( x ) sin (2* x ) sin (3* x ) ]

min(): return minimum value from a given list of numbers, matrices.


max(): return maximum value from a given list of numbers, matrices
subplot(): virtually grids the graphic window into an m-by-n matrix of sub-windows, and selects the pth sub-
window for receiving the forthcoming drawings.
subplot(m,n,p):grid a figure and set the plotting area to a chosen cell. It can be used to plot multiple figures in
one window.
title(): give an name to the figure and be able to modify its properties(such as name,color, position, size,. . . ).
xlabel(), ylabel(): label name to x and y axis and can also modify its properties.
bool2s():replace true value by 1 and false value by 0.
deff(): define a function by text, without an external file of source code.

2 Exercise 2

Digital Signal Processing Page 1/7


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

3 Exercise 3

4 Exercise 4

Source:
1 n = -5:5;
2 msignal = n .* bool2s (n >=0) ;
3 plot2d3 (n , msignal )

Digital Signal Processing Page 2/7


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

5 Exercise 5
1 clf ;
2 n = -1:1;
3 x =[1 ,3 , -2];
4 subplot (2 ,1 ,1) ;
5 plot2d3 (n , x , style =5)
6 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
7 ylabel ( ’ x ( n ) ’,’ color ’ , ’ blue ’) ;
8 title ( ’ Discrete - Time Signal ’ , ’ color ’ , ’ red ’) ;
9 a = gca () ;
10 a . x_location =" origin ";
11 a . data_bounds =[ -4 , -4;4 ,4];
12 xe =0.5*( x + flipdim (x ,2) ) ;
13 subplot (2 ,2 ,3) ;
14 plot2d3 (n , xe , style =5)
15 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
16 ylabel ( ’ xe ( n ) ’,’ color ’ , ’ blue ’) ;
17 title ( ’ Even signal component ’ , ’ color ’ , ’ red ’) ;
18 a = gca () ;
19 a . x_location =" origin ";
20 a . data_bounds =[ -4 , -4;4 ,4];

Digital Signal Processing Page 3/7


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

21 xo =0.5*( x - flipdim (x ,2) ) ;


22 subplot (2 ,2 ,4) ;
23 plot2d3 (n , xo , style =5)
24 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
25 ylabel ( ’ xo ( n ) ’,’ color ’ , ’ blue ’) ;
26 title ( ’ Odd signal component ’ , ’ color ’ , ’ red ’) ;
27 a = gca () ;
28 a . x_location =" origin ";
29 a . data_bounds =[ -4 , -4;4 ,4];

6 Exercise 6
1 clf ;
2 n =0:3;
3 x1 =[0 ,1 ,3 , -2];
4 subplot (221)
5 plot2d3 (n , x1 , style =5)
6 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
7 ylabel ( ’ x1 ( n ) ’,’ color ’ , ’ blue ’) ;

Digital Signal Processing Page 4/7


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

8 title ( ’ Signal x1 ( n ) ’,’ color ’ , ’ red ’) ;


9 a = gca () ;
10 a . x_location =" origin ";
11 a . data_bounds =[ -4 , -4;4 ,4];
12 n1 = -1:2;
13 x2 =[0 ,1 ,2 ,3];
14 subplot (222) ;
15 plot2d3 ( n1 , x2 , style =5)
16 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
17 ylabel ( ’ x2 ( n ) ’,’ color ’ , ’ blue ’) ;
18 title ( ’ Signal x2 ( n ) ’,’ color ’ , ’ red ’) ;
19 a = gca () ;
20 a . x_location =" origin ";
21 a . data_bounds =[ -4 , -4;4 ,4];
22 n2 = -1:3;
23 y =[ zeros (1) + x2 (1) , x1 (1:3) + x2 (2:4) , x1 (4) + zeros (1) ];
24 subplot (212) ;
25 plot2d3 ( n2 , y , style =5)
26 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
27 ylabel ( ’ x2 ( n ) ’,’ color ’ , ’ blue ’) ;
28 title ( ’ Addition of x1 and x2 ’ , ’ color ’ , ’ red ’) ;
29 a = gca () ;
30 a . x_location =" origin ";
31 a . data_bounds =[ -4 , -6;4 ,6];

Digital Signal Processing Page 5/7


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

7 Exercise 7
1 clf ;
2 n =0:3;
3 x1 =[0 ,1 ,3 , -2];
4 subplot (221)
5 plot2d3 (n , x1 , style =5)
6 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
7 ylabel ( ’ x1 ( n ) ’,’ color ’ , ’ blue ’) ;
8 title ( ’ Signal x1 ( n ) ’,’ color ’ , ’ red ’) ;
9 a = gca () ;
10 a . x_location =" origin ";
11 a . data_bounds =[ -4 , -4;4 ,4];
12 n1 = -1:2;
13 x2 =[0 ,1 ,2 ,3];
14 subplot (222) ;
15 plot2d3 ( n1 , x2 , style =5)
16 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
17 ylabel ( ’ x2 ( n ) ’,’ color ’ , ’ blue ’) ;
18 title ( ’ Signal x2 ( n ) ’,’ color ’ , ’ red ’) ;
19 a = gca () ;

Digital Signal Processing Page 6/7


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

20 a . x_location =" origin ";


21 a . data_bounds =[ -4 , -4;4 ,4];
22 n2 = -1:3;
23 y =[ zeros (1) * x2 (1) , x1 (1:3) .* x2 (2:4) , x1 (4) * zeros (1) ];
24 subplot (212) ;
25 plot2d3 ( n2 , y , style =5)
26 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
27 ylabel ( ’ x2 ( n ) ’,’ color ’ , ’ blue ’) ;
28 title ( ’ M ultiplicatio n of x1 and x2 ’ , ’ color ’ , ’ red ’) ;
29 a = gca () ;
30 a . x_location =" origin ";
31 a . data_bounds =[ -4 , -2;4 ,10];

8 Exercise 8
1 clf ;
2 n = -2:1;
3 x =[1 , -2 ,3 ,6];
4 subplot (221)

Digital Signal Processing Page 7/7


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

5 plot2d3 (n , x , style =5)


6 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
7 ylabel ( ’ x ( n ) ’,’ color ’ , ’ blue ’) ;
8 title ( ’ Signal x ( n ) ’,’ color ’ , ’ red ’) ;
9 a = gca () ;
10 a . x_location =" origin ";
11 a . data_bounds =[ -4 , -4;4 ,6];
12 n1 = -1:2;
13 subplot (222) ;
14 plot2d3 ( n1 , flipdim (x ,2) , style =5)
15 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
16 ylabel ( ’ y1 ( n ) ’,’ color ’ , ’ blue ’) ;
17 title ( ’ Signal y1 ( n ) = x ( - n ) ’,’ color ’ , ’ red ’) ;
18 a = gca () ;
19 a . x_location =" origin ";
20 a . data_bounds =[ -4 , -4;4 ,6];
21 n2 = -5:0;
22 y2 =[ x , zeros (1 ,2) ];
23 subplot (223) ;
24 plot2d3 ( n2 , y2 , style =5)
25 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
26 ylabel ( ’ y2 ( n ) ’,’ color ’ , ’ blue ’) ;
27 title ( ’ Signal y2 ( n ) = x ( n +3) ’,’ color ’ , ’ red ’) ;
28 a = gca () ;
29 a . x_location =" origin ";
30 a . data_bounds =[ -6 , -4;6 ,6];
31 n3 =0:4;
32 f =[ x , zeros (1) ];
33 y3 =2.*[ flipdim (f ,2) ];
34 subplot (224) ;
35 plot2d3 ( n3 , y3 , style =5)
36 xlabel ( ’n ’ , ’ color ’ , ’ blue ’) ;
37 ylabel ( ’ y3 ( n ) ’,’ color ’ , ’ blue ’) ;
38 title ( ’ Signal y3 ( n ) =2.* x ( -n -2) ’,’ color ’ , ’ red ’) ;
39 a = gca () ;
40 a . x_location =" origin ";
41 a . data_bounds =[ -6 , -8;6 ,12];

Digital Signal Processing Page 8/7


HCMC UNIVERSITY OF TECHNOLOGY - VNU-HCM
FACULTY OF COMPUTER SCIENCE AND ENGINEERING

Digital Signal Processing Page 9/7

You might also like