calculation of the fft using the radix 2 algorithm in a ... · using the radix 2 algorithm in a...

8
JOURNAL OF APPLIED SCIENCES RESEARCH ISSN: 1819-544X Published BY AENSI Publication EISSN: 1816-157X http://www.aensiweb.com/JASR 2016 December; 12(12): pages 46-53 Open Access Journal To Cite This Article: Néstor Fernando Hortúa Díaz, Yuli Alexandra Velásquez Pulido, Dario Amaya Hurtado, Calculation of The Fft Using The Radix 2 Algorithm In A Fpga Cyclone Iv, 2016. Journal of Applied Sciences Research. 12(12); Pages: 46-53 Calculation of The Fft Using The Radix 2 Algorithm In A Fpga Cyclone Iv 1 Néstor Fernando Hortúa Díaz, 2 Yuli Alexandra Velásquez Pulido, 3 Dario Amaya Hurtado 1 Engineer in Mechatronics, Military University New Granada. Student of Master in Mechatronics Engineering, New Granada Military University. 2 Engineer in Mechatronics, Military University New Granada. Student of Master in Mechatronics Engineering, New Granada Military University. 3 Head of Control and Automation Area, Mechatronics Engineering Program. GAV Mechatronics Research Group, New Granada Military University. Received 7 September 2016; Accepted 13 December 2016; Published 31 December 2016 Address For Correspondence: Néstor Fernando Hortúa Díaz, Engineer in Mechatronics, Military University New Granada. Student of Master in Mechatronics Engineering, New Granada Military University, Copyright © 2016 by authors and American-Eurasian Network for Scientific Information (AENSI Publication). This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/ BACKGROUND The fast Fourier transform (FFT) is a method to calculate efficiently the discrete Fourier transform, the implementation of an algorithm for calculating the FFT on an FPGA (Field Programmable Gate Array) is important to reduce the computation time of the same, it is useful in signals processing. OBJECTIVE Develop a program in VHDL language, validated in Visual Basic, for implementation of radix 2 FFT the algorithm in a Cyclone IV FPGA of Altera, in order to obtain the discrete transform of the sum of two sine signals, previously recorded in memory. RESULTS The good performance of the algorithm was confirmed using MATLAB software, in which the FFT of the same signal was performed using internal functions of the program and exporting the results graphically. CONCLUSION By means of the implementation of algorithms for the calculation of the FFT it was possible to determine with low computational load the spectral components of the sum of two sine signals of different frequency. KEYWORDS: Radix-2 FFT algorithm, Digital signal processing, Discrete Fourier Transform, Fast Fourier Transform. INTRODUCTION The spectrum of a signal is the information about the distribution of the frequencies that compose it and their respective amplitudes [1], which allows to study aspects of the signal that would be difficult and even impossible to observe in their representation in the time domain. For example, if you have the sum of two sine- type signals, with a large amplitude difference, it is possible that the resulting signal looks like a simple sine- wave signal. In this type of cases it would be possible to determine the frequencies of the signals that actually compose it only by spectral analysis. The spectrum of a signal is obtained by the Fourier transform. It is known that the Fourier transform is very important in signal processing [2], since it is one of the main analytical tools for the analysis of continuous and discrete signals [3]. The Fourier transform can be defined as a linear transformation, which allows a signal,

Upload: ngongoc

Post on 10-Apr-2018

246 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Calculation of The Fft Using The Radix 2 Algorithm In A ... · Using The Radix 2 Algorithm In A Fpga Cyclone Iv, 2016. Journal of Applied Sciences R ... calculation of the DFT proves

JOURNAL OF APPLIED SCIENCES RESEARCH

ISSN: 1819-544X Published BY AENSI Publication EISSN: 1816-157X http://www.aensiweb.com/JASR

2016 December; 12(12): pages 46-53 Open Access Journal

To Cite This Article: Néstor Fernando Hortúa Díaz, Yuli Alexandra Velásquez Pulido, Dario Amaya Hurtado, Calculation of The Fft

Using The Radix 2 Algorithm In A Fpga Cyclone Iv, 2016. Journal of Applied Sciences Research. 12(12); Pages: 46-53

Calculation of The Fft Using The Radix 2 Algorithm In A Fpga Cyclone Iv

1Néstor Fernando Hortúa Díaz, 2Yuli Alexandra Velásquez Pulido, 3Dario Amaya Hurtado 1Engineer in Mechatronics, Military University New Granada. Student of Master in Mechatronics Engineering, New Granada Military University. 2Engineer in Mechatronics, Military University New Granada. Student of Master in Mechatronics Engineering, New Granada Military University. 3Head of Control and Automation Area, Mechatronics Engineering Program. GAV Mechatronics Research Group, New Granada Military University. Received 7 September 2016; Accepted 13 December 2016; Published 31 December 2016

Address For Correspondence: Néstor Fernando Hortúa Díaz, Engineer in Mechatronics, Military University New Granada. Student of Master in Mechatronics Engineering, New Granada Military University,

Copyright © 2016 by authors and American-Eurasian Network for Scientific Information (AENSI Publication). This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/

BACKGROUND The fast Fourier transform (FFT) is a method to calculate efficiently the discrete Fourier transform, the implementation of an algorithm for calculating the FFT on an FPGA (Field Programmable Gate Array) is important to reduce the computation time of the same, it is useful in signals processing.

OBJECTIVE Develop a program in VHDL language, validated in Visual Basic, for implementation of radix 2 FFT the algorithm in a Cyclone IV FPGA of Altera, in order to obtain the discrete transform of the sum of two sine signals, previously recorded in memory.

RESULTS The good performance of the algorithm was confirmed using MATLAB software, in which the FFT of the same signal was performed using internal functions of the program and exporting the results graphically.

CONCLUSION By means of the implementation of algorithms for the calculation of the FFT it was possible to determine with low computational load the spectral components of the sum of two sine signals of different frequency.

KEYWORDS: Radix-2 FFT algorithm, Digital signal processing, Discrete Fourier Transform, Fast Fourier Transform.

INTRODUCTION

The spectrum of a signal is the information about the distribution of the frequencies that compose it and

their respective amplitudes [1], which allows to study aspects of the signal that would be difficult and even

impossible to observe in their representation in the time domain. For example, if you have the sum of two sine-

type signals, with a large amplitude difference, it is possible that the resulting signal looks like a simple sine-

wave signal. In this type of cases it would be possible to determine the frequencies of the signals that actually

compose it only by spectral analysis.

The spectrum of a signal is obtained by the Fourier transform. It is known that the Fourier transform is very

important in signal processing [2], since it is one of the main analytical tools for the analysis of continuous and

discrete signals [3]. The Fourier transform can be defined as a linear transformation, which allows a signal,

Page 2: Calculation of The Fft Using The Radix 2 Algorithm In A ... · Using The Radix 2 Algorithm In A Fpga Cyclone Iv, 2016. Journal of Applied Sciences R ... calculation of the DFT proves

47 Néstor Fernando Hortúa Díaz et al., 2016/ Journal of Applied Sciences Research. 12(12) December 2016, Pages: 46-53

originally captured in the time domain, to be represented in the frequency domain [4]. The discrete Fourier

transform (DFT) is the discrete form of this transform, applicable to discrete signals in the time domain. The

calculation of the DFT proves to be a challenge in terms of computational efficiency [5], for this reason the FFT

was developed, which is a series of efficient algorithms for the calculation of DFT [6].

The objective of the project that describes this article is to develop a program to perform the calculation of

the FFT of the result of the summation of two sine signals, to implement it in an FPGA Cyclon IV of Altera, in

order to be able to observe the frequencies of the Signals that make up the summation on a screen.

Referential Framework:

Fast Fourier transform (FFT):

The Fourier transform allows to determine the frequency spectrum of a signal. The Fourier transform [7], of

a signal was determined by equation 1.

