You are on page 1of 18

Lab 1: INTRODUCTION TO MATLAB

Lab 2: SOME FUNDAMENTAL PROPERTIES OF SIGNALS

1.Consider the discrete-time signal

and assume N=12. For M=4, 5, 7 and 10, plot xM [n] on the interval 0 ≤ n ≤ 2N -1. Use
stem to create your plots, and be sure to appropriately label your axes. What is the
fundamental period of each signal?
Trả Lời:
N=12;
n=[0:2*N-1];
M=4
x_M=sin((2*pi*M*n)/N);
figure(1)
stem(n,x_M,'filled')
title('x[n]=sin(2*pi*M*n/N)')
xlabel('Time')ylabel('Amplitude')
Ta lần lượt thế M= 5,7,10 ta được các tín hiệu như sau:

M=4 M=5
M=7 M=10
2) Now consider the following signals:

Assume N=6 for each signal. Determine whether or not each signal periodic. If a signal is
periodic, plot the signal for two periods, starting at n=0. Plot the signal for 0 ≤ n ≤ 7N and
explain why it is periodic or not. Remember to use stem and to appropriately label your
axes.
Trả lời:
N=6;
n=[0:7*N];
x2=2*cos(2*n/N)+cos(3*n/N);
x3=cos(2*pi*n/N)+3*sin(5*(pi/2)*n/N);
subplot(2,1,1),stem(n,x2)
title('x2[n]')
subplot(2,1,2),stem(n,x3)title('x3[n]')
3) a) Define a MATLAB vector nx to be the time indices - 3 ≤ n ≤ 7 and the MATLAB
vector x to be the values of the signal x[n] is given by

If you have defined these vectors correctly, you should be able to plot this discrete time
sequence by typing stem(nx,x).
Trả lời:
nx=[-3:7];
x=[0 0 0 2 0 1 -1 3 0 0 0];
stem(nx,x,'filled')
title('x[n]')
xlabel('n')
ylabel('x[n]')

b) For this part, you will define MATLAB vectors y1 through y4 to represent the
following discrete-time signals:

to do this, you should define y1 through y4 to be equal to x. The key is to define


correctly the corresponding index vectors ny1 through ny4. First, you should figure out
how the index of a given sample of x[n] changes when transforming to yi[ ] n . The index
vectors need not span the same of indices as nx, but they should all be at least 11
samples long and include the indices of all nonzero samples of associated signal.
Trả Lời:
n=[-3:7];
x=[2 0 1 -1 3 0];
nx=[0 0 0 x 0 0];
ny1=n+2;
ny2=n-1;
ny3=-n;
ny4=-n+1;
figure(1)
subplot(2,1,1),stem(ny1,nx,'filled')
xlabel('time')
ylabel('x[n-2]')
title('x[n-2]')
subplot(2,1,2),stem(ny2,nx,'filled')
xlabel('time')
ylabel('x[n+1]')
title('x[n+1]')
figure(2)
subplot(2,1,1),stem(ny3,nx,'filled')
xlabel('time')
ylabel('x[-n]')
title('x[-n]')
subplot(2,1,2),stem(ny4,nx,'filled')
xlabel('time')
ylabel('x[-n+1]')
title('x[-n+1]')
Lab3: SOME FUNDAMENTAL PROPERTIES OF SYSTEMS

1. Linearity:
Exercise 1
The system is [ ] n ( [ ]) is not linear. Show
that it violates linearity by giving a counter example. A
good example is the set of signals

Write a MATLAB code to demonstrate this example. This can be done as follows:
Define the domain of the two signals to be from -3 to 3 and save it as a vector n
Define the signal x1 as a vector of the values [0 0 0 1 0 0 0]
Define the signal x2 =2x1
Evaluate the output corresponding to the x1 input, and label it as y1
Evaluate the output corresponding to the x2 input, and label it as y2
On the same graph window, plot the signals x1, x2, y1 and y2 using the commands (subplot) and
(stem). Your results should be as depicted in Figure 1.
Trả lời:
n= [-3:3];
x1=[0 0 0 1 0 0 0];
x2=[0 0 0 2 0 0 0];
y1=sin(pi*x1/2);
y2=sin(pi*x2/2);
figure(1)
subplot(2,1,1),stem(n,x1,'filled')
title('x1[n]')
subplot(2,1,2),stem(n,y1,'filled')
title('y[n]')
figure(2)
subplot(2,1,1),stem(n,x2,'filled')
title('x2[n]')
subplot(2,1,2),stem(n,y2,'filled')
title('y[n]')
Q: Is y2 equal to 2y1, what is your coment?
Giá trị biên độ của y2 thay đổi tăng 2 lần so với ban đầu:

