Sie sind auf Seite 1von 15

LABSHEET-1

Manasvi Bhatt
(SC14B102)
Sub: Digital Signal Processing Lab
Date of Submission: August 7, 2016

Department: B Tech (Avionics)

Question No.1:Basic Signal Generation and Plotting


Generate standard signals with a single MATLAB command: Use stem command to plot them and label
and mark values on x- and y- axis.
a) Unit impulse signal with x-axis range -10 to 10
b) Unit step signal with x-axis range -10 to 10
c) Real exponential signal with a = 0.9 and x-axis range 0 to 10
d) A random signal of length 100 whose elements are uniformly distributed in the interval [2, 2].
e) A Gaussian random signal of length 75 whose elements are normally distributed with zero mean and
a variance of 3.
a)
t= (-10:1:10);
impulse= t==0;
stem(t,[impulse]);
title(Unit Impulse Signal)
ylabel(x[n]);
xlabel(n);
b)
t= (-10:1:10);
step= t>=0;
stem(t,[step]);
title(Unit Step Signal)
ylabel(x[n]);
xlabel(n);
c)
X = linspace(0,10,20);
Y = (exp(0.9*X));
stem(X,Y);
title(Real Exponential Signal)
ylabel(x[n]);
xlabel(n);
d)
r = randi([-2,2],1,100);
stem(r);
title(Uniformly Distributed Random Signal)
ylabel(x[n]);
xlabel(n);
e)
x = [-38:.1:37];
1

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.

Figure 1: Unit Impulse signal

Figure 2: Unit Step Signal

Figure 3: Real exponential signal

Figure 4: Uniformly distributed Random signal

Figure 5: Gaussian Random signal

Question No.2: Basic Signal Operations


a) Generate a ramp signal x[n] with x-axis range 0 to 10 (Display Stem plot).
Signal Translation:
b) Signal delay: From x[n], generate a delayed sequence with a delay of 5 samples.
c) Signal advance: From x[n], generate an advanced sequence with an advance of 5 samples.
d) Amplitude Scaling: Obtain a signal y[n] that is 5 times the amplitude of x[n].
e) Time scaling: Obtain y[n] = x[a*n] with
i) a=2 (down sampling)
ii) a=0.5 (upsampling: Insert zeroes for non-integer indices of x[n])
f) Time reversal: Obtain a sequence y[n] = x[-n].
a)
t = (0:1:10);
unitstep = t>=0;
ramp = t.*unitstep;
stem(t,[ramp]);
title( Ramp signal )
ylabel(x[n]);
xlabel(n);
b)t = (0:1:10);
unitstep = t>=0; td=t-5;
ramp = t.*unitstep;
stem(td,[ramp]);
title( Delayed Signal )
ylabel(x[n]);
xlabel(n);
c)t = (0:1:10);
unitstep = t>=0; td=t+5;
ramp = t.*unitstep;
stem(td,[ramp]);
title(advanced signal )
ylabel(x[n]);
xlabel(n);
d)
t = (0:1:10);
unitstep = t>=0;
ramp = 5*t.*unitstep;
stem(t,[ramp]);
title(Amplitude scaling )
ylabel(x[n]);
xlabel(n);
e)
i)t = (0:1:10); t1 = (0:1:10);
unitstep = t>=0; t1 = 2*t;
ramp = t.*unitstep;
stem(t1,[ramp]);
title(Time scaling: Downsampling )
ylabel(x[n]);
xlabel(n);
ii)t = (0:1:10); t1 = (0:1:10);
unitstep = t>=0; t1 = 0.5*t;
ramp = t.*unitstep;
4

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.

Figure 6: Ramp signal

Figure 7: Delayed signal

Figure 8: Advanced Signal

Figure 9: Amplitude scaling

Figure 10: Time Scaling: Downsampling

Figure 11: Time Scaling: Upsampling

Figure 12: Time reversed signal

Question No.3: Complex Exponentials


a) Plot real and imaginary parts of complex exponential signal: y[n] = r.nexp(jn*pi/3), where r = 0.8 ;
(and r = 1.2) and 0= n = 20.
b) Plot magnitude and phase signals of the above complex exponential using appropriate MATLAB
functions.
a)
n=0:20;
c = (pi/3)*i;
K = 0.8;
x = (K.^n).*exp(c*n);
subplot(2,1,1);
stem(n,real(x));
title(Real Part);
subplot(2,1,2);
stem(n,imag(x));
title(Imaginary Part);
b)
n=0:20;
c = (pi/3)*i;
K = 0.8;
x = (K.^n).*exp(c*n);
subplot(2,1,1);
stem(n,abs(x));
title(Magnitude signal);
subplot(2,1,2);
stem(n,angle(x));
title( Phase signal);
Inference:Using function real and imag for determining the real and imaginary part of the signal is used. For
magnitude abs and for phase angle function is used.

Figure 13: Real and imaginary parts

Figure 14: Magnitude and phase signals

Question No.4: Sinusoids


a) Write a program to generate a sinusoidal sequence of length 50, frequency 0.08, amplitude 2.5, and
phase shift 90 degrees and display it.
b) Write a MATLAB program to generate and display five sample sequences of a random sinusoidal
signal of length 31 X[n] = A . cos(0n+ phi) where the amplitude A and the phase are statistically
independent random variables with uniform probability distribution in the range 0 = A = 4 for the
amplitude and in the range 0 phi 2 for the phase.

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.

Figure 15: Sinusoidal wave

Figure 16: Random Sinusoidal Signal of length 31

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.

Figure 17: x1, x2 and x1+x2

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.

Figure 18: signals convolved

12

Figure 19: By fliping the signal and convolving

Figure 20: Using Matlab commands

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

Figure 21: Convolution

Figure 22: Cross corelation

Figure 23: Autocorelation x1

15
Figure 24: Autocorelation x2

Das könnte Ihnen auch gefallen