LAB3
LAB3
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]
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"
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);*/
return 0;
}
Main function:
#include "stdio.h"
#include "ezdsp5535.h"
void StopTest()
{
//SW_BREAKPOINT;
return;
}
8
/*
*
* main( )
*
*/
void main( void )
{
/* Initialize BSL */
EZDSP5535_init( );
/* Display test ID */
printf( "\nConvolution Lab...\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:
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);
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
{
printf("Error! Empty File!!!");
exit(1);
}
13
}
Matlab code
Fs = 5000; % takes 101 samples
Ts = 1/Fs;
fc = 50;
Tc = 1/fc;
t = 0:Ts:Tc ;
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');
14
Results:
From MATLAB
15
Figure 5. Graph of function x(t)
16
Figure 6. Graph of function h(t)
17
From CSS
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