Professional Documents
Culture Documents
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:
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]')
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 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