0% found this document useful (0 votes)
51 views22 pages

Lab 5 Report: Digital Signal Processing

The document is a lab report summarizing steps to generate and calculate the 128-point discrete Fourier transform (DFT) of a periodic signal using MATLAB and a TMS320C5515 digital signal processor. It includes generating the signal in MATLAB, taking the DFT, and comparing the results to those from implementing the DFT on the C5515 chip. Code snippets are provided for both MATLAB and C to generate the signal and compute the DFT. The signal and DFT results are plotted and shown to match between the two implementations.

Uploaded by

Nguyễn Tài
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)
51 views22 pages

Lab 5 Report: Digital Signal Processing

The document is a lab report summarizing steps to generate and calculate the 128-point discrete Fourier transform (DFT) of a periodic signal using MATLAB and a TMS320C5515 digital signal processor. It includes generating the signal in MATLAB, taking the DFT, and comparing the results to those from implementing the DFT on the C5515 chip. Code snippets are provided for both MATLAB and C to generate the signal and compute the DFT. The signal and DFT results are plotted and shown to match between the two implementations.

Uploaded by

Nguyễn Tài
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/ 22

Vietnam National University

Ho Chi Minh City University of Technology

Digital Signal Processing

LAB 5 REPORT
Generate and calculate DFT of a periodic signal
Using TMS320C5515 eZDSPTM USB Stick

Instructor: Assoc. Prof. Dr. Thuong Le -Tien


Teaching Asisstants: Chi Hieu, Quoc Huy

Group 7:
Dat Nguyen-Si ID: ILI11006 In-class ID: 2
Trung Le ID: 41103857 In-class ID: 3

April, 24th 2014


Table of Contents
Table of Contents...........................................................1 April, 24th 2014

Abstract..........................................................................2

Introduction....................................................................3

Matlab Implementation.................................................4

C5515 Implementation...................................................7

Software generation.....................................................16

Compare the results and Conclusions..........................18

1 Lab 5 report
Abstract
This report outlines steps to generate and April, 24th 2014
calculate 128 - DFT of a given signal using
TMS320C5515 eZDSPTM USB Stick Development
Tool. The report includes a Matlab-based
demonstration and hardware-based
programming. The two outcomes are also
analyzed and compared.

2 Lab 5 report
Introduction
In mathematics, the discrete Fourier transform (DFT) is a specific kind of Fourier transform,
used in Fourier analysis. It transforms one function into another, which is called the th
April, 24 2014
frequency domain representation, or simply the DFT, of the original function (which is often
a function in the time domain). In DFT, both input and output are discrete (i.e. discrete in
time domain and frequency domain).

The input to the DFT is a finite sequence of real or complex numbers , making the DFT ideal
for processing information stored in computers.

The sequence of N complex numbers is transformed into an N-periodic


sequence of complex numbers:
N −1
X k = ∑ x n . e−2 πkn / N , k ∈ Z
0

The DFT can be computed efficiently in practice using a fast Fourier transform (FFT)
algorithm.

FFT algorithms are so commonly employed to compute DFTs that the term "FFT" is often
3 Lab 5 report
used to mean "DFT" in colloquial settings. Formally, there is a clear distinction: "DFT" refers
to a mathematical transformation or function, regardless of how it is computed, whereas
"FFT" refers to a specific family of algorithms for computing DFTs.

In this lab session, we will generate and calculate 128-DFT of the following signal:

x(t)=-2 cos(400πt) + cos(200πt) - 1.5cos(600πt)

Using Matlab, TMS320C5515 eZDSPTM USB Stick Development Tool. The signal is also
generated by VIRTIN Multi-Instrument 3.2. Then, the results of Matlab and C5515 are
compared.
Matlab implementation

I)FLOW CHART April, 24th 2014

Start

Generate x(t)

Sketch x(t)

Take 128-DFT

4 Sketch X(f)
Lab 5 report

Save signal data

End
II)MATLAB CODES
April, 24th 2014
clc;
close all;
clear all;

% generate 128 signal samples with Fs=1000Hz


t=0:0.001:0.127;
x=-2*cos(400*pi*t) + cos(200*pi*t) - 1.5*cos(600*pi*t);

%sketch the signal


figure(1);
plot(t,x);
ylabel('Amplitude');
xlabel('Time');

