You are on page 1of 15

8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

ĐẠI HỌC ĐÀ NẴNG


TRƯỜNG ĐẠI HỌC BÁCH KHOA
KHOA ĐIỆN TỬ - VIỄN THÔNG

----     ----

BÁO CÁO LAB1:

Introduction to
MATLAB and
Scripts

Giáo viên hướ ng dẫn: Nguyễn Hải Triều Anh


Sinh viên thự c hiện: Phan Quốc Thắng
Lớ p : 08DT3
Nhóm: 14B

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 1/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

1.  Ma trận:
  Tạo ma tr ận x:

>> x=[3 1 5; 6 4 1]

x =

3 1 5

6 4 1

  Truy cậ p giá tr ị của ma tr ận x:

>> x(1,2)

ans =

  Tạo ma tr ận z t ừ ma tr ận y:

>> y=[1 2 3]

y =

1 2 3

>> z=[1 2 3]'


z =

  Các phép toán từ ma tr ận:

>> x=[2;4] >> y=[3;1]


x = y =

2 3

4 1

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 2/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

>> x*y' >> x'*y >> x.*y

  ans = ans = ans =

6 2 10 6

12 4 4

2.  Plot and Subplot:

  title('Here is a title'); - Adds the text "Here is a title" to the top of the plot.
  xlabel('Control Voltage (mV)'); - Adds text to the X-axis.
  ylabel('Current (mA)'); - Adds text to the Y-axis.
  grid on; - Adds a grid to the plot.

Vẽ đồ thị  theo 3 tr ục x, y, z

>> subplot(3,1,1);

>> subplot(3,1,2);

>> subplot(3,1,3);

0.5

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0.5

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

0.5

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 3/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

 
Create and plot a signal x0 (t) = te^(-t)
  Lệnh matlab:

>> t = -10:0.1:10;

xo = t .* exp(-abs(t));

plot(t, xo);

grid;

  Đồ thị thu đượ c:

0.4 

0.3 

0.2 

0.1 

-0.1 

-0.2 

-0.3 

-0.4 
-10  -8  -6  -4  -2  0  2  4  6  8  10 

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 4/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

  create the signals: xe (t) = !t!*e^(-!t!)

x (t) = 0:5 _ [x0 (t) + xe (t)]

  Plot all signals together using 3 plots stacked on top of each other with the subplot

command:
Lệnh matlab:

>> t = -10:0.1:10;

xo = t .* exp(-abs(t));

xe=abs(t).*exp(-abs(t));

x = 0.5 * [xo + xe];

subplot(3,1,1);

plot(t,xo);

subplot(3,1,2);

plot(t,xe);

  Đồ thị vẽ đượ c từ matlab:

0.5

-0.5
-10 -8 -6 -4 -2 0 2 4 6 8 10

0.4

0.2

0
-10 -8 -6 -4 -2 0 2 4 6 8 10

0.4

0.2

0
-10 -8 -6 -4 -2 0 2 4 6 8 10

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 5/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

3.  Complex Numbers: 


Lệnh matlab:

>> sqrt(-1)

ans =

0 + 1.0000i

  MATLAB uses the letter i instead of j by default. Electrical Engineers prefer using j
however,
and MATLAB will recognize that as well. Try entering i+j, does this make sense.

  De_ne z1 = 1 + j . Find the magnitude, phase, real and imaginary parts of z (using abs(),
angle(), real(), imag(), respectively).

>> abs(z1)

ans =

1.4142

>> real(z1)

ans =

>> imag(z1)

ans =

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 6/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

  Find the magnitude of z1 + z2 where z2 = 2e^(j*pi/3)

>> z1=1+j

z1 =

1.0000 + 1.0000i

>> z2=2*exp(j*pi/3)

z2 =

1.0000 + 1.7321i

>> z=z1+z2

z =

2.0000 + 2.7321i

  Compute the value of j^j:

>> j^j

ans =

0.2079

4.  Complex Functions: 


Create a signal x1 (t) = te*(jt):
Lệnh matlab:

>> t = -10:0.1:10;

>> x1=t.*exp(j*t);

>> plot(t, x1); grid;

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 7/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

10

-2

-4

-6

-8

-10
-10 -8 -6 -4 -2 0 2 4 6 8 10

5.  Playing and Plotting a Sound: 


Lệnh matlab:

>> load handel;

plot(linspace(0,9,7311
3),y);

sound(y);

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8
0 1 2 3 4 5 6 7 8 9

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 8/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

6.  Script Files:


a.  Ex er cise 1:
 Now we are going to edit the dampedCosine.m file to create our own script file. At
the top of the file, you will see the following commands

diary 'your_name_Lab1.txt'
disp('NAME: your name')
disp('SECTION:your section')

1.Edit the dampedCosine.m (download from link above) script and enter your name and
section where indicated. Save this new version of the script as yourName_dampedCosine.m

2. Edit the script to create a second signal where the cosine with twice the period
(which gives half the frequency) of the first.

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 9/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

3. Add to the script the commands to plot these together with the first signal on top and the
second on the bottom. In other words, you should have a single figure with two different plots,
one on top and one on bottom. You will need to use subplot and plot. Save this plot as
yourName_dampedCosine.fig

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 10/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

f(x)=exp(-abs(x))cos(2*pi*x)
1

0.5
    e
     d
    u
     t
     i
     l
    p 0
    m
    a
-0.5

-1
-5 -4 -3 -2 -1 0 1 2 3 4 5
time
f(x)=exp(-abs(x))cos(pi*x)
1

    e 0.5
     d
    u
     t
     i
     l
    p
    m
    a 0

-0.5
-5 -4 -3 -2 -1 0 1 2 3 4 5
time
 

4. Show the TA your dampedCosine plot. What is the period of the cosine?

-  y1(x) signal have the period of the cosine is :



T1 =

 =1 (s)

-  y2(x) signal have the period of the cosine is



T2=  =2 (s)

b.Exercise 2:

Download and run compexp.m2 , which includes a 3-D plot of a complex exponential, y
(t) , as well as 2-D magnitude/phase and real/imaginary plots. You need 2 2-D plots to have the
same information as the 3-D plot

Để dễ dàng khảo sát sự thay đổi của tín hiệu,ta sử dụng thêm 2 lệnh:
a=input('push a:');

f=input('push f:');

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 11/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

 vớ i f và a là các giá tr ị nhậ p từ bàn phím

Ta được hàm như sau: 

Khi chạy chương trình,trên cửa sổ command sẽ xuất hiện:

 push a:

 push f:

ta sẽ lần lượ t nhậ p các giá tr ị của f và a vào.

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 12/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

1/ How would you change the script to make the oscillation frequency lower by half?

Để tần số giảm đi một nửa,ta giữ nguyên giá tr ị của a=1,và lần lượt thay đổi giá tr ị của f là f=1
và f=0.5.Ta đượ c hình vẽ như sau: 

Khi a=1,f=1 Khi a=1,f=0.5

2/ How would you change the script to make the decay faster?

Để giảm biên độ của tín hiệu,ta giữ nguyên giá tr ị f=1,và lần lượt thay đổi giá tr ị của a là a=1 và
a=2.Ta đượ c hình vẽ như sau 

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 13/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

  Khi a=1,f=1 Khi a=2,f=1

Tín hiệu y(t) được phân tích như sau:  

y(t)= ()  

=3   *   

=3   *(cos(-2  jsin(-2)

=3    *(cos() +jsin(  ))

Chính vì vậy,khi ta thay đổi a thì sẽ làm cho biên độ của tín hiệu thay đổi,và khi thay đổi f chính
là thay đổi tần số của tín hiệu(hay thay đổi chu kì của tín hiệu)

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 14/15
8/13/2019 Bao Cao Lab1 DSP Thang 08DT3

http://slidepdf.com/reader/full/bao-cao-lab1-dsp-thang-08dt3 15/15

You might also like