0% found this document useful (0 votes)
110 views

LAB3

The document describes implementing a program to calculate the convolution of two discrete time signals x(n) and h(n). It provides the C code to define the signals, calculate the convolution as y(n)=x(n)*h(n), and display the result on an OSD9616 LCD module. The program takes in the lengths and values of the signals x(n) and h(n), calculates each value of y(n) as the sum of x(n) multiplied by h(m-n), and prints the results to the LCD screen.

Uploaded by

Thinh Lê
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views

LAB3

The document describes implementing a program to calculate the convolution of two discrete time signals x(n) and h(n). It provides the C code to define the signals, calculate the convolution as y(n)=x(n)*h(n), and display the result on an OSD9616 LCD module. The program takes in the lengths and values of the signals x(n) and h(n), calculates each value of y(n) as the sum of x(n) multiplied by h(m-n), and prints the results to the LCD screen.

Uploaded by

Thinh Lê
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

FACULTY OF ELECTRICAL

AND ELECTRONIC ENGINEERING


2020 – 2021
-------*-------

DIGITAL SIGNAL PROCESSING – LABORATORY


Minor project 4: DFT/FFT

Lecturer: Prof. Dr. Thuong Le – Tien

Students: Le Ngoc Thinh - 1751094 - No. 11


Nguyen Vinh Hung - 1751044 - No. 9
Nguyen Thuyet Hieu - 1751029 - No. 8
Ho Chi Minh City, 4/2021

2
CONTENTS
1. Abstract.........................................................................................................3
2. Introduction...................................................................................................3
3. Implement......................................................................................................3
3.1. Write a program to calculate the convolution y(n) = x(n)*h(n)................3
3.2. Generate the signal by “Signal Generator” (External)............................10
4. Conclusion.....................................................................................................19
5. References.....................................................................................................19

3
1. Abstract
This report introduces the LCD module on the TMS320C5515 eZDSPTM USB
Stick Development Tool. It also outlines basic steps to configure and use the
module to calculate the convolution of two signals.

2. Introduction
The convolution of the input signal with the impulse response function of the
system. In the signal processing literature it is common to write:

y(t)=x(t)∗h(t)

Although this is a bit sloppy notation (for a mathematician this looks like an
expression involving real numbers not functions) it is used a lot and even in
some cases it helps to make clear what the functions involved are.

y(t)=x(t)∗h(t)

Consider the case of discrete time signals. Let x[n] be the input signal to a
linear LTI system that is characterized with its impulse response h[n]. The
output signal then is given by:

y[n]=x[n]∗h[n]y[n]=x[n]∗h[n]

So although mathematically quite sloppy this notation allows clear distinction


between coninuous time and discrete time systems.

3. Implement
3.1. Write a program to calculate the convolution y(n) = x(n)*h(n)
Given:
x(n) ={-2, 1, 3, 0, 2, 7}

4
h(n) ={-1, -3, 1,- 2}
CCS code:
Convolution.c
#include"ezdsp5535.h"
#include"ezdsp5535_lcd.h"
#include "ezdsp5535_i2c.h"
#include "ezdsp5535_gpio.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"

#define OSD9616_I2C_ADDR 0x3C // OSD9616 I2C address


char x[100];
char h[100];
char y[100];
int j=0;
int k=0;
int n=0,m=0;
int one_digit,ten_digit;
char c=(3+0x30);

Int16 printLetter(Uint16 l1,Uint16 l2,Uint16 l3,Uint16 l4)


{
EZDSP5535_OSD9616_send(0x40,l1);
EZDSP5535_OSD9616_send(0x40,l2);
EZDSP5535_OSD9616_send(0x40,l3);
EZDSP5535_OSD9616_send(0x40,l4);
EZDSP5535_OSD9616_send(0x40,0x00);
return 0;
}