%take 128-FFT of the given signal


X=fft(x,128);
X=fftshift(X);

%sketch the FFT


f = (-64:63)*(1000/128);
figure(2);
5 stem(f,abs(X)); Lab 5 report
ylabel('Amplitude');
xlabel('Frequency');

%store the signal data


samples = round(x);
temp = zeros(1,256);
for i = 0:127
temp(1+2*i) = samples(1+i);
end
samples = temp;
id = fopen('D:\samples3.bin','wb');
fwrite(id, samples, 'int16');
fclose(id);
We have the follwong results:

Signal result:

April, 24th 2014

FFT result:

6 Lab 5 report

The main frequencies ( 100 Hz, 200 Hz, 300 Hz) are shown correctly.
C5515 implementation
I)FLOW CHART

April, 24th 2014

Start

Generate x(t)

Sketch x(t)

Take 128-DFT

Sketch X(f)

Save signal data


7 Lab 5 report

End
II)SOURCE CODES

1. Signal generation

Flowchart: April, 24th 2014

Start
Start

set Fs=48Khz

set
set f1,f2,f3
f1,f2,f3

calculate x(t) samples in double

multiply
multiply 1333
1333 to
to the
the samples
samples for
for greater-than-1
greater-than-1 values
values

Convert
Convert them into intergers
them into intergers

8 Lab 5 report
Play the signal
Play the signal

End

We only modify the aic3204_tone_headphone module:


#include "stdio.h"
#include "usbstk5515.h"
extern Int16 AIC3204_rset( Uint16 regnum, Uint16 regval);
#define XmitL 0x10
#define XmitR 0x20

#define Fs 48000
#define F1 200
#define F2 100
#define F3 300

#define PI 3.141592654

#include "math.h"
/* ------------------------------------------------------------------------ *
* *
* AIC3204 Tone *
* Output a 1 kHz tone through the HEADPHONE jack *
* *
* ------------------------------------------------------------------------ */
Int16 aic3204_tone_headphone( )
{
double * signal;
short * ptsig;
int x; April, 24th 2014
int nsample = (Fs) / F2;

signal = (double*) malloc( nsample * sizeof(double));

for ( x = 0; x < nsample; x++)


{
signal[x] = 1333*( -2*cos (2*PI*x*F1/Fs) + cos(2*PI*x*F2/Fs) -
1.5*cos(2*PI*x*F3/Fs) );
}
ptsig = (short*) malloc( nsample * sizeof(short));
for ( x = 0; x < nsample; x++)
{
ptsig[x] = (short) signal[x];
}

/* Configure AIC3204 */
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 1, 1 ); // Reset codec
AIC3204_rset( 0, 1 ); // Select page 1
AIC3204_rset( 1, 8 ); // Disable crude AVDD generation from DVDD
AIC3204_rset( 2, 1 ); // Enable Analog Blocks, use LDO power
9 AIC3204_rset( 0, 0 ); Lab 5 report
/* PLL and Clocks config and Power Up */
AIC3204_rset( 27, 0x0d ); // BCLK and WCLK are set as o/p; AIC3204(Master)
AIC3204_rset( 28, 0x00 ); // Data ofset = 0
AIC3204_rset( 4, 3 ); // PLL setting: PLLCLK <- MCLK, CODEC_CLKIN <-PLL
CLK
AIC3204_rset( 6, 7 ); // PLL setting: J=7
AIC3204_rset( 7, 0x06 ); // PLL setting: HI_BYTE(D=1680)
AIC3204_rset( 8, 0x90 ); // PLL setting: LO_BYTE(D=1680)
AIC3204_rset( 30, 0x88 ); // For 32 bit clocks per frame in Master mode ONLY
// BCLK=DAC_CLK/N =(12288000/8) = 1.536MHz = 32*fs
AIC3204_rset( 5, 0x91 ); // PLL setting: Power up PLL, P=1 and R=1
AIC3204_rset( 13, 0 ); // Hi_Byte(DOSR) for DOSR = 128 decimal or 0x0080
DAC oversamppling
AIC3204_rset( 14, 0x80 ); // Lo_Byte(DOSR) for DOSR = 128 decimal or 0x0080
AIC3204_rset( 20, 0x80 ); // AOSR for AOSR = 128 decimal or 0x0080 for
decimation filters 1 to 6
AIC3204_rset( 11, 0x82 ); // Power up NDAC and set NDAC value to 2
AIC3204_rset( 12, 0x87 ); // Power up MDAC and set MDAC value to 7
AIC3204_rset( 18, 0x87 ); // Power up NADC and set NADC value to 7
AIC3204_rset( 19, 0x82 ); // Power up MADC and set MADC value to 2
/* DAC ROUTING and Power Up */
AIC3204_rset( 0, 1 ); // Select page 1
AIC3204_rset( 0x0c, 8 ); // LDAC AFIR routed to HPL
AIC3204_rset( 0x0d, 8 ); // RDAC AFIR routed to HPR
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 64, 2 ); // Left vol=right vol
AIC3204_rset( 65, 0); // Left DAC gain to 0dB VOL; Right tracks Left
AIC3204_rset( 63, 0xd4 ); // Power up left,right data paths and set channel
AIC3204_rset( 0, 1 ); // Select page 1
AIC3204_rset( 0x10, 0x00 );// Unmute HPL , 0dB gain
AIC3204_rset( 0x11, 0x00 );// Unmute HPR , 0dB gain
AIC3204_rset( 9, 0x30 ); // Power up HPL,HPR
AIC3204_rset( 0, 0 ); // Select page 0
USBSTK5515_wait( 100 ); // wait
/* ADC ROUTING and Power Up */ April, 24th 2014
AIC3204_rset( 0, 1 ); // Select page 1
AIC3204_rset( 0x34, 0x30 );// STEREO 1 Jack
// IN2_L to LADC_P through 40 kohm
AIC3204_rset( 0x37, 0x30 );// IN2_R to RADC_P through 40 kohmm
AIC3204_rset( 0x36, 3 ); // CM_1 (common mode) to LADC_M through 40 kohm
AIC3204_rset( 0x39, 0xc0 );// CM_1 (common mode) to RADC_M through 40 kohm
AIC3204_rset( 0x3b, 0 ); // MIC_PGA_L unmute
AIC3204_rset( 0x3c, 0 ); // MIC_PGA_R unmute
AIC3204_rset( 0, 0 ); // Select page 0
AIC3204_rset( 0x51, 0xc0 );// Powerup Left and Right ADC
AIC3204_rset( 0x52, 0 ); // Unmute Left and Right ADC