2. Causality
Exercise 2
The system [ ] [ ] [ ] is not
causal. Use the input signal [ ] [ ] to
show this, as follows:
Define the time (sample) interval to be
between -6 and 9, and label it as n.
Define the signal x[n]=U[n] as an array
with the values 0 for n<0 and 1 for n>=0
and label it as x.
Define the signal x[n+1] =U[n+1] as an array of zeros for n<-1 and 1 for n>=-1 and label
it as x_shift.
Define the output signal y[n] as x[n]+x[n+1] .
On the same window, plot the signals x[n], x[n+1] and y[n] using the commands
(subplot) and (stem).You should have a plot identical to the one shown in Figure 2.
Trả lời:
n= [-6:9];
x1= [0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1];
x2= [0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0];
y= x1+x2;
figure(1)
subplot(3,1,1),stem(n,x1,'filled')
title('x[n]')
subplot(3,1,2),stem(n,x2,'filled')
title('x[n+1]')
subplot(3,1,3),stem(n,y,'filled')
title('y[n]')

Q: What is your comment about the system causality?


Tín hiệu đầu ra sẽ phụ thuộc vào tín hiệu đầu vào của hệ thống
3. Stability
Exercise 3
The system y[n]=log(x[n]) is not stable because the (log) function goes to minus infinity at the 0
input. Write a MATLAB code to illustrate this. Proceed as follows:
Define the domain vector as n ranging between -2 and 3.
Define the input signal x as a vector of the values: 1, 2, 0, 3, 4 and 5.
Declare the output vector as y= log(x). using the(log) function.
Using stem and subplot commands, plot the input signal x[n] and the corresponding
output signal y[n]. The result should appear as shown in Figure 3.
Trả lời:
n=[-2:3];
x=[1 2 0 3 4 5];
y=log(x);
figure(1)
subplot(2,1,1),stem(n,x,'filled')
title('x[n]')
subplot(2,1,2),stem(n,y,'filled')
title('y[n]')
Q: Comment on your result. How does this result indicate that the system is unstable?
Hệ thống tăng dần từ -2 đến 3 nhưng đến 3 nhưng tới điểm 0 thì tín hiệu không tăng và tăng đều từ 1

4. Invertible and Inverse


Systems
Exercise 4
The system y[n] = sin(2πx[n]) where x[n]=[0 1 2 3 4 0] is not invertible. Illustrate this by
showing that the system is not one-to-one. As follows:
Define a vector of n values of 0,1,2,3,4 and 5 and label it as n.
Define x[n] as a vector of the values 0,1,2,3,4 and 5.
Define the output as y[n] = sin(2πx[n]).
Plot x[n] and y[n] using the commands (stem) and (subplot). Your result should be as
shown in Figure4.
Trả lời:
n= [0:5];
x= [0 1 2 3 4 0];
y=sin(2*pi*x);
figure(1)
subplot(2,1,1),stem(n,x,'filled')
title('x[n]')
subplot(2,1,2),stem(n,y,'filled')
title('y[n]')
Q: Comment on the result justifying the claim that the system in not invertible
LAB 4
The Convolution Sum and Integral
Exercise 1
Use MATLAB to evaluate the convolution of x[n] with itself, where

Procedure:
Define the signal x as a vector of values [ 1 1 1 1 1 1], using the (ones) command.
Use the (conv) function to evaluate the convolution of x with itself, and name it as y.
Define the index vector n to range from 0 to 10.
Using the function (stem), plot y versus n.
Label the vertical and horizontal axes as (Amplitude) and (Time), respectively.
Title the figure as (y[n]).
Trả lời:
n= [0:10];
u=ones(1,6);
y=conv(x,u);
x= [1 1 1 1 1 1];
figure(1)
stem(n,y,'filled')
ylable('bien do')
xlable('thoi gian')
title('y[n]')

Q: Comment on the relationship between the length of y[n] and x[n]


Exercise 2
I. Consider the discrete time signals:

Define the signal x as a vector of values [0 1 2 3 4 5].


Define the signal u as a vector of values [ 1 1 1 1 1 1], using the (ones) command.
Use the function (conv) function to evaluate the convolution of x with u, and name it as
y.
Define the index vector n to range from 0 to 10.
Using the function (stem), plot y versus n.
Label the vertical and horizontal axes as (Amplitude) and (Time), respectively.
Title the figure as (y[n]).
Trả lời:
x= [0:5];
u=ones(1,6);
y=conv(x,u);
n=[0:10];
figure(1)
stem(n,y,'filled')
ylabel('bien do')
xlabel('thoi gian')
title('y[n]')

II. Repeat part I using u[n+5] instead of u[n].


Trả lời:
x=[0 1 2 3 4 5];
u=ones(1,6);
y=conv(x,u);
n=[-5:5];
figure(1)
stem(n,y,'filled')
xlabel('Thoi gian')
ylabel('bien do')
title('x[n]*u[n+5]')

Q: Comment on the relationship between y[n] in part I, and y[n] of part II.
Biên độ ở y[n] phần 1 bắt đầu ở khoảng thời gian là 0 kết thúc ở 10 và biên độ tăng dần theo mốc thời
gian 0 đến 6 và bắt đầu giảm dần.
Biên độ y[n] ở phần 2 bắt đầu ở khoảng thời gian -5 kết thúc ở 6 và biên độ tăng dần theo mốc thời gian
-5 đên 0 và bắt đầu giảm dần.

