You are on page 1of 58

ECE DEPT, PRESIDENCY UNIVERSITY

Electronics and Communication Engineering


Digital Signal Processing Lab
ECE-260
(2017-18)

City Office: University House, 8/1, King Street, Richmond Town,


Bengaluru - 560025
Campus: Presidency University, Itgalpur, Rajankunte, Bengaluru -
560064

Digital Signal Processing Lab Page 1


ECE DEPT, PRESIDENCY UNIVERSITY

Program Title

P1 Verification of Sampling theorem.

P2 Impulse response of a given system

P3 Linear and Circular convolution of two given sequences.

P4 Solving a given difference equation/plot pole zero plot and impulse response.

P5 Computation of N point DFT of a give sequence and to plot magnitude


and phase spectrum.
P6 Linear convolution of two sequences using DFT and IDFT.

P7 Circular convolution of two given sequences using DFT and IDFT

P8 Design and implementation of FIR filter to meet given specification.

P9 Design and implementation of IIR filter to meet given specification

P10 Linear convolution of two given sequences on DSP Board with CCS.

P11 Circular convolution of two given sequences on DSP Board with CCS.

P12 Computation of N point DFT of a given sequences on DSP Board with CCS.

P13 Realization of an FIR filter (any type) to meet given specification. The input can be signal from
function generator/speech signal.

Digital Signal Processing Lab Page 2


ECE DEPT, PRESIDENCY UNIVERSITY

Common Procedure to all Programs in MATLAB


1. Click on the MATLAB Icon on the desktop.
2. MATLAB window open.
3. Click on the „FILE‟ Menu on menu bar.
4. Click on NEW M-File from the file Menu.
5. An editor window open, start typing commands.
6. Now SAVE the file in directory.
7. Then Click on DEBUG from Menu bar and Click Run.

Digital Signal Processing Lab Page 3


ECE DEPT, PRESIDENCY UNIVERSITY

EXPERIMENT NO-1

AIM: Verification of Sampling theorem.


EQUIPMENTS: Operating System - Windows 7 Constructor -
Simulator Software - CCStudio 3 & MATLAB 2017.
Sampling: Is the process of converting a continuous time signal into a
discrete time signal. It is the first step in conversion from analog signal
to digital signal
Sampling theorem: Sampling theorem states that “Exact reconstruction
of a continuous time base-band signal from its samples is possible, if the
signal is band-limited and the sampling frequency is greater than twice
the signal bandwidth”. i.e. fs > 2W, where W is the signal bandwidth
Program:

clc;

T=0.04; % Time period of 50 Hz signal


t=0:0.0005:0.04;
f = 1/T;
disp(f);
xa_t=sin(2*pi*2*t/T);
subplot(2,2,1);
plot(200*t,xa_t);
title('Verification of sampling theorem');
title('Continuous signal');
xlabel('t');
ylabel('x(t)');
ts1=0.002;%>niq rate
ts2=0.01;%=niq rate
ts3=0.1;%<niq rate
n=0:40;
x_ts1=2*sin(2*pi*n*ts1/T);
subplot(2,2,2);
stem(n,x_ts1);
title('greater than Nq');
xlabel('n');
ylabel('x(n)');
n=0:8;

Digital Signal Processing Lab Page 4


ECE DEPT, PRESIDENCY UNIVERSITY

x_ts2=2*sin(2*sym('pi')*n*ts2/T);
subplot(2,2,3);
stem(n,x_ts2);
title('Equal to Nq');
xlabel('n');
ylabel('x(n)');
n=0:8;
x_ts3=2*sin(2*pi*n*ts3/T);
subplot(2,2,4);
stem(n,x_ts3);
title('less than Nq');
xlabel('n');
ylabel('x(n)');

25

Digital Signal Processing Lab Page 5


ECE DEPT, PRESIDENCY UNIVERSITY

EXPERIMENT NO-2

AIM: IMPULSE RESPONSE OF A GIVEN SYSTEM

EQUIPMENTS: Operating System - Windows 7 Constructor - Simulator Software - CCStudio 3 &


MATLAB 2017.

THEORY: A discrete time system performs an operation on an input signal based on predefined criteria
to produce a modified output signal. The input signal x(n) is the system excitation, and y(n) is the
system response. The transform operation is shown as,

