0% found this document useful (0 votes)
6K views10 pages

Discrete Fourier Transform in Excel Tutorial

This is the first tutorial in our ongoing series on time series spectral analysis. In this entry, we will closely examine the discrete Fourier transform (aka DFT) and its inverse, as well as data filtering using DFT outputs. The DFT is basically a mathematical transformation and may be a bit dry, but we hope that this tutorial will leave you with a deeper understanding and intuition through the use of NumXL functions and wizards. In future entries, we will dedicate more time for discrete data filters, their construction, and off course, application.

Uploaded by

NumXL Pro
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
6K views10 pages

Discrete Fourier Transform in Excel Tutorial

This is the first tutorial in our ongoing series on time series spectral analysis. In this entry, we will closely examine the discrete Fourier transform (aka DFT) and its inverse, as well as data filtering using DFT outputs. The DFT is basically a mathematical transformation and may be a bit dry, but we hope that this tutorial will leave you with a deeper understanding and intuition through the use of NumXL functions and wizards. In future entries, we will dedicate more time for discrete data filters, their construction, and off course, application.

Uploaded by

NumXL Pro
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 10

DiscreteFourierTransformTutorial 1 SpiderFinancialCorp,2013

DiscreteFourierTransform
Thisisthefirsttutorialinourongoingseriesontimeseriesspectralanalysis.Inthisentry,wewillclosely
examinethediscreteFouriertransform(akaDFT)anditsinverse,aswellasdatafilteringusingDFT
outputs.TheDFTisbasicallyamathematicaltransformationandmaybeabitdry,butwehopethatthis
tutorialwillleaveyouwithadeeperunderstandingandintuitionthroughtheuseofNumXLfunctions
andwizards.
Infutureentries,wewilldedicatemoretimefordiscretedatafilters,theirconstruction,andoffcourse,
application.
Background
Youhaveprobablyoccasionallytransformedyourdatatostabilizethevariance(e.g.logtransform)orto
improvethevaluesdistributioninthesampledata.

1 2
1 2
{ , ..., }
log(x )
{ , ..., }
t T
t t
t T
x x x x
y
y y y y
=
=
=

Inmathematics,thediscreteFouriertransform(DFT)convertsafinitelistofequallyspacedsamplesofa
functionintoalistofcoefficientsofafinitecombinationofcomplexsinusoids,orderedbytheir
frequencies,whichhavethosesamesamplevalues.DFTconvertsthesampledfunctionfromitsoriginal
domain(oftentimeorpositionalongaline)tothefrequencydomain.
Insum,theFouriertransformhasthefollowingproperties:
1. Thetransformeddataisnolongerinthetimedomain.
2. Thetransformationoperatesonthewholedataset.Itisnotapointbypointtransformationas
wehaveseenwithearliertransformationsinthetimedomain.

1 2
1 2
1 2
1
1 2 1 2
{ , ..., }
({ , ..., })
{ , ..., }
{ , ..., } ({ , ..., })
T
T
K
T K
x x x x
Y F x x x
Y y x x
x x x F y x x

=
=
=
=

3. Thetransformeddataiscomplex(notrealvalued).
WhatistheDFT?
Inplainwords,thediscreteFouriertransformdecomposestheinputtimeseriesintoasetofcosine
functions.

DiscreteFourierTransformTutorial 2 SpiderFinancialCorp,2013

1
1
cos( )
N
m k k
k
x A k m
N
| e
=
= +


So,youcanthinkofthekthoutputoftheDFTasthe
k k
A | .The
k
A isreferredtoastheamplitude,
andthe
k
| asthephase(inradians).
Theinputtimeseriescannowbeexpressedeitherasatimesequenceofvalues,orasafrequency
sequenceof [ ]
k k
A | pairs.Knowingthesetof [ ]
k k
A | ,wecanrecovertheexactinputtimeseries.
Whatis e?
eisthefundamentalortheprincipalradianfrequency.ITisexpressedasfollows:

2
T
t
e =
Where:
- T isthenumberofobservationsintheequallyspacedinputtimeseries.
WhatisN?
Thenumberof [ ]
k k
A | pairsweneedtohave,sowecanrecovertheoriginalinputtimeserieswitha
floorvalueof
2
T
.
Notethatthezerofrequencycomponent(i.e.k=0)isalwaysrealvalue,andinthecaseofevensized
timeseries,thelastfrequencycomponentisalsorealvalue,whichbringsthetotalnumberofvalues
(amplitudeandphase)toT.Thereisnogainorlossofinformationorstoragerequirementbecauseof
thistransform.
Finally,notethat
k k T k T k
k k k T k T
A A
A A
| |
| |

+ +
=
=

Inessence,onlythevaluesofthefirst
2
T
frequencycomponentsareneeded,whereastherestcanbe
easilyimpliedfromthem.Furthermore,theDFTvaluesareperiodicwithacyclelengthof T
.

DiscreteFourierTransformTutorial 3 SpiderFinancialCorp,2013

Whydecomposetimeseriesdataintoaseriesofcosinefunctions?
Considerthefollowingtimeseries
1 2 25
( , ,..., ) x x x :

Now,letscomputethetimeseriesusingasubsetofthefrequencysequence:
Case1:Usingazerofrequencycomponent:
(0)
m o
x A =

Usingthezerofrequency,wegetthelongrunaverageofthetimeseries.

DiscreteFourierTransformTutorial 4 SpiderFinancialCorp,2013

Case2:Usingfirstfrequencycomponent(k=1)
(0)
(1) (0)
1 1 1 1
cos( ) cos( )
m o
m o m
x A
x A A m x A m | e | e
=
= + + = + +

