Professional Documents
Culture Documents
HK231 CO2036 Lab02 2053321 NgoChanPhong
HK231 CO2036 Lab02 2053321 NgoChanPhong
HK231 CO2036 Lab02 2053321 NgoChanPhong
LAB 02
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 ) ]
2 Exercise 2
3 Exercise 3
4 Exercise 4
Source:
1 n = -5:5;
2 msignal = n .* bool2s (n >=0) ;
3 plot2d3 (n , msignal )
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];
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 ’) ;
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 () ;
8 Exercise 8
1 clf ;
2 n = -2:1;
3 x =[1 , -2 ,3 ,6];
4 subplot (221)