x(n) y(n) = T[(x(n)]

If the input to the system is unit impulse i.e. x(n) = δ(n) then the output of the system is known as
impulse response denoted by h(n)

Program:

clc;

clear all;

close all;
% Difference equation of a second order system
% y(n) = x(n)+0.5x(n-1)+0.85x(n-2)+y(n-1)+y(n-2)
b=input('enter the coefficients of x(n),x(n-1)-----');
a=input('enter the coefficients of y(n),y(n-1)----');
N=input('enter the number of samples of imp response ');
[h,t]=impz(b,a,N);
plot(t,h);
title('plot of impulse response');
ylabel('amplitude');
xlabel('time index----->N');
disp(h);
grid on;

Digital Signal Processing Lab Page 6


ECE DEPT, PRESIDENCY UNIVERSITY

enter the coefficients of x(n),x(n-1)-----[1 0.5 0.85]


enter the coefficients of y(n),y(n-1)----[1 -1 -1]
enter the number of samples of imp response 4
1.0000
1.5000
3.3500
4.8500

enter the coefficients of x(n),x(n-1)-----[1 0.5 0.85]

enter the coefficients of y(n),y(n-1)----[1 -1 -1]

enter the number of samples of imp response 20

1.0e+04 *

Digital Signal Processing Lab Page 7


ECE DEPT, PRESIDENCY UNIVERSITY

0.0001

0.0001

0.0003

0.0005

0.0008

0.0013

0.0021

0.0034

0.0056

0.0090

0.0145

0.0235

0.0381

0.0616

0.0997

0.1612

0.2609

0.4221

0.6830

1.1052

Digital Signal Processing Lab Page 8


ECE DEPT, PRESIDENCY UNIVERSITY

Digital Signal Processing Lab Page 9


ECE DEPT, PRESIDENCY UNIVERSITY

EXPERIMENT NO-3

AIM: TO IMPLEMENT LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES

EQUIPMENTS: Operating System - Windows 7 Constructor - Simulator Software - CCStudio 3 &


MATLAB 2017.

THEORY: Convolution is an integral concatenation of two signals. It has many applications in numerous areas of
signal processing. The most popular application is the determination of the output signal of a linear time-invariant
system by convolving the input signal with the impulse response of the system.
Note that convolving two signals is equivalent to multiplying the Fourier Transform of the two signals.

Program:

clc;
x1=input('enter the first sequence');
subplot(3,1,1);
stem(x1);
ylabel('amplitude');
title('plot of the first sequence');
x2=input('enter 2nd sequence');
subplot(3,1,2);
stem(x2);
ylabel('amplitude');
title('plot of 2nd sequence');
f=conv(x1,x2);
disp('output of linear conv is');
disp(f);
subplot(3,1,3);
stem(f);
xlabel(„time index n‟);
ylabel(„amplitude f‟);
title('linear conv of sequence');

Output:
enter the first sequence[1 2 3 4 5]
enter 2nd sequence[1 2 3]
output of linear conv is
1 4 10 16 22 22 15

Digital Signal Processing Lab Page 10


ECE DEPT, PRESIDENCY UNIVERSITY

Program-2

clc;

clear all;
close all;
disp('linear convolution program');

x=input('enter i/p x(n):');


m=length(x);
h=input('enter i/p h(n):');
n=length(h);

x=[x,zeros(1,n)];
subplot(2,2,1),stem(x);
title('i/p sequence x(n) is:');
xlabel('---->n');

Digital Signal Processing Lab Page 11


ECE DEPT, PRESIDENCY UNIVERSITY

ylabel('----->h(n)');grid;

h=[h,zeros(1,m)];
subplot(2,2,2),stem(h);
title('i/p sequence 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
y
subplot(2,2,[3,4]),stem(y);
title('convolution of x(n)&y(n) is:');
xlabel('--->n');
ylabel('---->y(n)');grid;

linear convolution program


enter i/p x(n):[1 2 3 4 5]
enter i/p h(n):[1 2 3]
convolution of x(n)&h(n) is y(n):

y=

1 4 10 16 22 22 15

Digital Signal Processing Lab Page 12


ECE DEPT, PRESIDENCY UNIVERSITY

Digital Signal Processing Lab Page 13


ECE DEPT, PRESIDENCY UNIVERSITY

EXPERIMENT NO-4

AIM: TO IMPLEMENT CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES

EQUIPMENTS: Operating System - Windows 7 Constructor - Simulator Software - CCStudio 3 &


MATLAB 2017.

THEORY:

Circular convolution:
Let x1(n) and x2(n) are finite duration sequences both of length N with DFT‟s X1(k) and X2(k). Convolution of two
given sequences x1(n) and x2(n) is given by the equation,

Program:

function y=circular_convolution(x,h)
x= input ('enter the first sequence');
h= input ('enter the second sequence');
N1= length(x);
N2= length(h);
N=max(N1,N2);%length of sequence
x=[x zeros(1,N-N1)]; %modified first sequence
h=[h zeros(1,N-N2)]; %modified second sequence
for n=0:N-1;
y(n+1)=0;
for i=0:N-1
j=mod(n-i,N);
y(n+1)=y(n+1)+x(i+1)*h(j+1); %shifting and adding
end
end
%to display and plot circular convolution
n=1:N;
disp('output sequence of circular convolution');
disp(y);%to view output in command window
pause;
stem(n,y);%plotting circular convolution
grid minor;
xlabel('time index');
ylabel('amplitude');
title('circular convolution sequence of x and h');

Digital Signal Processing Lab Page 14


ECE DEPT, PRESIDENCY UNIVERSITY

>> circular_convolution
enter the first sequence[1 2 3 4 5]
enter the second sequence[1 2 3]
output sequence of circular convolution
23 19 10 16 22

ans =

23 19 10 16 22

Digital Signal Processing Lab Page 15


ECE DEPT, PRESIDENCY UNIVERSITY

EXPERIMENT NO-5

AIM: To find h[n] of the difference equation and plot impulse response and pole-zero plot.

EQUIPMENTS: Operating System - Windows 7 Constructor - Simulator Software - CCStudio 3 &


MATLAB 2017

THEORY: A General Nth order Difference equations looks like,

y[n] + a1y[n-1] + a2y[n-2] + …+ aNy[n-N) =

b0x[n] + b1x[n-1] + …. + bMx[n-M]


% to find out h(n) of the difference equation
% y(n)-(1/2)*y(n-1) = (1/2)*x(n)+(1/2)*x(n-1)
%For manual calculation of h(n), take the Z transform on both sides,
%find H(Z)=Y(Z)/X(Z). Take inverse Z transform to get h(n)

Program:

close all;

disp('Difference Equation of a digital system');


N= input('Desired Impulse response length = ');
b= input('Coefficients of x[n] terms = ');
a= input('Coefficients of y[n] terms = ');
h=impz(b,a,N);
disp('Impulse response of the system is h = ');
disp(h);
n=0:1:N-1;
figure(1);
stem(n,h);
xlabel('time index');
ylabel('h[n]');
title('Impulse response');
figure(2);
zplane(b,a);
xlabel('Real part');
ylabel('Imaginary part');
title('Poles and Zeros of H[z] in Z-plane');

Digital Signal Processing Lab Page 16


ECE DEPT, PRESIDENCY UNIVERSITY

OUTPUT:
Difference Equation of a digital system
Desired Impulse response length = 4
Coefficients of x[n] terms = [0.5 0.5]
Coefficients of y[n] terms = [1 -0.5]
Impulse response of the system is h =
0.5000
0.7500
0.3750
0.1875

Digital Signal Processing Lab Page 17


ECE DEPT, PRESIDENCY UNIVERSITY

Digital Signal Processing Lab Page 18


ECE DEPT, PRESIDENCY UNIVERSITY

EXPERIMENT NO-6

AIM: TO COMPUTE N-POINT DFT OF A GIVEN SEQUENCE AND TO PLOT MAGNITUDE AND PHASE
SPECTRUM.

EQUIPMENTS: Operating System - Windows 7 Constructor - Simulator Software - CCStudio 3 &


MATLAB 2017

THEORY:

Discrete Fourier Transform: The Discrete Fourier Transform is a powerful computation tool which allows
us to evaluate the Fourier Transform X(ejω) on a digital computer or specially designed digital hardware. Since
X(ejω) is continuous and periodic, the DFT is obtained by sampling one period of the Fourier Transform at a finite
number of frequency points. Apart from determining the frequency content of a signal, DFT is used to perform
linear filtering operations in the frequency domain.

Program:

x = input('Enter the sequence for which DFT is to be calculated');


n=[0:1:N-1];
k=[0:1:N-1];
WN=exp(-1j*2*pi/N);
nk=n'*k;
WNnk=WN.^nk;
Xk=x*WNnk;
MagX=abs(Xk); % Magnitude of calculated DFT
PhaseX=angle(Xk)*180/pi; % Phase of the calculated DFT
figure(1);
subplot(2,1,1);
plot(k,MagX);
subplot(2,1,2);
plot(k,PhaseX);

OUTPUT:
enter the number of Points DFT to be computed N == 8
Enter the sequence for which DFT is to be calculated x == [1 2 3 4 5 6 7 8]
Columns 1 through 6

36.0000 + 0.0000i -4.0000 + 9.6569i -4.0000 + 4.0000i -4.0000 + 1.6569i -4.0000 - 0.0000i -
4.0000 - 1.6569i

Digital Signal Processing Lab Page 19


ECE DEPT, PRESIDENCY UNIVERSITY

Columns 7 through 8

-4.0000 - 4.0000i -4.0000 - 9.6569i

Digital Signal Processing Lab Page 20


ECE DEPT, PRESIDENCY UNIVERSITY

EXPERIMENT NO-7

AIM: LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES USING DFT AND IDFT

EQUIPMENTS: Operating System - Windows 7 Constructor - Simulator Software - CCStudio 3 &


MATLAB 2017

THEORY: Convolution is an integral concatenation of two signals. It has many applications in numerous areas of
signal processing. The most popular application is the determination of the output signal of a linear time-invariant
system by convolving the input signal with the impulse response of the system.
Note that convolving two signals is equivalent to multiplying the Fourier Transform of the two signals.

Program:

clc;

clear all;
x1=input('enter the first sequence');
x2=input('enter the second sequence');
n=input('enter the no of points of the dft');
subplot(3,1,1);
stem(x1,'filled');
title('plot of first sequence');
subplot(3,1,2);
stem(x2,'filled');
title('plot the second sequnce');
n1 = length(x1);
n2 = length(x2);
m = n1+n2-1; % Length of linear convolution
x = [x1 zeros(1,n2-1)]; % Padding of zeros to make it of
% length m
y = [x2 zeros(1,n1-1)];
x_fft = fft(x,m);
y_fft = fft(y,m);
dft_xy = x_fft.*y_fft;
y=ifft(dft_xy,m);
disp('the circular convolution result is ......');
disp(y);
subplot(3,1,3);
stem(y,'filled');
title('plot of circularly convoluted sequence');

Digital Signal Processing Lab Page 21


ECE DEPT, PRESIDENCY UNIVERSITY

OUTPUT:
enter the first sequence[1 2 3 4 5]
enter the second sequence[1 2 3]
enter the no of points of the dft8
the circular convolution result is ......
1.0000 4.0000 10.0000 16.0000 22.0000 22.0000 15.0000

Digital Signal Processing Lab Page 22


ECE DEPT, PRESIDENCY UNIVERSITY

EXPERIMENT NO-8

AIM: TO IMPLEMENT CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES USING DFT AND
IDFT

EQUIPMENTS: Operating System - Windows 7 Constructor - Simulator Software - CCStudio 3 &


MATLAB 201

THEORY:

Circular convolution:
Let x1(n) and x2(n) are finite duration sequences both of length N with DFT‟s X1(k) and X2(k). Convolution of two
given sequences x1(n) and x2(n) is given by,

Program:

clc; % Program for circular convolution

clear all;
x1=input('enter the first sequence');
x2=input('enter the second sequence');
n=input('enter the no of points of the dft');
subplot(3,1,1);
stem(x1,'filled');
title('plot of first sequence');
subplot(3,1,2);
stem(x2,'filled');
title('plot the second sequnce');
y1=fft(x1,n);
y2=fft(x2,n);
y3=y1.*y2;
y=ifft(y3,n);
disp('the circular convolution result is ......');
disp(y);
subplot(3,1,3);
stem(y,'filled');
title('plot of circularly convoluted sequence');

Digital Signal Processing Lab Page 23


ECE DEPT, PRESIDENCY UNIVERSITY

OUTPUT:
enter the first sequence[1 2 3 4 5]
enter the second sequence[1 2 3]
enter the no of points of the dft5
the circular convolution result is ......
23 19 10 16 22

Digital Signal Processing Lab Page 24


ECE DEPT, PRESIDENCY UNIVERSITY

EXPERIMENT NO-9

AIM: DESIGN AND IMPLEMENTATION OF FIR FILTER TO MEET GIVEN SPECIFICATIONS (LOW
PASS FILTER USING HAMMING WINDOW)

EQUIPMENTS: Operating System - Windows 7 Constructor - Simulator Software - CCStudio 3 &


MATLAB 201

THEORY:

Finite Impulse Response (FIR) Filter: The FIR filters are of non-recursive type, whereby the present
output sample is depending on the present input sample and previous input samples.

Program:

%program for FIR HPF using blackman window


n=20;
fp=300;
fq=200;
fs=1000;
fn=2*fp/fs;
window=blackman(n+1);
b=fir1(n,fn,'high',window);
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('mag res of hpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase res of hpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');

Digital Signal Processing Lab Page 25


ECE DEPT, PRESIDENCY UNIVERSITY

Digital Signal Processing Lab Page 26


ECE DEPT, PRESIDENCY UNIVERSITY

%Program for FIR LPF using blackman window


n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=blackman(n+1);
b=fir1(n,fn,window);
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('magnitude response of lpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase response of lpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');

Digital Signal Processing Lab Page 27


ECE DEPT, PRESIDENCY UNIVERSITY

%program for FIR LPF using Hamming window


n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=hamming(n+1);
b=fir1(n,fn,window);
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('magnitude response of lpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase response of lpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');

Digital Signal Processing Lab Page 28


ECE DEPT, PRESIDENCY UNIVERSITY

%program for FIR LPF using hanning window


n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=hann(n+1);
b=fir1(n,fn,window);
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('magnitude response of lpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase response of lpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');

Digital Signal Processing Lab Page 29


ECE DEPT, PRESIDENCY UNIVERSITY

%Program for FIR LPF using rectangular window


n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=rectwin(n+1);
b=fir1(n,fn,window);
[H, W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('magnitude response of lpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase response of lpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');

Digital Signal Processing Lab Page 30


ECE DEPT, PRESIDENCY UNIVERSITY

%program for FIR LPF using triangular window


n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=triang(n+1);
b=fir1(n,fn,window);
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('magnitude response of lpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase response of lpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');

Digital Signal Processing Lab Page 31


ECE DEPT, PRESIDENCY UNIVERSITY

EXPERIMENT NO-10

AIM: DESIGN AND IMPLEMENTATION OF IIR FILTER TO MEET GIVEN


SPECIFICATIONS

EQUIPMENTS: Operating System - Windows 7 Constructor - Simulator Software - CCStudio 3 &


MATLAB 201

THEORY: Basically digital filter is a linear time-invariant discrete time system.

Infinite Impulse Response(IIR) filter: IIR filters are of recursive type, whereby the present output
sample depends on the present input, past input samples and output samples.

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);
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:');
Digital Signal Processing Lab Page 32
ECE DEPT, PRESIDENCY UNIVERSITY

xlabel('(b) Normalized freq. -->');


ylabel('Phase in radians-->');

OUTPUT 1 :
enter the IIR filter design specifications
enter the passband ripple15
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:

Digital Signal Processing Lab Page 33


ECE DEPT, PRESIDENCY UNIVERSITY

OUTPUT 2 :

enter the IIR filter design specifications


enter the passband ripple15
enter the stopband ripple60
enter the passband freq1500
enter the stopband freq3000
enter the sampling freq7000
enter choice of filter 1. LPF 2. HPF
2
Frequency response of IIR HPF is:

Digital Signal Processing Lab Page 34


ECE DEPT, PRESIDENCY UNIVERSITY

PART-II
(Code Composer Studio)
+
(DSP KIT-LCDK6748 PROCESSOR)

Digital Signal Processing Lab Page 35


ECE DEPT, PRESIDENCY UNIVERSITY

General Procedure to work on Code Composer Studio V5 for non-real time projects

1. Launch CCS
Launch the CCS v5 icon from the Desktop or goto All Programs -> Texas Instruments ->
CCSv5

2. Choose the location for the workspace, where your project will be saved.

3. Create a new Target Configuration File:


A. Select File-> New -> Target Configuration file

Digital Signal Processing Lab Page 36


ECE DEPT, PRESIDENCY UNIVERSITY

B. Specify any arbitrary target name. For Eg., C6748LCDK.ccxml (Extension should be
.ccxml).. Click Finish then you will get configuration window for the created target.

Digital Signal Processing Lab Page 37


ECE DEPT, PRESIDENCY UNIVERSITY

C. Select the Connection as Texas Instruments XDS100v2 USB Emulator and Board or Device as
LCDKC6748, then click Save.

D. Goto Advanced tab and Open the GEL file named “C6748_LCDK.gel” from “<Installed
directory>\Texas Instruments\pdk_C6748_2_0_0_0\gel” and Save.

Digital Signal Processing Lab Page 38


ECE DEPT, PRESIDENCY UNIVERSITY

E. Go to view option and select the Target Configuration:


View->Target Configuration.
A wizard will open in the workspace expand the User Defined folder and you can find your
target, Right click on C6748LCDK.ccxml and select the Launch Selected Configuration.

Digital Signal Processing Lab Page 39


ECE DEPT, PRESIDENCY UNIVERSITY

F. Now connect CCS to the target by Run -> Connect Target

Now our target is successfully configured and connected.


In future we no need to repeat these steps.

If we are working with the same hardware we can just open the already configured target and
launch the selected configuration and connect it.

4. Creating the New Project


Step P1:
Change the Perspective Debug to CCS Edit from the right corner of the CCS

Step P2:
Go to File  New  CCS Project.

Digital Signal Processing Lab Page 40


ECE DEPT, PRESIDENCY UNIVERSITY

Step P3:
Specify the name of the project in the space provided e g., Project Name: Hello LCDK.

Specify the “Device” properties as shown in the figure below and select an “Empty Project”.

Click Finish

Digital Signal Processing Lab Page 41


ECE DEPT, PRESIDENCY UNIVERSITY

Digital Signal Processing Lab Page 42


ECE DEPT, PRESIDENCY UNIVERSITY

5. To write a program, select one new source file.


A. Go to File  New  Source File.

B. Specify the arbitrary source file name with “.c” extension. It should be in the source folder
(current project name).

Digital Signal Processing Lab Page 43


ECE DEPT, PRESIDENCY UNIVERSITY

C. Type your C Code and save.

6. BUILD
Build the program to check your code.

Digital Signal Processing Lab Page 44


ECE DEPT, PRESIDENCY UNIVERSITY

Go to

Project  Build project.

If your code doesn‟t have any errors and warnings, a message will be printed in the console
window that “**** Build Finished ****”

Problems window display errors or warnings, if any.

7. LOAD
A. Now for loading the program to the hardware, change the perspective to CCS Debug and
goto Run -> Load -> Load Program.

B. Open the „.out‟ from the <project directory>/debug and click OK. Wait for the program to be
Digital Signal Processing Lab Page 45
ECE DEPT, PRESIDENCY UNIVERSITY

loaded and C file detected.

8. RUN
The program will be loaded to the hardware.
Now you can run the code, by selecting Run-> Resume.

Once you run the program the output will be printed in the Console Window.

Digital Signal Processing Lab Page 46


ECE DEPT, PRESIDENCY UNIVERSITY

We can also double click on the Console Window to view it on full screen.

Digital Signal Processing Lab Page 47


ECE DEPT, PRESIDENCY UNIVERSITY

PROGRAM 10: LINEAR CONVOLUTION USING DSP KIT AND CCS

To Verify Linear Convolution:

Linear Convolution involves the following operations.


1. Folding
2. Multiplication
3. Addition
4. Shifting

These operations can be represented by a Mathematical Expression as follows:

x[ ]= Input signal Samples


h[ ]= Impulse response co-efficient.
y[ ]= Convolution output.
n = No. of Input samples
h = No. of Impulse response co-efficient.

Algorithm to implement ‘C’ or Assembly program for Convolution:

Eg: x[n] = {1, 2, 3, 4}


h[k] = {1, 2, 3, 4}

Where: n=4, k=4. ;Values of n & k should be a multiple of 4.


If n & k are not multiples of 4, pad with zero’s to make
multiples of 4
r= n+k-1 ; Size of output sequence.
= 4+4-1
= 7.
r= 0 1 2 3 4 5 6
n= 0 x[0]h[0] x[0]h[1] x[0]h[2] x[0]h[3]
1 x[1]h[0] x[1]h[1] x[1]h[2] x[1]h[3]
2 x[2]h[0] x[2]h[1] x[2]h[2] x[2]h[3]
3 x[3]h[0] x[3]h[1] x[3]h[2] x[3]h[3]

Output: y[r] = {1, 4, 10, 20, 25, 24, 16}.

NOTE: At the end of input sequences pad ‘n’ and ‘k’ no. of zero’s

Digital Signal Processing Lab Page 48


ECE DEPT, PRESIDENCY UNIVERSITY

PROGRAM: linear.c

#include<stdio.h>

#define LENGHT1 6 /*Lenght of i/p samples sequence*/

#define LENGHT2 4 /*Lenght of impulse response Co-efficients */

int x[2*LENGHT1-1]={1,2,3,4,5,6,0,0,0,0,0}; /*Input Signal Samples*/

int h[2*LENGHT1-1]={1,2,3,4,0,0,0,0,0,0,0}; /*Impulse Response Coefficients*/

int y[LENGHT1+LENGHT2-1];

main()

int i=0,j;

for(i=0;i<(LENGHT1+LENGHT2-1);i++)

y[i]=0;

for(j=0;j<=i;j++)

y[i]+=x[j]*h[i-j];

for(i=0;i<(LENGHT1+LENGHT2-1);i++)

printf("%d\n",y[i]);

Procedure:

1. Open Code Composer Studio v5.


2. Connect the target (step 3).
3. Create new project with name as linear convolution(step 4).
4. Create new source file and type the code „linear.c‟ and save it (step 5).

Digital Signal Processing Lab Page 49


ECE DEPT, PRESIDENCY UNIVERSITY

5. Now perform steps 6,7and 8. Once you run the program you can watch convolution
result in the console window.

6. To view the values in graph


Go to

Tools  Graph Single Time

Set the Graph Properties as shown

Buffer size : 9

DSP Data Type : 32-Bit Signed Integer

Start Address: y

Display Data Size : 9

Click : Ok

The graph has been plotted as shown below.

Things to try, change x and h values and see corresponding change in output and graph.

Digital Signal Processing Lab Page 50


ECE DEPT, PRESIDENCY UNIVERSITY

PROGRAM 11: CIRCULAR CONVOLUTION USING DSP KIT AND CCS

To Verify Circular Convolution:

Program:
#include<stdio.h>
intm,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) /*Iflenght 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)*/

Digital Signal Processing Lab Page 51


ECE DEPT, PRESIDENCY UNIVERSITY

a[j]=h[n-j];

/*Circular convolution*/
for(i=0;i<n;i++)
y[0]+=x[i]*a[i];
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]);

