Beruflich Dokumente
Kultur Dokumente
Manasvi Bhatt
(SC14B102)
Sub: Digital Signal Processing Lab
Date of Submission: August 7, 2016
norm = normpdf(x,0,1);
figure;
stem(x,norm);
title(Gaussian Random Signal)
ylabel(x[n]);
xlabel(n);
Inference:Different signals were generated using normal multiplication and plotted by using function stem. For
normal distribution function normpdf is used.
stem(t1,[ramp]);
title( Time Scaling: Upsampling)
ylabel(x[n]);
xlabel(n);
f)t = (0:1:10);
unitstep = t>=0; td=-t;
ramp = t.*unitstep;
stem(td,[ramp]);
title(Time reversal )
ylabel(x[n]);
xlabel(n);
Inference:Basic signal operations were done by defining new axis in relation to old one and plotted.
a)
n = 0:49;
f = 0.08;
phase = pi/2;
A = 2.5;
arg = 2*pi*f*n - phase;
x = A*cos(arg);
stem(n,x);
title(Sinusoidal wave);
xlabel(n);
ylabel(x[n]);
b)
n = 0:30;
f = 0.1;
Am = 4;
phi = 2*pi;
rand(state,sum(100*clock));
A = Am*rand;
phif = phi*rand;
angle = 2*pi*f*n + phif;
op = A*cos(angle);
stem(n,op);
title( Random Sinusoidal Signal of length 31);
xlabel(n);
ylabel(Amplitude);
8
Inference:Using basic multiplication techniques and command rand for generating random numbers, the sinusoidal waves were generated.
Question No.5:
Given two sinusoids with the following amplitude and phases:
x1(t) = 5 cos (2 *500t)
x2(t) = 5 cos (2 *1200 t + 0.25 )
Create a MATLAB program to sample each sinusoid and generate a sum of sinusoids, that is, x(n) =
x1(n) + x2(n), using a sampling rate of 8000 Hz, and plot the sum x(n) for 20 seconds.
n=0:32;
fsamp=8e+3;
fone=500;
ncycle=2;
t=0:1/fsamp:ncycle*1/fone;
x1=cos(2*pi*fone*t);
subplot(3,1,1);
title(x1[n]);
stem(n,x1);
title(x1[n]);
xlabel(n);
ylabel(x1[n]);
ftwo=1200;
ncycle=2;
t=0:1/fs:ncycle*1/fone;phi=pi/4;
x2=cos((2*pi*ftwo*t)+phi);
subplot(3,1,2);
title(x1[n]);
stem(n,x2);
title(x2[n]);
xlabel(n);
ylabel(x2[n]);
x=x1+x2;
subplot(3,1,3);
stem(n,x);
title(sum);
xlabel(n);
ylabel(x[n]);
Inference:Two signals were added using simple addition technique and sampled by defining a sample frequency
and taking the values at that time.
10
Question No.6:
a) Find the convolution of given two finite sequences using MATLAB:
x1 = [4 2 6 3 8 1 5]
x2 =[3 8 6 9 6 7]
Note: Arrow points to zero location in above sequences. Since MATLAB command does not give time
index of the convolved result , derive it from the signals to be convolved.
b) Find the auto correlation and cross correlation of x1 and x2, with the help of convolution.
c) Verify the results using matlab function for auto-correlation and cross-correlation.
a)
x1=[4 2 6 3 8 1 5];
x2=[3 8 6 9 6 7];
c=conv(x1,x2);
t=-10:10;
stem(t,c);
title(Convolution of x1 and x2);
xlabel(n);
ylabel(x1*x2);
b)
x1=[4 2 6 3 8 1 5];
x2=[3 8 6 9 6 7];
c=conv(x1,x2);
xinx1=fliplr(x1);
xinx2=fliplr(x2);
c=conv(x1,xinx1);
subplot(3,1,1);
stem(c);
title(Autocorrelation of x1:x1[n]*x1[-n]);
xlabel(n);
ylabel();
c=conv(x2,xinx2);
subplot(3,1,2);
stem(c);
title(Autocorrelation of x2:x2[n]*x2[-n]);
xlabel(n);
ylabel();
c=conv(x1,xinx2);
subplot(3,1,3);
stem(c);
title(Cross correlation of x1 and x2:x1[n]*x2[-n]);
xlabel(n);
ylabel();
c)
x1=[4 2 6 3 8 1 5];
x2=[3 8 6 9 6 7];
c=xcorr(x1,x1);
subplot(3,1,1);
stem(c);
title(Autocorrelation of x1::x1[n]*x1[-n]);
xlabel(n);
ylabel(x1[n]*x1[-n]);
c=xcorr(x2,x2);
subplot(3,1,2);
stem(c);
title(Autocorrelation of x2:x2[n]*x2[-n]);
11
xlabel(n);
ylabel(x2[n]*x2[-n]);
c=xcorr(x1,x2);
subplot(3,1,3);
stem(c);
title(Cross correlation of x1 and x2:x1[n]*x2[-n]);
xlabel(n);
ylabel(x1[n]*x2[-n]);
Inference:Using the function conv for the convolution the autocorrelation and crossrelation is found by flipping
the signal and then convolving it. After that the values are verified by using using xcorr function
which finds autocorelation.
12
Question No.7:
Write a generalized MATLAB code for the convolution and correlation of two finite sequences and verify
your code for the sequences given in question 6
a)
x1=input(Enter x1: )
x2=input(Enter x2: )
m=length(x1);
n=length(x2);
X=[x1,zeros(1,n)];
H=[x2,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
13
for j=1:m
if(i-j+1>0)
Y(i)=Y(i)+X(j)*H(i-j+1);
else
end
end
end
Y
stem(Y);
ylabel(Y[n]);
xlabel(n);
title(Convolution without conv function);
b)
x=input(Enter the first Sequence : );
h=input(Enter the second sequence : );
n=length(x);
m=length(h);
k=n+m-1;
x=[x zeros(1,k-n)];
h=wrev(h);
h=[h zeros(1,k-m)];
for i=1:k
c(:,i)=circshift(x,i-1);
end
y=c*h; stem(y); title(Cross corelation without xcorr);
xlabel(n);
ylabel(Amplitude)
disp(Correlation of the sequences)
disp(y);
c)
x=input(Enter the first Sequence : );
h=x;
n=length(x);
m=length(h);
k=n+m-1;
x=[x zeros(1,k-n)];
h=wrev(h);
h=[h zeros(1,k-m)];
for i=1:k
c(:,i)=circshift(x,i-1);
end
y=c*h; stem(y); title(Auto corelation without xcorr);
xlabel(n);
ylabel(Amplitude)
disp(Correlation of the sequences)
disp(y);
Inference:The generalized functions for convolution and correlation is verified
14
15
Figure 24: Autocorelation x2