Exercise 3
In this part, continuous time convolution will be simulated in the discrete case. Consider the
continuous time signals x(t) and h(t). Generate these functions using a time step of 0.1.

Procedure:
Define the domain of x as a vector ranging from 1 to 5, with a time step of 0.1. Name it
as tx.
Define the domain of h as a vector ranging from 2 to 7, with a time step of 0.1. Name it
as th.
Define the signal x as a vector of ones over the index vector tx, using the (ones),(length)
command,
Define the signal h as a vector of ones of the index vector th, using the (ones) ),(length)
command
Declare the total time length of the convolution to range from 3 to 12, with a 0.1 step.
Name it as ty.
Use the function (conv) function to evaluate the convolution of x(t) with h(t), and name it
as y. Hint: Don’t forget to multiply the conv. by Ts=0.1 (Ts step time)
Using the function (stem), plot y versus ny.
Label the vertical and horizontal axes as (Amplitude) and (Time), respectively.
Title the figure as (y(t)).
Trả lời:
tx=1:0.1:5;
th=2:0.1:7;
x=ones(1, length(tx));
h=ones(1, length(th));
ty=3:0.1:12;
y=0.1*conv(x, h);
subplot(2,1,1),stem(ty,y,'filled');
ylabel('bien do')
xlabel('thoi gian')
title('y(t)');

Q: Comment on the relationship between the time length of y(t)and that of x(t) and h(t)
LAB 5:DIFFERENTIAL EQUATIONS
1. LTI Systems Described by Differential Equations:
Exercise 1

Consider the causal LTI system described by the first order differential equation:
The latter equation can be rewritten as
Write a MATLAB code to simulate the step response of this system. This can be done as
follows:
Define the system coefficient vectors(a) and (b)
Define the time vector t ranging from 0 to 10, with a 1 time increment.
Define input as a row vector x of ones with the same length of t.
Use the function (lsim) to evaluate the output y.
Plot the output vector y versus time vector t with dashed lies (- -).
Label the axes as the (output), (time), respectively.
Title the figure as (Simulated Output).
To compare the simulated output to the actual one, plot the solution of the differential equation
versus time as follows:
Define the time vector t ranging from 0 to 10, with a 1 time increment.
Plot the function , versus time.
Label the axes and title the figure as( Exact Output)
Your answer should be as indicated in Fig1 .
Trả lời:
b=1;
a=[1, 0.5];
t=0:1:10;
x=ones(size(t));
y=lsim(b, a, x, t);
plot(t,y,'--');
xlabel('time');
ylabe('output');
title('Simulated Output');
y_exact=2*(1-exp(-t/2));
figure
plot(t,y_exact);
xlabel('time');
ylabel('output');
title('Exact Output');
Exercise 2
Following a similar procedure to that of exercise 1, use (lsim) to compute the response of the
system:

To the input:
Your answer should be as indicated in Fig2.
a = [1,1/2];
b = [1];
t = [0:1:10];
x=ones(1,length(t));
y=lsim(b,a,x,t);
plot(t,y,'--');
title('simulated output');
Exercise 3
Plot the step and impulse responses of the system described by:

Proceed as follows:
Define the system coefficient vectors(a) and (b)
Define the time vector t ranging from 0 to 10, with a 0.1 time increment.
Define input as a row vector x of ones with the same length of t.
Use the function (step) to evaluate the step response of the system, and name it as s.
Use the function (impulse) to evaluate the step response of the system, and name it as i.
Use the command (subplot) to plot the step impulse response(s) on the top, and impulse
response (i) in the bottom of the same graph window.
Label the axes and title the figures.
Your answer should be as indicated in Fig2.

Trả lời:
b=1;
a=[1, 2];
t= 0:0.01:10;
x=t>=2;
y= lsim(b, a, x, t);
plot (t, y);
xlabel('time');
ylabel('output');
title('Response of the System');
LAB 6
FOURIER SERIES and FOURIER TRANSFORM REPRESENTATION
6.1 Compute the DTFS with fft:
Exercise 1:
Consider using MATLAB to solve Problem 3.3(a) in (Simon Haykin 2nd Edition) book. For the

DTFS coefficient, the signal:


This signal has period N=24.
Procedure:
Define the signal period N.
Define the index vector n to range from 0 to 23.
Define the signal x as a vector of ones using the (ones) command plus sin valus. Also
plot the signal in figure 1 using stem.
Use the function (fft) function to evaluate the DTFS coefficients. and store it in X.
Plot the real and imaginary parts of fourier series coefficient x using subplot and stem on
figure 2.
Plot the absolute value and angles of fourier series coefficient x using subplot and stem
on figure 3.
Use the function (ifft) function to reconstruct the orginal time domain signal x . and
store it in x_recon. Plot it on figure 4 as real and imaginary part using subplot.
Q: Comment on the relationship between figures of x[n] and x_recon?

You might also like