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

Lab Report 2 DSP

This lab report summarizes an introductory lab on discrete time signal processing in MATLAB. The lab objectives were to understand discrete time signals and their MATLAB representation. Students generated various signals like a cosine wave, exponential wave, running average, and computed variance and mean of a signal. Impulse and step sequences were also generated from each other. The critical analysis concluded that MATLAB can only generate finite signals over a defined index range.

Uploaded by

Khansa Maryam
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)
18 views8 pages

Lab Report 2 DSP

This lab report summarizes an introductory lab on discrete time signal processing in MATLAB. The lab objectives were to understand discrete time signals and their MATLAB representation. Students generated various signals like a cosine wave, exponential wave, running average, and computed variance and mean of a signal. Impulse and step sequences were also generated from each other. The critical analysis concluded that MATLAB can only generate finite signals over a defined index range.

Uploaded by

Khansa Maryam
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

LAB REPORT # 01

NAME: KHANSA MARYAM.

ROLL NO.: FA20-BEE-232.

SUBMITTED TO: SIR MOBEEN SABIR.

SUBJECT: DIGITAL SIGNAL PROCESSING.

DATED: 01-03-2023.

1
Lab # 02:
Introduction to Discrete Time Signal Processing on
MATLAB
Objective:
This introductory lab allows students to understand the basic concept of the discrete-time signals
and their representation on MATLAB. Furthermore, it demonstrates some basic MATLAB codes
in order to achieve hands-on it.

Lab Tasks:
Task-1:
Generate a Continuous time cosine signal and plot it.

CODE:
x=1:0.1:10;
y=cos(x);
plot(y)
xlabel 'time'
ylabel 'amp'

Task-2:
Generate a Discrete time exponential signal and plot it.

CODE:
x=1:0.1:10;
y=exp(x);
stem(y)
xlabel 'time'

2
ylabel 'amp'

Task-3:
Write a MATLAB program for the ‗running average‟, a running total is a sequence of
partial sum of a given sequence/signal.

CODE:
function y = average(x)
L=length(x);
sum = 0;
for i = 1:L
sum = sum + x(i);
end
y = sum /L;

OUTPUT:

Task-4:
Write a program to compute the variance and mean of a signal x.

CODE:
x= 1:1:1000

3
for i = 1:100;
b=0;
b=x(i)-mean(x);
sum=0;
sum= sum+b;
end
var= 1/length(x)*sum

OUTPUT:

Task-5:
Can you explain what the following program does:

CODE:
x=-5:5
L = length(x);
for i = 1: L
if x (i) < 0
x (i) = -1;
end
end

OUTPUT:
x=
-5 -4 -3 -2 -1 0 1 2 3 4 5

Comments:
This program checks the values of array named ‘x’. Array values less than zero, will be replaced
by -1.
In this task we can observe that if statement is used, that evaluates the expression and executes a
group of statements when the expression is true. An expression is true when its result is non-
empty and contains only nonzero elements. Otherwise, the expression is false. For loop is also
used to execute the loop a specific number of times. 

4
Task-5:
Generate a step sequence u [n], use it to generate an impulse as δ [n] = u[n] – u[n-1].

CODE:
n=-15:1:15;
x= heaviside(n);
subplot(3,1,1)
stem(n,x)
title('u(n)')
x1=heaviside(n-1)
subplot(3,1,2)
stem(n,x1)
title('u(n-1)')
z= x-x1;
subplot(3,1,3)
stem(n,z)
title('y(n)=u(n)-u(n-1)')

Task-7:
Generate an impulse sequence δ [n] use it to generate step sequence 𝑢[𝑛]=∑𝛿[𝑛−𝑘].

CODE:
n0=0;
n=-10:10;
x=zeros(1,length(n));
i=11;
if n0<0
x(i+n0)=1;
elseif n0>0
x(i+n0)=1;
else
x(i)=1;
end
subplot(2,1,1);
stem(n,x);
title('Delayed Impulse (n0=0)');

5
k=10;
for j=i:i+k
x(j)=1;
end
subplot(2,1,2);
stem(n,x);
title('Step function u[n]');

Task-8:
Generate the following sequences using step and impulse sequence.
PART a:

CODE:
n=-15:1:15;
x=(n>=0);
subplot(3,1,1)
stem(n,x)
title('u(n)')
x1=heaviside(n-10)
subplot(3,1,2)
stem(n,x1)
title('u(n-1)')
z= x-x1;
subplot(3,1,3)
stem(n,z)
title('y(n)=u(n)-u(n-10)')

6
PART b:

CODE:
n=-10:10;
x1=(n>=0);
subplot(2,1,1);
stem(n,x1);
title('Unit Step Sequence u[n]');
a=0.8;
x=(a.^n).*heaviside(n);
subplot(2,1,2);
stem(n,x);
title('Desired Sequence x[n]');

PART c:

CODE:
n=-5:5;
x1=(n==0);
subplot(2,1,1);
stem(n,x1);
title('Unit Impulse Sequence');

7
a=2;
k=-5:5;
x2=((n-k)==0);
v=a.^n;
x=v.*sum(x2);
subplot(2,1,2);
stem(x);
title('Desired Sequence x[n]');

OUTPUT:

CRITICAL ANALYSIS / CONCLUSION:


In this lab we studied discrete time signal and their representation in MATLAB. In MATLAB,
we can only generate finite signals so we must define a finite range of indices. Which means for
generating a discrete sinusoid we require a finite range of index (time-index) only then will the
signal be plotted correctly. While plotting the signals, we considered them to be functions of
only one variable, ‘n’ which takes discrete values only. We also studied step sequence and
impulse sequence.

You might also like