Professional Documents
Culture Documents
---- ----
Introduction to
MATLAB and
Scripts
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
>> x(1,2)
ans =
>> y=[1 2 3]
y =
1 2 3
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
6 2 10 6
12 4 4
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.
>> 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
-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
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));
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
>> 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
>> 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
>> j^j
ans =
0.2079
>> t = -10:0.1:10;
>> x1=t.*exp(j*t);
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
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
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?
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
push a:
push f:
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:
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
y(t)= ()
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