You are on page 1of 48

Dr.K.V.

SUBBA REDDY COLLEGE OF ENGINEERING


FOR WOMEN
(Approved by AICTE, Affiliated to JNTUA)
NH -44, Opposite Dupadu Railway Station , Kurnool-518218

LABORATORY MANUAL OF

DIGITAL SIGNAL PROCESSING LAB


For
III.B.Tech - II Sem

Prepared by
K PRASAD BABU M.Tech (Ph.D)
Associate Professor
SYED NOORULLAH M.Tech
Assistant Professor

DEPARTMENT OF
ELECTRONICS & COMMUNICATIONS ENGINEERING
INDEX

S.No List Of Experiments Page No


1 Generation Of Various Signals & Sequences 1
2 Find Average Power And Energy Of A Given Signal 10
3 Convolution And Correlation Of Signals 12
4 DTFT Of A Given Signal 18
5 N-Point FFT Algorithm 21
Design Of FIR Filter Using Windowing Technique And Verify The
6 Frequency Response Of The Filter 23

Design Of IIR Filter Using Any Of The Available Methods And Verify The
7 Frequency Response Of The Filter 28

8 Generation Of Sine Wave And Square Wave 31


9 Convolution 33
10 N-Point Fast Fourier Transform 37
11 FIR Filter Design 39
12 IIR Filter Design 41
Add –on Experiments
1 Implementation of Decimation Process 42
2 Implementation of Interpolation Process 44
DSP Lab Manual

1. GENERATION OF VARIOUS SIGNALS & SEQUENCES


AIM: To generate random Signal and plot the same as waveform showing all the
Specification.

APPARATUS: Computer

MATLAB 7.8.0.347(R2009a) Software.

PROCEDURE:

1. Open the MATLAB software by double clicking the ICON on desktop.

2. Open the new M-file by using file menu

3. Write the program in new file

4. Click on save and run the icon

5. Perform error check which displayed on command window

6. Plot the waveforms which displays on figure window.

7. Note down the values, which displays on the work space.

PROGRAM:
t=-10:0.1:10
%--------------------Unit Impulse---------------------%
x1=1;
x2=0;
x =x1.*(t==0) %generate Unit Impulse Signal
figure(1), stem(t,x); % plot the generated Unit Impulse Signal
xlabel('t'); ylabel('x(t)'); title('Unit impulse Signal');
%------------------ Unit Step signal------------------%
x1 =1;
x2 = 0;
x = x1.*(t>=0)+x2.*(t<0); %generate Unit Step Signal
figure(2); stem(t,x); %Plot the generated unit step signal
xlabel('t'); ylabel('x(t)'); title('Unit Step Signal');
%---------------------- Ramp Signal------------------%
x1 = t;
x2 = 0;
x = x1.*(t>=0)+x2.*(t<0); %generate unit ramp signal
figure(3);stem(t,x); % plot the generated ramp signal
xlabel('t'); ylabel('x(t)'); title(' Ramp Signal');
%----------------------rectangular pulse------------%
t1=-10:0.01:10
a7=rectpuls(t1/10)
figure(4),stem(t1,a7), grid on,axis([-10 10 -2 2])
xlabel('time')
ylabel('magnitude')
title('rectangular pulse')
%-------------------- triangular pulse---------------%
t2=-10:0.1:10

Dr K V Subba Reddy College Engineering For Women Page 1


DSP Lab Manual
a8=tripuls(t2)
figure(5),stem(t2,a8), grid on
title('triangular pulse')
xlabel('time')
ylabel('magnitude')
%--------------- Sinc Signal----------------------%
x = sinc(t); %generate sinc signal
figure(6);stem(t,x); % plot the generated sinc signal
xlabel('t'); ylabel('x(t)'); title('sinc Signal');
%-----------------Sinusoidal Signal----------------%
T = 2; %declare time period
F = 1/T; %compute frequency
x = sin(2*pi*F*t); %generate sinusoidal signal
figure(7);stem(t,x); % plot the generated sinusoidal signal
xlabel('t'); ylabel('x(t)'); title('sinusoidal Signal');
%---------------- Sawtooth signal-----------------%
fs = 10000;
t = 0:1/fs:1.5;
x = sawtooth(2*pi*50*t); %generate sawtooth
signal
figure(8);stem(t,x); axis([0 0.2 -1 1]); %plot the generated sawtooth
signal

xlabel('t'); ylabel('x(t)'); title('sawtooth Signal');


%----------------- square signal---------------------%
t=(0:0.001:10);
sq_wave=square(4*pi*t); %generate square signal
figure(9); stem(t,sq_wave); axis([0 5 -2 2]) %plot the
generated square signal
xlabel('t'); ylabel('x(t)'); title('square signal');
%---------------------periodic triangle------------%
T=20;
x=linspace(0,5*T,10000);
y1=min(0.5,mod(x,T)/T);
y2=min(0.5,1-mod(x,T)/T);
figure(10),stem(x,y1+y2),grid on
xlabel('time')
ylabel('magnitude')
title('periodic triangle wave')

tc = gauspuls('cutoff',50e3,0.6,[],-40);
t = -tc : 1e-6 : tc;
yi = gauspuls(t,50e3,0.6);
figure(11),stem(t,yi),grid on
xlabel('time')
ylabel('magnitude')
title('Aperiodic triangle wave')

%---------------------Random Bipolar Sequence ------------%