X(w) = ∫ 𝑥(𝑡) ∗ 𝑒−𝑗𝜔𝑡𝑑𝑡∞

−∞ (1)

The DFT provides the calculation of the Fourier transform for discrete signals [8], and it was calculated by

equation 2 [9] - [10].

𝑋(𝑘) = ∑ 𝑥(𝑛) ∗ 𝑊𝑁𝑛𝑘𝑁−1

𝑛=0 𝑘 = 0,1, … , 𝑁 − 1 (2)

Where N was the number of samples, n was the position of the vector of the signal sampled in the time

domain, k was the position of the output vector and "W" was known as twiddle factors, defined as in equation 3

[9] [10].

𝑊𝑁𝑛𝑘 = 𝑒−𝑗(2𝜋/𝑁)𝑛𝑘 (3)

The twiddle factor can be expressed in terms of sine and cosine as shown in Equation 4 [11].

𝑊𝑛𝑁𝑘 = cos(2𝜋𝑛𝑘/𝑁) + 𝑗 ∗ sin (2𝜋𝑛𝑘/𝑁) 0 ≤ 𝑘 < 𝑁 (4)

The DFT implies a large computational load, due to the amount of operations required to reach the result

[12], for this reason the FFT algorithms were implemented. With which the calculation of the Fourier transform

is easy and fast using the FFT [13], because it allows to obtain the same result of the DFT in a shorter time.

One of the FFT algorithms is the decimation in time-base 2 [8] - [14]. Figure 1 shows the graphical

interpretation of the combination of calculations required to obtain the FFT from a group of 8 samples using this

algorithm, which was based on divide the input signal into two other signals of N/2 samples, odd and even

numbers, and each of these subdivisions was sent to an FFT of size N/2. Each of the output coefficients of the

FFT of the odd samples was multiplied by the twiddle factor corresponding to the value of k and was added to

the even samples. In turn, the FFT of N/2 points can be solved in this same way, performing this procedure

iteratively it is arriving at the calculation of the FFT for groups of 2 samples.

The output of the algorithm described above was obtained in a disordered manner, for this reason it was

necessary to use the algorithm called Bit-reversal [15], for the purpose of ordering it and make a good

interpretation of the results obtained.

Description of Work:

A documentary study of the FFT (Fast Fourier Transform) was carried out. In order to determine the

algorithm that would be implemented in the FPGA Cyclone IV for the calculate of the same, based on the study,

the calculation algorithm for FFT called "FFT in base 2" was chosen.

Page 3: Calculation of The Fft Using The Radix 2 Algorithm In A ... · Using The Radix 2 Algorithm In A Fpga Cyclone Iv, 2016. Journal of Applied Sciences R ... calculation of the DFT proves

48 Néstor Fernando Hortúa Díaz et al., 2016/ Journal of Applied Sciences Research. 12(12) December 2016, Pages: 46-53

Fig. 1: Graphic interpretation of the algorithm base 2 for the calculation of the FFT.

This algorithm performs a series of iterations that relate the number of samples with the value of the

samples and the value of the twiddle factor to generate a disordered series of points that later were re-ordered.

The points of greater value determine the frequency of the signal analysed.

Once the algorithm "FFT in base 2" was selected, it was implemented by Macros in Excel (programming in

Visual Basic in C language), in order to a better understand of this algorithm and to have a comparison point

once Implemented in the FPGA Cyclone VI. Figure 2 shows a section of the program, developed in Visual

Basic, in which the partitions were made to the samples, the multiplication of the odd sections by the twiddle

factors which were added to the even section and at the end it generates the output of the data in a disordered

way.

Fig. 2: Developed section program in Visual Basic for the FFT calculation.

In order to optimize resources, the twiddle factor, which was constant (equation 3 and 4), was determined in

MATLAB software, which was the calculation of sines and cosines of the half-number of samples in power of 2

multiplied by 2π.

Due to the FFT algorithm in base 2, has as outputs values in disordered positions, it was used the algorithm