Digital Signal Processing Lab Page 52


ECE DEPT, PRESIDENCY UNIVERSITY

PROGRAM 12: Discrete fourier transform Using DSP kit and CCS
DFT of a discrete time signal transforms the signal in time domain into frequency domain signal.

DFT EQUTION:

The sequence of N complex numbers x0, ..., xN−1 is transformed into another sequence of N
complex numbers according to the DFT formula:

Note:

1 It is periodic. (i.e. it goes round and round the circle !!)


2 That the vectors are symmetric
3 The vectors are equally spaced around the circle

The inverse discrete Fourier transform (IDFT) is given by:

Digital Signal Processing Lab Page 53


ECE DEPT, PRESIDENCY UNIVERSITY

C. PROGRAM TO IMPLEMENT DFT.

#include<stdio.h>
#include<math.h>
int N,k,n,i;
float pi=3.1416,sumre=0, sumim=0,out_real[8]={0.0}, out_imag[8]={0.0};
int x[32];
void main(void)
{
printf(" enter the length of the sequence\n");
scanf("%d",&N);
printf(" enter the sequence\n");
for(i=0;i<N;i++)
scanf("%d",&x[i]);
for(k=0;k<N;k++)
{
sumre=0;
sumim=0;

for(n=0;n<N;n++)
{
sumre=sumre+x[n]* cos(2*pi*k*n/N);
sumim=sumim-x[n]* sin(2*pi*k*n/N);
}
out_real[k]=sumre;
out_imag[k]=sumim;
printf("X([%d])=\t%f\t+\t%fi\n",k,out_real[k],out_imag[k]);
}
}