%Nb is the number of bits to be transmitted
Nb=10;
% Generate Nb bits randomly
b=rand(1,Nb)>0.5;
%Rb is the bit rate in bits/second
Rb=10000;

fs=50; % For T=0.2s fs =50Hz%


NRZ_out=[];

Dr K V Subba Reddy College Engineering For Women Page 2


DSP Lab Manual
%Vp is the peak voltage +v of the waveform
Vp=1;
%Here we encode input bitstream as Bipolar NRZ-L waveform
for index=1:size(b,2)
if b(index)==1
NRZ_out=[NRZ_out [1 1 1 1 1 1 1 1 1 1]*Vp];
elseif b(index)==0
NRZ_out=[NRZ_out [1 1 1 1 1 1 1 1 1 1]*(-Vp)];
end
end

figure(12);
stem((1:Nb*10)/10,NRZ_out);
xlabel('bits-->');
ylabel('Amplitude (volts)-->');
title(' Bipolar Random data for 10kbps NRZ-L encoded bit stream');

OUTPUT:
Unit impulse Signal
1

0.9

0.8

0.7

0.6
x(t)

0.5

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
t

Dr K V Subba Reddy College Engineering For Women Page 3


DSP Lab Manual

Unit Step Signal


1

0.9

0.8

0.7

0.6
x(t)

0.5

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
t

Ramp Signal
10

6
x(t)

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
t

Dr K V Subba Reddy College Engineering For Women Page 4


DSP Lab Manual

rectangular pulse
2

1.5

0.5
magnitude

-0.5

-1

-1.5

-2
-10 -8 -6 -4 -2 0 2 4 6 8 10
time

triangular pulse
1

0.9

0.8

0.7

0.6
magnitude

0.5

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
time

Dr K V Subba Reddy College Engineering For Women Page 5


DSP Lab Manual

sinc Signal
1

0.8

0.6

0.4
x(t)

0.2

-0.2

-0.4
-10 -8 -6 -4 -2 0 2 4 6 8 10
t

sinusoidal Signal
1

0.8

0.6

0.4

0.2
x(t)

-0.2

-0.4

-0.6

-0.8

-1
-10 -8 -6 -4 -2 0 2 4 6 8 10
t

Dr K V Subba Reddy College Engineering For Women Page 6


DSP Lab Manual

sawtooth Signal
1

0.8

0.6

0.4

0.2
x(t)

-0.2

-0.4

-0.6

-0.8

-1
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
t

square signal
2

1.5

0.5
x(t)

-0.5

-1

-1.5

-2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
t

Dr K V Subba Reddy College Engineering For Women Page 7


DSP Lab Manual

periodic triangle wave


1

0.9

0.8

0.7

0.6
magnitude

0.5

0.4

0.3

0.2

0.1

0
0 10 20 30 40 50 60 70 80 90 100
time

Aperiodic triangle wave


1

0.8

0.6

0.4
magnitude

0.2

-0.2

-0.4

-0.6

-0.8
-4 -3 -2 -1 0 1 2 3 4
time -5
x 10

Dr K V Subba Reddy College Engineering For Women Page 8


DSP Lab Manual

Bipolar Random data for 10kbps NRZ-L encoded bit stream


1

0.8

0.6

0.4
Amplitude (volts)-->

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7 8 9 10
bits-->

RESULT: Generations of various sequence and random sequence & plot the same as
waveform showing all the Specification is done using MATLAB.

Dr K V Subba Reddy College Engineering For Women Page 9


DSP Lab Manual

2. FIND AVERAGE POWER AND ENERGY OF A GIVEN SIGNAL


AIM: To Compute the Average power and energy of the given signal.

APPARATUS: Computer

MATLAB 7.8.0.347(R2009a) Software.

PROCEDURE:

1. Open the MATLAB software by double clicking the ICON on desktop.

2. Open the new M-file by using file menu

3. Write the program in new file

4. Click on save and run the icon

5. Perform error check which displayed on command window

6. Plot the waveforms which displays on figure window.

7. Note down the values, which displays on the work space.

PROGRAM:
%-------------------computation of energy and power---------------%
t=-10:0.1:10;
x=10*sin(10*pi*t);To=10
xsq=x.^2;
E = trapz(t,xsq);
P = E/(2*To);
disp([' Energy, E = ', num2str(E),' Joules']);
disp([' Power, P = ', num2str(P),' Watts']);

Dr K V Subba Reddy College Engineering For Women Page 10


DSP Lab Manual

RESULT: Computed the Average power and energy of the given signal done using
MATLAB.

Dr K V Subba Reddy College Engineering For Women Page 11


DSP Lab Manual

3. CONVOLUTION AND CORRELATION OF SIGNALS


AIM: To Perform Convolution and Correlation (auto and cross correlation) of discrete
sequences without using built in functions for convolution and correlation operations

APPARATUS: Computer

MATLAB 7.8.0.347(R2009a) Software.

PROCEDURE:

1. Open the MATLAB software by double clicking the ICON on desktop.

2. Open the new M-file by using file menu

3. Write the program in new file

4. Click on save and run the icon

5. Perform error check which displayed on command window

6. Plot the waveforms which displays on figure window.

7. Note down the values, which displays on the work space.

PROGRAM: Linear Convolution