of re-ordering called reverse bit to organize the data [15]. In Figure 3 was the section of the Visual Basic

program where this algorithm was applied.

Page 4: Calculation of The Fft Using The Radix 2 Algorithm In A ... · Using The Radix 2 Algorithm In A Fpga Cyclone Iv, 2016. Journal of Applied Sciences R ... calculation of the DFT proves

49 Néstor Fernando Hortúa Díaz et al., 2016/ Journal of Applied Sciences Research. 12(12) December 2016, Pages: 46-53

Fig. 3: Reversal bit algorithm in Visual Basic.

In order to execute the application developed in the Excel, 2048 signal samples were taken with frequencies

ranging from 1 Hz to 9 Hz, generated and exported in the software (Figure 4), which were sampled at a

frequency of 20 Hz for Ensure that there was no aliasing. Then two of these signals were selected and added

point by point, that sum was taken as the input of the signal for the calculation of the FFT inside the Macro of

Excel, indicating the number of samples to be analysed (the greater the number of Samples will best be the

analysis of the signal) the Macro executes resulting in different magnitudes, then these were plotted and the

frequencies of the input signal were determined based on the graph.

Fig. 4: Generation of signals in Matlab®

Figure 5 shows the screen of the file that was generated in Excel where the buttons execute the programs

previously developed in Visual Basic. In the Figure 6 was the graph obtained from the execution of the macro,

where the calculation of the FFT was performed for a group of 512 samples of a signal conformed by the sum of

two sinusoidal signals of frequency 1Hz and 8Hz.

Fig. 5: Excel screen for the FFT calculation.

In order to correctly interpret Figure 6, it was necessary to know the frequency with which the signal was

sampled, due to the half of this sampling frequency was located in the centre of the generated graph and from

this point it reflects the above graph.

Page 5: Calculation of The Fft Using The Radix 2 Algorithm In A ... · Using The Radix 2 Algorithm In A Fpga Cyclone Iv, 2016. Journal of Applied Sciences R ... calculation of the DFT proves

50 Néstor Fernando Hortúa Díaz et al., 2016/ Journal of Applied Sciences Research. 12(12) December 2016, Pages: 46-53

Fig. 6: Result of the FFT calculation in Excel.

For this case, the sampling frequency was 20 Hz, so, the half of the graph corresponds to 10 Hz, so from the

first half it follows that the frequencies that formed the input signal are 1Hz and 8Hz, because in these points

were the greatest amplitude observed.

In the implementation of the algorithm selected for the calculation of the FFT in a Macro in Excel, it was

programmed in VHDL language in Quartus II software. 12.1 Web Edition oriented to FPGA Cyclone IV. At the

beginning of the program the input ports were defined as the clock and button that initiates the calculation of the

FFT and the output ports in order to use the VGA port. Subsequently the program constants were defined as the

twiddle factor, which was stored in two constant arrangements of 1024 positions in which the value of the

calculation of the cosines (real part) and sines (imaginary part) multiplied by thousand. With the end of not use

values of real type, due to the operations between real numbers present multiple complications in the

development of the program in VHDL. Nine constant arrays containing nine sine-wave signals of 512 samples

were defined, each sample multiplied by one thousand and the value of the number of samples to be analysed

were defined as 512, due to the output graphic that was transmitted by the VGA port to the screen in his

horizontal component could have maximum 620 positions to graph point to point.

Once the constants were declared, the signals of the counters used for the VGA display and signal used to

store the results of the magnitudes obtained from the FFT calculation were declared.

After declaring the constants and signals, a process was created for the calculation of the FFT in which

different variables were defined that store the values that were produced as the iterations were performed. The

signal to be analysed was then calculated by summing two of the constant signals of 512 samples point by point,

this sum was being saved in the real part of the input signal, while the imaginary part will always start at zero.

Subsequently, the number of stages was calculated in relation to the number of samples to be analysed,

which in this case were 512, i.e. the calculation of the FFT was developed in 9 stages, also the number of

samples was calculated according to the value of the step between the values of the twiddle factor. Once these

