You are on page 1of 7

DSP Lab # 2 07-02-2017

TYPES OF SEQUENCES
1. Unit sample sequence:

{
(nn 0)= 1,n=n 0
0,n n 0

Question 1:
Write a MATLAB function to implement unit sample sequence (n) over theinterval
n1 n0 n2
Write your own matlab function having 3 input arguments n0, n1, n2. This function
should return two vectors x, n. Do not use zeros command.

Question 1 part 2:
. Generate and plot the following sequence over the indicated interval
x(n) = 2(n + 2) (n 4), 5 n 5.

2. Unit step sequence

{
u(nno)= 1,n n 0
0,n< n 0

Question 2:
. Write a MATLAB function to implement unit step sequence u(n) over theinterval
n1 n0 n2
and having 3 input arguments n0, n1, n2. This function should return two vectors x, n. Do
not use zeros and ones command.

3. Complex Exponential Signals:

Question 3:
Define x1=5exp(i*n*pi/4) in MATLAB and plot using n = -50:50.
Define another signal x2= an.
Multiply these two(x1 and x2) signals (use point-by-point multiplication
of the two signals). Plot the real as well as the imaginary parts
for0<a<1 and a>1.

Question 3 part 2:
Generate the complex-valued signal
x(n) = e(0.1+j0.3)n, 10 n 10
and plot its magnitude, phase, the real part, and the imaginary part in
four separate subplots.
DSP Lab # 2 07-02-2017

4. Periodic sequence:

A sequence x(n) is periodic if x(n) = x(n + N),n.

Question 4:
. Generate and plot the following sequence over the indicated interval
x(n) = {..., 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, 5, 4, 3, 2, 1, ...}; 10 n 9.

Hint: concatenate rows using (:) operator.

Question 5:

Generate two 3000 hertz sinusoids with different amplitudes and phases.
x1(t) = A1 cos(2(3000)t + ) x2(t) = A2 cos(2(3000)t + )

(a) Select the value of the amplitudes as follows: let A1 = 13 and use your
age for A2. For the phases, use the last two digits of your telephone
number for (in degrees), and take = -30. computations

(b) Make a plot of both signals over a range of t that will exhibit
approximately 3 cycles. Make sure the plot starts at a negative time so
that it will include t = 0, and make sure that you have at least 20
samples per period of the wave.

(c) Verify that the phase of the two signals x1(t) and x2(t) is correct at t =
0, and also verify that each one has the correct maximum amplitude.

(d) Use subplot (3,1,1) and subplot(3,1,2) to make a three-panel subplot

that puts both of these plots on the same window.
(e) Create a third sinusoid as the sum: x3(t) = x1(t) + x2(t). In Matlab this
amounts to summing the vectors that hold the samples of each
sinusoid. Make a plot of x3(t) over the same range of time as used in
the previous two plots. Include this as the third panel in the window by
using subplot (3,1,3).
(f) Measure the magnitude and phase of x3(t) directly from the plot.
Explain how the magnitude and phase were measured by making
annotations on each of the plots.

SINUSOIDS (literature for question 5)

Sinusoidal sequences are implemented using sin() & cos().
Example: a continuous-time sinusoid

f0 = 3;
A = 5;
DSP Lab # 2 07-02-2017

t = -1:0.005:1;
y = A*cos(2*pi*f0*t);
figure, plot(t, y,'*:');
xlabel('Time, sec'), ylabel('Amplitude');
title('Graph of sinusoid');

Program: Discrete-Time Sinusoid

M=10; %samples/sec
n=-3:1/M:3;
A=2;
phase=0;
f=1;
x=A * sin(2*pi*f*n + phase);
stem(n,x,'linewidth', 2)
title('Discrete-Time Sine Wave: A sin(2*\pi*f*n + \phi)')
xlabel('Time Index')
ylabel('Signal Amplitude')
axis([n(1) n(end) -A A])
grid
DSP Lab # 2 07-02-2017

SAMPLING A CONTINUOUS-TIME SIGNAL

A continuous time signal can be sampled using a command:
stem(x,y);
Following example shows the sampled version of the continuous time cosine
signal.
Example:

t = 0:0.0005:1;
f = 13;
xa = cos(2*pi*f*t);
subplot(2,1,1)
plot(t,xa);grid
xlabel('Time, msec');
ylabel('Amplitude');
title('Continuous-time signal x_{a}(t)');
axis([0 1 -1.2 1.2])
subplot(2,1,2);
T = 0.1;
n = 0:T:1;
xs = cos(2*pi*f*n);
k = 0:length(n)-1;
stem(k,xs); grid
xlabel('Time index n');
ylabel('Amplitude');
title('Discrete-time signal x[n]');
axis([0 (length(n)-1) -1.2 1.2])
DSP Lab # 2 07-02-2017

CASE 1: When Frequency, Phases, and amplitude of the sinusoids
are same

t=-2:0.01:2;
x1=cos(2*pi*0.5*t);
x2=cos(2*pi*0.5*t);
x3=x1+x2;
subplot(3,1,1);
plot(t,x1,'linewidth',3);
grid;
ylabel('Amplitude');
xlabel('Time');
title('COS WAVE , AMPLITUDE = 1, FREQ = 0.5 HZ, Phase = 0
subplot(3,1,2);
plot(t,x2,'linewidth',3);
grid;
ylabel('Amplitude');
xlabel('Time');
title('COS WAVE , AMPLITUDE = 1, FREQ = 0.5 HZ, Phase= 0 RADIAN');
subplot(3,1,3);
plot(t,x3,'linewidth',3);
grid;
ylabel('Amplitude');
xlabel('Time');
title('SUM OF THE ABOVE TWO COSINE SIGNALS');
DSP Lab # 2 07-02-2017

CASE 2: When Frequencies and Phases of the sinusoids are same but
Amplitudes are different.

t=-2:0.01:2;
x1=2*cos(2*pi*0.5*t);
x2=cos(2*pi*0.5*t);
x3=x1+x2;
subplot(3,1,1);
plot(t,x1,'linewidth',3);
grid;
ylabel('Amplitude');
xlabel('Time');
title('COS WAVE , AMPLITUDE = 2, FREQ = 0.5 HZ, Phase = 0
subplot(3,1,2);
plot(t,x2,'linewidth',3);
grid;
ylabel('Amplitude');
xlabel('Time');
title('COS WAVE , AMPLITUDE = 1, FREQ = 0.5 HZ, Phase= 0
subplot(3,1,3);
plot(t,x3,'linewidth',3);
grid;
ylabel('Amplitude');
xlabel('Time');
title('SUM OF THE ABOVE TWO COSINE SIGNALS');
DSP Lab # 2 07-02-2017