% MATLAB program for linear convolution
%linear convolution program
clc;
clear all;
close all;
disp('linear convolution program');
x=input('enter the input secquence x(n):');
m=length(x);
h=input('enter the impulse response h(n):');
n=length(h);
x=[x,zeros(1,n)];
subplot(2,2,1), stem(x);
title('input sequence x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
h=[h,zeros(1,m)];
subplot(2,2,2), stem(h);
title('impulse response h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
disp('convolution of x(n) & h(n) is y(n):');
y=zeros(1,m+n-1);
for i=1:m+n-1
y(i)=0;
for j=1:m+n-1
if(j<i+1)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end

Dr K V Subba Reddy College Engineering For Women Page 12


DSP Lab Manual
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n) & h(n) is :');
xlabel('---->n');
ylabel('---->y(n)');grid;

PROGRAM: Circular Convolution


clc;
clear all;
close all;
x=input ('Enter the input sequence :');
h=input ('Enter the impulse response :');
subplot(3, 1,1);
stem(x);
title('input sequence');
xlabel('time----->');
ylabel('amplitude------>');
subplot(3, 1,2);
stem(h);
title('impulse response');
xlabel('time----->');
ylabel('amplitude------>');
n1=length(x);
n2=length(h);
n3=max(n1,n2);
n4=n1-n2;
%======================================================

%Appending zeros if lengths of the sequences are not equal


if(n4>0)
h=[h,zeros(1,n4)];
else
x=[x,zeros(1,-n4)];
end
%======================================================
%======================================================
%Loop for circular convolution
for(n=1:n3);
y(n)=0;
for(i=1:n3);
j=n-i+1;
if(j<=0)
j=j+n3;
end
y(n)=y(n)+x(i)*h(j);
end
end
%======================================================
disp('circ convolution of given sequences is….');
disp(y);
subplot(3,1,3);
stem(y);
title('output sequence(circular convolution)');
xlabel('n----->');
ylabel('amplitude------>');

Dr K V Subba Reddy College Engineering For Women Page 13


DSP Lab Manual

PROGRAM: AutoCorrelation.
clc;
clear all;
close all;
x=input ('Enter the input sequence :');
disp(x);
stem(x);figure(1),subplot(2,2,1),
title('input samples');
xlabel('samples----->');
ylabel('amplitude------>');
y = xcorr2(x);
disp('Auto correlation of the sequences is….');
disp(x);
stem(x);
title('input samples');
xlabel('samples----->');
ylabel('amplitude------>');
subplot(2,2,2),
disp(y);
stem(y);
title('Auto correlation');
xlabel('samples----->');
ylabel('amplitude------>');

PROGRAM: Cross Correlation.


clc;
clear all;
close all;
%% Inputs
% You can specify the inputs or can take them through command window
h= input ('enter the sequence h');
x= input ('enter the sequence x');

pp=h;qq=x;
% Plot the inputs
subplot(3,1,1); stem(h,'m'); title ('h');ylabel('amplitude')
% %
subplot(3,1,2); stem(x,'b'); title ('x');ylabel('amplitude')
%% calculate the cross correlation
l1= length (h); % calculate length of sequence h
l2= length (x); % calculate length of sequence x
l=abs (l1-l2); % calculate difference in lengths of sequence
if (l1 > l2)
x= [x zeros(1,l)];
else if(l2 > l)
h= [h zeros(1,l)];
end
end
h= [h zeros(1, max (l1, l2))];
for shift= 0:max(l1,l2);
new_x = [zeros(1, shift) x zeros(1, (max (l1 , l2))-shift)];
y(shift+1,:)= sum(h.* new_x);
end
y=y';
% Display the correlation sum
subplot(3,1,1); stem(pp,'m'); title ('h');ylabel('amplitude')
subplot(3,1,2); stem(qq,'b'); title ('x');ylabel('amplitude')
subplot(3,1,3); stem(y,'r'); title ('cross correlation'); xlabel('time');

Dr K V Subba Reddy College Engineering For Women Page 14


DSP Lab Manual

OUTPUT:

linear convolution program


enter the input secquence x(n):[1 2 3 4 5]
enter the impulse response h(n):[2 1 3 4 5]
convolution of x(n) & h(n) is y(n):
input sequence x(n)is: impulse response h(n)is:
6 6

4 4
---->x(n)

---->h(n)
2 2

0 0
0 5 10 0 5 10
---->n ---->n
convolution of x(n) & h(n) is :
50

40
---->y(n)

30

20

10

0
1 2 3 4 5 6 7 8 9
---->n

Dr K V Subba Reddy College Engineering For Women Page 15


DSP Lab Manual

Enter the input sequence :[1 2 3 4 5]


Enter the impulse response :[1 3 5 7 9]
circ convolution of given sequences is….
75 85 85 75 55

input sequence
amplitude------>

0
1 1.5 2 2.5 3 3.5 4 4.5 5
time----->
impulse response
amplitude------>

10

0
1 1.5 2 2.5 3 3.5 4 4.5 5
time----->
output sequence(circular convolution)
amplitude------>

100

50

0
1 1.5 2 2.5 3 3.5 4 4.5 5
n----->

Dr K V Subba Reddy College Engineering For Women Page 16


DSP Lab Manual

Auto Correlation
Enter the input sequence :[1 2 3 4 5 6]
1 2 3 4 5 6
Auto correlation of the sequences is….
1 2 3 4 5 6
6 17 32 50 70 91 70 50 32 17 6
amplitude------> input samples amplitude------> Auto correlation
6 100

4
50
2

0 0
0 2 4 6 0 5 10 15
samples-----> samples----->

Cross Correlation
enter the sequence h[1 3 5 7 9]
enter the sequence x[1 2 3 4 5]

h
10
amplitude

0
1 1.5 2 2.5 3 3.5 4 4.5 5
x
5
amplitude

0
1 1.5 2 2.5 3 3.5 4 4.5 5
cross correlation
100

50

0
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
time

RESULT: Performed Convolution and Correlation (auto and cross correlation) of discrete
sequences without using built in functions for convolution and correlation operations done
using MATLAB.

Dr K V Subba Reddy College Engineering For Women Page 17


DSP Lab Manual

4. DTFT OF A GIVEN SIGNAL


AIM: To Perform the DTFT of given sequence using MATLAB.

APPARATUS: Computer

MATLAB 7.8.0.347(R2009a) Software.

PROCEDURE:

1. Open the MATLAB software by double clicking the ICON on desktop.

2. Open the new M-file by using file menu

3. Write the program in new file

4. Click on save and run the icon

5. Perform error check which displayed on command window

6. Plot the waveforms which displays on figure window.

7. Note down the values, which displays on the work space.

PROGRAM:
% Write a MATLAB program to find the DTFT of a given sequence.
x=input('Enter the sequence : ')
N=length(x)
n=0:N-1
K=0:N-1
wn=exp(-j*2*pi/N)
nK=n'*K
wNnK=wn.^nK
df=x*wNnK
subplot(3,1,1)
stem(x,abs(df))
title('DTFT')
xlabel('K')
ylabel('Magnitude')
subplot(3,1,2)
stem(x,angle(df))
title('DTFT')
xlabel('K')

OUTPUT:
Enter the sequence : [1 2 3 4]
x= 1 2 3 4
N= 4
n= 0 1 2 3
K=
0 1 2 3
wn =
3.1328e-008

Dr K V Subba Reddy College Engineering For Women Page 18


DSP Lab Manual

nK =
0 0 0 0
0 1 2 3
0 2 4 6
0 3 6 9
wNnK =
1.0000 1.0000 1.0000 1.0000
1.0000 0.0000 0.0000 0.0000
1.0000 0.0000 0.0000 0.0000
1.0000 0.0000 0.0000 0.0000
df =

10.0000 1.0000 1.0000 1.0000


wn =
3.1921e+007
nK =
0 0 0 0
0 1 2 3
0 2 4 6
0 3 6 9
wNnK =
1.0e+067 *
0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 0.0000
0.0000 0.0000 0.0000 3.4406
inversdf =
1.0e+067 *
0.0000 0.0000 0.0000 3.4406

Dr K V Subba Reddy College Engineering For Women Page 19


DSP Lab Manual

DTFT
Magnitude 10

0
1 1.5 2 2.5 3 3.5 4
K
DTFT
1
phase

-1
1 1.5 2 2.5 3 3.5 4
K
67
x 10 Inverse DTFT
4
Magnitude

0
1 1.5 2 2.5 3 3.5 4
N

RESULT: Performed the DTFT of given sequence done using MATLAB.

Dr K V Subba Reddy College Engineering For Women Page 20


DSP Lab Manual

5. N-POINT FFT ALGORITHM


AIM: To Perform N-Point FFT algorithm sequence using MATLAB.

APPARATUS: Computer

MATLAB 7.8.0.347(R2009a) Software.

PROCEDURE:

1. Open the MATLAB software by double clicking the ICON on desktop.

2. Open the new M-file by using file menu

3. Write the program in new file

4. Click on save and run the icon

5. Perform error check which displayed on command window

6. Plot the waveforms which displays on figure window.

7. Note down the values, which displays on the work space.

PROGRAM:
%fast fourier transform
clc;
clear all;
close all;
tic;
x=input('enter the sequence');
n=input('enter the length of fft');
%compute fft
disp('fourier transformed signal');
X=fft(x,n)
subplot(1,2,1);stem(x);
title('i/p signal');
xlabel('n --->');
ylabel('x(n) -->');grid;
subplot(1,2,2);stem(X);
title('fft of i/p x(n) is:');
xlabel('Real axis --->');
ylabel('Imaginary axis -->');grid;

OUTPUT:
enter the sequence [1 2 3 4 4 3 2 1]
enter the length of fft8
fourier transformed signal

X=
Columns 1 through 5

Dr K V Subba Reddy College Engineering For Women Page 21


DSP Lab Manual

20.0000 -5.8284 - 2.4142i 0 -0.1716 - 0.4142i 0


Columns 6 through 8
-0.1716 + 0.4142i 0 -5.8284 + 2.4142i
i/p signal fft of i/p x(n) is:
4 2.5

2
3.5

1.5
3
1

Imaginary axis -->


2.5
0.5
x(n) -->

2 0

-0.5
1.5

-1
1
-1.5

0.5
-2

0 -2.5
0 2 4 6 8 0 2 4 6 8
n ---> Real axis --->

RESULT: Performed the FFT of given sequence done using MATLAB.

Dr K V Subba Reddy College Engineering For Women Page 22


DSP Lab Manual

6. DESIGN OF FIR FILTER USING WINDOWING TECHNIQUE


AND VERIFY THE FREQUENCY RESPONSE OF THE FILTER
AIM: To Perform Design of FIR filter using Windowing technique and verify the
frequency response of the filter

APPARATUS: Computer

MATLAB 7.8.0.347(R2009a) Software.

PROCEDURE:

1. Open the MATLAB software by double clicking the ICON on desktop.

2. Open the new M-file by using file menu

3. Write the program in new file

4. Click on save and run the icon

5. Perform error check which displayed on command window

6. Plot the waveforms which displays on figure window.

7. Note down the values, which displays on the work space.

PROGRAM:
%fir filt design window techniques
clc;
clear all;
close all;
rp=input('enter passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter passband freq');
fs=input('enter stopband freq');
f=input('enter sampling freq ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end
c=input('enter your choice of window function 1. rectangular 2. triangular
3.kaiser: \n ');
if(c==1)
y=rectwin(n1);
disp('Rectangular window filter response');
end
if (c==2)
y=triang(n1);
disp('Triangular window filter response');

Dr K V Subba Reddy College Engineering For Women Page 23


DSP Lab Manual
end
if(c==3)
y=kaiser(n1);
disp('kaiser window filter response');
end
%LPF
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);
title('LPF');
ylabel('Gain in dB-->');
xlabel('(a) Normalized frequency-->');
%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);
title('HPF');
ylabel('Gain in dB-->');
xlabel('(b) Normalized frequency-->');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);
title('BPF');
ylabel('Gain in dB-->');
xlabel('(c) Normalized frequency-->');
%BSF
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);
title('BSF');
ylabel('Gain in dB-->');
xlabel('(d) Normalized frequency-->');