values have been determined, the program enters to three whiles nets, where 8 operations were performed with

different points of the input signal in real and imaginary part, four of these operations were performed by

multiplying the signal with different values of the twiddle factor and the results were stored in the other four

variables, these were stored into the same arrays of the input signal (real and imaginary part) to be reused with

the iterations step inside these while's (Figure 7), this process by stages was shown in Figure 1 for eight

samples.

Once the operations were completed inside the while's, the code for the reverse bit algorithm was

implemented, in order to re-organize the output of the previous calculations.

Page 6: Calculation of The Fft Using The Radix 2 Algorithm In A ... · Using The Radix 2 Algorithm In A Fpga Cyclone Iv, 2016. Journal of Applied Sciences R ... calculation of the DFT proves

51 Néstor Fernando Hortúa Díaz et al., 2016/ Journal of Applied Sciences Research. 12(12) December 2016, Pages: 46-53

Fig. 7: While’s nest for the calculation of the FFT in the VHDL language.

This algorithm combines two whiles nested, where it temporarily stores values of the output vectors (real

and imaginary) in two variables and then replaces them with values of the same vector and thus iteratively

organizes the 512 values of each output vector (Figure 8).

Fig. 8: reversal bit algorithm implemented in VHDL language.

Once the output vectors were organized, it was calculated the magnitude due to the real and the imaginary

values, in the first instance it was calculate the sum of the squares of the real and imaginary parts and they were

stored in a variable arrangement of 512 positions defined for this purpose. After calculating the 512 sums of

squares, it was proceeded to calculate the square root of them, but because the "Math_real" library did not work

correctly in Quartus II software. 12.1 Web Edition, an algorithm for calculating the approximate square root was

programmed, the square root was overwritten on the variable that contain the sum of the squares of the real and

imaginary part.

Finally, it was graphed on the screen making use of the VGA port. The arrangement of the pixels in VGA

configuration for a screen corresponds to 480 pixels in height and 620 pixels in width, therefore the graph

generated from the calculation of the FFT was pixel to pixel, where the height corresponds to the values stored

in Each of the positions of the output vector and the horizontal distribution was determined in relation to the

position of the output vector.

Results Obtained:

In the Figure 9 was shown the result of the calculation of the FFT of a signal composed of the sum of

y1=2+1*sin(2*π*x*1), frequency 1Hz, and y8=2+1*sin(2*π*x*8), frequency 8Hz, using the program developed

in VHDL language and implemented in the FPGA Cyclone IV. Figure 10 and Figure 11 shows the calculation

of the FFT of the same signal, the first in the program developed in a Macro in Excel and the other using the

Matlab program.

Page 7: Calculation of The Fft Using The Radix 2 Algorithm In A ... · Using The Radix 2 Algorithm In A Fpga Cyclone Iv, 2016. Journal of Applied Sciences R ... calculation of the DFT proves

52 Néstor Fernando Hortúa Díaz et al., 2016/ Journal of Applied Sciences Research. 12(12) December 2016, Pages: 46-53

Fig. 9: Calculation of the FFT in the cyclone IV FPGA using the algorithm base 2.

The similarity in the previous figures was evident (Figure 9, Figure 10 and Figure 11), from which the same

graphic result was obtained. In them, it was observed that from the middle of the graph it behaves like a mirror.

Fig. 10: Calculation of the FFT in a macro of excel using the algorithm base 2.

Of the first half, it was deduced the value of the frequencies that compose the signal to which the

calculation of the FFT was made.

Fig. 11: Calculation of the FFT in Matlab® using the own function of the software.

Taking into account that the sampling frequency was 20Hz. It was deduced from each graph that the input

signal had 1Hz and 8Hz frequency components.

Page 8: Calculation of The Fft Using The Radix 2 Algorithm In A ... · Using The Radix 2 Algorithm In A Fpga Cyclone Iv, 2016. Journal of Applied Sciences R ... calculation of the DFT proves

