Lab Tasks: Introduction To Discrete Time Signal Processing On MATLAB
Lab Tasks: Introduction To Discrete Time Signal Processing On MATLAB
Lab Tasks: Introduction To Discrete Time Signal Processing On MATLAB
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
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:
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.
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:
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');
Figure:
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
Figure