Đa Nang university of technology -----

-----

Lab report 1

INTRODUCTION TO MATLAB AND SCRIPTS
Group 8

Members: Pham Thi Trang Ong Thi Hoang Anh Duong Viet Le Ngoc Tan

LAB 1 REPORT: 3. MATLAB COMMANDS MATLAB TIPS 1 2. Perform the following operations in MATLAB a. x = [2 4]’ and y = [3 1]’ b. x * y’ = [ x’ * y = 10 x .* y = [ ] ‘ means transpose. For example, x = [2 4]’=[ ] * means multiplying the two matrices together using normal matrix multiplication. .* The array multiplication operator works on an element by element basis. For example, A = [ A*B = [ ] and B = [ ] and A .* B = [ ] ] ]

c. All answers from computing by hand and by MATLAB are the same.

3. MATLAB TIPS 2 t=-10:0.1:10; xo = t.* exp(-abs(t)); plot(t, xo); grid; And here is the result
0.4 0.3 0.2 0.1 0 -0.1 -0.2 -0.3 -0.4 -10

-8

-6

-4

-2

0

2

4

6

8

10

xe = abs(t) .* exp(-abs(t)); x = 0.5 .* (xo + xe); subplot(3,1,1); plot(t,xo); grid; subplot(3,1,2); plot(t,xe); grid; subplot(3,1,3); plot(t,x); grid; Here is the result

0.5

0

-0.5 -10 0.4

-8

-6

-4

-2

0

2

4

6

8

10

0.2

0 -10 0.4

-8

-6

-4

-2

0

2

4

6

8

10

0.2

0 -10

-8

-6

-4

-2

0

2

4

6

8

10

4. Complex Numbers: a. sqrt(-1) = 0 + 1.0000i Yes, it makes sense. It represent the imaginary number. b. i + j = 0 + 2.0000i Yes, it makes sense c. z1 = 1 +j; abs(z) = 1.4142 angle(z)= 0.7854 real(z) = 1 imag(z)=1 The phase in radian d. z2 = 2.* ; z2 = 2 .* exp(2 .* pi/3);

magnitude : abs(z1 + z2) = 17.2700 e. j^j = 0.2079. (It means j power j) Yes, that’s all I expect 5. Complex functions: t=-10:0.1:10; x=t.*exp(j.*t); y= real(x); z=imag(x); subplot(2,1,1); plot(t, y);grid; subplot(2,1,2); plot(t, z);grid;

10 5 0 -5 -10 -10

-8

-6

-4

-2

0

2

4

6

8

10

10 5 0 -5 -10 -10

-8

-6

-4

-2

0

2

4

6

8

10

In this figure, first figure is odd fuction; the other is even function 6. Sound load handel; plot(linspace(0,9,73113),y); sound(y); Plot the sound load in figure
0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8

0

1

2

3

4

5

6

7

8

9

4.Script Files Exercise 1: 1. diary Group8 %INSERT your name and section into these display commands disp('NAME: Group8')

disp('SECTION: lab 1’) datestr(cputime) Save this new version of the script group8_dampedCosine.m in path C:\Users\admin\Desktop\EE235\lab1 The runs group8_dampedCosine.m the results:

2. subplot(2,1,2); y2=exp(-abs(x)).*cos(pi*x); plot(x,y2);

1

0.5

0

-0.5 -5

-4

-3

-2

-1

0

1

2

3

4

5

3.

x = -5:0.01:5; y2=exp(-abs(x)).*cos(pi*x); subplot(2,1,1); plot(x,y2); xlabel('time'); ylabel('amplitude'); title('f(x)=exp(-|x|)cos(pi*x)'); subplot(2,1,2); y1=exp(-abs(x)).*cos(2*pi*x); plot(x,y1); xlabel('time'); ylabel('amplitude'); title('f(x)=exp(-|x|)cos(2*pi*x)');

f(x)=exp(-|x|)cos(pi*x) 1

amplitude

0.5

0

-0.5 -5

-4

-3

-2

0 1 time f(x)=exp(-|x|)cos(2*pi*x)

-1

2

3

4

5

1 0.5

amplitude

0 -0.5 -1 -5

-4

-3

-2

-1

0 time

1

2

3

4

5

The period of the first figure is 2s and the second is 1s. Exercise 2: First, we set f = 5 and d = 4, then we have

3-D plot of a Complex Exponential

Im(y)

5 0 -5 4 2 0 3 4 5

-2

-4

0 5

1

2

Re(y) Magnitude - |y(t)| 3

tPhase - Arg(y(t))

Magnitude

Angle
0 2 4 6

2 1 0 5

0

-5 5

Re(y(t)) t

0

2

Im(y(t)) t

4

6

Magnitude

0

Angle
0 2 t 4 6

0

-5

-5

0

2 t

4

6

We change the script to make the oscillation frequency lower by half: f = 2.5 and d=4, then we have

3-D plot of a Complex Exponential

Im(y)

5 0 -5 4 2 0 3 4 5

-2

-4

0 5

1

2

Re(y) Magnitude - |y(t)| 3

tPhase - Arg(y(t))

Magnitude

Angle
0 2 4 6

2 1 0 5

0

-5 5

Re(y(t)) t

0

2

Im(y(t)) t

4

6

Magnitude

0

Angle
0 2 t 4 6

0

-5

-5

0

2 t

4

6

Similarly, we change the script to make the decay faster by twice we increase d is double. f = 5 and d = 8, then we have

3-D plot of a Complex Exponential

Im(y)

5 0 -5 4 2 0 3 4 5

-2

-4

0 5

1

2

Re(y) Magnitude - |y(t)| 3

tPhase - Arg(y(t))

Magnitude

Angle
0 2 4 6

2 1 0 5

0

-5 5

Re(y(t)) t

0

2

Im(y(t)) t

4

6

Magnitude

0

Angle
0 2 t 4 6

0

-5

-5

0

2 t

4

6

Sign up to vote on this title
UsefulNot useful