Introduction: Arduino: Frequency Transform (DFT)

Picture of Arduino: Frequency Transform (DFT)

this program is to calculate frequency transform on arduino with batter control over is solved using desecrate fouriior transform.

this is not FFT .

FFT is algorithm used to solve DFT with smaller time.

Step 1: How It Works(concept):

Picture of How It Works(concept):

Given program for frequency transform provides great control over output you required. this program evaluates frequency range given by user at given input for data-set.

  • In figure a data set made of two frequencies named f2 and f5 given which need to be tested. f2 and f5 are random names for two frequency, higher number for relatively higher frequency. here smaller frequency f2 has higher amplitude and f5 has smaller amplitude.
  • It can be shown mathematically that -summation of multiplication of two harmonic data-set having different frequency tends to zero(higher number of data can lead to batter result). In our case If these two multiplication frequency has same (or very close) frequency that sum of multiplication is nonzero number where amplitude depends on amplitude of data.
  • to detect specific frequency given data-set can be multiplied by various test frequencies and result can give component of that frequency in data.

Step 2: How It Works(in Code):

Picture of How It Works(in Code):

for that given data (f2+f5) one by one f1 to f6 is multiplies and value of sum is noted down. that final sum represents content of that frequency. rest (non-matching) of frequency should be ideally zero but it is not possible in real case. to make sum zero it is required to have infinite size of data-sets.

  • as can be shown in figure f1 to f6 trial frequency and its multiplication with data set at every point is shown.
  • in second figure summation of that multiplication at each frequency is plotted. two peaks at 1 and 5 is identifiable.

so using same approach for a random data we can evaluate for so many frequency and analyze frequency content of data.

Step 3: Using Code for Frequency Analysing:

Picture of Using Code for Frequency Analysing:

for an example lets use this code to find DFT of square wave.

  • first paste attached code(dft function) after loop as shown image.


  1. an array of which dft need to be taken
  2. size of an array
  3. time interval between 2 reading in array in milliSECONDS
  4. lower value of frequency range in Hz
  5. upper value of frequency range in Hz
  6. size of steps for frequency range
  7. repeatation of a signal(minimum 1) higher number batter accuracy but increased solution time
  8. window function:

    0 for no window
    1 for flat-top window
    2 for hann window
    3 for hamming window

(if you do not have any idea about selecting window keep default 3)

example: dft(a,8,0.5,0,30,0.5,10,3); here a is an array of size 8 element to be checked for 0 Hz to 30 Hz with 0.5 step (0,0.5,1,1.5, ... ,29,29.5,30) 10 repeatation and hamming window

here it is possible to use bigger sized array as much as arduino can handle.

Step 4: Output:

Picture of Output:

if you comment out


from code serial plotter will give nature of frequency spectrum an if not Serial monitor would give frequency with its amplitude.

Step 5: Checking Various Window and Sample Sizes:

Picture of Checking Various Window and Sample Sizes:

in figure, frequency of sine wave is measured using different setting.

Step 6: Example:

Picture of Example:

in figure transform of data using SciLab and arduino is compared.


KOE1046 (author)2017-10-09

I saw it well.

What I would like to do is to DFT the current measured when current is applied to the nonlinear device.

I would like to analyze the fundamental wave 3-wave 5-wave by DFT the current.

If you know what to do, give me advice.

I am Korean, and I am beginner to deal with Arduino.


Reply to

abhilash_patel (author)KOE10462017-10-13

this code is way more slower for real time application. i highly recommend you to use fft.
follow this article: (author)2017-07-04

but how to remove the dc component?

pankaj4tech (author)2016-09-07

How to use this code for applying dft on readings from adc

first you need to specify an array and than store your data from adc to array. and dft of an array can be taken as explained.

About This Instructable



More by abhilash_patel:DIY: Arduino Based RC Transmitter and ReceiverSolar RC Plane Under 60$Simple Arduino Trigger for DSLR
Add instructable to: