3. Abstract
☼ A method of calculating FFT using a C8051 MCU is
introduced in this paper. The software is aimed at
computational efficiency and accuracy.
☼ By three key techniques: (1)avoidance of multiplication
whenever possible; (2)16-bit integer storage; (3)on-chip
PLL, a real-time audio spectrum is achieved.
☼ The results are displayed on a LCD screen and carefully
analyzed. Basic theories of FFT and common problems in
practice are discussed in detail.
4. BACKGROUNDS
A. Discrete Fourier Transform and Fast Fourier Transform
B. FFT Bit-Reversal Algorithm
C. Anti-aliasing Filtering and Windowing
D. Function Overview of the C8051 MCU
5. A. Discrete Fourier Transform and Fast Fourier Transform
,
)
(
)
(
1
0
N
n
nk
N
W
n
x
k
X 1
,...
2
,
1
,
0
N
k N
j
N e
W /
2
☼ For a length N complex sequence x(n), n=0,1,2,…N-1,
the discrete Fourier transform(DFT) is defined by
where
☼ According to periodicity and symmetry
)
(
)
(
)
( k
H
W
k
G
k
X k
N
1
2
/
,...
2
,
1
,
0
N
k
)
(
)
(
)
2
/
( k
H
W
k
G
N
k
X k
N
1
2
/
,...
2
,
1
,
0
N
k
1
2
0
2
/
)
2
(
)
(
N
n
kn
N
W
n
x
k
G
1
2
0
2
/
)
1
2
(
)
(
N
n
nk
N
W
n
x
k
H
where
,
.
6. )
0
(
)
0
(
)
0
( 0
4 H
W
G
X
)
1
(
)
1
(
)
1
( 1
4 H
W
G
X
)
0
(
)
0
(
)
2
( 0
4 H
W
G
X
)
1
(
)
1
(
)
3
( 1
4 H
W
G
X
A. Discrete Fourier Transform and Fast Fourier Transform
We have the FFT process as the following:
(N=4)
(N=8)
11. D. Function Overview of the C8051 MCU
☼ A high performance
C8051 MCU by Silicon
Laboratories™—
C8051F120.
☼ On-chip PLL, the peak speed of the
chip can reach as high as 100MIPS.
☼ A 2-cycle 16×16 MAC engine
accelerates the computation
☼ Pipelined instruction
architecture 8051 core
enables it to execute
most of instruction set in
only 1 or 2 system clocks.
☼ Rich analog on-chip
sources a 12-bit, 8-
channel, 100kHz sample
rate ADC, two 12-bit
DACs, two analog
comparators, a voltage
reference, etc.
13. A. ADC0_ISR( )
☼ Conversation is initiated when a Timer3 overflow happens.
☼ The data is then stored in the ADC0H :ADC0L registers.
☼ The overflow interval of Timer3 is determined by a configurable
macro variable SAMPLE_RATE .
14. B. WindowCalc( )
☼ Pre-calculated
The window coefficients are pre-calculated and stored in the header
file FFT_Code_Tables.h. The type define variable WINDOW_TYPE
can be selected from 0 to 4.
☼ Single-ended to differential
The function also converts the single-ended data collected by ADC0
into differential, in order to remove the DC component of the input
signal. The process is carried out by XOR the input data with 0x8000,
which has the same effect with subtracting 32768 from the input
data, so that the data ranges from 32752 to -32768.
15. C. Bit_Reverse( )
☼ To save data storage space, only half of the bit-reverse
array is stored, the other half is useless for the data will be
exchanged by the first half of operation.
☼ For example, an 8-point FFT may use the following bit-
reverse array:
BRTable[ ]={0,2,1,3};
And the sentence NewIndex=BRTable[PreviousIndex]*2
will help us location the nth reversed index.
17. E. Spectrum_Display( )
The FFT result is in complex form, of which the real part is stored in
Real[], and the imaginary part is stored in Imag[]. Based on the
two arrays, the magnitude spectrum and phase spectrum can be
easily obtained. This software only calculates power spectrum of the
input signal. The spectrum is displayed on a 128×64 point LCD
screen.
18. EXPERIMENT RESULTS AND DISCUSSION
A. Function Change
B. Software Configuration Change
C. Property of Symmetry
19. A. Function Change
☼ Magnitude and Frequency Change of a Sinusoidal Signal
Fig.TR.1. A 2.5kHz 1.3V sine. Fig.TR.2 A 2.5kHz 2.0V sine.
Fig.TR.3 A 2.5kHz 2.0V sine. Fig.TR.4 A 5kHz 2.0V sine.
20. A. Function Change
☼ Wave Form Change
Fig.TR.5. Triangular signal. Fig.TR.6. Rectangular signal.
21. B. Software Configuration Change
Name of variable Function
NUM_FFT Number of points of FFT algorithm
SAMPLE_RATE Sampling rate of ADC0 in Hz
WINDOW_TYPE Type of windows
RUN_ONCE Program runs once when the value is 0,many times when
the value is non-zero.
22. B. Software Configuration Change
☼ NUM_FFT Change
Fig.TR.7. A 256-point square wave Fig.TR.8. A 128-point square wave
23. B. Software Configuration Change
☼ WINDOW_TYPE Change
Fig.TR.9. Rectangular without windowing. Fig.TR.10.Rectangular with Blackman window.
24. B. Software Configuration Change
☼ SAMPLE_RATE Change
Fig.TR.11. 5k sine at 40kHz sampling rate. Fig.TR.12. 5k sine at 20kHz sampling rate.
25. B. Software Configuration Change
☼ RUN_ONCE Change
To check the speed of the system, RUN_ONCE is set to zero. For
all audio signals at a sampling rate of 40kHz, the LCD screen
never blinks and a steady frequency spectrum of the input time
domain signals can be read without any obstacles. This proves the
real-time property of the system.
26. C. Property of Symmetry
Fig.TR.13. 2kHz square wave at full range. Fig.TR.14. 13kHz square wave at full range.
The real part of FFT output exhibits even symmetry and imaginary
part of FFT output exhibits odd symmetry. This results in the
symmetry of frequency spectrum. That is, for N-point FFT products,
point N/2+1 is the same as point N/2-1, point N/2+2 is the same as
point N/2-2, etc. To illustrate this property, set the full range of the
screen to 40kHz. Here are the results.