Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
32 views8 pages

DSP Lab 2 (171003)

This document outlines a lab report on Continuous Time and Discrete Time Signals in MATLAB, authored by Syed Yawar Imam Kazmi as part of a Bachelor of Electrical Engineering course. The objectives include generating basic signals, performing operations on them, and plotting in time-domain. Key concepts covered include unit impulse sequences, signal generation procedures, and tasks involving various signal types and MATLAB code implementations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views8 pages

DSP Lab 2 (171003)

This document outlines a lab report on Continuous Time and Discrete Time Signals in MATLAB, authored by Syed Yawar Imam Kazmi as part of a Bachelor of Electrical Engineering course. The objectives include generating basic signals, performing operations on them, and plotting in time-domain. Key concepts covered include unit impulse sequences, signal generation procedures, and tasks involving various signal types and MATLAB code implementations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Digital Signal Processing

Name SYED YAWAR IMAM KAZMI (171003)

BACHELOR OF ELECTRICAL
ENGINEERING (Spring 2021)

Submitted To:
Engr.Anum
zulqarnain
Lab Engineer

DEPARTMENT OF ELECTRICAL AND COMPUTER


ENGINEERING FACULTY OF ENGINEERING
AIR UNIVERSITY,ISLAMABAD
Lab 02- Continuous Time Signals and Discrete Time
Signals Representation in MATLAB
INTRODUCTION TO CT AND DT SIGNALS

OBJECTIVE:
1. To learn how to generate some basic discrete-time signals and continuous time signals
in MATLAB and perform elementary operations on them i.e. adding two signals, also
delaying signals etc.
2. To learn the application of some basic MATLAB commands and how to apply them
in simple digital signal processing problems.
3. To learn how plot signals in time-domain with a variety of flavors.

DISCUSSION:
In this lab we studied the basic principles of continuous time and discrete time signals.

INTRODUCTION:
Unit Impulse Sequence:
The unit impulse sequence, often called the discrete-time impulse, denoted by δ[n], is defined
by
δ[n] = 1, for n = 0,

0, for n ≠ 0.

Discrete Shifted Unit Impulse:

δ[n-k] = 1, for n =k,


0, for n ≠ k.

Creation of Unit Impulse sequence:

A unit impulse sequence I[n] of length N can be generated using the MATLAB Command:

ud = [zeros(1,N) 1 zeros(1,M)];

Procedure for Signal generation:

1. Start the program

2. Get the inputs for signal generation

3. Use the appropriate library function

4. Display the waveform

Real Exponential Sequence:

 If |α | > 1 the magnitude of the signal grows exponentially with n (Figure a),
 If |α | <1 we have a decaying exponential (Figure b).
 Furthermore, if α is positive, all the values of Aα n are of the same sign, but if α is
negative then the sign of x[n] alternates.
 Note also that if α = 1, then x[n] is a constant, whereas if α = -1, x[n] alternates is
value between +A and –A.
LAB TASKS

TASK#01
We will often need the functions for these general signals:
• a unit impulse: δ(n-n0) of desired length
• a unit step: u(n-n0) of desired length
• shifter: a function which gives the input signal an arbitrary shift of n0
Program code:
function y = saad(x)
y = x>=0;
end

function y = delta (x)


yf = x==0;
y_in = yf==1; %where delta (0) occurs
yf(y_in) = 1;
y = yf;
end

%Command line code to execute above functions

n=-20:0.001:20; % using sampling frequency of 1khz


x = delta (n);
x1 =delta (n-10);
plot (n,x, 'linewidth',1.5)
title('Unit Impulse Function')
figure
plot (n,xl, 'r', 'linewidth',1.5)
title ('shifted Impulse Function')
xu = unitstep (n-10);
figure
plot (n, unitstep (n), 'linewidth',1.5)
title('unit Step Function')
figure
plot (n, xu,'r', 'linewidth', 1.5)
title('unit step shifter')
end

Task#02
Generate the following signals in MATLAB:
x1[n] = 2 δ(n + 2) - δ(n-4), -5 ≤ n ≤ 5
x2[n] = n(u[n] – u[n-10]) + 10 exp(-0.3(n-10)) (u[n-10]-u[n-20]) 0 ≤ n ≤ 20
x3[n] = cos(0.04πn) + 0.02w[n], for 0 ≤ n ≤ 50,
where w[n] is a gaussian random signal
x4[n] is signal of four periods of sequence [5,4,3,2,1], in the range -10 ≤ n ≤
9
Program code:
n=-5:0.001:5; %using sampling frequency of 1 Khz
x1 = @(d) dirac (n-d);
x_index = [find (2*x1(-2) ==inf) find (x1(4)==inf)]:

