this program is to calculate frequency transform on arduino with batter control over parameters.it is solved using desecrate fouriior transform.
this is not FFT .
FFT is algorithm used to solve DFT with smaller time.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: 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):
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:
for an example lets use this code to find DFT of square wave.
- first paste attached code(dft function) after loop as shown image.
8 TERMS THAT NEEDS TO BE SPECIFY
- an array of which dft need to be taken
- size of an array
- time interval between 2 reading in array in milliSECONDS
- lower value of frequency range in Hz
- upper value of frequency range in Hz
- size of steps for frequency range
- repeatation of a signal(minimum 1) higher number batter accuracy but increased solution time
- 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:
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:
in figure, frequency of sine wave is measured using different setting.
Step 6: Example:
in figure transform of data using SciLab and arduino is compared.