AIC3204_rset( 0, 0 );
USBSTK5515_wait( 200 ); // Wait

/* I2S settings */
I2S0_SRGR = 0x0;
I2S0_CR = 0x8010; // 16-bit word, slave, enable I2C
I2S0_ICMR = 0x3f; // Enable interrupts

/* Play Tone */
10 for ( i = 0 ; i < 1000 ; i++ ) Lab 5 report
{
for ( j = 0 ; j < 1000 ; j++ )
{
for ( sample = 0 ; sample < nsample ; sample++ )
{
while((XmitR & I2S0_IR) == 0); // Wait for transmit
interrupt to be pending

I2S0_W0_MSW_W = (ptsig[sample]) ; // 16 bit left channel transmit


audio data
I2S0_W1_MSW_W = (ptsig[sample]) ; // 16 bit right channel
transmit audio data
}
}
}
/* Disable I2S */
I2S0_CR = 0x00;

return 0;
}
The fllowing result is shown on Oscilliscope( Soundcard Scope):

Signal Sketch:

April, 24th 2014

11 Lab 5 report

It has the similar shape of the wave generated by Matlab.


Frequency domain sketch:

April, 24th 2014

12 Lab 5 report

The main frequencies are also clearly shown on the graph.


2. FFT implementation:
Flow chart:

Start

April, 24th 2014


Load the samples (generated by Matlab)

calculate 128-FFT

Save the result

Show the result on


Matlab

End
13 Lab 5 report
Source code:

#include <stdio.h>
#include <math.h>
#include <tms320.h>
#include <dsplib.h>
#include "usbstk5515.h"
#define NX 128

Uint16 ImportFile( Uint32 pixel, Uint16 *p_buffer_data )