xl = dirac (n);
x1(x_index)=1; %Replacing infinity by 1
plot (n,xl, 'r', 'linewidth', 1.5)
n=0:0.001:20;
u =@(n) n>=0;
x2 = n.* (u(n) - u(n-10) + 10.*exp(-0.3 .* (n-10%). * (u(n-
10)-u(n-20));
figure
plot (n,x2, 'r', 'linewidth',1.5)
n=0:0.001:50;
figure
x3 = cos (0.04*pi*n) + 0.02*randn (1, length (n));
plot (n,x3, 'r')
p = [5,4,3,2,1];
n=-0: (1/p (1)):9;
x4_5 = sin(2-pi (1/(2*p(1) ) ) *n);
figure
plot (n,x4_5)
n=-10: (1/p(2)) : 9;
x4_4 = sin(2-pi (1/(2*p(2)))*n); With period 4
figure
plot (n,x4_4)
n=-10: (1/p(1)):9;
x4_3 = sin(2-pi+ (1/(2*p (3)))*n); with period 3
figure
plot (n,x43)
n=-10: (1/p(1)):9;
x4_2 = sin (2-pi: (1/(2*p(4)))*n); with period 2
figure
plot (n,x4_2)
n=-10: (1/p(1)):9;
X4_1 = sin(2*pi- (1/(2*p (5)) )*n); Wich period 1
figure

Task#03
Sinusoids--- the most general category of signals. Yes, it’s true. Believe it or
not, every signal in this
universe contains nothing but sinusoids. We’ll explore this aspect in detail
in our later labs, but for now,
these signals are quite interesting and beautiful to be looked in detail.
x1[n] = sin ( 17
π
n), 0 ≤ n ≤ 25
x2[n] = cos (17πn), -15 ≤ n ≤ 15
x3[n] = sin (3 π n), -10 ≤ n ≤ 10
x4[n] = cos (23πn), 0 ≤ n ≤ 50
See the figures for each of the signals and comment about each with the
aspect of even and odd, periodic and
aperiodic etc. Can you think of representing x3[n] without trigonometric
functions?
We would be dealing with sinusoids quite frequently in future. It’s a good
idea if we can understand the
mathematics of a sinusoidal signal and write a general function for it.
(i) Write a function to generate a sinusoid of given specifications: it should
take six parameters: Freq,
Amplitude, Initial Phase, Sampling Freq., Start-Time, Stop Time.
(ii) Generate: s(t) = 50cos(2pi*1200*t + pi/4), using the above function.
If you are done with the simple practice session, Change the start and stop
time in the above function to
generate a cosine which appears to be a sine.
Program code:
amp = input ( 'enter amplitude');
freg = input('anter frequency');
phi = input('enter phase');
samp = input('enter sampling frequency');
start_time = input('enter start time');
end_time = input('enter end time');
n= (end_time - start_time)/samp;
b = ceil (n)
x = zeros (b, 2)
i=1;
while (i<=b)
x (i, 1) = start_time;
omega =2*pi*freq* (start_time);
x(1,2) =amp*sin (omega + phi);
start_time = start_time + samp;
i=i+1;
end;
(iii) Complex Exponentials: Generate x0[n] = exp(j*n/3), for some range
and see its real
and imaginary parts separately. Also make the following signals:
• x1[n] = e(-0.1+j0.3)n, -10 ≤ n ≤ 10
• x2[n] = an u[n], where a=0.9, and 1.1 for -50 ≤ n ≤ 100
• x3[n] = 3 sin (17πn) + j 4 cos (17πn), 0 ≤ n ≤ 25
(iv) Let x(n) = {1,2,3,4, 5, 6, 7, 6, 5, 4, 3, 2, 1}, Determine and plot the
following sequences.
 x1(n) = 2x(n-5) – 3x(n+4)
 x2(n) = x(3-n) + x(n)x(n-2)
Program code:
PART (A)
t=0:20:100;
u=1;
x0=exp(j*t/3);
plot(t, x0)
title('xo (n)');
figure;
subplot (2, 1, 1)
plot (t, imag (x0));
title('imaginary part of x0')
subplot (2,1,2)
plot(t, real (x0));
title('real part of x0')
Figure;
n=-10:1:10;
xl=exp(-0.1+j*0.3) *n;
subplot (2,1,1)
plot {n, imag (x1));
title('imaginary part of xl')
subplot (2,1,2)
plot (n, real (x1));
title ('real part of x1')
Figure;
nl=1:10:100;
al=0.9;
x2=a2 *nl;
subplot (2,1,1)
plot (nl, x2);
title('x2(n) when a=0.9');
a2=1.1;
x2=a2 *nl;
subplot (2,1,2)
plot (nl, x2);
title('x2(n) when a=1.1');
PART (B)
clear all;
n=0:1:12;
syms x n
x (n) = [1,2,3,4,5,6,7, 6,5,4,3,2,1]
xl (n) = 2 *x (n-5)-3*x (n+4)
x2 (n) =x (3-n)+x (n).* x(n-2)
plot (xl(n))
title('x1(n)')
figure;
plot (x2(n))
title('x2(n)')

Learning Outcomes
In this lab we learned how to make a sequence of signal equation and also shown that what is
the effect of scaling and shifting on the sequence. We also learned the differences between
continuous time and discrete time signals. We also understood the terms unit impulse, unit
step, ramp, exponential signals from this lab.

You might also like