Notethatthegraphontherightisessentiallythesameastheoneontheleft,butwith
(1)
m
x plottedusing
therighthandsideaxisscale.
Case2:Usingfirstandsecondfrequencycomponents(k=2)

(0)
(1) (0)
1 1 1 1
(2) (1)
2 2
cos( ) cos( )
cos( 2 )
m o
m o m
m m
x A
x A A m x A m
x x A m
| e | e
| e
=
= + + = + +
= + +


Note,
(2)
m
x isclosertotheoriginaltimeseriesthan
(1)
m
x duetotheaddedcosinefunction,but
(1)
m
x is
smoother.

DiscreteFourierTransformTutorial 5 SpiderFinancialCorp,2013

Inessence,theprocessofrecoveringtheoriginaltimeseriesfromthesubsetissimilartotimeseries
smoothing,butwithoutthedrawbackofthelageffect.

Case3:Usingthefirst8frequencycomponents(k=8)
(0)
(1) (0)
1 1 1 1
(2) (1)
2 2
(3) (2)
3 3
(8) (7)
8 8
cos( ) cos( )
cos( 2 )
cos( 3 )
....
cos( 8 )
m o
m o m
m m
m m
m m
x A
x A A m x A m
x x A m
x x A m
x x A m
| e | e
| e
| e
| e
=
= + + = + +
= + +
= + +
= + +

Insum,bydecomposingtheinputtimeseriesintocosinefunctions,wecanseparatethecomponent(s)
attributedtonoise(highfrequency),uncoverperiodicity,andfindalongrunvaluefortheprocess.

DiscreteFourierTransformTutorial 6 SpiderFinancialCorp,2013

Process
First,letsorganizeourinputdata.Wecanstartbyplacingthevaluesofthesampledatainaseparate
column.

NowwearereadytoconstructourDFToutputtable.First,selecttheemptycellinyourworksheet
whereyouwishtheoutputtabletobegenerated,thenlocateandclickontheFouriericoninthe
NumXLtab(ortoolbar).

TheDFTWizardpopsup.

Selectthecellsrangeforthevaluesoftheinputvariable.

DiscreteFourierTransformTutorial 7 SpiderFinancialCorp,2013

Notes:
1. Bydefault,thetablecellsrangeissettothecurrentselectedcellinyourworksheet.
Finally,onceweselecttheinputdata(X)cellsrange,theOptionsandMissingValuestabsbecome
available(enabled).
Next,selecttheOptionstab:

Initially,thetabissettothefollowingvalues:
- FrequencyComponentOutputischecked.Leavethisoptionchecked.
o TheAmplitudeandPhaseoptionsarechecked.Leavethoseoptionscheckedaswell.
o Thenumberofcomponentscorrespondstothesizeoftheoutputtable.Setthisvalueto
five(5)togeneratethefirstfivefrequencycomponents.
- Ontherightside,InputVariableOutputisunchecked.Checkthisoptiontogeneratebackthe
inputtimeseriesusingasubsetofthefrequencycomponents.
o UnderNo.ofComponents,setthisvalueto4.Youcanchangethisvaluelateronin
theoutputtable.
Now,clickontheMissingValuestab.

DiscreteFourierTransformTutorial 8 SpiderFinancialCorp,2013

Inthistab,youcanselectanapproachtohandlemissingvaluesinthedataset(Xs).Bydefault,DFT
wizarddoesnotallowanymissingvalueintheanalysis.
Thistreatmentisagoodapproachforouranalysis,soletsleaveitunchanged.
Now,clickOKtogeneratetheoutputtables.

DiscreteFourierTransformTutorial 9 SpiderFinancialCorp,2013

Inthefirsttable(ontheleft),itdisplaystheamplitudeandphase(inradians)fordifferentfrequency
components(i.e.cosinefunctions).Notethatcomponentzerohaszerophase.

Inthesecondtable,itcarriesontheinverseFouriertransformusingasubsetofthefrequencies.

Ifyouwishtochangethenumberofcomponents,simplyeditthenumberinthecelltable,andthe
valuesundertheFittedtitlewillberecalculated.
Conclusion
Inthistutorial,wepresentedtheinterpretationofthediscreteFouriertransform(DFT)anditsinverse
(IDFT),aswellastheprocesstocarryouttherelatedcalculationinExcelusingNumXLsaddinfunctions.
Wheredowegofromhere?
UsingDFT,weconstructedananalyticalformularepresentationfortheinputtimeseries.
Onedirectapplicationthatwecanthinkofistocomputevaluesforthenewintermediateobservation,
ortoalterthesamplingfrequency(i.e.upsample)andintroduceanewtimeseries.
Butwhataboutmissingvalues?Whatifwedonthaveafixedsamplingrate?DifferenttypesofFourier
transformsareavailable(e.g.nonuniformtimediscreteFouriertransform(NUTDFT))tohandleun
equallyspacedinputtimeseries,whichgenerateafinitediscretesetoffrequencies.Thiswillproveto
beusefulforimputingintermediatemissingvaluesusingthedynamicsofthewholedataset,ratherthan
adjacentobservations,asisthecaseininterpolationorGaussianbridgemethods.

DiscreteFourierTransformTutorial 10 SpiderFinancialCorp,2013

Thetimeseriesspectrumcontainsasignificantamountofinformation,whichwebarelyscratchedinthis
tutorial.Inournextentry,wewilllookatthediscretefilter(operator)definitioninbothtimeand
frequencydomain,anditsapplicationtoourtimeseriesanalysis/modeling.

You might also like