Lab Tasks: Introduction To Discrete Time Signal Processing On MATLAB

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

1

DSP Lab Manuals, Electrical Engineering Department, COMSATS University, Islamabad

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
In-Lab Task-1: Generate a Continuous time cosine signal and plot it.
t=0:0.01:10;
a=cos(t);
plot(t,a);
xlabel('Time (s)');
ylabel('Cos(t)');
title('CONTINOUS GRAPH');

Figure

MUHAMMAD UMAIR KHAN (Fa18-bce-010)


SHOAIB AHMAD KHAN TAREEN (Fa18-bce-009)
2
DSP Lab Manuals, Electrical Engineering Department, COMSATS University, Islamabad

In-Lab Task-2: Generate a Discrete time exponential signal and plot it.
n=-20:1:20;
a=(.9.^n).*[n>=0];
stem(n,a)
xlabel('Time (s)');
ylabel('0.9^n');
title('DISCRETE EXPONENTIAL GRAPH');
Figure:

MUHAMMAD UMAIR KHAN (Fa18-bce-010)


SHOAIB AHMAD KHAN TAREEN (Fa18-bce-009)
3
DSP Lab Manuals, Electrical Engineering Department, COMSATS University, Islamabad

In-Lab Task-3: Write a MATLAB program for the ‘running average’, a running total is
a sequence of partial sum of a given sequence/signal. For example, the running totals of
the signal {a, b, c,} are a, a+b, a+b+c, Use that program to find the running total of the
discrete time signal of length N=100. Write your program so that it is flexible. That is,
you should be able to invoke your program from the command window as follows:
>> y=running_averagel(x) where x is the input signal, and y is the running total of that
signal.

MUHAMMAD UMAIR KHAN (Fa18-bce-010)


SHOAIB AHMAD KHAN TAREEN (Fa18-bce-009)
4
DSP Lab Manuals, Electrical Engineering Department, COMSATS University, Islamabad

function y=runningaverage(x)
sum=0;
x=[1:100];
for i=1:100;
sum=sum+x(i);
y(i)=sum;
end
end

Command Window
>> runningaverage(x)
ans =
Columns 1 through 7
1 3 6 10 15
21 28
4278 4371 4465 4560 4656
4753 4851
Columns 99 through 100
4950 5050

Post-Lab Tasks
Post-Lab Task-1: Write a program to compute the variance and mean of a signal
x. The variance σ is defined to be:

MUHAMMAD UMAIR KHAN (Fa18-bce-010)


SHOAIB AHMAD KHAN TAREEN (Fa18-bce-009)
5
DSP Lab Manuals, Electrical Engineering Department, COMSATS University, Islamabad

Where ‘m’ is the mean value of the signal x. For signal x, use all the integers from 1 to
1000.

clear all
close all
t=1:0.01:10;
n=1:10;
x=sin(t);
sum=0;
for i=1:1000
sum=sum+i;
end
mean=sum./length(x)
sum=0;
for i=1:1000
sum=sum+(i-mean);
end
variance=sum./length(x)

Command Window

>> Untitled
mean =
555.4939
variance =
-61.0365
Post-Lab Task-2: Can you explain what the following
program does:
L = length(x);
For i = 1: L
If x (i) < 0 x (i) = -1;
End
End

Does nothing

Post-Lab Task-3: Generate a step sequence u [n] as described in In-Lab section, use it
to generate an impulse as δ [n] = u[n] – u[n-1].
t=-5:5;
unit=t>=0;
dunit=(t-1)>=0;
tunit=(t>=0)-((t-1)>=0);
stem(t,tunit)
xlabel('Time (s)');
ylabel('Dirac Delta');

MUHAMMAD UMAIR KHAN (Fa18-bce-010)


SHOAIB AHMAD KHAN TAREEN (Fa18-bce-009)
6
DSP Lab Manuals, Electrical Engineering Department, COMSATS University, Islamabad

title('Dirac Delta from Heaviside');

Figure:

Post-Lab Task-4: Generate an impulse sequence δ [n] as described in In-Lab generate a


step sequence section, use it to

s=input('Enter Value of Samples: ');


a=0:s-1;

MUHAMMAD UMAIR KHAN (Fa18-bce-010)


SHOAIB AHMAD KHAN TAREEN (Fa18-bce-009)
7
DSP Lab Manuals, Electrical Engineering Department, COMSATS University, Islamabad

b=ones(1,s); %impulses
stem(a,b)
xlim([-s s+1]);ylim([0 1.2])
xlabel('Time (s)');
ylabel('Heaviside');
title('Heaviside from Dirac Delta');

Command Window

Enter Value of Samples: 5

Figure

MUHAMMAD UMAIR KHAN (Fa18-bce-010)


SHOAIB AHMAD KHAN TAREEN (Fa18-bce-009)

You might also like