Lab 5 Report: Đại học Duy Tân Khoa Điện - Điện tử
Lab 5 Report: Đại học Duy Tân Khoa Điện - Điện tử
Lab 5 Report: Đại học Duy Tân Khoa Điện - Điện tử
LAB 5 REPORT
Generate and calculate DFT of a periodic signal
Using TMS320C5515 eZDSPTM USB Stick
Lab 5 report 1
Table of Contents
Table of Contents ........................................................... 1
Abstract .......................................................................... 2
Introduction .................................................................... 3
Abstract
This report outlines steps to generate and 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.
Lab 5 report 3
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
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
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.
Lab 5 report 4
Matlab implementation
I)FLOW CHART
Start
Generate x(t)
Sketch x(t)
Take 128-DFT
Sketch X(f)
End
Lab 5 report 5
II)MATLAB CODES
clc;
close all;
clear all;
Signal result:
FFT result:
The main frequencies ( 100 Hz, 200 Hz, 300 Hz) are shown correctly.
Lab 5 report 7
C5515 implementation
I)FLOW CHART
Start
Generate x(t)
Sketch x(t)
Take 128-DFT
Sketch X(f)
End
Lab 5 report 8
II)SOURCE CODES
1. Signal generation
Flowchart:
Start
set Fs=48Khz
set f1,f2,f3
End
#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"
/* ------------------------------------------------------------------------ *
* *
Lab 5 report 9
* AIC3204 Tone *
* Output a 1 kHz tone through the HEADPHONE jack *
* *
* ------------------------------------------------------------------------ */
Int16 aic3204_tone_headphone( )
{
double * signal;
short * ptsig;
int x;
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
AIC3204_rset( 0, 0 );
/* 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
Lab 5 report 10
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 */
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 */
for ( i = 0 ; i < 1000 ; i++ )
{
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;
}
Lab 5 report 11
Signal Sketch:
2. FFT implementation:
Flow chart:
Start
calculate 128-FFT
End
Source code:
#include <stdio.h>
#include <math.h>
#include <tms320.h>
#include <dsplib.h>
#include "usbstk5515.h"
#define NX 128
fclose ( fp ) ;
return 0 ;
}
void main()
{
int i;
DATA x[2*NX], *px = x ;
printf(" Import samples3.bin \n ") ;
ImportFile( 2*NX , (Uint16*)px ) ;
printf(" Processing \n ") ;
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)
Lab 5 report 15
Software generation
Using Multitones function of the Signal Generator in VIRTIN Multi-Instrument 3.2, we
generated the above signal:
Lab 5 report 16
However, when we looped back the signal using C5515, the shape is changed like this:
Lab 5 report 17
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.
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.
Lab 5 report 21
References
[1] Texas Instruments, C5515 eZDSP USB Stick Development Tool description 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..