Digital Signal Processing Lab Page 54


ECE DEPT, PRESIDENCY UNIVERSITY

PROCEDURE
1. Open Code Composer Studio v5.
2. Connect the target (step 3).
3. Create new project with name as sinewave(step 4).
4. Create new source file and type the code give above and save it.(step 5)
5. Now build and run the project.
Once you run the program. Console window will ask for length of sequence. Enter the
length.

Now it will ask for sequence. Enter the sequence.

DFT of the given input will appear in console window as shown below.

Digital Signal Processing Lab Page 55


ECE DEPT, PRESIDENCY UNIVERSITY

PROGRAM 13: Realization of an FIR filter (any type) to meet given


specification. The input can be signal from function generator/speech signal .

FIR filters ar filters whose impulse response is of finite duration. These filters are very stable,
in contrast to IIR filters. Most FIR filters are non-recursive and are carried out by convolution. Thus,
the output y of a linear time invariantsystem is determined by convolving its input signal x with its
impulse response h. For a discrete time filter, the output iss therefore a weighted sum of the
current sample and a finite number of previous input samples. The impulse response of a Nth-order
FIR filter has a length of N+1 samples.

Digital Signal Processing Lab Page 56


ECE DEPT, PRESIDENCY UNIVERSITY

PROCEDURE
 Click on Project New CCS Project, name the project as fir_filter.
 Configure the project as that of previous LAB1.
 Click on the newly created project in Project Explorer Space, Open main.c, Select all and