{
FILE *fp ;
Uint16 data , pdata[2] ;
Uint32 i ;
fp = fopen ("D:\\samples3.bin","rb") ;
if ( fp == (FILE*)NULL)
{
printf(" Error : can't open file_in \n") ;
return 1 ;// check error
}
for( i = 0 ; i < pixel; i++ ){
fread(pdata, 1, 2, fp);
data = *(pdata) | ((*(pdata+1) ) << 8);
p_buffer_data[i] = data ;
}
fclose ( fp ) ;
return 0 ;
}

Uint16 ExportFile( Uint32 pixel, Uint16 *p_buffer_data )


{
FILE *fp ;
Uint32 i ;
fp = fopen ("D:\\FFT4.bin","wb" ) ; April, 24th 2014
if ( fp == (FILE*) NULL)
{
printf(" Error : can't open file_in \n") ;

return 1 ;// check error


}
for (i = 0; i < pixel; i++ )
{
fputc(p_buffer_data[i] & 0xFF, fp);
fputc(p_buffer_data[i] >> 8, fp);
}
fclose(fp) ;
return 0 ;
}

void main()
{
int i;
DATA x[2*NX], *px = x ;
printf(" Import samples3.bin \n ") ;
ImportFile( 2*NX , (Uint16*)px ) ;
14 printf(" Processing \n ") ; Lab 5 report
cfft(x,NX, NOSCALE);
cbrev(x,x,NX);
printf(" Export FFT4.bin \n ") ;
ExportFile(2 * NX, (Uint16*)px ) ;
printf(" Done \n ") ;
}

After the FFT is calculated, matlab used this data to sketch FFT using the following codes:
clc;
close all;
clear all;
id=fopen('D:\FFT4.bin','rb');
fft_board = fread(id,256,'int16','ieee-be');
fclose(id);
fft_board = fft_board';
new = zeros(1,128);
for k=0:127
new(k+1) = fft_board(1+2*k) + 1i*fft_board(2+2*k);
%new(k+1) = fft_board(1+2*k) + 0*fft_board(2+2*k);
end
f = (-64:63)*(1000/128);
f1 = (-128:127)*(1000/256);
abs_new = abs(fftshift(new));
figure(1);
stem(f,abs_new)
The result is:

April, 24th 2014

15 Lab 5 report

Software generation
Using Multitones function of the Signal Generator in VIRTIN Multi-Instrument 3.2, we
generated the above signal:
April, 24th 2014

However, when we looped back the signal using C5515, the shape is changed like this:

16 Lab 5 report
Even so, the main frequencies are still the same: April, 24th 2014

17 Lab 5 report

Therefore, we suppose there must be changes in the amplitudes of the frequencies.


Compare the results and Conclusions
April, 24th 2014
Here are the waves given by C5515 and Matlab (respectively) :

18 Lab 5 report

As previously stated, they have the same shape.


Here are the 128-FFT done by C5515 and Matlab( respectively) :

April, 24th 2014

19 Lab 5 report

They are almost the same.


To sum up, in this lab session, we have learnt to create samples of a given signal with a
given Fs. This gives us a better understanding of how an arbitrary signal is sampled.
The results, however, is not identical, especially the shape of the signal when we use C5515 to
sample the given signal. This phenonmena, in our opinion, is the effect of the sampling frequency
and some “invisible” filters which have changed the amplitudes of the frequencies.
April, 24th 2014
We also learned that the generated signal voltage cannot reach 3V ( with our C5515, the signal is
bent when the value exceed ~2.5 V). We then figure out a certain number to multiple with the
given signal to maintain the right shape of the signal sketched on oscilloscope.

The sampling rate is also important. With different sampling rates, we got different results, even the
main frequencies are changed. The reason could be with inappropriate sampling frequency, a sine
wave is sampled at different positions in its different cycles.

20 Lab 5 report
References
[1] Texas Instruments, C5515 eZDSP USB Stick Development Tool description April, 24th 2014
and features,
http://www.ti.com/tool/tmdx5515ezdsp, retrieved on February, 27th 2014.
[2] sensorasia, TMS320C5515_eZdip_USB stick.MP4, http://www.youtube.com/watch?
v=ZFnvH1iZoY8, retrieved on February, 27th 2014.
[3] Sophocles J. Orfanidis, Introduction to Signal Processing, Pearson Education, .Inc, New
Jersey, 2009.
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..

21 Lab 5 report

You might also like