53 Néstor Fernando Hortúa Díaz et al., 2016/ Journal of Applied Sciences Research. 12(12) December 2016, Pages: 46-53

Conclusions:

By means of the implementation of algorithms for the calculation of the FFT it was possible to determine

with low computational load the spectral components of the sum of two sine signals of different frequency.

For the implementation of the algorithm in VHDL language it became necessary to calculate the twiddle

factors in computer and search for an algorithm for the calculation of the approximate square roots due to the

"Math_real" library of Quartus II software. 12.1 Web Edition did not allow the use of the sine, cosine and

square root functions in variable numbers.

It was possible to visualize on a VGA screen the frequency spectrum calculated into the FPGA by

implementing the FFT base 2 algorithm.

ACKNOWLEDGEMENT

The authors acknowledgement the Nueva Granada Military University and the Mechatronics Engineering

program for providing their facilities, materials and laboratory equipment for the adequate development of the

project.

REFERENCES

1. Wu, R. and T. Tsao, 2003. “The Optimization of Spectrum Analysis for Digital Signals” IEEE Transactions

on Power Delivery, 18(2): 398-405.

2. You, J., S.S. Wong, 1993. “Serial-parallel FFT array processor”, IEEE Transactions on Signal Processing,

41: 1472-1476.

3. Grigorya, M., 1993. “Fourier Transform representation by frequency-Time Wavelets”, IEEE Transactions

on Signal Processing, 53(7): 1472-1476.

4. Hennelly, B.M., J.T. Sheridan, 2003. "Image encryption and the fractional Fourier transform", Optik

114(6): 251-265.

5. Silva, V., F. Perdigao, 2002. "Generalising the simultaneous computation of the DFTs of two real

sequences using a single N-point DFT", Signal Processing, 82: 503-505.

6. Wang, Y., Y. Tang, Y. Jiang, J. Chung, S. Song, M. Lim, 2007. “Novel Memory Reference Reduction

Methods for FFT implementations on DSP Processors”, IEEE Transactions on Signal Processing, 55: 2338-

2349.

7. Zill, D.G., J.M. Dewar, 2008. “Método de la transformada integral” en Matemáticas Avanzadas para

Ingeniería 2: Calculo vectorial, Análisis de Fourier y Análisis Complejo, Tercera edición, pp: 382-384.

8. Pei, S., M. Yeh, T. Luo, 1999. “Fractional Fourier Series Expansion for Finite Signals and dual extension to

discrete-time fractional Fourier transform”, IEEE Transactions on Signal Processing, 47(10): 993-1001.

9. Bouguezel, S., M. Omair Ahmad, M.N.S. Swamy, 2004. “New radix-(2×2×2)/(4×4×4) and radix-

(2×2×2)/(8×8×8) Dif Fft Algorithms For 3-D Dft ”, IEEE Transactions On Circuits And Systems—I:

Regular Papers, 51(9).

10. Wang, L., X. Zhou, G.E. Sobelman, R. Liu, 2012. “Generic Mixed-Radix FFT Pruning”, IEEE Signal

Processing Letters, 19(3): 167-170.

11. Kang, H., B. Yang, J. Lee, 2013. “Low complexity twiddle factor multiplication with ROM partitioning in

FFT processor”, Electronics Letters, 49(9).

12. Hossen, A.N., U. Heute, O.V. Shentov, S.K. Mitra, 1995. "Subband DFT-Part II: Accuracy, complexity and

application", Signal Processing, 41: 279-294.

13. Drouiche, K., 2001. “A new efficient computational algorithm for bit reversal mapping”, IEEE Transactions

on Signal Processing, 49: 251-254.

14. Despain, M., 1974. “Fourier transform computers using CORDIC iterations”, IEEE Transactions on Signal

Processing, c-23(10): 1472-1476.

15. Sundararajan, D., M. Omair Ahmad, M.N.S. Swamy, 1994. "A fast FFT bit-reversal algorithm", Circuits

and Systems II: Analog and Digital Signal Processing, 41: 701-703.