clear main.c
 Edit main.c as

#include "L138_LCDK_aic3106_init.h" #define N 31 float h[N] = {-0.000035,-0.000234,-


0.000454,0.000000,0.001933,0.004838, 0.005671,-0.000000,-0.013596,-0.028462,-
0.029370,0.000000,0.064504,
0.148863,0.221349,0.0249983,0.221349,0.148863,0.064504,0.000000, -0.029370,-0.028462,-
0.013596,-0.000000,0.005671,0.004838,0.001933, 0.000000,-0.000454,-0.000234,-0.000035
};//FILTER CO-EFFICIENTS

Program:

Digital Signal Processing Lab Page 57


ECE DEPT, PRESIDENCY UNIVERSITY


 Save main.c
 Right Click on Project[fir_filter], select Add Files
 Browse to C:/DSPLIB/support_files, select
 L138_LCDK_aic3106_init.h L138_LCDK_aic3106_init.c linker_dsp.cmd vectors_intr.asm
 Select Link to Files.
 You should delete C6748.cmd, as you already have linker_dsp.cmd[C6748.cmd is added by
default when you create a new project].
 Right Click on your ProjectPropertiesGeneral, add run time support library as
rts6740.lib
 In project Properties go to C6000 CompilerInclude Options, Add include search path
 Browse for location-

 C:/DSPLAB/board_support_lib/inc, click on OK C:/DSPLAB/support_files, click on OK


 In the Project Properties go to C6000 LinkerFile Search Path, in Add File Path,

 Browse C:/DSPLAB/board_support_lib/lib/evmomapl138_bsl.lib, click on open and finally


ok.
 Exit Project Properties window by clicikng on OK, make sure you have selected rts6740.lib as
directed earlier.
 Reset the LCDK board, Select your project, build it, debug it. 
  Connect audio source to LINE IN JACK(top)and speaker/headphone to LINE OUT
JACK(bottom).
  Play audio available at DSPLAB folder in C:/DSPLAB/Test_signal, it has a 1kHz tone as noise
to voice signal and in Debug window, click on RESUME, the code will run and you can hear
filtered audio on the headphone side.
  If you don’t hear anything, terminate the debug session, reset your hardware, Debug and
run once again.
  The 1 kHz tone is removed from the signal, using FIR FILTER.
 NOTE: The FILTER CO-EFFICIENTS h[N] are generated using MATLAB FIR1 function.We have
used filter coefficients for LOW PASS FILTER with cut-oo frequency of 1KHz, since the noise
in our test signal is 1KHz.

Digital Signal Processing Lab Page 58

You might also like