5th SEM DSP LAB Manual (17ECL57)
5th SEM DSP LAB Manual (17ECL57)
VSM’s
Somashekhar R Kothiwale Institute of
Technology, Nipani-591237
DSP LAB
18ECL57
BY
Prof.GOVIND M R
1 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
INTRODUCTION TO MATLAB
MATLAB is a software package for high performance numerical computation
and visualization provides an interactive environment with hundreds of built in
functions for technical computation, graphics and animation. The MATLAB
name stands for MATrixLABoratory.
The diagram shows the main features and capabilities of MATLAB.
MATLAB
Toolbox
Signal Processing
Image Processing
Statistics
Control system
Neutral networks
Communications
and many more….
2 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
3 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Input-output:
MATLAB supports interactive computation taking the input from the screen
and flushing the output to the screen. In addition it can read input files and
write output files.
0 1 2 3 4 5 6 7 8 9 10
2) T= Zeros (2, 3)
The above instruction creates a vector of two rows and three columns whose
values are zero.
T=
0 0 0
0 0 0
3) T=Ones (3,2)
The above instruction creates a vector of three rows and two columns whose
values are one
T=
1 1
1 1
1 1
4 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
4) a = [1 2 3] b = [4 5 6]
MATLAB allows you to process all of the values in a matrix using a single
arithmetic operator or function.
To create a matrix that has multiple rows, separate the rows with semicolons.
a = [1 2 3; 4 5 6; 7 8 10]
a=
1 2 3
4 5 6
7 8 10
a + 10
ans =
11 12 13
14 15 16
17 18 20
sin(a)
ans =
0.8415 0.9093 0.1411
-0.7568 -0.9589 -0.2794
0.6570 0.9894 -0.5440
To transpose a matrix, use a single quote ('):
a'
ans =
1 4 7
2 5 8
3 6 10
5 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
You can perform standard matrix multiplication, which computes the inner
products between rows and columns, using the * operator. For example,
confirm that a matrix times its inverse returns the identity matrix:
p = a*inv(a)
p=
1.0000 0 -0.0000
0 1.0000 0
0 0 1.0000
Notice that p is not a matrix of integer values. MATLAB stores numbersas
floating-point values, and arithmetic operations are sensitive to small
differences between the actual value and its floating-point representation. You
can display more decimal digits using the format command:
Format long:
p = a*inv(a)
p=
1.000000000000000 0 -0.000000000000000
0 1.000000000000000 0
0 0 0.999999999999998
Reset the display to the shorter format using format short format affects only
the display of numbers, not the way MATLAB computes or saves them. To
perform element-wise multiplication rather than matrix multiplication, use
the.* operator:
p = a.*a
p=
1 4 9
16 25 36
49 64 100
The matrix operators for multiplication, division, and power each have a
corresponding array operator that operates element-wise. For example, raise
each element of a to the third power:
6 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
a.^3
ans =
1 8 27
64 125 216
343 512 1000
Concatenation:
Concatenation is the process of joining arrays to make larger ones. In fact, you
made your first array by concatenating its individual elements. The pair of
square brackets [] is the concatenation operator.
A = [a,a]
A=
1 2 3 1 2 3
4 5 6 4 5 6
7 8 10 7 8 10
A = [a; a]
A=
1 2 3
4 5 6
7 8 10
1 2 3
4 5 6
7 8 10
7 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Complex Numbers:
Complex numbers have both real and imaginary parts, where the imaginary
unit is the square root of –1.
sqrt(-1)
ans = 0 + 1.0000i
Array Indexing:
Every variable in MATLAB is an array that can hold many numbers. When you
want to access selected elements of an array, use indexing.
For example, consider the 4-by-4 magic square A:
A = magic(4)
A=
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
There are two ways to refer to a particular element in an array. The most
common way is to specify row and column subscripts, such as
A(4,2)
ans = 14
Less common, but sometimes useful, is to use a single subscript that
traverses down each column in order:
A(8)
ans = 14
8 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
5 11 10 8 0
9 7 6 12 0
4 14 15 1 17
To refer to multiple elements of an array, use the colon operator, which allows
you to specify a range of the form start:end. For example, list the elements in
the first three rows and the second column of A:
A(1:3,2)
ans =2
11
The colon alone, without start or end values, specifies all of the elements in
that dimension. For example, select all the columns in the third row of A:
A(3,:)
ans = 9 7 6 12 0
The colon operator also allows you to create an equally spaced vector of
values using the more general form start:step:end.
9 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
6) Plot (t, m)
If m= [6 7 8 9]
t= [1 2 3 4]
This instruction will display a figure window which indicates the plot of
m versus t.
7) Stem (t,m)
This Instruction will display a figure window as shown below,
8) Subplot: This function divides the figure window into rows and
Columns.
Example: subplot(3,1,2)-----3-rows, 1-column, 2-location.
10 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
11 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
12 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
1. SAMPLING THEOREM
Aim: To verify sampling theorem for the following cases:
i) Under sampling ii) Right sampling iii) Over sampling
Program:
clc; % clears the command window
clear all;
close all;% clears the variables declared
k=input ('Enter the no of cycles = ');
a=input ('Enter the input signal amplitude= ');
fm=input ('Enter the input frequency = ');
t=0:1/(fm*fm):k/fm;
y=a*cos(2*pi*fm*t)
figure;
subplot(2,2,1)
plot(t,y)
grid on;
xlabel('------t');ylabel('amplitude');
title('The input signal');
fnq=2*fm
% under sampling
fs=3/4*fnq;
tx=0:1/fs:k/fm;
ys=a*cos(2*fm*pi*tx)
subplot(2,2,2);
stem(tx,ys);
hold on
plot(tx,ys,'r');xlabel('------tx');ylabel('amplitude');
title('The under sampling case');
13 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
% Nyquist sampling
fs=fnq;
tx=0:1/fs:k/fm;
ys=a*cos(2*pi*fm*tx)
subplot(2,2,3);
stem(tx,ys);
hold on;
plot(tx,ys,'g');xlabel('------tx');ylabel('amplitude');
title('The RIGHT SAMPLING case');
% over sampling
fs=10*fnq;
tx=0:1/fs:k/fm;
ys=a*cos(2*pi*fm*tx)
subplot(2,2,4);
stem(tx,ys);
hold on;
plot(tx,ys,'r');xlabel('------tx');ylabel('amplitude');
title('The OVER SAMPLING case');
14 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Result:
15 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Program:
clc;
clear all;
close all;
N = max(length(x),length(h));
Y=cconv(x,h,N) %y=xN h%
stem(Y);
xlabel('N----->'),ylabel('Amplitude----->')
title('Plot of circularly convoluted sequence');
Result:
16 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
N1=max(length(a1),length(b1))
N=max(N1,length(c1))
a=[a1,zeros(1,N-length(a1))]
b=[b1,zeros(1,N-length(b1))]
c=[c1,zeros(1,N-length(c1))]
x=cconv(a,b,N1)
y=cconv(b,a,N1) %commutative property aN b=bN a
if x==y
disp('commutative property is proved')
else
disp('commutative property is not proved')
end
t=cconv(b,c,N)
y1=cconv(a,t,N) %associative property aN (bN c)=(aN b) N c
y2=cconv(x,c,N)
if y1==y2
17 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
t1= b + c
y3=cconv(a,t1,N)
t2=cconv(a,c,N) % distributive property aN (b+c)=(aN b)+(aN c)
y4= x + t2
if y3==y4
18 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Properties of Auto-correlation:
Property 1:Rxx(l) = Rxx(-l) (Symmetry property).
Property 2: |rxx(l)| ≤rxx(0) = Ex (Energy property).
Program:
clc;
clear all;
close all;
x=input('Enter the sequence x[n]= ');
xsi=input('enter the starting index=');
Rxx=xcorr(x,x)
energy=sum(x.^2)
c_i=ceil(length(Rxx)/2)
Rxx_0=Rxx(c_i)
if Rxx_0==energy
disp('Eneregy property proved.');
else
disp('EnergyProperty not proved');
end
Rxxf=fliplr(Rxx)
if Rxx==Rxxf
disp('It is even.');
else
disp('It is not even.');
end
n1= xsi:length(x)+xsi-1;
n2= -(length(x)-1):(length(x)-1);
subplot(3,1,1),stem(n1,x),xlabel('n1'),ylabel('amplitude');
subplot(3,1,2),stem(n2,Rxx),xlabel('n2'),ylabel('amplitude');
subplot(3,1,3),stem(n2,Rxxf),xlabel('n2'),ylabel('amplitude');
19 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Program:
clc;
clear all;
close all;
x=input('Enter the first sequence=');
xsi=input('enter the starting index of x=');
xei=input('enter the ending index of x=');
y=input('Enter the second sequence= ');
ysi=input('enter the starting index of y=');
yei=input('enter the ending index of y=');
Ex=sum(x.^2);
Ey=sum(y.^2);
energy=sqrt(Ex*Ey);
Rxy=xcorr(x,y)
Ryx=xcorr(y,x)
Ryxf=fliplr(Ryx);
if Rxy==Ryxf
disp('Symmetry Property is proved');
else
disp('Symmetry property not proved');
end
n1=xsi:length(x)+xsi-1;
n2=ysi:length(y)+ysi-1;
n3=(xsi-yei):(xei-ysi)
subplot(1,4,1),stem(n1,x),xlabel('lag'),ylabel('amplitude');
subplot(1,4,2),stem(n2,y),xlabel('lag'),ylabel('amplitude');
subplot(1,4,3),stem(n3,Rxy),xlabel('lag'),ylabel('amplitude');
subplot(1,4,4),stem(n3,Ryxf),xlabel('lag'),ylabel('amplitude');
20 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
21 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Program:
clc;
clear all;
close all;
x = input('enter the input seq=')
N = length(x);
X = zeros(N,1)
for k = 0:N-1
for n = 0:N-1
X(k+1) = X(k+1) + x(n+1)*exp(-j*pi*2*n*k/N)
end
end
mag=abs(X)
phase=angle(X)*180/pi
t = 0:N-1
subplot(311)
stem(t,x);
xlabel('Time (s)');ylabel('Amplitude');
title('Time domain - Input sequence')
subplot(312)
stem(t,mag)
xlabel('Frequency');ylabel('|X(k)|');
title('Frequency domain - Magnitude response')
subplot(313)
stem(t,phase)
xlabel('Frequency');ylabel('phase(X(k))');
title('Frequency domain - phase response')
22 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
t = 0:N-1
subplot(311)
stem(t,x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Time domain - Input sequence');
subplot(312)
stem(t,X)
xlabel('Frequency');
ylabel('|X(k)|');
title('Frequency domain - Magnitude response');
subplot(313)
stem(t,angle(X))
ylabel('phase(X(k))');
title('Frequency domain - phase response');
23 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Parseval‘s theorem:
y1=a.*x1+b.*x1
Y1=fft(y1,N)
X1=fft(x1,N)
X2=fft(x2,N)
Y2=a.*X1+b.*X2
MagY1=abs(Y1)
MagY2=abs(Y2)
phaseY1=angle(Y1)*180/pi
phaseY2=angle(Y2)*180/pi
figure
k=0:1:(N-1)
subplot(2,2,1);stem(k,MagY1)
xlabel('N-point');ylabel('Magnitude of Y1')
subplot(2,2,3);stem(k,MagY2)
xlabel('N-point');ylabel('Magnitude of Y2')
24 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
subplot(2,2,2);stem(k,phaseY1)
xlabel('N-point');ylabel('phase of Y2')
subplot(2,2,4);stem(k,phaseY2)
xlabel('N-point');ylabel('phase of Y2')
if Y1==Y2
disp('Linearity property satisfied for the given sequence')
else
disp('Linearity property not satisfied for the given
sequence')
end
25 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
if y1==y2
disp('parsvals theorem proved');
else
disp('parsevals theorem not proved')
end
26 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
clc;
clear all;
close all;
x=[zeros(1,32),ones(1,64),zeros(1,32)]
X=fft(x)
X1=fftshift(X)
subplot(2,1,1)
plot(x)
xlabel('time')
ylabel('amplitude')
subplot(2,1,2)
plot(abs(X1))
xlabel('frequency')
ylabel('magnitude')
Output:
27 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
clc;
clear all;
close all;
t=0:0.001:1
x=A*square(2*pi*f*t,dc)
X=fft(x)
X1=fftshift(X)
subplot(2,1,1)
plot(x)
xlabel('time')
ylabel('amplitude')
subplot(2,1,2)
plot(abs(X1))
xlabel('frequency')
ylabel('magnitude')
28 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
clc;
clear all;
close all;
n=-pi:0.005:pi
x=sinc(n)
X=fft(x)
X1=fftshift(X)
subplot(2,1,1)
plot(x)
xlabel('time')
ylabel('amplitude')
subplot(2,1,2)
plot(abs(X1))
xlabel('frequency')
29 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
ylabel('magnitude')
30 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Rectangular(Boxcar)
1 21 dB 2
window
Triangular (Bartlett)
2 27 dB 4
window
3 Hanning window 44 dB 4
4 Hamming window 53 dB 4
5 Blackman window 75 dB 6
2. Determine the order of the FIR filter (number of coefficients) using the
relation;
2k
N≥
p s
Note: Choose N as odd. If N is even select next odd integer.
3. Choose the cut-off frequency of the filter as ωC=ωP+
2
31 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
N 1
4. Choose α = so that linear phase is ensured.
2
5. The impulse response of the filter is given by
sin c n
h(n) = *w(n); for 0<n<N-1 & n ≠ α
n
c
*w(n) ; for n = α
where w(n) is window function.
j N21 N 3
e
N 1 2
N 1
H(ω) = * h 2 2hn cos n 2
n 0
Design example:
I step: Choose an appropriate window function from the stop band attenuation
specification.
II step:Compute the order of the FIR filter (number of coefficients) using the
relation,
2k
N≥
p s [K=4 for Hamming window]
N≥ 53.5 (choose N=55)
32 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
III step:Choose the cut-off frequency of the filter as ωC= ωP+ rad.
2
N 1
IV step: Choose α = so that linear phase is ensured.
2
sin c n
h(n) = *w(n) ; for0<n<N-1 & n ≠ α.
n
where w(n) is window function.
j N21 N 3
e N 1
2
N 1
H(ω) = h
* 2 n 0
2 h n cos
n
2
For any N,
N 1
; H 0
2 2
3 N 1
; H 0
2 2
33 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Program:
clc;
clear all;
close all;
wp= input('Enter the pass band edge (rad)= ');
ws= input('Enter the stop band edge (rad)= ');
ks= input('Enter the stop band attenuation (dB)= ');
%If 43<Ks<54 choose hamming window.
%To select N,order of filter.
N= (2*pi*4)./(ws-wp); % k=4 for Hamming window.
N= ceil(N); %To round-off N to the next integer.
r = rem(N,2); %Choose odd N.
if(r==0)
N=N+1;
end
wc=(wp+(ws-wp)/2)./pi
% To obtain h(n)
h= fir1(N-1,wc,hamming(N))
% Frequency response
freqz(h,1); % 1 is the normalized frequency
title('Frequency response of the lowpass digital FIR filter')
figure(2), stem(h);
title('Impulse response of the lowpass digital FIR filter')
34 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Program:
clc; clear all; close all;
w2=2*fs/f;
[n,wn]=buttord(w1,w2,rp,rs,'s'); % Compute
order and cutoff frequency
[b,a]=butter(n,wn,'s'); % Compute poles and
zeros of frequency response w=0:0.001:pi;
[h,om]=freqs(b,a,w);
M=20*log10(abs(h));
subplot(4,1,1);
plot(om/pi,M);
xlabel('Normalized frequency');
ylabel('Gain in dB');
35 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
[b,a]=butter(n,wn,'high','s');
w=0:0.001:pi;
[h,om]=freqs(b,a,w);
M=20*log10(abs(h));
subplot(4,1,2);
plot(om/pi,M);
xlabel('Normalized frequency');
ylabel('Gain in dB');
[n,wn]=buttord(w1,w2,rp,rs,'s');
wn=[w1,w2];
[b,a]=butter(n,wn,'bandpass','s');
w=0:0.001:pi;
[h,om]=freqs(b,a,w);
M=20*log10(abs(h));
subplot(4,1,3);
plot(om/pi,M);
xlabel('Normalized frequency');
ylabel('Gain in dB');
36 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
[n,wn]=buttord(w1,w2,rp,rs,'s');
wn=[w1,w2];
[b,a]=butter(n,wn,'stop','s');
w=0:0.001:pi;
[h,om]=freqs(b,a,w);
M=20*log10(abs(h));
subplot(4,1,4);
plot(om/pi,M);
xlabel('Normalized frequency');
ylabel('Gain in dB');
37 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
38 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Applications
The main applications of DSP are audio signal processing, audio compression,
digital image processing, video compression, speech processing, speech
recognition and digital communications. Specific examples are speech
compression and transmission in digital mobile phones, equalisation of sound
in Hi-Fi equipment, weather forecasting, economic forecasting, seismic data
processing, analysis and control of industrial processes, computer-generated
animations in movies, medical imaging such as CAT scans and MRI, image
manipulation, and audio effects for use with electric guitar amplifiers. A
further application is very low frequency (VLF) reception with a PC soundcard.
39 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Digital Signal Processors follow Harvard architecture where Data memory and
Program Memory have separate data and address buses. Multiply and
accumulate, Program memory fetch and data memory write are all executed in
a single cycle.
40 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
41 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Now click on “<<Add” Button and then click on Save & Quit button.
Next Click on “Yes” Button to open CCS studio.
42 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Project→New→ProjectName→Location(C:\CCStudio_v3.1\MyProjects\)→Pr
ojecttype (.out Executable) →Target (TMS320C67xx).
43 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
file format.
Add this to the project. Project will be having .pjt extension. Right click
on.pjt file created, add the .c file that you have written.
Two other files are to be added to project. One is library file (*.lib) and
other is Linker command file (*.cmd).
Add rts6713.lib
C:\CCStudio_v3.1\C6000\cgtools\lib\rts6700.lib
Add hello.cmd
C:\CCStudio_v3.1\tutorial\dsk6713\hello1\hello.cmd
Compile the program using the „Project-compile‟ pull down menu or by
clicking the shortcut icon.
Build the program using the „Project-Build‟ pull down menu or by
clicking the shortcut icon.
Load the .out file (which will be in the debug folder where the project
is stored)using the „File-load program‟ pull down menu.
Run the program using „Debug - Run‟ pull down menu or by clicking
the shortcut icon.
44 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
1. LINEAR CONVOLUTION
Aim: To compute Linear Convolution of the two given sequences:
Program:
#include<stdio.h>
int y[20];
main()
{
int x[]={ };
int h[]={ };
int l= ,n,k;
for(n=0;n<l;n++)
{
y[n]=0;
for(k=0;k<=n;k++)
y[n]+=x[k]*h[n-k];
}
Printf(“\n Linear convolution output is\n”);
For(n=0;n<l;n++)
Printf(“y[%d]=%d”,n,y[n]);
}
45 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
2. CIRCULAR CONVOLUTION
Program:
#include<stdio.h>
int y[20];
main()
{
int x[]={ };
int h[]={};
int l=4,n,k;
int a[20],b[20],c[20],d[20];
y[0]=0;
a[0]=h[0];
a[k]=h[l-k];
y[0]=y[0]+x[n]*a[n];
y[1]=0;
b[0]=a[l-1];
b[k]=a[k-1];
y[1]=y[1]+x[n]*b[n];
y[2]=0;
46 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
c[0]=b[l-1];
c[k]=b[k-1];
y[2]=y[2]+x[n]*c[n];
y[3]=0;
d[0]=c[l-1];
d[k]=c[k-1];
y[3]=y[3]+x[n]*d[n];
for(n=0;n<l;n++)
Printf(“y[%d]=%d\n”,n,y[n]);
47 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Program:
#include<stdio.h>
#include<math.h>
main()
{
int N = ,n = 0, k = 0;
int x[] = { };
floatsumRe=0,sumIm=0,costerm=0,sinterm=0,pi= 3.1416;
for(k=0 ; k<N ; k++)
{
sumRe = 0;
sumIm = 0;
for (n=0; n<N ; n++)
{
costerm = cos(2*pi*k*n/N);
sinterm = sin(2*pi*k*n/N);
sumRe = sumRe + x[n] * costerm;
sumIm = sumIm - x[n] * sinterm;
}
printf("X[%d]= %7.3f %7.3fj \n", k,sumRe,sumIm );
}
}
48 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
4. IMPULSE RESPONSE
4a) Aim: To compute Impulse Response of the system defined by
its difference equation of first order.
Program:
#include<stdio.h>
#include<math.h>
float y[8];
void main()
float x[8];
int num= ;
x[-1]=0;
y[-1]= ;
for(n=0;n<num;n++)
{
if(n==0)
x[n]=1; else
x[n]=0;
y[n]= ;
printf("y[%d]=%f\n",n,y[n]);
49 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Program:
#include<stdio.h>
#include<math.h>
float y[8];
void main()
float x[8];
intnum= ;
x[-1]=0;
y[-1]= ;
y[-2]= ;
for(n=0;n<num;n++)
if (n==0)
x[n]=1;
else
x[n]=0;
y[n]= ;
printf("y[%d]=%f\n",n,y[n]);
50 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
5. FIR FILTER
Aim: Realization of an FIR filter (any type) to meet given
specifications.The input can be a signal from function generator /
speech signal.
Procedure:
(1) Connect CRO to the Socket provided for LINE OUTsocket.
(2) Connect a Signal generator to the LINE IN socket.
(3) Switch on the signal generator with a sine wave of frequency >20 Hz and
Vp-p=1v.
(4) Now switch on the DSK and bring up code composer studio on the PC.
(5) Create a new project with name Ex: FIR.pjt or IIR.pjt.
(6) From the File menu newDSP/BIOS Configurationselect
“dsk6713.cdb” and save it as “fir.cdb”
(7) Add “fir.cdb” to the current project.
(8) Add the given “CODEC.C” file to the current project which has the main
function and calls the other necessary routines.
(9) Add the library file “dsk6713bsl.lib” to the current project
path”c:\ccstudio\C6000\dsk6713\lib\dsk6713bsl.lib”
(10) Add new file to the project and save as fir.c and write the source code.
(11) Copy header files “dsk6713.h” and “dsk6713_aic23.h” from
C:\CCStudio_v3.1\c6000\dsk6713\include and paste it in the
Current project folder.
(12) Compile the program.
(13) Build the program.
(14) Load the generated object file (*.out) on to target board.
(15) Run the program
(16) Observe the waveform that appears on the CRO screen.
(17) Vary the frequency on function generator to see the response of filter.
51 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
CODEC.C
#include "fircfg.h"
#include "c:\ccstudio_v3.1\c6000\dsk6713\include\dsk6713.h"
#include"c:\ccstudio_v3.1\c6000\dsk6713\include\dsk6713_aic23.h"
DSK6713_AIC23_Config config = {\
*/\
*/\
};
void main()
DSK6713_AIC23_CodecHandle hCodec;
DSK6713_init();
52 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
DSK6713_AIC23_setFreq(hCodec, 3);
while(1)
l_output=FILTER(l_input);
r_output=l_output;
DSK6713_AIC23_closeCodec(hCodec);
53 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
FIR FILTER
Calculation:
54 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Program:
#define ORDER 30
-0.0132,0.0176,0.0383, 0.0256,-0.0181,
-0.0598,-0.0553,0.0184,0.1410, 0.2558,
0.3025, 0.2558,0.1410,0.0184,-0.0553,
-0.0598,-0.0181,0.0256,0.0383, 0.0176,
-0.0132,-0.0276,-0.0169,0.0062,0.0208,
0.0161};
int i=0;
in_buffer[0] = x;
for(i=ORDER;i>0;i--)
in_buffer[i] = in_buffer[i-1];
for(i=0;i<ORDER+1;i++)
return(output);
55 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Result:
The output plot is observed on the CRO.
This behaves as a low-pass filter.
See the effect of filtering by giving a sinusoidal input to DSP kit and
slowly varying its frequency.
Observe the cutoff frequency of the filter.
Change the filter co-efficients for different types of window & Cut-
off frequencies.
(Refer FIR filter design part from experiment-10 in part A-MATLAB)
56 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Additional Programs
1. Interference Suppression
Aim: To add noise above 3kHz and then remove; Interference
suppression using 400 Hz tone.
Procedure:
-1.4321,-1.8274,-1.8559,-1.5176,-0.9511,
-0.3808,-0.0312,-0.0411,-0.4102,-1.0000,
-1.5858,-1.9432,-1.9333,-1.5564,-0.9511,
-0.3420, 0.0462, 0.0747,-0.2565,-0.8090,
-1.3583,-1.6800,-1.6356,-1.2252,-0.5878,
0.0520, 0.4693, 0.5253, 0.2197,-0.3090,
-0.8365,-1.1384,-1.0764,-0.6506,0.0000};
float h[31]={0.0048,0.0054,0.0072,0.0101,0.0141,
0.0188,0.0243,0.0301,0.0361,0.0419,
0.0474,0.0523,0.0563,0.0593,0.0612,
0.0618,0.0612,0.0593,0.0563,0.0523,
0.0474,0.0419,0.0361,0.0301,0.0243,
0.0188,0.0141,0.0101,0.0072,0.0054,
0.0048};
float y[101]={0.0};
void main()
{
int N=30,k=0,n=0;
float sum;
for (n=0;n<101;n++)
{
sum=0;
for(k=0;k<N;k++)
if(n-k>=0)
{
sum=sum+h[k]*x[n-k];
}
y[n]=sum;
}
for(n=0;n<101;n++)
printf("y[%d] = %f \n",n,y[n]);
}
58 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
Result:
The 4kHz interfering tone is successfully suppressed and is
observed in the plot and also the obtained result is verified in the
MATLAB.
59 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
clc;
clear all;
close all;
x1=input('enter the 1st input seq=')
x2=input('enter the 2nd input seq=')
N= input('enter the value for N=')
y1=cconv(x1,x2,N)
X1=fft(x1,N)
X2=fft(x2,N)
H=X1.*X2
y2=ifft(H,N)
if y1 == y2
disp('circular convolution property is proved');
else
disp('circular convolution property is not proved');
end
subplot(2,1,1)
stem(y1);
xlabel('N------>'),ylabel('amplitude')
subplot(2,1,2)
stem(y2);
xlabel('N------>'),ylabel('amplitude')
60 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
REFERENCES
[1]. Digital signal processing using MATLAB –SanjeetMitra, TMH,2001.
[2]. Digital signal processing using MATLAB - J. G. Proakis&Ingale, MGH,
2000.
[3]. Digital Signal Processors, B. Venkataramani and Bhaskar, TMH,2002.
[4]. A.Gilat, MATLAB: An Introduction with Applications, John Wiley &
Sons, Inc. 2004.
[5]. R. Pratap, Getting Started with MATLAB 7: A Quick Introduction for
Scientists and Engineers, Oxford University Press, 2009.
[6]. D. Hanselman and B. Little_eld, Mastering MATLAB 5: A
Comprehensive Tutorial and Reference,Prentice Hall, 1998.
[7]. B. R. Hunt, R. L. Lipsman, and J. M. Rosenberg (with K. R. Coombes,
J. E. Osborn, and G. J.Stuck), A Guide to MATLAB: for beginners and
experienced users, Cambridge University Press 2001.
[8] RulphChassaing, “DSP Applications Using C and the TMS320C6X
DSK”, John Wiley, New York, 2002
61 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
VIVA
1) What is DSP? Why do we need DSP?
2) List the merits and demerits of DSP
3) What are the applications of DSP?
4) What is sampling theorem?
5) What is aliasing effect?
6) Define Quantization.
7) Explain the principle of operation of analog to digital conversion of the
signal with a neat diagram.
8) Explain the significance of Nyquist rate and aliasing during the
sampling of continuous time signals.
9) What do you mean by process of reconstruction?
10) What are techniques of reconstructions?
11) What do you mean Aliasing? What is the condition to avoid aliasing
for sampling?
12) Write the conditions of sampling.How many types of sampling there?
13) Explain the statement: t= 0:0.000005:0.05
In the above example what does colon (: ) and semicolon (; ) denotes.
14) What is a) Undersampling b) nyquist plot c) Oversampling.
15) What is MATLAB? What are the applications of MATLAB?
16) What is the use of command ‗legend‘?
17) Distinguish between ‗plot‘ and ‗stem‘ functions.
18) Explain the function ‗subplot‘?
19) What is convolution? What are the properties of convolution?
20) What is linear convolution?
21) Distinguish between Linear convolution and circular convolution.
22) How will you obtain linear convolution from circular convolution?
23) Explain how convolution syntax built in function works.
24) What is the total output length of linear convolution sum?
25) What is an LTI system?
62 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
63 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
64 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
77) What are the methods available for designing analog IIR filter?
78) Mention the importance of IIR filter.
79) What is warping effect?
80) Compare analog and digital filter.
81) What is FIR and IIR filter define, and distinguish between these two.
82) Explain the command – N=ceil(6.6*pi/tb)
83) What is the matlab command for Hamming window? Explain.
84) What do you mean by cut-off frequency?
85) What are the differences between FIR and IIR filters?
86) What are the differences between Butterworth and Chebyshevfilters?
87) What do you mean by command ‗butter‘ and ‗cheby1‘?
88) Explain the command in detail-[N,wc]=buttord(2*fp/fs,2*fstp/fs,rp,As)
89) What are the Features of TMS320C6713 DSK Kit?
90) What are the Difference between the Microcontroller and the DSP
Processor?
91) What is CCS? Explain in detail to execute a program using CCS.
92) Why do we need of CCS?
93) How to execute a program using 'dsk' and 'simulator'?
94) Which IC is used in CCS? Explain the dsk, dsp kit.
95) What do you mean by noise?
96) Explain the program for linear convolution for your given sequence.
97) Why we are using command 'float' in CCS programs.
98) Where we use 'float' and where we use 'int'?
99) Explain the command: i=(n-k)%N
100) Explain the entire CCS program in step by step of execution.
65 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
2) Using MATLAB Compute the linear convolution of two given finite length of
sequences. Given: x(n)=[……………. ] and h(n)=[ ……………]
3) Using MATLAB Compute the circular convolution of two given finite length
of sequences. Given: x(n)=[ ………………..] and h(n)=[……………….]
6) Using MATLAB Compute the cross correlation of two given finite length of
sequences and verify its properties. Given: Ref sequence x(n)=[……………]
and h(n)=[……………..]
66 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
11) Using MATLAB design a low-pass FIR filter with the following
Specifications:
a) Pass band cut-off frequency : ωP=__________rad
b) Stop band cut-off frequency : ωS=__________rad
c) Stop band attenuation : kS=__________dB
Plot the Frequency, phase and impulse response of the designed filter.
12) Using MATLAB, design a low-pass IIR Butterworth filter with the
following specifications.
kP = Pass band attenuation(dB) =
kS = Stop band attenuation( dB) =
fP = Pass band edge(Hz) =
fS = Stop band edge(Hz) =
1
FS = = Sampling rate (samples/sec) =
TS
Plot the Magnitude Frequency response of the low-pass Butterworth
filter.
13) Using MATLAB ,design alow-pass IIR Chebyshev type I filter with the
Following specifications.
kP = Pass band attenuation(dB) =
kS = Stop band attenuation( dB) =
fP = Pass band edge(Hz) =
fS = Stop band edge(Hz) =
1
FS = = Sampling rate (samples/sec) =
TS
67 Dept Of ECE,VSMSRKIT
DSP LAB -17ECL57
3) Write a C program to find the impulse response of first and second order
system for DSP Processor (TMS320C6713). Assume zero initial conditions
for an initially relaxed system.
Given: First order equation:……………………….
Second order equation: ……………………
Execute the program on Simulator/Emulator (DSP Starter kit - Board).
68 Dept Of ECE,VSMSRKIT