Instructions
instructions
User Manual: Pdf
Open the PDF directly: View PDF
.
Page Count: 4

ProgrammingAssignmentWeek2
KalmanFilter⎼TargetTracking
1.Introduction
InthisassignmentyouwillbeimplementingaKalmanfilterforballtrackingin2Dspace.Imaginea
soccerrobotwantstopredicttheball’slocationconstantlyforplanningitsnextmotion.Thefigure
belowdepictsanexampleofballlocationmeasurements,locationestimates,andapredicted
locationatcertaintime.
2.Instructions
Phase1.DesignyourKFModel
1. DynamicsModel(=SystemModel)
a. Inordertohaveanestimateof2Dlocationandpredictafuturelocation,thestate
vector(s)shouldincludevelocity(v)aswellasposition(p)ofbothdimensions,x
andy.
Example:s=[pxvxpyvy]’ors=[pxpyvxvy]’
*Notethatthesymbols
isusedtoindicatethestatevector,whichisdenotedasxinthelecture
material.ThisistoavoidconfusionwiththenotationxoftheCartesiancoordinatex,y.

b. DefineyourtransitionmatrixA(Seep.3ofslides[221]),wheredt=0.033sec.
c. Nowconsiderthetypeofthesystemnoisecovariance .ThemostsimpleformΣm
isadiagonalmatrix,withthefourvariances: =diag
([ , , , ])orΣmσpx
2 σpy
2 σvx
2σvy
2
=diag
([ , , , ]).Σmσpx
2 σvx
2σ py
2 σvy
2
Ingeneral,youdon’thavetorestricttheform,butadiagonalmatrixisagood
startingpointifyoudonothaveastrongreasonnottodoso.Howtosetthe
values?ItwillbeexplainedPhase2.
2. MeasurementModel
a. Themeasurementdataisreadilyinthe2Dlocationunit.
z=[zxzy]’=[pxpy]’
HencetheobservationmatrixCwillbea2by4matrixwithtwoonesandsix
zeros.PleasefigureoutwhatCisbyyourself!
b. Considerthetypeofthemeasurementnoisecovariance .ThemostsimpleΣo
formisadiagonalmatrix,withthetwovariances: =diag
([ , ]).WewillΣoσzx
2 σzy
2
seehowtosetthevaluesinPhase2.
3. Reviewthemodels[Advancedoption].
a. Ifyouhavechosen(block)diagonalformsforthenoisecovariances,thexandy
componentsarenowuncorrelated
.Thenyoucansimplifythemodelandhavetwo
independentidenticalfilters.Thesimplifiedfilterhass=[pv]’,2by2Aand ,z=Σm
p,thescalarvariance ,and1by2C.Σo

You only need to keep two instances of this filter, one for x, and the other for y.
This idea (separating uncorrelated systems) reduces the computational load, which
canbeeffectiveforhighdimensionalsystems.
*Notethatthisreductionisoptionalinthisassignment.IfyougotmoreconfusedbecauseofStep3.a,
thenjustignoreitandgoaheadtoPhase2.
b. Ifyouhavecorrelatedterms,thatisfine.Youwillkeepthemodelasitis.
Phase2.SetParameterValues
1. Inordertosettheinitialvaluesofthestateandstateerrorcovariance,youmayusethefirst
measurementastheposition,andsetzeroforthevelocity.Also,youmaysetthestate
covariancePtobeaverylargeidentitymatrix,whichimpliesalargeuncertaintyofthe
state.
2. Youalsoneedtosetthemodelnoiseparameters and .ThinkaboutaroughyetΣmΣo
reasonablerangeoftheparametersbyconsideringthephysicalunitsofthe
noise/uncertaintymodeloftheproblem.
Forexample,Ifthemeasurementnoiseisinmeters,thenitcouldrangefromO(0.01)to
O(0.1).Similarly,ifthedynamicsmodelincludespositionandvelocity,thentheyhaveunits
suchasmeterandmeter/sec.Becauseyoursystemisasmallballrollingonthefloor,the
velocitywillNOTbeaslargeas10meter/sec.
3. CoarseTests
a. Stillyouwillhavemanymanychoices.Nowyoucantestthenumbersofthe
reasonablerangeFIRSTCOARSELY.
b. Onegoodstartingpointistosetthesystemmodelnoisecovariancetohave
unreasonablylarge(forexample,1e^6),andthemeasurementnoisecovarianceto
besmallinthereasonablerange.ThenyourKFshouldjustfollowyour
measurements,unlessyouhaveabuginyourcode.
c. Afterthat,youcantestdifferentvaluesofthesystemmodelnoiseparameter.
4. FineTuning
a. OnceyourKFseemstowork,thenyoucanfinetunetheparameters.
b. Youcaneventrymorecomplexparameters,suchasnondiagonalcovariance
matrixoradaptive(nonconstant)covariances.WesuggestthatyoudothisONLY
AFTERyoursimplestKFworks.
5. Becareful,thevarianceorcovariancetakesasquaredform.

Phase3.Implementation
1. Youwillcompleteafunctionthattakesthestate,parameters,andsensordata(x,y)asinput,
andreturnsaballpositionprediction,possiblyusefulforgoalieapplications.Thesignature
ofthefunctionisgivenas:
function[predictx,predicty,state,param]=kalmanFilter(t,x,y,state,param,previous_t)
2. Pleasepassthestateandstatecovarianceasinput/outputarguments.Thusparam
should
havethefollowingfields:
param
.P
Youcannameitdifferently,butmakesurethatyoukeeptrackofthestatecovarianceP.(If
youhavetwoindependentfilters,thenyoumayhaveparam
.Pxandparam
.Py).Youmay
useparam
toaddotherfieldsifyouneed.
3. Yourfunctionshouldreturnthepredictedxandypositionsoftheballatatime330msinto
thefuture.Witharateof30Hz,this330msintimerepresents10framesinthefuture.Inthe
kalmanFilterfunction,anaiveimplementationshowshowtouseinstantaneousvelocity
fromonlytwoframesandnostatetocalculatethefuturepositionoftheball,returnedas
predictxandpredicty.Youwillkeeptrackofthefourstatecomponents,comprisedofx
position,yposition,xvelocity,andyvelocity.Thisstatewillbefedintoeachfunctioncall.
4. example_test.misprovidedtohelpvisualizeyourresult.
Phase4.Evaluationandsubmission
Tosubmityourresulttoourserver,youneedtorunthescriptrunevalinyourMATLAB
commandwindow.Pleasespecifythepathwheretheencryptedtestdataarelocated.Ascript
willthenevaluateyourkalmanFilterfunctionandgenerateanoutputfile,
SubmissionFilter.mat,tobeuploadedtotheCourserawebUI.Youmaysubmityourresult
multipletimes,andwewillcountonlythehighestscoretowardsyourgrade.Thescorereflects
howcloseyourpredictedballpositionsaretotheobservedballpositions.