EasyFFT Frequency Transform For Arduino PDF
EasyFFT Frequency Transform For Arduino PDF
by abhilash_patel
Measurement of frequency from the captured signal signal analysis. The motive of this project was to
can be a di cult task, especially on Arduino as it has prepare a code that is easy to implement on Arduino
lower computational power. There are methods without getting into the background of it.
available to capture zero-crossing where the
frequency is captured by checked how many times This project does not explain the Working of FFT but
the signal crosses zero lines within the given time. explains the application of the FFT function. The same
Such a method may not work when the signal is a process is also explained in the attached video.
combination of various frequencies.
If you are only interested in the application of code
This is somehow di cult to code if you are not from and not into an explanation of it. You may skip directly
such a background. But being a tinkerer this code may to step no 3.
be highly useful for various projects related to music,
https://youtu.be/kJ-g9MfY0Wg
Download
https://www.instructables.com/ORIG/FWO/ZWPR/KAFNFZA4/FWOZWPRKAFNFZA4.ino
…
application). similar is the case for f3, f4. However for intense calculation takes a higher time.
the value, f2 and f5 output won't be zero, but Mathematically it is shown that for N number of
signi cantly higher than the rest of the values. samples it takes N*N complex multiplication.
Calculation FFT takes the value of various sine and cosine multiple times. The inbuilt function of Arduino is not fast
enough and takes a good amount of time to provide the required value. Which makes code signi cantly slower
(doubles time for 64 samples). To counter this issue value of sine for 0 to 90 degrees is stored as multiple of 255.
Doing so will eliminate the need of using storing numbers as oat and we can store it as byte which takes 1/4th
space on Arduino. T he s ine _da t a [ ] ne e ds t o pa s t e a t t o p o f co de t o de cla re it a s a g lo ba l v a ria ble .
Apart from sine_data, an array called f _pe a ks [] de cla re d a s a g lo ba l v a ria ble . After every run of FFT
function this array updates. Where f_peaks[0] is the most dominant frequency and further values in descending
order.
As we have stored value of sine for 0 to 90 degree any value of sine or cosine can be calculated. Below function the
rst round of the number to zero decimal point and return value from stored data. this method needs only one
oating division. This can be further reduced by directly storing sine values (not 255 multiple). but that eats up high
memory on Arduino.
Using the above procedure reduces accuracy but improves speed. For 64 points, it gives the advantage of 8ms and
for 128 points it gives an advantage of 20ms.
FFT can only be performed for the sample size of 2,4,8,16,32,64 and so on. if the value is not 2^n, than it will take
the lower side of value. For example, if we choose the sample size of 70 then it will only consider the rst 64
samples and omit rest.
Two oats out_r and out_im will take a high amount of memory. for Arduino nano won't work for samples higher
than 128 (and in some cases 128) due to lack of available memory.
Further ow is as follow:
1. Code generates a bit reversed the order for the given sample size (details on bit reversing on references: step 2)
3. FFT performed
[to access other data (apart from peak frequency) code should be modi ed, so that local variable can be copied to
some prede ned global variable]
As can be shown from the raw output, value is for Arduino nano it takes:
matching with the FFT calculated by Scilab. however,
these values are not exactly the same as we low 16 Points : 4ms
accuracy but faster sine wave. 32 Points : 10ms
64 Points : 26ms
In output frequency array frequency are 1.25 and 3.75. 128 Points: 53ms
it is not necessary to get the exact value every time.
typically these numbers are called frequency bins. so
Step 6: Conclusion
This FFT code can be used in real-time applications. As it takes around 30 ms to complete the calculation. However,
its resolution limited by a number of samples. The number of the sample is limited by Arduino memory. By using
Arduino Mega or other higher performance board accuracy can be improved.