Professional Documents
Culture Documents
LABORATORY MANUAL OF
Prepared by
K PRASAD BABU M.Tech (Ph.D)
Associate Professor
SYED NOORULLAH M.Tech
Assistant Professor
DEPARTMENT OF
ELECTRONICS & COMMUNICATIONS ENGINEERING
INDEX
Design Of IIR Filter Using Any Of The Available Methods And Verify The
7 Frequency Response Of The Filter 28
APPARATUS: Computer
PROCEDURE:
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
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')
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
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
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
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
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
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
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
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.
APPARATUS: Computer
PROCEDURE:
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']);
RESULT: Computed the Average power and energy of the given signal done using
MATLAB.
APPARATUS: Computer
PROCEDURE:
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------>');
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');
OUTPUT:
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
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----->
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.
APPARATUS: Computer
PROCEDURE:
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
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 =
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
APPARATUS: Computer
PROCEDURE:
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
2
3.5
1.5
3
1
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 --->
APPARATUS: Computer
PROCEDURE:
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');
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
>>
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-->
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-->
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
APPARATUS: Computer
PROCEDURE:
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);
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:
>>
-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. -->
2
Frequency response of IIR HPF is:
>>
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.
AIM:- To generate a sine wave and square wave using C6713 simulator
EQUIPMENTS:-
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
ProjectAdd 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
ProjectAdd files to Project (path: C\CCStudio\cgtools\lib\rts6700.lib)
7. Compile the program using „projectCompile‟ menu or by Ctrl+F7
8. Build the program using „projectBuild‟ menu or by F7
9. Load the sinewave.out file (from project folder lcconv\Debug) using FileLoad Program
10. Run the program using „DebugRun or F5
11. To view the output graphically Select ViewGraphTime 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>
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
2. LINEAR CONVOLUTION
EQUIPMENTS:-
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 ViewGraph Time and Frequency
12. Observe the values in the output window.
PROGRAM:
OUTPUT:-
CIRCULAR CONVOLUTION
AIM : To write a program in ‘C’ to compute circular convolution between two discrete time
sequences.
APPARATUS:
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]);
RESULT: Thus the Circular convolution between two discrete time sequences is performed
using C6713 simulator
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) ‘Projectadd 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
{
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
EQUIPMENTS:-
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;
}
}
OUTPUT:
Rectangular Window:
Triangular Window ;
EQUIPMENTS:-
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);
}
ADDITIONAL EXPERIMENTS
Experiment No: 1
AIM: To implement the decimation of given sequence by factor M by using MAT LAB
Software.
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
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.
Experiment No: 2
(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
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.