Uploaded by mustafa khan

DS lAB REPORT 1

advertisement
IN LAB TASK1:
 Generate a Continuous time cosine signal and plot it:
Sol:
t=0:0.01:10;
a=cos(t);
plot (t,a);
xlabel ('Time (s)');
ylabel ('Cos(t)');
title ('CONTINOUS GRAPH');
IN LAB TASK2:
 Generate a Discrete time exponential signal and plot it:
Sol:
n=linspace(0,2.5,15);
A=1;
sig=2;
x=A*exp(sig*n);
stem(n,x)
xlabel('Time (s)');
ylabel('0.9^n');
title('DISCRETE EXPONENTIAL GRAPH');
IN LAB TASK3:
 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=runningaverage(x);
Sol:
function y=runningaverage(x)
sum=0;
x=[1:10];
for i=1:10;
sum=sum+x(i);
y(i)=sum;
end
Ans =
1
3
6 10 15 21 28 36 45 55
POST LAB TASK1:
 Write a program to compute the variance and mean of a signal x. The variance σ is
defined to be:
Sol:
x=[1 2 3];
sub=0;
a=cumsum(x);
sum=a(1,3);
l=length(x);
mean=sum/l;
fprintf('mean is %d',mean);
for i=0:length(x)-1
sub=((x(i+1)-mean)^2)+sub;
end
st=sub/l;
variance=sqrt(st) % Self Calculated
simulatedVariance=var(x) % Simulated Variance
fprintf('The Calculated Variance is " %d " whereas Simulated
Variance is " %d "','variance,simulatedVariance');
mean is 2
variance = 0.8165
simulated Variance = 1
POST LAB TASK2:
 Generate a step sequence u [n], use it to generate impulse as δ [n] = u[n] – u[n-1]:
Sol:
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');
title('Dirac Delta from Heaviside');
POST LAB TASK3:
 Generate an impulse sequence δ [n], use it to generate a step sequence:
Sol:
s=5;
a=0:s-1;
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');
Related documents
Download