DSP Lab Manual Final Presidency University
DSP Lab Manual Final Presidency University
Program Title
P4 Solving a given difference equation/plot pole zero plot and impulse response.
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.
EXPERIMENT NO-1
clc;
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
EXPERIMENT NO-2
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,
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;
1.0e+04 *
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
EXPERIMENT NO-3
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
Program-2
clc;
clear all;
close all;
disp('linear convolution program');
x=[x,zeros(1,n)];
subplot(2,2,1),stem(x);
title('i/p sequence x(n) is:');
xlabel('---->n');
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;
y=
1 4 10 16 22 22 15
EXPERIMENT NO-4
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');
>> 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
EXPERIMENT NO-5
AIM: To find h[n] of the difference equation and plot impulse response and pole-zero plot.
Program:
close all;
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
EXPERIMENT NO-6
AIM: TO COMPUTE N-POINT DFT OF A GIVEN SEQUENCE AND TO PLOT MAGNITUDE AND PHASE
SPECTRUM.
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:
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
Columns 7 through 8
EXPERIMENT NO-7
AIM: LINEAR CONVOLUTION OF TWO GIVEN SEQUENCES USING DFT AND IDFT
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');
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
EXPERIMENT NO-8
AIM: TO IMPLEMENT CIRCULAR CONVOLUTION OF TWO GIVEN SEQUENCES USING DFT AND
IDFT
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:
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');
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
EXPERIMENT NO-9
AIM: DESIGN AND IMPLEMENTATION OF FIR FILTER TO MEET GIVEN SPECIFICATIONS (LOW
PASS FILTER USING HAMMING WINDOW)
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:
EXPERIMENT NO-10
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
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:
OUTPUT 2 :
PART-II
(Code Composer Studio)
+
(DSP KIT-LCDK6748 PROCESSOR)
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.
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.
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.
If we are working with the same hardware we can just open the already configured target and
launch the selected configuration and connect it.
Step P2:
Go to File New CCS Project.
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
B. Specify the arbitrary source file name with “.c” extension. It should be in the source folder
(current project name).
6. BUILD
Build the program to check your code.
Go to
If your code doesn‟t have any errors and warnings, a message will be printed in the console
window that “**** Build Finished ****”
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
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.
We can also double click on the Console Window to view it on full screen.
NOTE: At the end of input sequences pad ‘n’ and ‘k’ no. of zero’s
PROGRAM: linear.c
#include<stdio.h>
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:
5. Now perform steps 6,7and 8. Once you run the program you can watch convolution
result in the console window.
Buffer size : 9
Start Address: y
Click : Ok
Things to try, change x and h values and see corresponding change in output and graph.
Program:
#include<stdio.h>
intm,n,x[30],h[30],y[30],i,j,temp[30],k,x2[30],a[30];
void main()
{
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];
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]);
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:
#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]);
}
}
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.
DFT of the given input will appear in console window as shown below.
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.
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
Program:
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 ProjectPropertiesGeneral, add run time support library as
rts6740.lib
In project Properties go to C6000 CompilerInclude Options, Add include search path
Browse for location-