DSP Lab r20 Regulation
DSP Lab r20 Regulation
OBSERVATION BOOK
Branch :_____________________________________________
The Programs shall be implemented in Software (Using MATLAB / Lab View / C Programming/
Equivalent) and Hardware (Using TI / Analog Devices / Motorola / Equivalent DSP processors).
List of Experiments:
1. Generate the following standard discrete time signals.
i) Unit Impulse ii) Unit step iii) Ramp iv) Exponential v) Sawtooth
2. Generate sum of two sinusoidal signals and find the frequency response (magnitude and
phase).
3. Implement and verify linear and circular convolution between two given signals.
4. Implement and verify autocorrelation for the given sequence and cross correlation between
two given signals.
5. Compute and implement the N-point DFT of a given sequence and compute the power
density spectrum of the sequence.
6. Implement and verify N-point DIT-FFT of a given sequence and find the frequency response
(magnitude and phase).
7. Implement and verify N-point IFFT of a given sequence.
8. Design IIR Butterworth filter and compare their performances with different orders (Low
Pass Filter /High Pass Filter)
9. Design IIR Chebyshev filter and compare their performances with different orders (Low Pass
Filter /High Pass Filter).
10. Design FIR filter (Low Pass Filter /High Pass Filter) using windowing technique.
i. Using rectangular window
ii. Using hamming window
iii. Using Kaiser window
11. Design and verify Filter (IIR and FIR) frequency response by using Filter design and Analysis
Tool.
12. Compute the Decimation and Interpolation for the given signal.
13. Real time implementation of an audio signal using a digital signal processor.
14. Compute the correlation coefficient for the two given audio signals of same length using a
digital signal processor.
LABORATORY INSTRUCTIONS
➢ While entering the Laboratory, the students should leave the footwear
outside the lab. Female Students should tie their hair back.
➢ The students should bring their observation note book, practical manual,
record note book and calculator and necessary stationary items for the lab
classes without which the students will not be allowed for doing the
practical.
➢ Each experiment after completion should be written in the observation note
book and should be corrected by the lab in charge on the same day of the
practical class.
➢ Each experiment should be written in the record note book only after getting
signature from the lab in charge in the observation note book.
➢ Record note book should be submitted in the next lab after completion of
experiment.
➢ 100% attendance should be maintained for the practical classes
INTRODUCTION TO MATLAB
INTRODUCTION: MATLAB is a mathematical software package which is used extensively
in academic and industry.
➢ MATLAB stands for MATrix LABoratory.
➢ It is one of the leading Scientific and Technical computing software, used by many
engineers and scientists.
➢ This was developed by CLEVE MOLER, a professor of mathematics and computer
science.
➢ Over the last two decades MATLAB has evolved into a much powerful and versatile
package, useful for a wide variety of academic, research and industrial applications.
IMPORTANCE OF MATLAB:
➢ As a matrix based system it is great tool for simulation and data analysis.
➢ It is simple, powerful and easy to learn programming language as it provides extensive
online help.
➢ Unlike other high-level languages like FORTRAN, C, etc., it does not require any
variable declaration and dimension statements at the beginning.
➢ MATLAB programs written for solving complex problems take a fraction of time and
look very small in general when compared to the codes of high-level language.
➢ It also enables the users to write their own functions for easy customization.
➢ It is excellent and very powerful for two and three dimensional graphics and animation.
➢ It is an indispensable Graphical User Interface (GUI) tool and used for proper
understanding of concepts in advanced subjects like mathematics, signals and systems,
control systems, digital signal processing, VLSI design, etc .
➢ It also provides several optional ‘tool boxes’ such as statistics toolbox, control system
toolbox, signal processing toolbox, etc. where toolbox provides a set of functions written
for specific application.
➢ It is compatible, with most operating systems such as windows, Linux, etc.
➢ It uses matrix notation it replaces several ‘for’ loops which are usually found in C type of
codes.
GETTING STARTED WITH MATLAB:
➢ LAUNCHING MATLAB: If MATLAB is installed on your computer, you can possibly
find the MATLAB icon as a shortcut on your desktop of the windows-based system, after
you login to the computer using your user id and the password.
➢ MATLAB DESKTOP LAYOUT: When you launch MATLAB for the first time the
MATLAB desktop appears with a default layout. You can change the desktop
configuration to suits your need.
INDEX
EXPERIMENT: 1 DATE:___________
ylabel('amplitude');
title('unit step signal');
%generation of unit step sequence
subplot(2,1,2);
stem(n,y3);
xlabel('n');
ylabel('amplitude');
title('unit step sequence');
% Ramp signal
clc;
close all;
n= input('enter the length of ramp');
t= 0: n;
subplot(2,1,1)
plot(t);
xlabel('t');
ylabel('amplitude');
title ('ramp signal')
subplot(2,1,2);stem(t);
xlabel('n');
ylabel('amplitude');
title ('ramp sequence')
8
x 10 exponential sequence
5
4.5
3.5
3
amplitude
2.5
1.5
0.5
0
0 20 40 60 80 100 120
samples
RESULT:
EXPERIMENT: 2 DATE:___________
Generate sum of two sinusoidal signals and find the frequency response
(magnitude and phase).
AIM: To write a MATLAB program to generate and add two sinusoidal signals
EQUIPMENTS REQUIRED:
PC with MATLAB Software
PROCEDURE:-
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAM:
clear all;
close all;
clc;
a1 = input('amplitude of signal 1');
a2 = input('amplitude of signal 2');
f1 = input('frequency of signal 1');
f2 = input('frequency of signal 2');
p1 = input('phase of signal 1');
p2 = input('phase of signal 2');
t = 0: 2*pi/100 : 2*pi;
x = a1 * sin (f1*t + p1);
y = a2 * sin(f2*t + p2);
z = x+y;
subplot(4,1,1); plot(t,x,'-g');%displays sine signal 1
subplot(4,1,2); plot(t,y,'-g');%displays sine signal 2
subplot(4,1,3); plot(t,z,'-b');%displays sum of two signals
DEPT. OF ECE, SEAGI Page 10
20A04502P - Digital Signal Processing Lab
Wave forms:
RESULT:
EXPERIMENT: 3 DATE:___________
Implement and verify linear and circular convolution between two given
signals.
AIM: To write a MATLAB Program and finding the Convolution (linear & circular) of discrete
sequence without using built in functions.
EQUIPMENTS REQUIRED:
PC with MATLAB Software
PROCEDURE:-
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
Program:
%Linear Convolution
clc;
clear all;
close all;
disp ('linear convolution program');
x=input('enter input x(n):');
m=length(x);
h=input('enter input h(n):');
n=length(h);
x=[x,zeros(1,n)];
l1=0:length(x)-1;
subplot(2,2,1);
stem(l1,x);
OUTPUT:
Linear convolution program
Enter i/p x(n):[1 2 3]
Enter i/p h(n):[3 4 5]
Convolution of x(n) & h(n) is y(n):
3 10 22 22 15
%Circular Convolution
clc;
clear all;
close all;
disp('circular convolution program');
x= input('enter input x(n):');
m=length(x);
h=input('enter input sequence h(n)');
n=length(h);
subplot(2,2,1), stem(x);
title(‘input sequencce x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
subplot(2,2,2), stem(h);
title('input sequencce h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
disp('circular convolution of x(n) & h(n) is y(n):');
if(m-n~=0)
if(m>n)
h=[h,zeros(1,m-n)];
n=m;
end
x=[x,zeros(1,n-m)];
m=n;end
y=zeros(1,n);
y(1)=0;
a(1)=h(1);
for j=2:n
a(j)=h(n-j+2);
end
%ciruclar conv
for i=1:n
y(1)=y(1)+x(i)*a(i);
end
for k=2:n
y(k)=0;
% circular shift
for j=2:n
x2(j)=a(j-1);
end
x2(1)=a(n);
for i=1:n
if(i<n+1)
a(i)=x2(i);
y(k)=y(k)+x(i)*a(i);
end
end
end
disp(y);
subplot(2,2,[3,4]),stem(y);
title('Circular convolution of x(n) & h(n) is:');
xlabel('---->n');
ylabel('---->y(n)');
grid;
OUTPUT:
Circular Convolution Program
Enter I/P x(n):[1 2 3]
Enter I/P Sequence h(n):[4 6 7]
Circular Convolution of x(n) & h(n) Is y(n):
36 35 31
4
2
---->x(n)
---->h(n)
2
1
1
0 0
0 1 2 3 4 5 0 1 2 3 4 5
---->n ---->n
Linear Convolution of x(n) & h(n) is :
30
20
---->y(n)
10
0
0 0.5 1 1.5 2 2.5 3 3.5 4
---->n
6
2
---->x(n)
---->h(n)
4
1
2
0 0
1 1.5 2 2.5 3 1 1.5 2 2.5 3
---->n ---->n
Circular convolution of x(n) & h(n) is:
40
30
---->y(n)
20
10
0
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
---->n
RESULTS
EXPERIMENT: 4 DATE:___________
Implement and verify autocorrelation for the given sequence and cross
correlation between two given signals.
AIM: To write a MATLAB Program and finding the Convolution (linear & circular) of discrete
sequence without using built in functions.
EQUIPMENTS REQUIRED:
PC with MATLAB Software
PROCEDURE: -
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAM:
%Cross Correlation
clc;
clear all;
close all;
z=input('Enter first sequence x(n):');
n1=length(z);
x=fliplr(z);
m=length(x);
h=input('Enter Second sequence h(n):');
n=length(h);
l1=0:n1-1;
figure;
subplot(2,2,1);
stem(l1,z);
ylabel('---->y(n)');
grid;
OUTPUT:
%Cross Correlation
Enter first sequence x(n):[1 2 3]
Enter Second sequence h(n):[4 5]
Cross Correlation of x(n) & h(n) is y(n):
12 23 14 5
%Auto Correlation
clc;
clear all;
close all;
x=input('Enter the sequence x(n):');
n=length(x);
z=fliplr(x);
m=length(z);
l1=0:n-1;
figure;
subplot(2,1,1);
stem(l1,x);
title('Input Sequence x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');
grid;
x=[x,zeros(1,m)];
z=[z,zeros(1,n)];
disp('Auto Correlation of x(n) & x(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)+z(j)*x(i-j+1);
end
end
end
disp(y);
l2=-(n-1):(n-1);
subplot(2,1,2);
stem(l2,y);
title('Auto Correlation of x(n) & x(n) is :');
xlabel('---->n');
ylabel('---->y(n)');
grid;
OUTPUT:
%Auto Correlation
Enter the sequence x(n):[1 2 3]
Auto Correlation of x(n) & x(n)is y(n):
3 8 14 8 3
2 4
---->x(n)
---->h(n)
1 2
0 0
0 0.5 1 1.5 2 0 0.2 0.4 0.6 0.8 1
---->n ---->n
Cross Correlation of x(n) & h(n) is :
30
20
---->y(n)
10
0
-2 -1.5 -1 -0.5 0 0.5 1
---->n
2
---->x(n)
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
---->n
Auto Correlation of x(n) & x(n) is :
15
10
---->y(n)
0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
---->n
RESULTS:
EXPERIMENT: 5 DATE:___________
Compute and implement the N-point DFT of a given sequence and compute
the power density spectrum of the sequence.
AIM: To Compute and implement the N-point DFT of a given sequence and compute the power
density spectrum of the sequence.
EQUIPMENTS REQUIRED:
PC with MATLAB Software
PROCEDURE: -
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAM:
% Program to find the DFT/IDFT of a sequence without using the inbuilt functions
clc
close all;
clear all;
xn=input('Enter the sequence x(n)'); %Get the sequence from user
ln=length(xn); %find the length of the sequence
xk=zeros(1,ln); %initilise an array of same size as that of input sequence
ixk=zeros(1,ln); %initilise an array of same size as that of input sequence
%code block to find the DFT of the sequence
for k=0:ln-1
for n=0:ln-1
xk(k+1)=xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/ln));
end
end
%code block to plot the input sequence
t=0:ln-1;
subplot(221);
stem(xn);
grid
ylabel ('Amplitude');
xlabel ('Time Index');
title('Input Sequence');
magnitude=abs(xk); % Find the magnitudes of individual DFT points
%code block to plot the magnitude response
t=0:ln-1;
subplot(222);
stem(t,magnitude);
grid
ylabel ('Amplitude');
xlabel ('K');
title ('Magnitude Response');
phase=angle(xk); % Find the phases of individual DFT points
%code block to plot the magnitude sequence
t=0:ln-1;
subplot(223);
stem(t,phase);
grid
ylabel ('Phase');
xlabel ('K');
title('Phase Response');
% Code block to find the IDFT of the sequence
for n=0:ln-1
for k=0:ln-1
ixk(n+1)=ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/ln));
end
end
ixk=ixk./ln;
%code block to plot the input sequence
t=0:ln-1;
subplot(224);
stem(t,xn);
grid;
ylabel ('Amplitude');
xlabel ('Time Index');
title ('IDFT sequence');subplot(3,1,3);
phase=angle(X);
stem(k,phase);
title('Phase Spectrum');
xlabel('k');
ylabel('Phase');
grid;
OUTPUT
RESULT:
EXPERMENT: 6 DATE:___________
Implement and verify N-point DIT-FFT of a given sequence and find the
frequency response (magnitude and phase).
AIM: To Implement and verify N-point DIT-FFT of a given sequence and find the frequency
response (magnitude and phase).
EQUIPMENTS REQUIRED:
PC with MATLAB Software
PROCEDURE:-
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAM:-
clc; clear all;
x = input('Enter the input sequence = '); N = length(x);
for k = 1:N y(k) = 0;
for n = 1:N
y(k) =y(k)+x(n)*exp(-1i*2*pi*(k-1)*(n-1)/N); end
end
%code block to plot the input sequence t = 0:N-1;
subplot(2,2,1);
stem(t,x); ylabel('Amplitude ---->');
xlabel('n ---->'); title('Input Sequence'); grid on;
magnitude = (y); % Find the magnitudes of individual FFT points disp('FFT
Sequence = ');
disp(magnitude);
%code block to plot the FFT sequence t = 0:N-1;
THEORITICAL CALCULATIONS:
OUTPUT:
FFT
Sequence =
Columns 1
through 5
Columns 6 through 8
EXPERIMENT: 7 DATE:___________
EQUIPMENTS REQUIRED:
PC with MATLAB Software
PROCEDURE:-
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAM:
clc;
clear all;
xlabel('n ---->'); title('Input Sequence'); grid on; R = length(y); for n = 1:R x1(n) = 0;
for k = 1:R
end
end
t = 0:R-1;
subplot(2,2,3);
stem(t,x1);
disp(x1);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('IFFT sequence');
grid on;
INPUT
input Sequence =
[
6.0000 -0.7071 - 1.7071i 1.0000 - 1.0000i 0.7071+0.2929i 0 -0.0000i
OUTPUT:
[1 1 1 1 1 1 0 0]
EXPERMENT: 8 DATE:___________
Design IIR Butterworth filter and compare their performances with different orders (Low Pass
Filter /High Pass Filter)
AIM: To design IIR Butterworth filter and compare their performances with different orders
(Low Pass Filter /High Pass Filter)
EQUIPMENTS REQUIRED:
PC with MATLAB Software
PROCEDURE:-
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAM:
%IIR/LP
clear all; close all
%INPUT:-
fp=input('Enter the pass band frequency
fp = '); fs=input('Enter the stop band frequency fs = ');
rp=input('Enter the pass band attenuation rp = ');
rs=input('Enter the stop band attenuation rs = ');
f=input ('Enter the sampling frequency f = ');
wp=2*fp/f;
ws=2*fs/f; [n,wn]=buttord(wp,ws,rp,rs);
[b,a]=butter(n,wn,'low'); freqz(b,a,500,f);
title ('Magnitude and phase response of the IIR butter worth filter');
INPUTS:
Enter the pass band
frequency fp = 20 Enter the
stop band frequency fs = 50
Enter the pass band
attenuation rp = 1 Enter the
stop band attenuation rs = 2
Enter the sampling
frequency f =1000
OUTPUT:
IIR/HP
clear all; close all;
fp=input('Enter the pass band frequency fp =');
fs=input('Enter the stop band frequency fs = ');
rp=input('Enter the pass band attenuation rp = ');
rs=input('Enter the stop band attenuation rs = ');
f=input ('Enter the sampling frequency f =');
wp=2*fp/f; ws=2*fs/f;
[n,wn]=buttord(wp,ws,rp,rs);
[b,a]=butter(n,wn,'high'); freqz(b,a,500,f);
title ('Magnitude and phase respose of the IIR butterworth filter');
INPUT:-
Enter the pass band frequency fp = 20
Enter the stop band frequency fs = 50
Enter the pass band attenuation rp = 1
Enter the stop band attenuation rs = 2
Enter the sampling frequency f =1000
OUTPUT:
RESULT:
EXPERMENT: 9 DATE:___________
Design IIR Chebyshiev filter and compare their performances with different
orders (Low Pass Filter /High Pass Filter).
AIM: To design IIR Chebyshiev filter and compare their performances with different orders
(Low Pass Filter /High Pass Filter).
EQUIPMENTS REQUIRED:
PC with MATLAB Software
PROCEDURE:-
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAM:
%IIR/LP
fp=input('Enter the pass band frequency fp = ');
fs=input('Enter the stop band frequency fs = ');
rp=input('Enter the pass band attenuation rp = ');
rs=input('Enter the stop band attenuation rs = ');
f=input ('Enter the sampling frequency = ');
wp=2*fp/f;
ws=2*fs/f;
[n,wn]=cheb1ord(wp,ws,rp,rs);
[b,a]=cheby1(n,0.5,wn,'low');
freqz(b,a,500,f);
title ('Magnitude and phase respose of the IIR butterworth filter');
INPUTS:
Enter the pass band frequency fp = 20
Enter the stop band frequency fs = 50
Enter the pass band attenuation rp = 1
Enter the stop band attenuation rs = 2
Enter the sampling frequency f =1000
OUTPUT:-
%IIR/HP
clear all; close all;
fp=input('Enter the pass band frequency fp =');
fs=input('Enter the stop band frequency fs = ');
rp=input('Enter the pass band attenuation rp = ');
rs=input('Enter the stop band attenuation rs = ');
f=input ('Enter the sampling frequency f =');
wp=2*fp/f; ws=2*fs/f;
[n,wn]=cheb1ord(wp,ws,rp,rs);
[b,a]=cheby1(n,0.5,wn,'high'); freqz(b,a,500,f);
title('Magnitude and phase response of the IIR chebyshev filter');
INPUTS:-
Enter the pass band frequency fp = 20
Enter the stop band frequency fs = 50
Enter the pass band attenuation rp = 1
Enter the stop band attenuation rs = 2
Enter the sampling frequency f =1000
OUTPUT:
RESULT:
EXPERMENT: 10 DATE:___________
Design FIR filter (Low Pass Filter /High Pass Filter) using windowing
technique.
i. Using rectangular window
ii. Using hamming window
iii. Using Kaiser Window
AIM: To design FIR filter (Low Pass Filter /High Pass Filter) using windowing technique.
i. Using rectangular window ii. Using hamming window iii. Using Kaiser window
EQUIPMENTS REQUIRED:
PC with MATLAB Software
PROCEDURE:-
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAMS:
A) rectangular window
clc;
close all;
clear all;
format long;
rp=input('enter the pass band ripple');
rs=input('enter the stop band ripple');
fp=input('enter the pass band frequency');
fs=input('enter the stop band frequency');
f=input('enter the sampling frequency');
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;
DEPT. OF ECE, SEAGI Page 36
20A04502P - Digital Signal Processing Lab
y=boxcar(n1);
%Lowpass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,1);
plot(o/pi,m);
ylabel ('gain in db---->');
xlabel (‘normalized frequency---->');
title('FIR filter using Rectangular window of LPF ----');
grid on;
%highpass filter
b=fir1(n,wp,’high’, y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,2);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
grid on;
INPUT:-
Enter the stopband frequency 2000 Enter the sampling frequency 9000
OUTPUT:
-50
-100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalized frequency---->
FIR filter using Rectangular window of HPF ----
50
gain in db---->
-50
-100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency---->
B) hamming window
clear all;
close all;
clc;
n=1000;
fp=300;
fs=1000;
fn=2*fp/fs;
window=hamming(n+1);
b=fir1(n,fn,'low',window);
[h,w]=freqz(b,1,256);
subplot(2,1,1);
plot(w/pi,abs(h));
title('mag response of lpf');
ylabel('gain');
xlabel('normalised freq');
subplot(2,1,2);
plot(w/pi,angle(h));
title('phase response of lpf');
ylabel('angle');
xlabel('normalised freq');
clear all;
close all;
clc;
n=1000;
fp=300;
fs=1000;
fn=2*fp/fs;
window=hamming(n+1);
b=fir1(n,fn,'high',window);
[h,w]=freqz(b,1,256);
subplot(2,1,1);
plot(w/pi,abs(h));
title('mag response of hpf');
ylabel('gain');
xlabel('normalised freq');
subplot(2,1,2);
plot(w/pi,angle(h));
title('phase response of hpf');
ylabel('angle');
xlabel('normalised freq');
1
gain
0.5
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised freq
phase response of hpf
4
2
angle
-2
-4
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
normalised freq
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,1);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Kaiser window of LPF ----');
grid on;
%highpass filter
b=fir1(n,wp,’high’,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,2);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Kaiser window of HPF ----');
grid on;
INPUT:-
Enter the pass band ripple 0.02
OUTPUT:
0
gain in db---->
-50
-100
-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency---->
FIR filter using Kaiser window of HPF ----
50
0
gain in db---->
-50
-100
-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalised frequency---->
RESULT:
EXPERMENT: 11 DATE:___________
Design and verify Filter (IIR and FIR) frequency response by using Filter
design and Analysis Tool.
AIM: To design and verify Filter (IIR and FIR) frequency response by using Filter design and
Analysis Tool.
EQUIPMENTS REQUIRED:
PC with MATLAB Software
PROCEDURE:-
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAMS
%BUTTERWORTH LOWPASS FILTER
clear all;
fs=100;
t=(0:100)/fs;
s1=sin(2*pi*t*5);
s2=sin(2*pi*t*20);
s3=sin(2*pi*t*30);
s=s1+s2+s3;
subplot(3,2,3);
plot(t,s);
axis([0 0.5 -3 3]);
DEPT. OF ECE, SEAGI Page 42
20A04502P - Digital Signal Processing Lab
title('test signal');
n=4;
wn=10/50;
[b a]=butter(n,wn);
[h w]=freqz(b,a,512);
subplot(3,2,1);
plot(w*fs/(2*pi),abs(h));
title('butterworth lpf characteristics');
sf=filter(b,a,s);
subplot(3,2,4);
plot(t,sf);
xlabel('time');
ylabel('time waveform');
axis([0 0.5 -1 1]);
title('after filtering in lowpass filter');
s=fft(s,512);
sf=fft(sf,512);
w=(0:255)/256*(fs/2);
subplot(3,2,5);
plot(w,abs(s(1:256)));
xlabel('frequency');
ylabel('F(t)');
title('F(t) of test signal');
subplot(3,2,6);
plot(w,abs(sf(1:256)));
xlabel('frequency');
ylabel('F(t)');
OUTPUT:
0
0 20 40 60
time waveform
1
2
0 0
-2
-1
0 0.1 0.2 0.3 0.4 0 0.1 0.2 0.3 0.4
time
F(t) of test signal
100 50
F(t)
F(t)
50
0 0
0 20 40 60 0 20 40 60
frequency frequency
%'butterworth hpf
clear all;
fs=100;
t=(0:100)/fs;
s1=sin(2*pi*t*5);
s2=sin(2*pi*t*20);
s3=sin(2*pi*t*30);
s=s1+s2+s3;
subplot(3,2,3);
plot(t,s);
axis([0 0.5 -3 3]);
title('test signal');
n=4;
wn=30/50;
[b a]=butter(n,wn,'high');
DEPT. OF ECE, SEAGI Page 44
20A04502P - Digital Signal Processing Lab
[h w]=freqz(b,a,512);
subplot(3,2,1);
plot(w*fs/(2*pi),abs(h));
title('butterworth hpf characteristics');
sf=filter(b,a,s);
subplot(3,2,4);
plot(t,sf);
xlabel('time');
ylabel('time waveform');
axis([0 0.5 -1 1]);
title('after filtering in highpass filter');
s=fft(s,512);
sf=fft(sf,512);
w=(0:255)/256*(fs/2);
subplot(3,2,5);
plot(w,abs(s(1:256)));
xlabel('frequency');
ylabel('F(t)');
title('F(t) of test signal');
subplot(3,2,6);
plot(w,abs(sf(1:256)));
xlabel('frequency');
ylabel('F(t)');
OUTPUT:
0
0 20 40 60
time waveform
1
2
0 0
-2
-1
0 0.1 0.2 0.3 0.4 0 0.1 0.2 0.3 0.4
time
F(t) of test signal
100 40
F(t)
F(t)
50 20
0 0
0 20 40 60 0 20 40 60
frequency frequency
RESULTS:
EXPERMENT: 12 DATE:___________
AIM: To Compute the Decimation and Interpolation for the given signal.
EQUIPMENTS REQUIRED:
PC with MATLAB Software
PROCEDURE:-
• Open MATALB
• Open new M-file
• Type the program
• Save in current directory
• Compile and run the program
• For the output see the command window / figure window
PROGRAMS
%DECIMATION
clc;
clear all;
close all;
N=250 ;
n=0:1:N-1;
x=sin(2*pi*n/15);
M=2;
figure(1)
stem(n,x);
grid on;
xlabel('No.of.Samples');
ylabel('Amplitude');
title('Original Sequence');
DEPT. OF ECE, SEAGI Page 47
20A04502P - Digital Signal Processing Lab
a=1;
b=fir1(5,0.5,'Low');
y=filter(b,a,x);
figure(2)
stem(n,y);
grid on;
xlabel('No.of.Samples');
ylabel('Amplitude');
title('Filtered Sequence');
Date:………… DSP Lab Manual ………
Turbomachinery Institute of Technology & Sciences, Hyd. 319
x1=y(1:M:N);
n1=1:1:N/M;
figure(3)
stem(n1-1,x1);
grid on;
xlabel('No.of.Samples');
ylabel('Amplitude');
title('Decimated Sequence');
OUTPUTS:
Original Sequence
1
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
0 50 100 150 200 250
No.of.Samples
Original sequence
Filtered Sequence
1
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
0 50 100 150 200 250
No.of.Samples
Filtered sequence
Decimated Sequence
1
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
0 20 40 60 80 100 120 140
No.of.Samples
Decimated sequence
%INTERPOLATION
clc;
clear all;
close all;
N=125;
n=0:1:N-1;
x=sin(2*pi*n/15);
L=2;
figure(1)
stem(n,x);
grid on;
xlabel('No.of.Samples');
ylabel('Amplitude');
title('Original Sequence');
x1=[zeros(1,L*N)];
n1=1:1:L*N;
j =1:L:L*N;
x1(j)=x;
figure(2)
stem(n1-1,x1);
grid on;
xlabel('No.of.Samples');
ylabel('Amplitude');
title('Upsampled Sequence');
a=1;
b=fir1(5,0.5,'Low');
y=filter(b,a,x1);
figure(3)
stem(n1-1,y);
grid on;
xlabel('No.of.Samples');
ylabel('Amplitude');
title('Interpolated Sequence');
OUTPUT:
Original Sequence
1
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
0 20 40 60 80 100 120 140
No.of.Samples
Original sequence
Upsampled Sequence
1
0.8
0.6
0.4
0.2
Amplitude
-0.2
-0.4
-0.6
-0.8
-1
0 50 100 150 200 250
No.of.Samples
Filtered sequence
Interpolated Sequence
0.5
0.4
0.3
0.2
0.1
Amplitude
-0.1
-0.2
-0.3
-0.4
-0.5
0 50 100 150 200 250
No.of.Samples
Interpolated sequence
RESULTS :
EXPERMENT: 1 DATE:___________
TMS320C6x DIGITAL SIGNAL PROCESSOR
INTRODUCTION
The TMS320C6713 (C6713) is based on the VLIW architecture, which is very well suited for numerically
intensive algorithms. The internal program memory is structured so that a total of eight instructions can be
fetched every cycle. For example, with a clock rate of 225MHz, the C6713 is capable of fetching eight 32-
bit instructions every 1/(225 MHz) or 4.44 ns. Features of the C6713 include 264 kB of internal memory
(8kB as L1P and L1D Cache and 256kB as L2 memory shared between program and data space), eight
functional or execution units composed of six arithmetic-logic units (ALUs) and two multiplier units, a
32-bit address bus to address 4 GB (gigabytes), and two sets of 32-bit general-purpose registers.
The C67xx (such as the C6701, C6711, and C6713) belong to the family of the C6x floating-point
processors, whereas the C62xx and C64xx belong to the family of the C6x fixed-point processors. The
C6713 is capable of both fixed- and floating point processing.
An application-specific integrated circuit (ASIC) has a DSP core with customized circuitry for a
specific application. A C6x processor can be used as a standard general-purpose DSp programmed for a
specific application. Specific-purpose digital signal processors are the modem, echo canceler, and others.
A fixed-point processor is better for devices that use batteries, such as cellular phones, since it uses less
power than does an equivalent floating-point processor. The fixed-point processors, C1x, C2x, and C5x,
are 16-bit processors with limited dynamic range and precision. The C6x fixed-point processor is a 32-bit
processor with improved dynamic range and precision. In a fixed-point processor, it is necessary to scale
the data. Overflow, which occurs when an operation such as the addition of two numbers produces a result
with more bits than can fit within a processor’s register, becomes a concern.
A floating-point processor is generally more expensive since it has more “real estate” or is a larger
chip because of additional circuitry necessary to handle integer as well as floating-point arithmetic.
Several factors, such as cost, power consumption, and speed, come into play when choosing a specific
DSp. The C6x processors are particularly useful for applications requiring intensive computations. Family
members of the C6x include both fixed-point (e.g., C62x, C64x) and floating-point (e.g., C67x)
processors. Other DSp’s are also available from companies such as Motorola and Analog Devices.
TMS320C6X ARCHITECTURE
The TMS320C6713 onboard the DSK is a floating-point processor based on the VLIW architecture [6–
10]. Internal memory includes a two-level cache architecture with 4 kB of level 1 program cache (L1P), 4
kB of level 1 data cache (L1D), and 256 kB of level 2 memory shared between program and data space. It
has a glueless (direct) interface to both synchronous memories (SDRAM and SBSRAM) and
asynchronous memories (SRAM and EPROM). Synchronous memory requires clocking but provides a
compromise between static SRAM and dynamic DRAM, with SRAM being faster but more expensive
than DRAM. On-chip peripherals include two McBSPs, two timers, a host port interface (HPI), and a 32-
bit EMIF. It requires 3.3 V for I/O and 1.26 V for the core (internal). Internal buses include a 32-bit
program address bus, a 256-bit program data bus to accommodate eight 32-bit instructions, two 32-bit
data address buses, two 64-bit data buses, and two 64-bit store data buses. With a 32-bit address bus, the
total memory space is 232 = 4GB, including four external memory spaces: CE0, CE1, CE2, and CE3.
Figure shows a functional block diagram of the C6713 processor included with CCS.
Step 13: Start Address ‘a’ and DSP data type- 32 bit floating point
EXPERMENT: 2 DATE:___________
AIM: To write a CC STUDIO Program for finding the Convolution of discrete sequence without
using built in functions for convolutions operations.
EQUIPMENTS REQUIRED:
PC with C. C STUDIO
Program:
/*linear convolution*/
#include<stdio.h>
int x[15],h[15],y[15];
main()
{
int i,j,m,n;
printf("\n enter value for m");
scanf("%d",&m);
printf("\n enter value for n");
scanf("%d",&n);
printf(" enter value 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[i]*h[i-j]);
}}
//displaying the output
for(i=0;i<m+n-1;i++)
printf("\n the value of output y[%d]=%d",i,y[i]);
}
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]);
}
OUTPUT:
enter value for m4
enter value for n4
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
OUTPUT:-
Enter the length of the first sequence
4
Enter the length of the second sequence
3
Enter the first sequence
1234
Enter the second sequence
123
The circular convolution is
18 16 10 16
EXPERMENT: 3 DATE:___________
Design of FIR filter using windowing technique and verify the frequency response of the filter.
AIM: To design FIR filter using windowing technique and verify the frequency
EQUIPMENTS REQUIRED:
PC with C. C STUDIO
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\n 1.rect \n 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;
}}
OUTPUT:
Rectangular window:
Triangular window:
RESULT:
EXPERMENT: 4 DATE:___________
Design of IIR filter using any of the available methods and verify the frequency response of
the filter
AIM: To design an IIR filter using any of the available methods and verify the frequency
response of the filter.
EQUIPMENTS REQUIRED:
PC with C. C STUDIO
Program:
//IIR FILTERS USING C
#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);
}
OUTPUT:
IIR FILTER (LPF )
RESULT: