You are on page 1of 14

Muhammad Usman Ali 14-EE-26

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.
% Function to generate unit sample sequence
function [x,n]=impseq(no,n1,n2)
n=[n1:n2];
x=[(n-no) == 0];
end
In Command Window:
[x,n]=impseq(3,-50,50)
stem(n,x);
xlabel('n')
ylabel('x')
title('Unit Impulse');
Muhammad Usman Ali 14-EE-26

Unit Impulse
1

0.9

0.8

0.7

0.6

0.5
x

0.4

0.3

0.2

0.1

0
-50 0 50
n

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

n=[-5:5];
x=[2*impseq(-2,-5,5)-impseq(4,-5,5)];
stem(n,x)
Muhammad Usman Ali 14-EE-26

Unit impulse
2

1.5

0.5
x

-0.5

-1
-5 0 5
n

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.
% Function to generate unit step function
function [x,n]=stepseq(no,n1,n2)
n=[n1:n2];
x=[(n-no) >= 0];
end
Muhammad Usman Ali 14-EE-26

In Command Window:
[x,n]=stepseq(0,-20,20)
stem(n,x);
xlabel('n')
ylabel('x')
title('Unit Step');

Unit Step
1

0.8

0.6
x

0.4

0.2

0
-20 -15 -10 -5 0 5 10 15 20
n

3. Complex Exponential Signals:

Question 3:
Define x1=5exp(i*n*pi/4) in MATLAB and plot using n = -50:50.

n = -50:50;
x1=5*exp(i*n*pi/4);
Muhammad Usman Ali 14-EE-26

plot(n,x1)

-1

-2

-3

-4

-5
-50 0 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.
n=-50:50;
x1=5*exp(1i*n*pi/4);
x2=2*n;
X=x1.*x2;
subplot(1,2,1);
plot(n,real(X));
title('Real Part');
xlabel('N');
ylabel('Amplitude');
subplot(1,2,2);
plot(n,imag(X));
title('imaginary Part');
Muhammad Usman Ali 14-EE-26

xlabel('N');
ylabel('Amplitude');
Real Part imaginary Part
500 500

400 400

300 300

200 200

100 100
Amplitude

Amplitude
0 0

-100 -100

-200 -200

-300 -300

-400 -400

-500 -500
-50 0 50 -50 0 50
N N

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.

4. Periodic sequence:

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


n=-10:10;
x=exp(-0.1+1i*0.3).*n;
subplot(2,2,1);
stem(n,real(x));
title('Real Part');
xlabel('Samples(n)');
Muhammad Usman Ali 14-EE-26

ylabel('Amplitude');
subplot(2,2,2);
stem(n,imag(x));
title('Imaginary Part');
xlabel('Samples(n)');
ylabel('Amplitude');
subplot(2,2,3);
stem(n,abs(x));
title('Magnitude');
xlabel('Samples(n)');
ylabel('Amplitude');
subplot(2,2,4);
stem(n,angle(x));
title('Phase');
xlabel('Samples(n)');
ylabel('Amplitude');
Muhammad Usman Ali 14-EE-26

Real Part Imaginary Part


10 4

5 2
Amplitude

Amplitude
0 0

-5 -2

-10 -4
-10 -5 0 5 10 -10 -5 0 5 10
Samples(n) Samples(n)
Magnitude Phase
10 1

0
Amplitude

Amplitude
5 -1

-2

0 -3
-10 -5 0 5 10 -10 -5 0 5 10
Samples(n) Samples(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.

n=-10:9;
a=[5 4 3 2 1];
X=repmat(a,1,4);
stem(n,X);
title('Sequence');
xlabel('Number of samples');
ylabel('Amplitude');
Muhammad Usman Ali 14-EE-26

Sequence
5

4.5

3.5

3
Amplitude

2.5

1.5

0.5

0
-10 -5 0 5 10
Number of samples

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.
Muhammad Usman Ali 14-EE-26

SINUSOIDS (literature for question 5)


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

f0 = 3;
A = 5;
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
Muhammad Usman Ali 14-EE-26

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])
Muhammad Usman Ali 14-EE-26

ADDITION OF SINUSOIDS
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
RADIAN');
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');
Muhammad Usman Ali 14-EE-26

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
RADIAN');
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');
Muhammad Usman Ali 14-EE-26

You might also like