Beruflich Dokumente
Kultur Dokumente
Department of ECE
( 15A04608 )
DIGITAL SIGNAL PROCESSING
LABORATORY MANUAL
NAME:
REGISTER NO:
YEAR & SEMESTER:
Prepared Approved
By By
K.ANITHA
AP/ ECE
Mr. HARI KRISHNAN.S
HOD-ECE
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY ANANTAPUR
1.
2.
3.
4.
5.
6.
7.
8.
9.
10
11
12
1.Generation of random signal and plot the same as a waveform showing
all the specifications
AIM:
To generate the following discrete time signals using MATLAB:
Unit step
Unit Ramp
Impulse
Sine
Cosine
Software required: MATLAB
ALGORITHM:
CODING:
clc;
t=0:1:10;
f=0.1;
a=t;
%RAMP SIGNAL
subplot(3,2,1);
plot(t,a);
title('continuous ramp');
xlabel('time');
ylabel('x(t)');
subplot(3,2,2);
stem(t,a);
title('discrete ramp');
xlabel('n');
ylabel('x(n)');
%STEP SIGNAL
y1=ones(1,11);
subplot(3,2,3);
plot(t,y1);
title('continuous step');
xlabel('time');
ylabel('x(t)');
subplot(3,2,4);
stem(t,y1);
title('discrete step');
xlabel('n');
ylabel('x(n)');
%IMPULSE SIGNAL
p=-10:1:10;
y=[zeros(10,1);1;zeros(10,1)];
subplot(3,2,5);
stem(p,y);
title('discrete impulse');
xlabel('n');
ylabel('x(n)');
GENERATION OF SINE AND COSINE WAVEFORMS
clc;
t=0:0.2:10;
f=0.5;
a=10;
%SINE SIGNAL
s=a*sin(2*pi*f*t);
subplot(2,2,1);
plot(t,s);
title('continuous sine wave');
xlabel('time');
ylabel('x(t)');
subplot(2,2,2);
stem(t,s);
title('discrete sine wave');
xlabel('n');
ylabel('x(n)');
%COSINE SIGNAL
c=a*cos(2*pi*f*t);
subplot(2,2,3);
plot(t,c);
title('continuous cos wave');
xlabel('time');
ylabel('x(t)');
subplot(2,2,4);
stem(t,c);
title('discrete cos wave');
xlabel('n');
ylabel('x(n)');
10 10
5 5
x(n)
0 0
x(t)
-5 -5
-10 -10
0 2 4 6 8 10 0 2 4 6 8 10
tim e n
10 10
5 5
x(n)
0 0
x(t)
-5 -5
-10 -10
0 2 4 6 8 10 0 2 4 6 8 10
tim e n
ELEMENTARY SIGN
continuousramp discreteramp
10 10
5 5
x (n)
x (t)
0 0
0 2 4 6 8 10 0 2 4 6 8 10
time n
2 continuousstep 1 discretestep
1.5
1 0.5
0.5
0 0
0 2 4 6 8 10 0 2 4 6 8 10
time n
1 discreteimpulse
0.5
0
-10 -5 0 5 10
RESULT:
Thus the various discrete time signals are generated using MATLAB
2. CONVOLUTION and CORRELATION
AIM:
To generate the following convolution and correlation signals using MATLAB
CODING:
Linear convolution:
L=length(x);
M=length(h);
x1=[zeros(1,M-1),x,zeros(1,M-1)];
conv_matrix=[];
seq=x1(1,i:i+M-1);
seq1=fliplr(seq);
conv_matrix=[conv_matrix;seq1];
end
y=conv_matrix*h'
y1=conv(x,h)
subplot(221)
stem(x)
xlabel('n'); ylabel('x(n)');
grid on
title('INPUT SIGNAL');
subplot(223)
stem(y)
xlabel('n'); ylabel('y(n)');
grid on
title('OUTPUT SIGNAL');
subplot(222)
stem(h)
xlabel('n'); ylabel('h(n)');
grid on
title('SYSTEM RESPONSE');
subplot(224)
stem(y1)
xlabel('n'); ylabel('y1(n)');
grid on
output:
CIRCULAR CONVOLTION
clc;
g=input('Enter the sequence 1:');
h=input('Enter the sequence 2:');
N1=length(g);
N2=length(h);
N=max(N1,N2);
N3=N1-N2;
if(N3>0)
h=[h,zeros(1,N3)];
else
g=[g,zeros(1,-N3)];
end
for n=1:N;
y(n)=0;
for i=1:N;
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=[y(n)+(g(i)*h(j))];
end
end
disp('The resultant is');y
subplot(2,1,1);
stem(y);
xlabel('N->');
ylabel('Amplititude->');
OUTPUT:
Enter 1st sequence: [1 2 2 2]
Enter 2nd sequence: [1 2 3]
c =[ 11 10 9 12]
AUTO-CORRELATION
clc;
close all;
clear all;
x=input('Enter the sequence 1: ');
y=xcorr(x,x);
figure;
subplot(2,1,1);
stem(x);
ylabel('Amplitude->');
xlabel('n->');
title('Input sequence');
subplot(2,1,2);
stem(fliplr(y));
ylabel('amplitude');
xlabel('n->');
title('Output sequence');
disp('the resultant is ');
fliplr(y);
OUTPUT:
clc;
clear all;
close all;
x=input('Enter the sequence 1: ');
h=input('Enter the sequence 2: ');
y=xcorr(x,h);
figure;
subplot(3,1,1);
stem(x);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 1');
subplot(3,1,2);
stem(fliplr(y));
stem(h);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 2');
subplot(3,1,3);
stem(fliplr(y));
xlabel('n->');
ylabel('Amplitude->');
title('Output sequence');
disp('The resultant is');
fliplr(y);
OUTPUT:
RESULT:
Output:
enter sequence[1 2 3 4 5]
Columns 1 through 4
15.0000 -2.5000 + 3.4410i -2.5000
+ 0.8123i -2.5000 - 0.8123i
Column 5
-2.5000 - 3.4410i
enter sequence s
Columns 1 through 4
1.0000 - 0.0000i 2.0000 - 0.0000i 3.0000
4.0000 + 0.0000i
Column 5
5.0000 + 0.0000i
RESULT:
Hence we executed the DFT & IDFT of a given signal.
Computation of N point DFT of a given sequence and to plot magnitude and
phase spectrum.
SOURCE CODE:
WNnk=WN.^nk;
Xk=x*WNnk;
MagX=abs(Xk) % Magnitude of calculated DFT
PhaseX=angle(Xk)*180/pi % Phase of the calculated DFT figure(1);
subplot(2,1,1);
plot(k,MagX);
subplot(2,1,2);
plot(k,PhaseX);
OUTPUT
Enter the the value of N(Value of N in N-Point DFT)4 Enter the sequence for which DFT is to be
calculated [1 2 3 4]
MagX = 10.0000 2.8284 2.0000 2.8284
PhaseX = 0 135.0000 -180.0000 -135.0000
DFT of the given sequence is
10.0000-2.0000 + 2.0000i -2.0000 - 0.0000i -2.0000 -
2.0000i
4. N-point FFT / IFFT OF GIVEN DT SIGNAL
OUTPUT:-
enter the sequence[1 .25 .3 4]
enter the length of fft4
fourier transformed signal
X=
5.5500 0.7000 + 3.7500i -2.9500 0.7000 - 3.7500i
RESULT: The Fast Fourier Transform of given sequence is obtained. Hence the theory and practical
value are proved.
5. DESIGN OF FIR FILTER USING WINDOWING TECHNIQUE
AIM:
To design the following FIR filters using windowing techniques
LPF using Hamming window
HPF using Blackman window
hn=hd.*wb';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-.');grid;
title('FIR-High pass filter');
ylabel('magnitude');
xlabel('Normalised frequency');
hold off
BAND STOP FILTER:
CODING:
clc;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
alpha=(N-1)/2;eps=0.001;
n=0:1:N-1;
hd=(sin(wc1*(n-alpha+eps))-sin(wc2*(n-alpha+eps))+sin(pi*(n-alpha+eps)))./
(pi*(n-alpha+eps));
wr=boxcar(N);
hn=hd.*wr';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
wh=hamming(N);
hn=hd.*wh';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-.');
hold on
wb=blackman(N);
hn=hd.*wb';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));grid;
title('FIR-Bandstop filter');
ylabel('magnitude');
xlabel('Normalised frequency');
hold off
BAND PASS FILTER:
CODING:
clc;
wc1=0.25*pi;
wc2=0.75*pi;
N=25;
alpha=(N-1)/2;eps=0.001;
n=0:1:N-1;
hd=(sin(wc2*(n-alpha+eps))-sin(wc1*(n-alpha+eps)))./(pi*(n-alpha+eps));
wr=boxcar(N);
hn=hd.*wr';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h));
hold on
wh=hamming(N);
hn=hd.*wh';
w=0:0.01:pi;
h=freqz(hn,1,w);
plot(w/pi,abs(h),'-.');grid;
title('FIR-Bandpass filter');
ylabel('magnitude');
xlabel('Normalised frequency');
hold off
OUTPUT|:
RESULT:
Thus FIR filters have been designed using window technique.
6. DESIGN OF IIT FILTER USING BUTTERWORTH & CHEBYCHEV FILTER
AIM:
To design the following IIR filters :
Butterworth type
Chebychev type