void print_char(char c)
{
switch(c)
{
case '0': printLetter(0xFE,0x82,0xFE,0xFE); break; // 0 zero
case '1': printLetter(0x00,0xFE,0x04,0x00); break; // 1 one
case '2': printLetter(0x9E,0x92,0xf2,0xF2); break; // 2 two
case '3': printLetter(0xFE,0x92,0x82,0x82); break; // 3 three
case '4': printLetter(0xFE,0x10,0x1E,0x1E); break; // 4 four
case '5': printLetter(0xF2,0x92,0x9E,0x9E); break; // 5 five
case '6': printLetter(0xF2,0x92,0xFE,0xFE); break; // 6 six
case '7': printLetter(0x06,0xFA,0x02,0x02); break; // 7 seven
case '8': printLetter(0xFE,0x92,0xFE,0xFE); break; // 8 eight
case '9': printLetter(0xFE,0x92,0x9E,0x9E); break; // 9 nine
case ' ': printLetter(0x00,0x00,0x00,0x00); break; // space
case '-': printLetter(0x00,0x10,0x10,0x10); break; // -
}
}
char PrintResult(char value)
{
if(value<0)
{

5
value=-value;
if(value>9)
{
one_digit= value%10;
ten_digit= value/10;
print_char(one_digit+0x30);
print_char(ten_digit+0x30);
print_char(' ');
}
print_char(value+0x30);
printLetter(0x00,0x10,0x10,0x10);
return 0;
}
if(value >= 0 && value <= 9)
{
print_char(value+0x30);
print_char(' ');
}
if(value>9)
{
one_digit= value%10;
ten_digit= value/10;
print_char(one_digit+0x30);
print_char(ten_digit+0x30);
//print_char(' ');
}
return 0;
}
void convolution()
{
printf("Input length of x[n]:");
scanf("%d",&k);
printf("Input length of h[n]:");
scanf("%d",&j);
printf("x[n]={");
for (m=0;m<k;m++)
{
scanf("%d",&x[m]);
}
printf("}\n");
printf("h[n]={");
for (m=0;m<j;m++)
{
scanf("%d",&h[m]);
}
printf("}\n");
printf("y[n]={");
for (m=0;m<k+j-1;m++)
{
y[m]=0;
for (n=0;n<=m;n++)
{
if ((n<k)&&(m-n<j))
y[m]=y[m]+x[n]*h[m-n];
}
}
for (m=0;m<k+j-1;m++)

6
{
printf("%d,",y[m]);
}
for (m=k+j-2;m>=0;m--)
{
PrintResult(y[m]);
print_char(' ');
printLetter(0x00,0x00,0x00,0xC0);
}
printf("}\n");
}
/* ------------------------------------------------------------------------ *
* *
* Int16 oled_test() *
* *
* Testing function for the OSD9616 display *
* *
* ------------------------------------------------------------------------ */
Int16 Convolution()
{
Int16 i;
Uint16 cmd[10]; // For multibyte commands

EZDSP5535_OSD9616_init();

/* Fill page 0 */
EZDSP5535_OSD9616_send(0x00,0x00); // Set low column address
EZDSP5535_OSD9616_send(0x00,0x10); // Set high column address
EZDSP5535_OSD9616_send(0x00,0xb0+0); // Set page for page 0 to page 5
for(i=0;i<128;i++)
{
EZDSP5535_OSD9616_send(0x40,0xff);
}

/* Write to page 0 */
EZDSP5535_OSD9616_send(0x00,0x00); // Set low column address
EZDSP5535_OSD9616_send(0x00,0x10); // Set high column address
EZDSP5535_OSD9616_send(0x00,0xb0+0); // Set page for page 0 to page 5
for(i=0;i<128;i++)
{
EZDSP5535_OSD9616_send(0x40,0x00);
}

convolution();

// for(i=0;i<12;i++)
// {
// EZDSP5535_OSD9616_send(0x40,0x00); // Spaces
// }
/* Fill page 1*/
EZDSP5535_OSD9616_send(0x00,0x00); // Set low column address
EZDSP5535_OSD9616_send(0x00,0x10); // Set high column address
EZDSP5535_OSD9616_send(0x00,0xb0+1); // Set page for page 0 to page 5
for(i=0;i<128;i++)
{
EZDSP5535_OSD9616_send(0x40,0xff);

7
}
/* Write to page 1*/
EZDSP5535_OSD9616_send(0x00,0x00); // Set low column address
EZDSP5535_OSD9616_send(0x00,0x10); // Set high column address
EZDSP5535_OSD9616_send(0x00,0xb0+1); // Set page for page 0 to page 5
for(i=0;i<128;i++)
{
EZDSP5535_OSD9616_send(0x40,0x00);
}
for(i=0;i<5;i++)
{
EZDSP5535_OSD9616_send(0x40,0x00); // Spaces
}
/* Keep first 8 rows from vertical scrolling*/
cmd[0] = 0x00;
cmd[1] = 0xa3; // Set Vertical Scroll Area
cmd[2] = 0x08; // Set No. of rows in top fixed area
cmd[3] = 0x08; // Set No. of rows in scroll area
EZDSP5535_OSD9616_multiSend( cmd, 4 );
/* Set vertical and horizontal scrolling */

/*cmd[0] = 0x00;
cmd[1] = 0x29; // Vertical and Right Horizontal Scroll
cmd[2] = 0x00; // Dummy byte
cmd[3] = 0x00; // Define start page address
cmd[4] = 0x03; // Set time interval between each scroll step
cmd[5] = 0x01; // Define end page address
cmd[6] = 0x00; // Vertical scrolling offset
EZDSP5535_OSD9616_multiSend(cmd, 7);
EZDSP5535_OSD9616_send(0x00, 0x2f);*/

/* Keep first 8 rows from vertical scrolling*/


cmd[0] = 0x00;
cmd[1] = 0xa3; // Set Vertical Scroll Area
cmd[2] = 0x08; // Set No. of rows in top fixed area
cmd[3] = 0x08; // Set No. of rows in scroll area
EZDSP5535_OSD9616_multiSend( cmd, 4 );

return 0;
}

Main function:
#include "stdio.h"
#include "ezdsp5535.h"

extern Int16 Convolution( );

int TestFail = (int)-1;

void StopTest()
{
//SW_BREAKPOINT;
return;
}