OUTPUT:
enter passband ripple0.02
enter the stopband ripple0.01
enter passband freq1000
enter stopband freq1500
enter sampling freq 10000
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
1
Rectangular window filter response
>>

Dr K V Subba Reddy College Engineering For Women Page 24


DSP Lab Manual

LPF HPF
50 20

0
Gain in dB-->

Gain in dB-->
0
-20
-50
-40

-100 -60
0 0.5 1 0 0.5 1
(a) Normalized frequency--> (b) Normalized frequency-->
BPF BSF
50 20
Gain in dB-->

0 Gain in dB--> 0

-50 -20

-100 -40
0 0.5 1 0 0.5 1
(c) Normalized frequency--> (d) Normalized frequency-->

enter passband ripple0.02


enter the stopband ripple0.01
enter passband freq1000
enter stopband freq1500
enter sampling freq 10000
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
2
Triangular window filter response
>>

Dr K V Subba Reddy College Engineering For Women Page 25


DSP Lab Manual

LPF HPF
Gain in dB--> 0 0

Gain in dB-->
-20 -10

-40 -20

-60 -30
0 0.5 1 0 0.5 1
(a) Normalized frequency--> (b) Normalized frequency-->
BPF BSF
20 5

0 0
Gain in dB-->

Gain in dB-->
-20 -5

-40 -10

-60 -15
0 0.5 1 0 0.5 1
(c) Normalized frequency--> (d) Normalized frequency-->

enter passband ripple0.02


enter the stopband ripple0.01
enter passband freq1000
enter stopband freq1500
enter sampling freq 10000
enter your choice of window function 1. rectangular 2. triangular 3.kaiser:
3
kaiser window filter response
>>

Dr K V Subba Reddy College Engineering For Women Page 26


DSP Lab Manual

LPF HPF
50 20

0
Gain in dB-->

Gain in dB-->
0
-20
-50
-40

-100 -60
0 0.5 1 0 0.5 1
(a) Normalized frequency--> (b) Normalized frequency-->
BPF BSF
50 50
Gain in dB-->

0 Gain in dB--> 0

-50 -50

-100 -100
0 0.5 1 0 0.5 1
(c) Normalized frequency--> (d) Normalized frequency-->

RESULT: Design of FIR filter using Windowing technique and verify the frequency response
of the filter done using MATLAB

Dr K V Subba Reddy College Engineering For Women Page 27


DSP Lab Manual

7. DESIGN OF IIR FILTER USING ANY OF THE AVAILABLE


METHODS AND VERIFY THE FREQUENCY RESPONSE OF THE
FILTER
AIM: To Design of IIR filter using any of the available methods and Verify the frequency
response of the filter

APPARATUS: Computer

MATLAB 7.8.0.347(R2009a) Software.

PROCEDURE:

1. Open the MATLAB software by double clicking the ICON on desktop.

2. Open the new M-file by using file menu

3. Write the program in new file

4. Click on save and run the icon

5. Perform error check which displayed on command window

6. Plot the waveforms which displays on figure window.

7. Note down the values, which displays on the work space.

PROGRAM:
% IIR filters LPF & HPF
clc;
clear all;
close all;
disp('enter the IIR filter design specifications');
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband freq');
ws=input('enter the stopband freq');
fs=input('enter the sampling freq');
w1=2*wp/fs;w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
c=input('enter choice of filter 1. LPF 2. HPF \n ');
if(c==1)
disp('Frequency response of IIR LPF is:');
[b,a]=butter(n,wn,'low','s');
end
if(c==2)
disp('Frequency response of IIR HPF is:');
[b,a]=butter(n,wn,'high','s');
end
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure,subplot(2,1,1);plot(om/pi,m);

Dr K V Subba Reddy College Engineering For Women Page 28


