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

DSP Report Lab3 Official

This report outlines steps to generate a signal, calculate its 128-point discrete Fourier transform (DFT) using MATLAB and a TMS320C5515 microcontroller, and compare the results. MATLAB code is used to generate a signal, calculate its DFT, and plot the time domain and frequency domain signals. C++ code is created to calculate the 128-point DFT on the TMS320C5515 and export the results to a data file. Finally, MATLAB imports the data file and plots the frequency domain results for comparison to the initial MATLAB calculation. The plots are found to match, validating the DFT implementation on the microcontroller.

Uploaded by

bao.pham27sayze
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)
24 views

DSP Report Lab3 Official

This report outlines steps to generate a signal, calculate its 128-point discrete Fourier transform (DFT) using MATLAB and a TMS320C5515 microcontroller, and compare the results. MATLAB code is used to generate a signal, calculate its DFT, and plot the time domain and frequency domain signals. C++ code is created to calculate the 128-point DFT on the TMS320C5515 and export the results to a data file. Finally, MATLAB imports the data file and plots the frequency domain results for comparison to the initial MATLAB calculation. The plots are found to match, validating the DFT implementation on the microcontroller.

Uploaded by

bao.pham27sayze
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/ 11

ĐẠI HỌC QUỐC GIA THÀNH PHỐ HỒ CHÍ MINH

TRƯỜNG ĐẠI HỌC BÁCH KHOA




DIGITAL SIGNAL PROCESSING


Lab 3: DFT/FFT

Class: DTQ1 – Group: 12 – Semester: 223


Submission date: 22/08/2023
Instructor: Prof. Dr. Le Tien Thuong

Student’s name ID number


Phạm Ngọc Thuận 1851112
Phạm Viết Huy 1851071
Tables of Content

1. ABSTRACT.................................................................................................................1
2. INTRODUCTION.......................................................................................................1
3. DISCRETE FOURIER TRANSFORM.....................................................................1
4. MATLAB CODE TO SKETCH CONTINUOUS SIGNAL X(t) AND
CALCULATE DFT/FFT OF X(t)..............................................................................2
5. MATLAB CODE TO SKETCH DISCRETE SIGNAL X(n) AND CALCULATE
DFT/FFT OF X(n).......................................................................................................4
6. C++ PROGRAM TO CALCULATE 128-DFT/FFT OF X(n), X(t) AND
EXPORT AS DAT FILE.............................................................................................6
7. MATLAB CODE TO SKETCH THE RESULT OF C5515/35-BASED
SIMULATION AND COMPARE WITH RESULT FROM MATLAB BASED
SIMULATION.............................................................................................................8
8. CONCLUSION............................................................................................................9
9. REFERENCE...............................................................................................................9
1. 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.

2. INTRODUCTION
LCD of TMS320C5515/35 is a 96x16 OLED display screen which has 96 columns and
16 rows. The display screen is divided into two regions, so actually we have two 96x8
to display a text.

To know about how to use the OLED, we refer to the existing samples code in the lcd-
osd9616 project, which include the code for the oled. The changes are mainly come
from the oled_test.c source code. Further information about how to configure the LCD
modules is from the pdf file which was downloaded by follow the link written on the
board during lab 2. This SSD1306 driver allow us to:

 Set contrast control

 Turn on the display

 Set normal/inverse display

 Using various scrolling modes

 Set timing and driving scheme

3. DISCRETE FOURIER TRANSFORM


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
1
sequence of N complex numbers x0, x1, …,xN-1 is transformed into an N-periodic
sequence of complex numbers:

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:

x=3*sin(100*pi*t)+2*sin(250*pi*t)
Using Matlab, TMS320C5515 eZDSPTM USB Stick Development Tool. Then, the results
of Matlab and C5515 are compared.

2
4. MATLAB CODE TO SKETCH CONTINUOUS SIGNAL X(t)
AND CALCULATE DFT/FFT OF X(t):

