Lab 5 Report: Digital Signal Processing
Lab 5 Report: Digital Signal Processing
LAB 5 REPORT
Generate and calculate DFT of a periodic signal
Using TMS320C5515 eZDSPTM USB Stick
Group 7:
Dat Nguyen-Si ID: ILI11006 In-class ID: 2
Trung Le ID: 41103857 In-class ID: 3
Abstract..........................................................................2
Introduction....................................................................3
Matlab Implementation.................................................4
C5515 Implementation...................................................7
Software generation.....................................................16
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 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:
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
Start
Generate x(t)
Sketch x(t)
Take 128-DFT
4 Sketch X(f)
Lab 5 report
End
II)MATLAB CODES
April, 24th 2014
clc;
close all;
clear all;
Signal result:
FFT result:
6 Lab 5 report
The main frequencies ( 100 Hz, 200 Hz, 300 Hz) are shown correctly.
C5515 implementation
I)FLOW CHART
Start
Generate x(t)
Sketch x(t)
Take 128-DFT
Sketch X(f)
End
II)SOURCE CODES
1. Signal generation
Start
Start
set Fs=48Khz
set
set f1,f2,f3
f1,f2,f3
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
#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;
/* 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
return 0;
}
The fllowing result is shown on Oscilliscope( Soundcard Scope):
Signal Sketch:
11 Lab 5 report
12 Lab 5 report
Start
calculate 128-FFT
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
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:
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
18 Lab 5 report
19 Lab 5 report
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