Professional Documents
Culture Documents
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
{
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
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
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:
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
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.
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.
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');
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
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