DSP Lab Manual
title('magnitude response of IIR filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
title('phase response of IIR filter is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');

OUTPUT
enter the IIR filter design specifications
enter the passband ripple0.15
enter the stopband ripple60
enter the passband freq1500
enter the stopband freq3000
enter the sampling freq7000
enter choice of filter 1. LPF 2. HPF
1
Frequency response of IIR LPF is:
>>

magnitude response of IIR filter is:


0
Gain in dB-->

-100

-200

-300
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalized freq. -->
phase response of IIR filter is:
4
Phase in radians-->

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalized freq. -->

enter the IIR filter design specifications


enter the passband ripple0.15
enter the stopband ripple60
enter the passband freq1500
enter the stopband freq3000
enter the sampling freq7000
enter choice of filter 1. LPF 2. HPF

Dr K V Subba Reddy College Engineering For Women Page 29


DSP Lab Manual

2
Frequency response of IIR HPF is:
>>

magnitude response of IIR filter is:


200

0
Gain in dB-->

-200

-400

-600
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(a) Normalized freq. -->
phase response of IIR filter is:
4
Phase in radians-->

-2

-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
(b) Normalized freq. -->

RESULT: Design of IIR filter using any of the available methods and verify the frequency
response of the filter done using MATLAB.

Dr K V Subba Reddy College Engineering For Women Page 30


DSP Lab Manual

1) GENERATION OF SINE WAVE AND SQUARE WAVE

AIM:- To generate a sine wave and square wave using C6713 simulator

EQUIPMENTS:-

Operating System - Windows XP


Software - CC STUDIO 3
DSK 6713 DSP Trainer kit.
USB Cable
Power supply

PROCEDURE:-
1. Open Code Composer Setup and select C6713 simulator, click save and quit
2. Start a new project using „Project-> New‟ pull down menu, save it in a separate
directory (C:\My projects) with file name sinewave.pjt
3. Create a new source file using File->New->Source file menu and save it in the project
folder(sinewave.c)
4. Add the source file (sinewave.c) to the project
ProjectAdd files to Project Select sinewave.c
5. Add the linker command file hello.cmd
Project -> Add files to Project (path: C:\CCstudio\tutorial\dsk6713\hello\hello.cmd)
6. Add the run time support library file rts6700.lib
ProjectAdd files to Project (path: C\CCStudio\cgtools\lib\rts6700.lib)
7. Compile the program using „projectCompile‟ menu or by Ctrl+F7
8. Build the program using „projectBuild‟ menu or by F7
9. Load the sinewave.out file (from project folder lcconv\Debug) using FileLoad Program
10. Run the program using „DebugRun or F5
11. To view the output graphically Select ViewGraphTime and Frequency
12. Repeat the steps 2 to 11 for square wave

PROGRAM:

#include <stdio.h>
#include <math.h>
float a[500];
void main()
{
int i=0;
for(i=0;i<500;i++)
{
a[i]=sin(2*3.14*10000*i);
}
}
PROGRAM: (b)
#include <stdio.h>
#include <math.h>

Dr K V Subba Reddy College Engineering For Women Page 31


DSP Lab Manual

int a[1000];
void main()
{
int i,j=0;
int b=5;
for(i=0;i<10;i++)
{
for (j=0;j<=50;j++)
{
a[(50*i)+j]=b;
}
b=b*(-1) ;
}
}

OUTPUT:

RESULT: The sine wave and square wave has been obtained using C6713 simulator

Dr K V Subba Reddy College Engineering For Women Page 32


DSP Lab Manual

2. LINEAR CONVOLUTION

AIM: To verify Linear Convolution using C6713 simulator

EQUIPMENTS:-

Operating System - Windows XP


Software - CC STUDIO 3
DSK 6713 DSP Trainer kit.
USB Cable
Power supply

PROCEDURE:
1. Open Code Composer Setup and select C6713 simulator, click save and quit
2. Start a new project using Project New pull down menu, save it in a separate directory
(C:\My projects) with file name linearconv.pjt
3. Create a new source file using File New Source file menu and save it in the project
folder (linearconv.c)
4. Add the source file (linearconv.c) to the project
Project Add files to Project Select linearconv.c
5. Add the linker command file hello.cmd
Project Add files to Project
(path: C:\CCstudio\tutorial\dsk6713\hello\hello.cmd)
6. Add the run time support library file rts6700.lib
Project Add files to Project
(Path: C\CCStudio\cgtools\lib\rts6700.lib)
7. Compile the program using project Compile menu or by Ctrl+F7
8. Build the program using project  Build menu or by F7
9. Load the linearconv.out file (from project folder impulse response\Debug) using
File Load Program
10. Run the program using „Debug Run or F5
11. To view the output graphically
Select ViewGraph Time and Frequency
12. Observe the values in the output window.

PROGRAM:

// Linear convolution program in c language using CC Studio


#include<stdio.h>
int x[15],h[15],y[15];
main()
{
int i,j,m,n;
Dr K V Subba Reddy College Engineering For Women Page 33
DSP Lab Manual

printf("\n enter value for m");


scanf("%d",&m);
printf("\n enter value for n");
scanf("%d",&n);
printf("Enter values for i/p x(n):\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter Values for i/p h(n) \n");
for(i=0;i<n; i++)
scanf("%d",&h[i]);
// padding of zeros
for(i=m;i<=m+n-1;i++)
x[i]=0;
for(i=n;i<=m+n-1;i++)
h[i]=0;
/* convolution operation */
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(x[j]*h[i-j]);
}
}
//displaying the o/p
for(i=0;i<m+n-1;i++)
printf("\n The Value of output y[%d]=%d",i,y[i]);
}