8
/*
*
* main( )
*
*/
void main( void )
{
/* Initialize BSL */
EZDSP5535_init( );

/* Display test ID */
printf( "\nConvolution Lab...\n");

/* Call test function */


TestFail = Convolution( );

/* Check for test fail */


if ( TestFail != 0 )
{
/* Print error message */
printf( " FAIL... error code %d... quitting\n", TestFail );
}
else
{
/* Print pass message */
printf( " PASS\n" );
printf( "\n***ALL Tests Passed***\n" );
}

StopTest();
}
The results:

9
Figure 1. The result of convolution shown on the console of CCS

On Oled kit

10
Figure 2. The result of convolution shown on Oled of TSM320C5535
Matlab code:
function [y,ny] = conv_m(x,nx,h,nh)
% Modified convolution routine for signal processing
% --------------------------------------------------
% [y,ny] = conv_m(x,nx,h,nh)
% [y,ny] = convolution result
% [x,nx] = first signal
% [h,nh] = second signal
%
nyb = nx(1)+nh(1); nye = nx(length(x)) + nh(length(h));
ny = [nyb:nye]; y = conv(x,h);

Result:

3.2. Generate the signal by “Signal Generator” (External)

x(t)=0.5sin(100 π t)
and the impulse response h(t) = 0.5sin(100 π t) by the C5535 write program to
calculate y(t) = x(t)*h(t). Compare the Matlab to C5535’s result.
Matlab code to generate signal x(t)=0.5sin(100 π t)

t = 0: .0002: .02;

x = 0.5*sin(100*pi*t);

fileID = fopen('E:\202\TN DSP\lab4\Sine.txt', 'w');


fprintf(fileID, '%f\n', x);
fclose(fileID);

11
Figure 3. The data of x(t) = 0.5sin(100*pi*t) on file text

12
CCS code to calculate convolution
#include "stdio.h"
#include "math.h"
#define PI 3.1415926535

float h[200]; // initialize impulse response h(n)


float x[200]; // initialize signal x(n)
float y[203]; // initialize output y(n)
float i ;
int k, j = 0;
int m = 101;
int n = 101;

void main( void )


{
FILE *fptr;

for ( i = 0; i <= 0.02; )


{
h[j] = 0.5 * sin(100*PI*i)//generate impulse response in a period
j++;
i += 0.0002;
}
if ((fptr = fopen("E:\\202\\TN DSP\\lab4\\Sine.txt","r")) == NULL) // Check
file Sine.txt whether empty or not

{
printf("Error! Empty File!!!");
exit(1);
}

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


{
fscanf(fptr,"%f", &x[j]); // read data from fine Sine.txt
}
fclose(fptr);
for ( j = m; j < m+n-1; j++)
{
x[j] = 0; // zero padding for signal x(n)
}
for ( j = n; j < m+n-1; j++)
{
h[j] = 0; // zero padding for impulse response h(n)
}
for ( j = 0 ; j < m+n-1; j++)
{
y[j] = 0;
for ( k = 0; k <= j; k++)
{
y[j]+= x[k]*h[j-k];// Take the convolution y(n) = x(n)*h(n)
printf("%d",y[j]);
}
}

13
}

Matlab code
Fs = 5000; % takes 101 samples
Ts = 1/Fs;
fc = 50;
Tc = 1/fc;

t = 0:Ts:Tc ;

x = 0.5*sin(100*pi*t); % initilize signal x(n)


h = 0.5*sin(100*pi*t); % initilize signal h(n)
disp(x);
disp(h);
y = conv(x,h); % convolution 2 signals

figure()
plot(t, h);
title('h(n) = 0.5*sine(100*pi*t)');
xlabel('t');
ylabel('Amplitude');

figure()
plot(t, x,'g')
title('x(n) = 0.5*sine(100*pi*t)');
xlabel('t');
ylabel('Amplitude');

Fs1 = 10000; % takes 201 samples


fc1 = 50;
t = 0: 1/Fs1: 1/fc1;
figure()
stem(t,y,'r');
title('y(n) = x(n)*h(n)');
xlabel('t');
ylabel('Amplitude');

14
Results:

From MATLAB

Figure 4. The result of convolution y(n) = x(n)*h(n)

15
Figure 5. Graph of function x(t)

16
Figure 6. Graph of function h(t)

17
From CSS

Figure 7. Graph of function x(t)

Figure 8. Graph of function h(t)

18
Figure 9. The result of convolution y(n) = x(n)*h(n)

Comment: As we can see, the graphs plotted on Matlab and CCS are the same.

19
4. Conclusion
In this lab project, we have tried to do the comparison of the convolution
between Matlab and CCS (using kit TMS320C5535) by graphical method. We
have been successful when the results obtain similarly from Matlab and CCS .

5. References
[1] Texas Instruments, C5515 eZDSP USB Stick Development Tool description
and features, http://www.ti.com/tool/tmdx5515ezdsp.

.
Illustrating images of C5515 eZDSP USB Stick Development Tool are taken from
http://www.ti.com.
All source codes in this report are taken from the usbstk5515_v1 library associated
with C5515 eZDSP USB Stick Development Tool, provided by Spectrum Digital
Inc..

20

You might also like