170952212 fourier arduino

Upload: harold-david-gil-munoz

Post on 03-Jun-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 170952212 Fourier Arduino

    1/19

    Conceptualmente hablando FFT es bastante simple. En la prctica, la FFT es difcil! As que no voya entrar en todos los detalles de este al oritmo y voy a permanecer centrado en su uso yaplicaciones. Esta serie de mensa es va a terminar con una biblioteca con todas las funciones queusted ser capa" de utili"ar para todo tipo de aplicaciones, sin preocuparse de las matemticas.

    #a trama en un osciloscopio muestra una onda que est hecha de muestras que se caracteri"an por

    sus intensidades $ordenadas% y su tiempo de muestreo $abscisa%. Estamos en el dominio del tiempo.

    Cuanto ms simple sea la se&al $por e emplo, una onda sinusoidal simple%, el ms simple es lacaracteri"aci'n. #a transformada de Fourier propone para descomponer cualquier se&al en una sumade seno y coseno. (ara cada punto de datos del espectro de potencia de FFT corresponde unama nitud $ordenadas% y una frecuencia $abscisa%. Ahora estamos en el dominio de la frecuencia.

  • 8/12/2019 170952212 Fourier Arduino

    2/19

    Cuanto ms comple a es la se&al $por e emplo, la se&al ) ruido ) arm'nicos ) )% ...

    ..... ms comple a es la caracteri"aci'n.

    * +adivinen qu - El al oritmo de la FFT se puede e ecutar en modo inverso, de modo que a partirde una FFT puede reconstruir una se&al de la vida real. (odemos estudiar ms adelante c'mo esta

    propiedad puede ser utili"ado para la de eliminaci'n de ruido de las se&ales.

    FFT se aplica a vectores que contienen las muestras n, donde n debe ser una potencia de . E ecutarel al oritmo de estos datos puede conducir a resultados inesperados. #a ra"'n es que el vectortrunca la informaci'n de la se&al y pueden contener ondas incompletamente descritas $por e emplo,

  • 8/12/2019 170952212 Fourier Arduino

    3/19

    las ondas de ba a frecuencia%. Este efecto secundario puede ser corre ida por medio de pesa e de lase&al, dando menos importancia a los datos principales y colas. Esta es la funci'n de ventanas. #afunci'n de pesa e en la ventanas depende del tipo de se&al a anali"ar/

    Transients 0hose duration is shorter than the len th of the 0indo0 / 1ectan ular $2o3 car% Transients 0hose duration is lon er than the len th of the 0indo0 / E3ponential, 4ann 5eneral6purpose applications / 4ann 7pectral analysis $frequency6response measurements% / 4ann $for random e3citation%,

    1ectan ular $for pseudorandom e3citation% 7eparation of t0o tones 0ith frequencies very close to each other but 0ith 0idely differin

    amplitudes / 8aiser62essel 7eparation of t0o tones 0ith frequencies very close to each other but 0ith almost equal

    amplitudes / 1ectan ular Accurate sin le6tone amplitude measurements / Flat top 7ine 0ave or combination of sine 0aves / 4ann 7ine 0ave and amplitude accuracy is important / Flat top 9arro0band random si nal $vibration data% / 4ann 2roadband random $0hite noise% / :niform Closely spaced sine 0aves / :niform, 4ammin E3citation si nals $hammer blo0% / Force 1esponse si nals / E3ponential :n;no0n content / 4ann

  • 8/12/2019 170952212 Fourier Arduino

    4/19

    =indo0 type 4ammin /

  • 8/12/2019 170952212 Fourier Arduino

    5/19

    =indo0 type Flat top

  • 8/12/2019 170952212 Fourier Arduino

    6/19

    All plots e3ported from my >7( tool bo3 ?(anorama@

    4ere is a recap of the pieces of code that 0e need in order to convert a 0ave into a frequencyspectrum/

    7tore data in a vector $>ouble data type% =ei h this data accordin to one function $default is 1ectan le, also ;no0n as bo3 car, in

    other 0ords, no 0ei hin !% E3ecute the FFT al orithm Convert comple3 values in usable data

    =ithout ;no0in too much of the details from the various al orithms, you 0ill very quic;ly face adilemma/ 0ould you prefer speed or precision- (recision 0ill require lar e vectors of data, 0hilespeed 0ill require multiple vectors/ e. . instead of computin 0ei hed values for each ne0 set of

  • 8/12/2019 170952212 Fourier Arduino

    7/19

    data, 0e could compute 0ei hin factors once and apply them repeatedly. 7ame thou hts for the bitreversal at the top of the FFT al orithm.

    The proposed e3ample do not use pre6processin of data, to the benefit of the number of samples,and to the clarity of the code.

    Firstly, some constants shall be declared in the header $.h% file

    01 // Custom constants02 #define FORWARD 0x0103 #define REVERSE 0x0004 // Windo in! t" e0$ #define W%&'()*'REC(A&+,E 0x00// -ectan!.e ox ca-0 #define W%&'()*' A %&+ 0x01// 5ammin!06 #define W%&'()*' A&& 0x02// 5ann

    07 #define W%&'()*'(R%A&+,E 0x03// t-ian!.e a-t.ett08 #define W%&'()*' ,AC9 A& 0x04// :.ac;mann10 #define W%&'()*'F,('(O* 0x0$// f.at to11 #define W%&'()*'WE,C 0x0 // e.c5

    Then data shall be stored in one of the t0o fi3ed si"e vectors

    1 const uint7't sam .es < 4=2 dou:.e >Rea.?sam .es@=3 dou:.e >%ma!?sam .es@=

    And this is the 0ei hin routine

    01 >oid *.ainFF( indo in! dou:.e B>Data uint7't sam .es uint7'tindo (" e uint7't di-

    02 // (5e ei!5in! function is s"met-ic= 5a.f t5e ei!5s a-e-eco-ded03 dou:.e sam .es inusOne < dou:.e sam .es 1 0 =04 fo- uint7't i < 0= i G sam .es HH 1 = iII 0$ dou:.e index inusOne < dou:.e i =0 dou:.e -atio < index inusOne / sam .es inusOne =06 dou:.e ei!5in!Facto- < 1 0=07 // com ute and -eco-d ei!5tin! facto-08 s itc5 indo (" e 10 case W%&'()*'REC(A&+,E // -ectan!.e :ox ca-

    11 ei!5in!Facto- < 1 0=12 :-ea;=13 case W%&'()*' A %&+ // 5ammin!

  • 8/12/2019 170952212 Fourier Arduino

    8/19

    14 ei!5in!Facto- < 0 $4 0 4 B cos 2 0 B i B-atio =1$ :-ea;=1 case W%&'()*' A&& // 5ann

    16 ei!5in!Facto- < 0 $4 B 1 0 cos 2 0 B i B

    -atio =17 :-ea;=18 case W%&'()*'(R%A&+,E // t-ian!.e a-t.ett

    20 ei!5in!Facto- < 1 0 2 0 B a:s index inusOne sam .es inusOne / 2 0 / sam .es inusOne =21 :-ea;=22 case W%&'()*' ,AC9 A& // :.ac;mann

    23 ei!5in!Facto- < 0 42323 0 486$$ B cos 2 0 B iB -atio I 0 06822 B cos 4 0 B i B -atio =24 :-ea;=2$ case W%&'()*'F,('(O* // f.at to

    2 ei!5in!Facto- < 0 2710 38 0 $207862 B cos 2 0 Bi B -atio I 0 1870388 B cos 4 0 B i B -atio =26 :-ea;=27 case W%&'()*'WE,C // e.c5

    28 ei!5in!Facto- < 1 0 sJ index inusOne sam .es inusOne / 2 0 / sam .es inusOne / 2 0 =30 :-ea;=31 K32 if di- Data?i@ B< ei!5in!Facto-=34 >Data?sam .es i I 1 @ B< ei!5in!Facto-=3$ K3 e.se 36 >Data?i@ /< ei!5in!Facto-=37 >Data?sam .es i I 1 @ /< ei!5in!Facto-=38 K40 K41 K

    9otes/ There is a little tric; here. As the 0ei hin function is symetrical, 0hy bother computin

    them all- 4alf of them are computed and applied symetrically to the vector of data The dir parameter stands for direction/ remember, FFT is reversible, so that 0e can apply it

    in FORWARD or REVERSE mode

    FFT stands for fast Fourier Transform. The DFT $>irect Fourier Transform% applies to vectorscontainin any number of si nal samples. 2ut it issssssssssllllllllllllllllllllllloooooooooooooo00000000 due to the repeated number of operation.Computin a DFT of n points ta;es n arithmetical operations, 0hile an FFT can compute thesame result in only n lo $n% operations. The implemented al orithm is the ?CooleyBTu;ey@

  • 8/12/2019 170952212 Fourier Arduino

    9/19

    al orithm 0hich the far most popular. The ?only@ limitation is that the number of samples in thesi nal must be a power of two . 4o0ever, if the number of samples is less than that, it is possible toreplace missin data 0ith values 0ithout affectin the final result/ this is the zero padding .

    01 >oid *.ainFF( com ute dou:.e B>R dou:.e B>% uint7't sam .esuint7't di-

    02 // (5is com utes an in .ace com .ex to com .ex FF(03 // di- < 1 !i>es fo- a-d t-ansfo-m di- < 0 !i>es -e>e-set-ansfo-m04 // Re>e-se :its0$ uint7't L < 0=0 fo- uint7't i < 0= i G sam .es 1 = iII 06 if i G L 07 s a M>R?i@ M>R?L@ =08 s a M>%?i@ M>%?L@ =

    10 K11 uint7't ; < sam .es HH 1 =12 5i.e ; G< L 13 L < ;=14 ; HH< 1=1$ K1 L I< ;=16 K17 // Com ute t5e FF(

    18 dou:.e c1 < 1 0=20 dou:.e c2 < 0 0=21 uint7't .2 < 1=22 fo- uint7't . < 0= . G ex onent sam .es = .II 23 uint7't .1 < .2=24 .2 GG< 1=2$ dou:.e u1 < 1 0=2 dou:.e u2 < 0 0=26 fo- L < 0= L G .1= LII

    27 fo- uint7't i < L= i G sam .es= i I< .2 28 uint7't i1 < i I .1=30 dou:.e t1 < u1 B >R?i1@ u2 B >%?i1@=31 dou:.e t2 < u1 B >%?i1@ I u2 B >R?i1@=32 >R?i1@ < >R?i@ t1=33 >%?i1@ < >%?i@ t2=34 >R?i@ I< t1=3$ >%?i@ I< t2=3 K36 dou:.e N < u1 B c1 u2 B c2 =37 u2 < u1 B c2 I u2 B c1 =

  • 8/12/2019 170952212 Fourier Arduino

    10/19

    38 u1 < N=40 K41 c2 < sJ-t 1 0 c1 / 2 0 =42 if di- is 5a.f t5e siNe of >R and >%3 fo- uint7't i < 0= i G sam .es= iII 4 >R?i@ < sJ-t sJ >R?i@ I sJ >%?i@ =$ K

    K

    1ead this document about conversion $p %Computin the phase information is quite easy, but do not really care about it and it requires thearctangent() tri onometric 0hich does not come standard in Arduino lan ua e. 4o0ever if youneed it, you 0ill have to use the mat library % and compute the pahse values usin the follo0informula/ phaseGFFT$A%HIarctan ent$J ma GFFT$A%HJ K J1ealGFFT$A%HJ%.

    7o far so ood, 0e ot our ma nitude spectrum. =e may no0 analy"e it ust li;e any otherspectrum in order to et meanin ful information. n our case, 0e may 0ant to identify the main

    frequencies from the spectrum. Firstly 0e 0ill run a pea; pic;in al orithm in order to locate ma or pea;s, and then ;eep the most intense one. Those 0ho 0ant to perform spectral comparison 0illhave to ;eep all si nificant pea;s.

    ftp://ftp.ni.com/pub/devzone/pdf/tut_4278.pdfhttp://www.arduino.cc/en/Math/Hhttp://www.arduino.cc/en/Math/Hhttp://www.arduino.cc/en/Math/Hhttp://www.arduino.cc/en/Math/Hftp://ftp.ni.com/pub/devzone/pdf/tut_4278.pdf
  • 8/12/2019 170952212 Fourier Arduino

    11/19

    There are lots of pea; pic;in al orithm! 2ut the one 0e need has to be small and fast. This one is pretty trivial but it 0or;s reat.

    7econdly, because of the poor pea; shapes $lac; of lar e vectors of data% 0e need to interpolate the pea; ape3 in order to et an accurate frequency. am usin a non iterative quadratic interpolation0hich ives ood results too.

    2oth routines are mer ed in one function01 dou:.e maLo-*ea; dou:.e B>D uint7't sam .es 02 dou:.e max) < 0=03 uint7't %ndexOf ax) < 0=04 fo- uint7't i < 1= i G sam .es 1 = iII 0$ if >D?i 1@ G >D?i@ MM >D?i@ H >D?iI1@ 0 if >D?i@ H max) 06 max) < >D?i@=07 %ndexOf ax) < i=08 K10 K11 K

    12 dou:.e de.ta < 0 $ B >D?%ndexOf ax) 1@ >D?%ndexOf ax)I1@ / >D?%ndexOf ax) 1@ 2 0 B>D?%ndexOf ax)@ I >D?%ndexOf ax)I1@ =

    13 dou:.e inte- o.ated < %ndexOf ax) I de.ta /sam .in!Du-ation=14 -etu-n inte- o.ated =

    1$ K

    (lainFFT is a simple but effective library 0hich contains all the previously described functions forrunnin FFT on vectors of data.

    4ere is the e3ample code from the library files 0hich demonstrates the $pretty easy% use of the FFT.The content of the vectors of interest is printed on completion of each FFT sta e

    01 #inc.ude P*.ainFF( 5P02 03 *.ainFF( FF( < *.ainFF( = // C-eate FF( o:Lect

    04 // (5ese >a.ues can :e c5an!ed in o-de- to e>a.uate t5efunctions0$ const uint1 't sam .es < 4=0 dou:.e si!na.F-eJuenc" < 1000=06 dou:.e sam .in!F-eJuenc" < $000=07 uint7't si!na.%ntensit" < 100=08 // (5ese a-e in ut and out ut >ecto-s10 dou:.e >Rea.?sam .es@=11 dou:.e >%ma!?sam .es@=12 uint7't -unOnce < 0x00=

  • 8/12/2019 170952212 Fourier Arduino

    12/19

    13 14 #define SC,'%&DE 0x001$ #define SC,'(% E 0x011 #define SC,'FREQ E&C) 0x0216

    17 >oid setu18 Se-ia. :e!in 11$200 =20 Se-ia. -int.n PRead"P =21 K22 23 >oid .oo 24 if -unOnce oid -intVecto- dou:.e B>D uint7't n uint7't sca.e(" e 4$ dou:.e time%nte->a. < 1 0 / sam .in!F-eJuenc" =4 fo- uint1 't i < 0= i G n= iII 46 // *-int a:scissa >a.ue

    47 s itc5 sca.e(" e 48 case SC,'%&DE$0 Se-ia. -int i DEC =

  • 8/12/2019 170952212 Fourier Arduino

    13/19

    $1 :-ea;=$2 case SC,'(% E$3 Se-ia. -int i B time%nte->a. =$4 :-ea;=$$ case SC,'FREQ E&C)

    $ Se-ia. -int i / time%nte->a. B sam .es 1=$6 :-ea;=$7 K$8 Se-ia. -int P P =

    0 // *-int o-dinate >a.ue1 Se-ia. -int >D?i@ =2 Se-ia. -int.n =3 K

    4 Se-ia. -int.n =$ K

    Attention! The distributed code is sli htly different from the posted code due to last minute chan es

    and optimi"ations 7amples value must be a po0er of La;e sure you have enou h memory before incresin the si"e of vectors Mectors must contain unsi ned inte ers $ to N O%, you can easily chan e that to N bits

    inte ers $si ned or not% to the cost of doublin the vectors si"e... 1emember the 9yquist theorem 0hen chan in the samplin and the si nal frequencies

    (lease chec; t i" page if you are interested in the code. Feel free to pass your comments andsu estions.

    Those 0ho e3erci"ed the library and tried to chan e the default value from the customi"ablevariables $and most probably the si"e of both data vectors% probably faced some loc;ups, inifiniteloops or unpredicted operations.

    n most cases, the ans0er to these problems lies in the limited si"e of the arduino memoryP #etQs be positive and study this sub ect.

    >ependin upon the type of Arduino platform, you may use one of these microprocessors/ Arduino >iecimila/ ATLe aN R $ data sheet % Arduino >uemilanove/ ATLe aS R $ data sheet % Arduino :no/ ATme aS R $ data sheet %

    For other platforms, follo0 this threadFor older platforms, follo0 this thread

    Each of these microprocessors has three separate memories/ F#A74 memory/ this is a non volatile memory space 0here the s;etch is stored 71AL $7tatic 1andom Access Lemory%/ this is the memory sapce 0here the s;etch creates

    and manipulates variables at run time EE(1

  • 8/12/2019 170952212 Fourier Arduino

    14/19

    number of readK0rite cycle is estimated to be no more than N . , and it ta;es real time toet access to it

    #etQs o bac; to our problem. The si"e of the 71AL $0here the vectors are created at run time%depends upon the microprocessor/

    ATLe aN R/ #$%& bytes

    ATLe aS R/ %$&' bytesThat is not muchP and every byte counts!

    9o0 letQs consider the vectors. Firstly, 0e have to decide about the type of data to be recorded/ oolean or c ar or un"igned c ar or yte or uint' t / N byte each int or un"igned int or uint#* t or int#* t / bytes each long or un"igned long or uint+% t or int+% t/ bytes each float or dou le / bytes each

    For more information on data types, follo0 this thread

    This means that the follo0in vectors 0ill occupy/1 :"te > ?32@= // 32B7 ?32@= // 32B32e :een successfu.." a..ocated12 KThis code has been 0ritten by 1ob Faludi

    received some questions related to the use of the FFT library. This e3ample illustrate ho0 tointerface the FFT function to an acquisition en ine, such as the optimi"ed one from the (lainA>Clibrary.

    http://www.arduino.cc/en/Reference/HomePagehttp://www.faludi.com/http://www.arduino.cc/en/Reference/HomePagehttp://www.faludi.com/
  • 8/12/2019 170952212 Fourier Arduino

    15/19

    01 /B02 03 Exam .e of use of t5e ADC and FF( .i:-a-ies04 Co "-i!5t C 2010 Didie- ,on!ue>i..e0$

    0 (5is -o!-am is f-ee soft a-e "ou can -edist-i:ute itand/o- modif"

    06 it unde- t5e te-ms of t5e +& +ene-a. *u:.ic ,icense asu:.is5ed :"

    07 t5e F-ee Soft a-e Foundation eit5e- >e-sion 3 of t5e,icense o-08 at "ou- o tion an" .ate- >e-sion10

    11 (5is -o!-am is dist-i:uted in t5e 5o e t5at it i.. :eusefu.

    12 :ut W%( O ( A&) WARRA&()= it5out e>en t5e im .ied a--ant"of

    13 ERC A&(A %,%() o- F%(&ESS FOR A *AR(%C ,AR * R*OSE Seet5e14 +& +ene-a. *u:.ic ,icense fo- mo-e detai.s1$

    1 )ou s5ou.d 5a>e -ecei>ed a co " of t5e +& +ene-a. *u:.ic,icense

    16 a.on! it5 t5is -o!-am %f not see G5tt !nu o-!

  • 8/12/2019 170952212 Fourier Arduino

    16/19

    36 /B Data >ecto-s B/37 uint7't >Data?sam .es@=38 dou:.e >Rea.?sam .es@=40 dou:.e >%ma!?sam .es@=41

    42 >oid setu43 /B %nitia.iNe se-ia. comm o-t B/44 Se-ia. :e!in 11$200 = //4$ /B Set acJuisition a-amete-s B/4 ADC setAcJuisition*a-amete-s c5anne. sam .es f-eJuenc" =46 K47 48 >oid .oo $0 /B AcJui-e data and sto-e t5em in a >ecto- of :"tes B/$1 ADC acJui-eData >Data =$2 /B Con>e-t 7 :its unsi!ned data in 32 :its f.oats B/$3 fo- uint1 't i < 0= i G sam .es= iII $4 >Rea.?i@ < dou:.e >Data?i@ =$$ K$ /B Wei!5 data B/

    $6 FF( indo in! >Rea. sam .es FF('W%&'()*' A %&+FF('FORWARD =

    $7 /B Com ute FF( >Rea. and >%ma! >ecto-s contain t5e sou-cedata

    $8 and i.. contain t5e -esu.t data on com .etion of executin!t5e functionB/0 FF( com ute >Rea. >%ma! sam .es FF('FORWARD =

    1 /B Com ute ma!nitudes t5e -esu.tin! data can :e -ead f-omt5e >Rea. >ecto- B/2 FF( com .ex(o a!nitude >Rea. >%ma! sam .es =3 /B .oad f-eJuenc" s ect-um B/4 -intVecto- >Rea. sam .es HH 1 SC,'FREQ E&C) =

    $ /B *ause B/ de.a" $000 =

    6 K7 8 >oid -intVecto- dou:.e B>D uint7't n uint7't sca.e(" e

    60 /B u.it u- ose -intin! function B/61 dou:.e time%nte->a. < 1 0 / f-eJuenc" =62 fo- uint1 't i < 0= i G n= iII 63 /B *-int a:scissa >a.ue B/

    64 s itc5 sca.e(" e 6$ case SC,'%&DE Se-ia. -int i DEC = :-ea;=

  • 8/12/2019 170952212 Fourier Arduino

    17/19

    6 case SC,'(% E Se-ia. -int i B time%nte->a. =:-ea;=

    66 case SC,'FREQ E&C) Se-ia. -int i / time%nte->a. Bsam .es 1 = :-ea;=67 K

    68 Se-ia. -int P P =70 /B *-int o-dinate >a.ue B/71 Se-ia. -int >D?i@ =72 Se-ia. -int.n =73 K74 Se-ia. -int.n =7$ K7 G/ .ainfft 5HG/ .ainadc 5HG/5tt H

    4ere are a fe0 comments on the use of (lainFFT.First of all/ (lainFFT performs in place calculation, 0hich means that the results are recorded0ithin the vectors containin the source data.?:sable@ results are available on completion of the Comple3To1eal$% e3ecution. 2efore e3ecution,v1eal and v ma vectors contain the transformed results from the FFT. After e3ecution, the v1ealvector containsP t0o times the frequency spectrum in a perfectly symetric 0ay.The (lainFFTU N.ino s;ecth e3ample sho0s

    1 /B Com ute ma!nitudes B/2 FF( Com .ex(oRea. >Rea. >%ma! sam .es FF('SC,'()*'A *,%( DE ==hile in fact 0e could save processin time 0ith

    1 /B Com ute ma!nitudes B/

    2 FF( Com .ex(oRea. >Rea. >%ma! sam .es HH 1FF('SC,'()*'A *,%( DE =As lon as, in any 0ay the s;etch uses

    1 /B *-int f-eJuenc" s ect-um B/2 *-intVecto- >Rea. sam .es HH 1 SC,'FREQ E&C) =for printin the spectrum. CVF>.

    The samplin frequency $#etQs call this variable Fs% determines the frequency ran e of the spectrum0hile the number of points acquired durin si nal acquisition $#etQs call this variable 9% determinesthe resolution frequency. As a consequence of that//6 To ncrease the frequency ran e, increase the si nal samplin frequency6 To increase the frequency resolution for a iven frequency ran e, increase the number of pointsacquired at the same samplin frequency.

    The result from the FFT can be vie0ed as a collection of 9K ?bins@. To each bin corresponds afrequency ran e $or band0idth%, centred on a frequency value, as reported in the v1eal vector. The0idth of each bin $#etQs call this variable >f% is equal to FsK9. The last bin is centred on the ma3frequency $#etQs call this variable Fma3% at $FsK %6$FsK9%. The first bin is a little bit special/ t is

    centred on 4", so as to say on the >C component of the si nal. 7o that the raphical binrepresentation should be half the si"e of the other bins!

    All these parameters can be pictured in the follo0in 0ay

  • 8/12/2019 170952212 Fourier Arduino

    18/19

    in 1 in 2 in 3 in &/2 // // // //

    T T T T T T T T T &"Juist f-eJuenc" Fs/2

    T T T ax F-eJuenc" Fmax T T Df B 2 T Df B 1

    Df B 0 0 N DC

    n the real 0orld, the amount of si nal resultin from/6 >f W )K6 >f K , in other 0ords h", is read from v1eal G H6 >f W N )K6 >f K is read from v1eal GNH6 >f W )K6 >f K is read from v1eal G HAnd so on, up to6 >f W 9K )K6 >f K , so as to say Fma3, is read from v1eal G9K H

    Each bin contains the po0er of one or more si nals 0hich frequencies fit in the band band0ith.From this point, it is obvious that the narro0er the bin, the better the selectivity of the filter. nsome, not to say most, circumstances, the spectrum representation does not e3actly loo;s li;e purehisto rams.

    For a iven si nal characteri"ed by a pure sinusoidal function, the most abundant po0er is readfrom the bin 0hich corresponds to the si nal frequency, but the ad acent bins may contain some

    po0er abundances too. This is due to the frequency lea;a e. =e may use one from the ne3t optionsto overcome this phenomenon/6 ncrease the number of samples $9% in order to improve the selectivity6 Apply appropriate windowing6 Apply spectrum pea; interpolation

    (ea; interpolation helps improvin the most accurate pea; ape3 location than;s to some linear $e. .Vuadratic fit% or non6linear $e. . 5aussian fit%. =hile this interpolation applies to a limited numberof consecutive data points, 0e may apply simplified formula for computin ape3 locations. (ea;interpolation is almost mandatory 0hen all si nificant pea;s from a frequency spectrum must becorrelated $e. . Findin harmonics%.

    The follo0in pictures illustrate various use cases of (lainFFT for plottin frequency spectrum. nall cases, a 4ann 0indo0 0as applied as 0ell as 5aussian pea; ape3 interpolation.

    4ere is the frequency spectrum from a sinusoidal si nal acquired 0ith a samplin rate of N;4" overX samples/

    4ere is the frequency spectrum from a sinusoidal si nal acquired 0ith a samplin rate of N;4" overS O R samples/

    http://www.arduinoos.com/wordpress/?p=1022http://www.arduinoos.com/wordpress/wp-content/uploads/PlainFFT_01.jpghttp://www.arduinoos.com/wordpress/?p=1022
  • 8/12/2019 170952212 Fourier Arduino

    19/19

    4ere is the frequency spectrum from a sinusoidal si nal acquired 0ith a samplin rate of X 4"over X samples/

    ,ote / The pea; loo;s broader than in picture N, but this feelin is related to the narro0er scale!

    This is probably on over6simplified e3planation, but it is sufficient for usin (lainFFT in the mostappropriate manner. Feel free to add your comments and su estions.

    http://www.arduinoos.com/wordpress/wp-content/uploads/PlainFFT_03.jpghttp://www.arduinoos.com/wordpress/wp-content/uploads/PlainFFT_02.jpg