OUTPUT:-

enter value for m 4


enter value for n 4
Enter values for i/p 1234
Enter Values for n 1234

The Value of output y[0]=1


The Value of output y[1]=4
The Value of output y[2]=10
The Value of output y[3]=20
The Value of output y[4]=25
The Value of output y[5]=24
The Value of output y[6]=16

RESULT: Thus linear convolution of two sequences using C6713 simulator

Dr K V Subba Reddy College Engineering For Women Page 34


DSP Lab Manual

CIRCULAR CONVOLUTION

AIM : To write a program in ‘C’ to compute circular convolution between two discrete time
sequences.

APPARATUS:

 Operating System - Windows XP


 Software - CC STUDIO 3
 DSK 6713 DSP Trainer kit.
 USB Cable
 Power supply

PROGRAM

#include<stdio.h>
#include<math.h>
int m,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
printf(" enter the length of the first sequence\n");
scanf("%d",&m);
printf(" enter the length of the second sequence\n");
scanf("%d",&n);
printf(" enter the first sequence\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf(" enter the second sequence\n");
for(j=0;j<n;j++)
scanf("%d",&h[j]);
if(m-n!=0) /*If length of both sequences are not equal*/
{
if(m>n) /* Pad the smaller sequence with zero*/
{
for(i=n;i<m;i++)
h[i]=0;
n=m;
}
for(i=m;i<n;i++)
x[i]=0;
m=n;
}
y[0]=0;
a[0]=h[0];
for(j=1;j<n;j++) /*folding h(n) to h(-n)*/
a[j]=h[n-j];
/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
Dr K V Subba Reddy College Engineering For Women Page 35
DSP Lab Manual

for(k=1;k<n;k++)
{
y[k]=0;
/*circular shift*/
for(j=1;j<n;j++)
x2[j]=a[j-1];
x2[0]=a[n-1];
for(i=0;i<n;i++)
{
a[i]=x2[i];
y[k]+=x[i]*x2[i];
}
}
/*displaying the result*/
printf(" the circular convolution is\n");
for(i=0;i<n;i++)
printf("%d \t",y[i]);

TEST DATA enter the length of the first sequence :2


enter the length of the second sequence :2
enter the first sequence :1 2
enter the second sequence :1 2

EXPECTED OUTPUT: The circular convolution is :54

RESULT: Thus the Circular convolution between two discrete time sequences is performed
using C6713 simulator

Dr K V Subba Reddy College Engineering For Women Page 36


DSP Lab Manual

3. N-POINT FAST FOURIER TRANSFORM

AIM: To find the DFT of a sequence using FFT algorithm using C6713 simulator

EQUIPMENTS:
 Operating System - Windows XP
 Software - CC STUDIO 3
 DSK 6713 DSP Trainer kit.
 USB Cable
 Power supply

PROCEDURE:

1) Open Code Composer Studio, make sure the DSP kit is turned on.
2) Start a new project using ‘Project-new ‘ pull down menu, save it in a
3) separate directory(c:\ti\myprojects) with name “FFT.pjt”.
4) Add the source files “fft256.c“ and “fft.C” in the project using
5) ‘Projectadd files to project’ pull down menu.
6) Add the linker command file “hello.cmd”.
7) Add the rts file “rts6700.lib” .
8) Compile the program using the ‘Project-compile’ pull down menu or by
9) clicking the shortcut icon on the left side of program window.
10) Load the program in program memory of DSP chip using the ‘File-load program’ pull
down menu.
11) Run the program and observe output using graph utility.

PROGRAM

// N-point Fast Fourier Transform (FFT) algorithm program in c language using CC


Studio //
#include<stdio.h>
#include<math.h>
void main ()
{
short N=8;
short X[8]={1,2,3,4,4,3,2,1};//test data
float pi=3.1416;
float sumRe=0, sumlm=0;//init real/imag components
float cosine=0,sine=0;//initialize cosine/sine components
//output Real and imaginary components
float out_real[8]={0.0},out_imag[8]={0.0};
int n=0, k=0;
for(k=0;k<N;k++)

Dr K V Subba Reddy College Engineering For Women Page 37


DSP Lab Manual

{
sumRe=0;
sumlm=0;
for(n=0;n<N;n++)
{
cosine=cos(2*pi*k*n/N);
sine=sin(2*pi*k*n/N);
sumRe=sumRe+X[n]*cosine;
sumlm=sumlm-X[n]*sine;
}
out_real[k]=sumRe;
out_imag[k]=sumlm;
printf("[%d]%7.3f%7.3f\n",k,out_real[k],out_imag[k]);
}
}

OUTPUT:

RESULT: N-Point FFT program was written and implemented using C6713 simulator

Dr K V Subba Reddy College Engineering For Women Page 38


DSP Lab Manual

4. FIR FILTER DESIGN

AIM: To verify FIR filter using C6713 simulator

EQUIPMENTS:-

Operating System - Windows XP


Software - CC STUDIO 3
DSK 6713 DSP Trainer kit.
USB Cable
Power supply

PROGRAM:

#include<stdio.h>
#include<math.h>
#define pi 3.1415
int n,N,c;
float wr[64],wt[64];
void main()
{
printf("\n enter no. of samples,N= :");
scanf("%d",&N);
printf("\n enter choice of window function: 1.rect 2. triang \n c= :");
scanf("%d",&c);
printf("\n elements of window function are:");
switch(c)
{
case 1:
for(n=0;n<=N-1;n++)
{
wr[n]=1;
printf(" \n wr[%d]=%f",n,wr[n]);
}
break;
case 2:
for(n=0;n<=N-1;n++)
{
wt[n]=1-(2*(float)n/(N-1));
printf("\n wt[%d]=%f",n,wt[n]);
}
break;
}
}

Dr K V Subba Reddy College Engineering For Women Page 39


DSP Lab Manual

OUTPUT:

Rectangular Window:

Triangular Window ;

RESULT: Here we designed FIR filter using C6713 simulator

Dr K V Subba Reddy College Engineering For Women Page 40


DSP Lab Manual

5. IIR FILTER DESIGN


AIM: To verify IIR filter using C6713 simulator.

EQUIPMENTS:-

Operating System - Windows XP


Software - CC STUDIO 3
DSK 6713 DSP Trainer kit.
USB Cable
Power supply

PROGRAM:
#include<stdio.h>
#include<math.h>
int i,w,wc,c,N;
float H[100];
float mul(float, int);
void main()
{
printf("\n enter order of filter ");
scanf("%d",&N);
printf("\n enter the cutoff freq ");
scanf("%d",&wc);
printf("\n enter the choice for IIR filter 1. LPF 2.HPF ");
scanf("%d",&c);
switch(c)
{
case 1:
for(w=0;w<100;w++)
{
H[w]=1/sqrt(1+mul((w/(float)wc),2*N));
printf("H[%d]=%f\n",w,H[w]);
}
break;
case 2:
for(w=0;w<=100;w++)
{
H[w]=1/sqrt(1+mul((float)wc/w,2*N));
printf("H[%d]=%f\n",w,H[w]);
}
break;
}}
float mul(float a,int x)
{
for(i=0;i<x-1;i++)
a*=a;
return(a);
}

Dr K V Subba Reddy College Engineering For Women Page 41


DSP Lab Manual

OUTPUT FOR IIR FILTER LPF


enter order of filter 2
enter the cutoff freq 50
enter the choice for IIR filter 1. LPF 2.HPF: 1

OUTPUT FOR IIR FILTER HPF


enter order of filter 2
enter the cutoff freq 50
enter the choice for IIR filter 1. LPF 2.HPF: 2

RESULT: Here we designed IIR filter using C6713 simulator

Dr K V Subba Reddy College Engineering For Women Page 42


DSP Lab Manual

ADDITIONAL EXPERIMENTS

Experiment No: 1

Implementation of Decimation Process

AIM: To implement the decimation of given sequence by factor M by using MAT LAB
Software.

APPARATUS: (i) MATLAB Software


(ii) Computer

PROGRAM:
clc;
close all;
clear all;
M = input('enter Down-sampling factor : ');
N = input('enter number of samples :');
n = 0:N-1;
x = sin(2*pi*0.043*n) + sin(2*pi*0.031*n);
y = decimate(x,M,'fir');
subplot(2,1,1);
stem(n,x(1:N));
title('Input Sequence');
xlabel('Time index n');
ylabel('Amplitude');
subplot(2,1,2);
m = 0:(N/M)-1
stem(m,y(1:N /M));
title('Output Sequence');
xlabel('Time index n');ylabel('Amplitude');

OUTPUT:
enter Down-sampling factor : 3
enter number of samples :100

Dr K V Subba Reddy College Engineering For Women Page 42


DSP Lab Manual

Input Sequence
2

1
Amplitude

-1

-2
0 10 20 30 40 50 60 70 80 90 100
Time index n
Output Sequence
2

1
Amplitude

-1

-2
0 5 10 15 20 25 30 35
Time index n

RESULT: The decimator for a given sequence is observed for chosen factor M. Hence the
theory and practical is verified.

Dr K V Subba Reddy College Engineering For Women Page 43


DSP Lab Manual

Experiment No: 2

Implementation of Interpolation Process

AIM: To implement the interpolation for given sequence by factor L.

APPARATUS: (i) MATLAB Software

(ii) Computer

PROGRAM:
clc;
close all;
clear all;
L = input('Up-sampling factor = ');
N = input('enter number of samples :');
n = 0:N-1;
x = sin(2*pi*0.043*n) + sin(2*pi*0.031*n);
y = interp(x,L);
subplot(2,1,1);
stem(n,x(1:N));
title('Input Sequence');
xlabel('Time index n');
ylabel('Amplitude');
subplot(2,1,2);
m = 0:(N*L)-1;
stem(m,y(1:N*L));
title('Output Sequence');
xlabel('Time index n');
ylabel('Amplitude');

OUTPUT:
Up-sampling factor = 3
enter number of samples :100

Dr K V Subba Reddy College Engineering For Women Page 44


DSP Lab Manual

Input Sequence
2

1
Amplitude

-1

-2
0 10 20 30 40 50 60 70 80 90 100
Time index n

Output Sequence
2

1
Amplitude

-1

-2
0 50 100 150 200 250 300
Time index n

RESULT: The interpolation of given sequence is observed for factor value L. Hence the
theory and practical are verified.

Dr K V Subba Reddy College Engineering For Women Page 45

You might also like