Based on the above techniques, we have designed matlab code to sketch CT signal
X1,X2 to calculate Y1,Y2

4.1. Matlab code:

% generate 128 signal samples with Fs=1000Hz


t=0:0.001:0.127;

x=3*sin(100*pi*t)+2*sin(250*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 = (0:127)*(1000/128);
figure(2);
stem(f,abs(X));
ylabel('Amplitude');
xlabel('Frequency');

4.2. Result:
CT of signal x(t)

3
128-DFT/FFT of x(t):

5. MATLAB CODE TO SKETCH DISCRETE SIGNAL X(n) AND


CALCULATE DFT/FFT OF X(n):
Using the above code, we change plot commands to stem command.

5.1. Matlab code

% generate 128 signal samples with Fs=1000Hz


t=0:0.0025:0.3175;
x=3*sin(100*pi*t)+2*sin(250*pi*t);
%sketch the signal
figure(1);
stem(t,x);
ylabel('Amplitude');
xlabel('Time');
%take 128-FFT of the given signal
X=fft(x,128);
X=fftshift(X);
%sketch the FFT
f = (0:127)*(400/128);
figure(2);
stem(f,abs(X));
ylabel('Amplitude');
xlabel('Frequency');

4
5.2. Result
DT signal of x(n)

128-DFT/FFT of x(t)

5
6. C++ PROGRAM TO CALCULATE 128-DFT/FFT OF X(n), X(t) AND EXPORT
AS DAT FILE

C Code:
// C program for the above approach

#include <math.h>
#include <stdio.h>
// Driver Code
int main()
{
FILE *fileout1; fileout1=fopen("C:\Users\skyle\Desktop\
lab3.dat ","w+"); int len ;
printf("Input the length of "
"the sequence: ");
scanf("%d4", &len);
float xn[len];
float Xr[len];
float Xi[len];
int i, k, n, N ;
N=128;

6
float pi=3.14159265;
for (i = 0; i < len; i++) {
xn[i]=3*sin(100*pi*i/400)+2*sin(250*pi*i/400);
}
for (k = 0; k < N; k++) {
Xr[k] = 0;
Xi[k] = 0;
for (n = 0; n < len; n++) {
Xr[k]
= (Xr[k]
+ xn[n] * cos(2 * 3.141592 * k * n / N));
Xi[k]
= (Xi[k]
- xn[n] * sin(2 * 3.141592 * k * n / N));
}
fprintf(fileout1,"%f + %fi\n",Xr[k], Xi[k]);
printf("%f + %fi\n", Xr[k], Xi[k]);
}
fclose(fileout1);
return 0;
}

7
7. MATLAB CODE TO SKETCH THE RESULT OF C5515/35-BASED
SIMULATION AND COMPARE WITH RESULT FROM MATLAB BASED
SIMULATION
We use Matlab code to get data from lab4.dat file and sketch the C5515/35-based
simulation
7.2. Matlab Code:
clear ;

test = importdata("C:\Users\skyle\Desktop\lab3.dat");
V = str2double(test);
% subplot(2,1,2);
f =(0:127)*(400/128);
stem(f,abs(V));
ylabel('Amplitude');
xlabel('Frequency');

7.3. Result:

→ the figure is the same as the result in section 5.2

8
8. CONCLUSION
The results of the two simulations are identical.
Through this practice, we learned how to generate given signal samples for a given Fs.
This helps us better understand how an arbitrary signal is sampled. The results are almost
identical. We also know that sample rate affects the results, each result with a different
sample rate has a different form. The cause may be due to mismatched sampling frequency, a
sine wave is sampled at different positions during its different periods.

9. REFERENCE
[1] Texas Instruments, C5515 eZDSP USB Stick Development Tool description and features,
http://www.ti.com/tool/tmdx5515ezdsp
[2] MATLAB TUTORIAL - DISCRETE FOURIER TRANSFORM (DFT),
https://www.bogotobogo.com/Matlab/Matlab_Tutorial_DFT_Discrete_Fourier_Transform.php

You might also like