<<

CORDIC

AND

ITS APPLICATIONS IN DSP

ATHESISSUBMITTEDINPARTIALFULFILLMENTOFTHE REQUIREMENTSFORTHEDEGREEOF Bachelor of Technology

in

Electrical Engineering

By SAMBIT KUMAR DASH JASOBANTA SAHOO SUNITA PATEL

Department of Electrical Engineering

National Institute of Technology

Rourkela

2007

1

CORDIC ALGORITHM

AND

ITS APPLICATIONS IN DSP

ATHESISSUBMITTEDINPARTIALFULFILLMENTOFTHE REQUIREMENTSFORTHEDEGREEOF Bachelor of Technology in Electrical Engineering

By SAMBIT KUMAR DASH JASOBANTA SAHOO SUNITA PATEL

UndertheGuidanceof Prof.S.Mohanty

Department of Electrical Engineering

National Institute of Technology

Rourkela

2007

2

National Institute of Technology Rourkela

CERTIFICATE

This is to certify that the thesis entitled,” CORDIC Algorithm and it’s applications in DSP ” submitted by Sri Sambit Kumar Dash , Sri Jasobanta Sahoo, Sunita Patel inpartialfulfillmentoftherequirementsfortheawardofBachelorofTechnologyDegree inElectricalEngineeringattheNationalInstituteofTechnology,Rourkela(DeemedUniversity) isanauthenticworkcarriedoutbyhimundermysupervisionandguidance. Tothebestofmyknowledge,thematterembodiedinthethesishasnot beensubmittedtoanyotherUniversity/InstitutefortheawardofanyDegreeorDiploma. Date:02/05/07 Prof. S. Mohanty Place:Rourkela Dept.ofElectricalEngg. NationalInstituteoftechnology Rourkela769008

3

ACKNOWLEDGEMENT Iwouldliketoarticulatemydeepgratitudetomyprojectguide Prof. S. Mohanty whohas alwaysbeenmymotivationforcarryingouttheproject.

I wish to extend my sincere thanks to Prof. P. K. Nanda , Head of our Department, for allowingustousethefacilitiesofthe“ComputingandSimulationLab”

ItismypleasuretoreferMicrosoftWordexclusiveofwhichthecompilationofthisreport wouldhavebeenimpossible.Alsoitwouldnothavebeenpossibletocompletetheproject withoutthesimulationsoftware”MATLAB”

A project of this nature could never have been attempted with our reference to and inspiration from the works of others whose details are mentioned in references section. I acknowledgemyindebtednesstoallofthem.Lastbutnottheleast,mysincerethankstoall of my friends who have patiently extended all sorts of help for accomplishing this undertaking.

SAMBIT KUMAR DASH JASOBANTA SAHOO SUNITA PATEL

4 CONTENTS Certificatei Acknowledgementii Contentsiii Abstractivv 1.Introduction12 1.1Background 1.2Objective 2.CORDICAlgorithm&itsVariousModes37 2.1Mode 2.2VectoringMode 3.CORDICAlgorithm&itsApplications814 3.1&Cosine 3.2PolartoRectangularTransformation 3.3GeneralVectorRotation 3.4CartesianToPolarTransformation 3.5InverseCORDICfunctions 3.6Linear&Hyperbolicfunctions 4.CORDICAlgorithminDFT&DCT1519 4.1DFT&DCT 4.2BasicCORDIC 4.3Parallel&Pipelinedarrays 4.4AlgorithmforDFT 5SimulationUsingMATLAB2034 6.Conclusion35 7.References36

5

ABSTRACT OBJECTIVE : Thedigitalsignalprocessinglandscapehaslongbeendominatedbythe withenhancementssuchassinglecyclemultiplyaccumulateinstructionsand specialaddressingmodes.Whiletheseprocessorsarelowcostandofferextremeflexibility,they areoftennotfastenoughfortrulydemandingDSPtasks.Theadventofreconfigurablelogic computerspermitsthehigherspeedsofdedicatedhardwaresolutionsatcoststhatare competitivewiththetraditionalsoftwareapproach.Unfortunatelyoptimizedforthese microprocessorsbasedsystemsdonotmapwellintohardware.Whilehardwareefficient solutionsoftenexist,thedominanceofthesoftwaresystemshaskeptthesesolutionsoutofthe spotlight.Amongthesehardwareefficientalgorithmsisaclassofiterativesolutionsfor trigonometricandothertranscendentalfunctionsthatuseonlyshiftsandaddstoperform.The trigonometricfunctionsarebasedonvectorrotations,whileotherfunctionssuchassquareroot areimplementedusinganincrementalexpressionofthedesiredfunction.Thetrigonometric algorithmiscalledCORDICanacronymforCoordinateRotationDigitalComputer.The incrementalfunctionsareperformedwithaverysimpleextensiontothehardwarearchitecture andwhilenotCORDICinthestrictsense,areoftenincludedbecauseoftheclosesimilarity.The CORDICalgorithmsgenerallyproduceoneadditionalbitofaccuracyforeachiteration. DESCRIPTION : AdetailedstudyonvariousmodesofCORDICalgorithmisdone.Firstofalla studyismadehowtheCORDICalgorithmisderivedfromthegeneralvectorequation.Thena studyisdoneregardingthevariousmodesoftheCORDICalgorithmandhowitcanbeusedto findthesine,cosine,tanandfunctions,itsuseinconversionofcoordinatesystems.An attemptismadetocarryoutarigorousstudyofitsuseinDSPorientedapplicationsANDhowit hasrevolutionizedtheDSPscenario.FinallysimulationsarecarriedoutusingMATLABto supportthepurposeofourstudy. RESULTS TheresultsclearlybringouttheadvantageofusingCORDICalgorithm.Firstofall thesineandcosineofanyanglecouldbefoundouteasily.Similaristhecaseoflogarithmand hyperbolicfunctions.Thesimulationresultsprovethefactthatthehardwarecomplexitygets reducedbyusingtheCORDICalgorithm.Alargenoofplotswereobtainedfordifferent

6 functions.FinallytheimplementationinDCTwascarriedoutandtheresultsobtainedwerein linewiththoseofthetheoreticalvalues. CONCLUSION TheCORDICalgorithmspresentedinthispaperarewellknownintheresearch andsupercomputingcircles.HerethebasicCORDICalgorithmandapartiallistofpotential applicationsofpotentialapplicationsofaCORDICbasedprocessorarraytodigitalsignal processingispresented.TheCORDICbasedDCTarchitectureforlowpowerdesignhasbeen proposed.TheproposedmultiplierlessCORDICbasedDCTarchitectureproduceshigh throughputandiseasytoimplementingVLSI.Theproposedarchitecturereducedtheinputdata rangefortheCORDICprocessorbysplitandthenoofcompensationiterationsinCORDIC basedDCTcomputationbyutilizingthatmostimageshavesimilarneighboringpixels.The projectalsoshowsthatatoolisavailableforuseinFPGAbasedcomputingmachines,whichare thelikelybasisforthenextgenerationDSPsystems.

7 Chapter 1 INTRODUCTION Background Objective

8 1.1 BACKGROUND Thedigitalsignalprocessinglandscapehaslongbeendominatedbythemicroprocessorswith enhancementssuchassinglecyclemultiplyaccumulateinstructionsandspecialaddressing modes.Whiletheseprocessorsarelowcostandofferextremeflexibility,theyareoftennotfast enoughfortrulydemandingDSPtasks.Theadventofreconfigurablelogiccomputerspermits thehigherspeedsofdedicatedhardwaresolutionsatcoststhatarecompetitivewiththe traditionalsoftwareapproach.Unfortunatelyalgorithmsoptimizedforthesemicroprocessors basedsystemsdonotmapwellintohardware.Whilehardwareefficientsolutionsoftenexist,the dominanceofthesoftwaresystemshaskeptthesesolutionsoutofthespotlight.Amongthese hardwareefficientalgorithmsisaclassofiterativesolutionsfortrigonometricandother transcendentalfunctionsthatuseonlyshiftsandaddstoperform.Thetrigonometricfunctionsare basedonvectorrotations,whileotherfunctionssuchassquarerootareimplementedusingan incrementalexpressionofthedesiredfunction.ThetrigonometricalgorithmiscalledCORDIC anacronymforCoordinateRotationDigitalComputer.Theincrementalfunctionsareperformed withaverysimpleextensiontothehardwarearchitectureandwhilenotCORDICinthestrict sense,areoftenincludedbecauseoftheclosesimilarity.TheCORDICalgorithmsgenerally produceoneadditionalbitofaccuracyforeachiteration. ThetrigonometricCORDICalgorithmswereoriginallydevelopedas adigitalsolutionforrealtimenavigationproblems.TheoriginalworkiscreditedtoJackVolder .TheCORDICalgorithmhasfounditswayintodiverseapplicationsincludingthe8087math ,theHP35,radarsignalprocessorsandrobotics.CORDICrotationhas alsobeenproposedforcomputingDiscreteFourier[4],DiscreteCosine[4],SingularValue Decomposition[5],andsolvinglinearsystems[1]. 1.2 OBJECTIVE TheprojectattemptstosurveytheexistingCORDICandCORDIClikealgorithms withaneyetowardsitsimplementation.Firstabriefdescriptionofthetheorybehindthe algorithmandthederivationofseveralfunctionsarepresented.Thenthetheoryisextendedto thesocalledunifiedCORDICalgorithms.

9

Chapter 2 CORDIC ALGORITHM AND IT’S VARIOUS MODES

CORDIC THEORY: AN ALGORITHM FOR VECTOR ROTATION

10 Allofthetrigonometricfunctionscanbecomputedorderived fromfunctionsusingvectorrotations,aswillbediscussedinthefollowingsections.Vector rotationcanalsobeusedfrompolartorectangularandrectangulartopolarconversions,for vectormagnitude,andasabuildingblockincertaintransformssuchasDFTandDCT.The CORDICalgorithmprovidesaniterativemethodofperformingvectorrotationsbyarbitrary anglesusingonlyshiftsandadds.ThealgorithmcreditedtoVolder[4]isderivedfromthe generalrotationtransform x’=xcos Ø ysin Ø y’=ycos Ø+xsin Ø thisrotatesavectorinaCartesianplanebytheangleØ.

FIG2.1:RotationofavectorVbyangle ø Thesecanberearrangedsothat x’=cos Ø* [xytan Ø] y’=cosØ*[y+xtanØ] Sofarnothingissimplified.Howeveriftherotationanglesarerestrictedsothat tan( Ø)= ± 2−i ,thebythetangenttermisreducedtosimpleshiftoperation.Arbitary anglesofrotationareobtainablebyperformingaseriesofsuccessivelysmallerelementary operations.Ifthedecisionateachiterationi,iswhichdirectiontorotateratherthanwhetheror nottorotate,thenthecos( δi) termbecomesaconstantbecausecos( δi)=cos(δi).Theiterative rotationcannowbeexpressedas: –i x i+1 =K i[x i–y i×d i ×2 ]

11 i y i+1 =K i[y i+xi ×di×2 ] where:

1 i −2i K i=cos(tan 2 )=1/ 1+ 2

d i= ±1 Removingthescaleconstantfromtheiterativeequationsyieldsashiftaddalgorithmforvector rotation.TheproductoftheK i’scanbeappliedelsewhereinthesystemortreatedasapartofthe systemprocessinggain.Theproductapproaches0.6073asthenumberofiterationgoesto infinity.ThereforetherotationalgorithmhasagainA nofapproximately1.647.Theexactgain dependsonthenoofiterationsandobeystherelation

−2i A n= ∏ 1+ 2 n Theangleofacompositerotationisuniquelydefinedbythesequenceofthedirectionsofthe elementaryrotations.Thatsequencecanberepresentedbyadecisionvector.Thesetofall possibledecisionvectorsisanangularmeasurementsystembasedonbinaryarctangents. Conversionsbetweentheangularsystemsandanyothercanbeaccomplishedusingalookup.A betterconversionmethodusesanadditionalsubtractorthataccumulatetheelementary rotationanglesateachiteration.Theelementaryanglescanbeexpressedinanyconvenient angularunit.Thoseangularvaluesaresuppliedbyasmalllookuptableorarehardwired dependingontheapplication.Theangleaccumulatoraddsathirddifferenceequationtothe CORDICalgorithm: 1 –i z i+1 =z i–d i×tan (2 ) Obviously,incaseswheretheangleisusefulinthearctangentbase,thisextraelementisnot needed. TheCORDICrotatorisnormallyoperatedinoneoftwomode3s.Thefirstcalledrotationby Volder[4]rotatestheinputvectorbyaspecifiedangle.Thesecondmodecalledvectoringrotates theinputvectortothexaxiswhilerecordingtheanglerequiredtomakethatrotation. 2.1ROTATION MODE : Inrotationmode,theangleaccumulatorisinitializedwiththedesired rotationangle.Therotationdecisionateachiterationismadetodiminishthemagnitudeofthe residualangleintheangleaccumulator.Thedecisionateachiterationisthereforebasedonthe 12 signoftheresidualangleaftereachstep.Naturally,iftheinputangleisalreadyexpressedinthe binaryarctangentbase,theangleaccumulatormaybeeliminated.Forrotationmode,the CORDICequationsare: i x i+1 =x i–y i ×di×2 i yi+1=y i +x i × di×2 1 –i zi+1=z i–d i×tan (2 ) where

d i=1ifz i<0,+1otherwise whichprovidesthefollowingresult

xn=A n[x 0cosz0–y osinz 0]

y n=A n[yocosz0+x 0sinz 0]

zn=0 An= ∏ 1+ 2−2i n 2.2CORDIC ROTATION IN VECTORING MODE : InthevectoringmodetheCORDICvector rotatestheinputvectorthroughwhateverangleisnecessarytoaligntheresultvectorwiththex axis.Theresultofthevectoringoperationisarotationangleandthescaledmagnitudeofthe originalvector(thexcomponentoftheresult.Thevectoringfunctionworksbyseekingto minimizetheycomponentoftheresidualvectorateachrotation.Thesignoftheresidualy componentisusedtodeterminewhichdirectionistorotatenext.Iftheangleaccumulatoris initializedwithzero,itwillcontainthetraversedangleattheendoftheiterations.Invectoring modetheCORDICequationsare: i x i+1 =x i–y i ×d i× 2 –i y i+1 =y i +x i × di×2 1 –i z i+1 =z i–d i×tan (2 ) where

d i=+1ify i<0,1otherwise Then:

2 2 xn=A n× x0 + y0

yn=0 1 z n=z 0+tan (y o/x 0)

13 An= ∏ 1+ 2−2i n TheCORDICrotationandvectoringalgorithmsasstatedarelimitedtorotationanglesbetween 90 0and90 0.Forcompositerotationslargerthan90 0anadditionalrotationisrequired. Thisgivesthecorrectioniteration: x’=d×y y’=d ×x z’=z+d × ∏ /2 where d=+1ify<0,1otherwise Thereisnogrowthforthisinitialrotation.Alternativelyaninitialrotationofeither ∏ or0can bemadeavoidingthereassignmentofthexandycomponentstotherotatorelements.Again thereisnogrowthduetotheinitialrotation x’=d ×x y’=d×y z’=zifd=1,orz= ∏ ifd=1 d=1ifx<0,+1otherwise

FIG2.2:Iterativevectorrotation,initializedwithV0

14

Chapter 3

15 CORDIC ALGORITHM AND IT’S APPLICATIONS 3.1SINE AND COSINE : TherotationalmodeCORDICoperationcansimultaneouslycomputethesine andcosineoftheinputangle.Settingtheycomponentoftheinputvectortozeroreducesthe rotationmoderesultsto

x n=An ×x0cosz 0

y n=A n ×x0sinz 0

Bysettingx oequalto1/A nrotationproducestheunscaledsineandcosineoftheangleargument z0.Veryoftenthesineandcosinevaluesmodulateamagnitudevalue.Usingothertechniques requiresanoofmultiplierstoobtainthemodulation.TheCORDICtechniqueperformsthe multiplyaspartoftherotationoperationandthereforeeliminatestheneedforapairofexplicit multipliers.TheoutputoftheCORDICrotatorisscaledbytherotatorgain.Ifthegainisnot acceptable,asinglemultiplybythereciprocalofthegainconstantplacedbeforetheCORDIC rotatorwillyieldtheunscaledresults.Itisworthnotingthatthehardwarecomplexityofthe CORDICrotatorisapproximatelyequivalenttothatofasinglemultiplierwiththesameword size. 16 EXAMPLE : Tofindthesineof28.027 0 Ø=0 0 cos( ø)=1X=1 sin( ø)=1Y=0 0 0 0 Rotatefrom0 to45 (ø21 =45 ) X’=XY/1=10/1=1 Y’=X/1+Y=1/1+0=1 0 Rotatefrom450to18.4350( ø32 =26.565 ).Becausethisisanegativeangle,and becausethetangentfunctionisodd,wechangethesignofthenumbersthatgetshifted. X’=X+Y/2=1+1/2=1.5 Y’=X/2+Y=1/2+1=0.5 Theaggregateconstantisnotaffectedbecauseitisaproductofcosines,andthe cosinefunctioniseven. 0 0 Rotatefrom18.435 to32.4710( ø43 =14.036 ) X’=XY/4=1.50.5/4=1.375 Y’=X/4+Y=1.5/4+0.5=0.875 0 0 0 Rotatefrom32.471 to25.346 (ø54 =7.125 ) X’=X+Y/8=1.375+0.875/8=1.484375 Y’=X/8+Y=1.375/8+0.875=0.703125 0 0 0 Rotatefrom25.346 to28.922 (ø65 =3.576 ) X’=XY/16=1.4843750.703125/16=1.440429 Y’=X/16+Y=1.484375/16+0.703125=0.795898 0 0 0 Rotatefrom28.922 to27.132 (ø76 =1.790 ) X’=X+Y/32=1.440429+0.795898/32=1.465300 Y’=X/32+Y=1.440429/32+0.795898=0.750884 Rotatefrom27.1320to28.0270( ø87=0.8950) X’=XY/64=1.4653000.750884/64=1.453567 Y’=X/64+Y=1.456300/64+0.750884=0.773779 Afterthatwehavetojustmultiplybytheaggregateconstant sin(28.027 0)=0.607253*Y=0.46988 cos(28.027 0)=0.607253*X=0.88268

17 3.1 POLAR TO RECTANGULAR TRANSFORMATION : Alogicalextensiontosineandcosine computerisapolartoCartesiancoordinatetransformer.Thetransformationfrompolarto Cartesianspaceisdefinedby. x=rcos θ y=rsin θ Aspointedoutabove,themultiplicationbythemagnitudecomesforfreeusingtheCORDIC rotator.Thetransformationisaccomplishedbyselectingtherotationmodewithx 0=polarphase andy 0=0.ThevectorresultrepresentsthepolarinputtransformedtoCartesianspace.The transformhasagainequaltotherotatorgain,whichneedstobeaccountedsomewhereinthe system.Ifthegainisunacceptablethepolarmagnitudemaybemultipliedbythereciprocalof therotatorgainbeforeitispresentedtotheCORDICrotator.

3.2GENERAL VECTOR ROTATION : TherotationmodeCORDICrotatorisalsousefulfor performinggeneralvectorrotations,asareoftenencounteredinmotioncorrectionandcontrol systems.Forgeneralrotation,the2dimensionalinputvectorispresentedtotherotatorinputs. Therotatorrotatesthevectorthroughthedesiredangle.TheoutputisscaledbytheCORDIC rotatorgain,whichmustbeaccountedforelsewhereinthesystem.Ifthescalingisunacceptable, apairofconstantmultipliersisrequiredtocompensatethegain. 3.3ARCTANGENT : Thearctangent, θ=Atan(y/x)isdirectlycomputedusingthevectoringmode CORDICrotatoriftheangleaccumulatorisinitializedwithzero.Theargumentmustbe providedasaratioexpressedasavector(x,y).Sincethearctangentresultistakenfromtheangle accumulatortheCORDICrotatorgrowthdoesnotaffecttheresult. 1 z n=z 0+tan (y 0/x 0) ThevectoringmodeCORDICrotatorproducesthemagnitudeoftheinputvectorasabyproduct ofcomputingthearctangent.Afterthevectoringmoderotationthevectorisalignedwiththex axis.Themagnitudeofthevectoristhereforethesameasthexcomponentoftherotatedvector. Thisresultisapparentintheresultequationsforthevectormoderotator:

18 2 2 x n=A n x0 + y0 Themagnituderesultisscaledbytheprocessorgainwhichneedstobeaccountedforelsewhere inthesystem.TheCORDICimplementationrepresentsasignificanthardwaresavingsoveran equivalentPythagorasprocessor.Theaccuracyofthemagnituderesultimprovesby2bitsfor eachiterationperformed. 3.4CARTESIAN TO POLAR TRANSFORMATION : TheCartesiantopolartransformationconsists offindingthemagnitude(r=sqrt(x2+y2))andphaseangle( ø=atan[y/x])oftheinput vector(x,y).Thereaderwillimmediatelyrecognizethatbothfunctionsareprovided simulnteouslybythevectoringmodeCORDICrotator.Themagnitudeoftheresultwillbe sealedbytheCORDICrotatorgainandshouldbeaccountedforelsewhereinthesystem.Ifthe gainisunacceptable,itcanbecorrectedbymultiplyingtheresultantmagnitudebythereciprocal ofthegainconstant. 3.5INVERSE CORDIC FUNCTIONS InmostcasesifafunctionisgeneratedbyaCORDICstyle computer,itsinversecanbecomputed.UnlesstheCORDICrotatordescribedisusableto computeseveraltrigonometricfunctionsdirectlyandothersindirectly.Judiciouschoiceofinitial valuesandmodespermitsdirectcomputationofsine,cosine,arctangent,vectormagnitudeand transformationsbetweenpolarandCartesiancoordinates. ARCSINE AND ARCCOSINE : TheArcsinecanbecomputedbystartingwithaunitvectoronthe positivexaxis,thenrotatingitsothatitsycomponentisequaltotheinputargument.Thearcsine isthentheanglesubtendedtocausetheycomponentoftherotatedvectortomatchthe argument.Thedecisionfunctioninthiscaseistheresultofacomparisonbetweentheinput valueandtheycomponentoftherotatedvectorateachiteration. i x i+1 =x i–y i ×d i2 i y i+1 =y i +x i ×d i 2 1 i zi+1 =z i –d i× tan (2 ) where

d i =+1ify i

19 Rotationproducesthefollowingresult

2 2 x n = (An × x0 ) − c

y n =c

z n=z 0 +arcsin(c/A nx 0)

−2i A n = ∏ 1+ 2 n Thearcsinefunctionasstatedabovereturnscorrectanglesforinputs1

3.7EXTENSION TO LINEAR FUNCTIONS : AsimplemodificationtotheCORDICequationpermitsthe computationoflinearfunctions i xi+1 =x i–0 ×di2 =x i i y i+1 =y i+x i×di 2 i zi+1 =z i–d i×(2 )

Forrotationmode(d i=1ifz i<0,+1otherwise)thelinearrotationproduces

xn=x 0

y n=y 0+x 0×z0

z n=0 Thisoperationissimilartotheshiftaddimplementationofamultiplierandasmultipliersgois notanoptimalsolution.ThemultiplicationishandyinapplicationswhereaCORDICstructureis alreadyavailable.Thevectoringmodeismoreinterestingasitprovidesamethodforevaluating ratios

xn=x 0

yn=0

zn=z 0–y 0/x 0 Therotationsinthelinearcoordinatesystemhaveaunitygain,sonoscalingcorrectionsare required. 3.EXTENSION TO : 20 Thecloserelationshipbetweenthetrigonometrican hyperbolicfunctionssuggeststhesamearchitecturecanbeusedtocomputethehyperbolic functions.WhilethereisearlymentionofusingtheCORDICstructureforhyperboliccoordinate transforms[4]thefirstdescriptionofthealgorithmisthatbyWather[1].TheCORDICequations forhyperbolicrotationsarederivedusingthesamemanipulationasthoseusedtoderivethe rotationinthecircularcoordinatesystem.Forrotationmodetheseare i x i+1 =x i+yi ×di ×2 i y i+1 =y i +x i ×di × 2 1 i zi+1 =z i –d i×tanh (2 ) where

d i=1ifz i<0,+1otherwise Then

x n=A n[x 0coshz o+y 0sinhz 0]

y n =A n[y 0 coshz 0+x osinhz 0]

z n =0 An= ∏ 1− 2−2i =0.80 n Theelementalrotationsinthehyperboliccoordinatesystemsdonotconverge.Howeveritcanbe shown[1]thatconvergenceisachievedifcertainiterationsarerepeated. Thehyperbolicequivalentsforallthefunctionsdiscussedforthecircularcoordinatesystemcan becomputedinasimilarfashion.AdditionallyasWather[1]pointsout,Thefollowingfunctions canbederivedfromtheCORDICfunctions tan α=sin α/cos α tanh α=sinh α/cosh α exp α=sinh α+cosh α ln α =2tanh 1[y/x]wherex= α+1andy= α1 (α) 2/1 =(x 2–y 2 )2/1 wherex= α+ 1/4andy= α1/4 ItisworthnotingthesimilaritiesbetweentheCORDICequationsforcircular,linearand hyperbolicsystems.Theselectionofcoordinatesystemcanbemadebyintroducingamode variablethattakesonvalues1,0or1forcircular,linearandhyperbolicsystemsrespectively. Theunified[1]CORDICiterationequationsarethen i x i+1 =x im ×y i ×di ×2 i y i+1 =y i +x i ×di × 2

21 zi+1 =z i –d i×ei wheree i istheelementaryangleofrotationforiterationiintheselectedcoordinatesystem. 1 i i 1 i Specificallye i =tan (2 )form=1,ei =2 form=0,ande i=tanh (2 )form=1.Theunification duetoWatherpermitsthedesignofageneralpurposeCORDICprocessor.Thereareanumber ofwaystoimplementaCORDICprocessor.TheidealarchitectureDependsonthespeedversus areatradeoffsintheintendedapplication.Firstwewillexamineaniterativearchitecturethatisa directtranslationfromtheCORDICequationsandthenwewilllookataminimumhardware solutionandamaximumperformancesolution.

Chapter 4 CORDIC ALGORITHM IN DFT & DCT

22

4.1DISCRETE FOURIER TRANSFORM :

Thesequenceof Ncomplexnumbersx0,..., xN−1 istransformedintothesequenceof Ncomplex numbers X0,..., XN−1 bytheDFTaccordingtotheformula:

N −1 −2Πikn / N X k= ∑ xne k=0,1………..N1 n=0 where eisthebaseofthenaturallogarithm, istheimaginaryunit( i2=−1),andπispi.The transformissometimesdenotedbythesymbolF,asinX=F(X)orFX

TheinversediscreteFourierTransform(IDFT)isgivenby

− N 1 2Πikn N X n=1/N ∑ X k e n=0,1…………N1 K =0

NotethatthenormalizationfactormultiplyingtheDFTandIDFT(here1and1/ N)andthesigns oftheexponentsaremerelyconventions,anddifferinsometreatments.Theonlyrequirements oftheseconventionsarethattheDFTandIDFThaveoppositesignexponentsandthatthe productoftheirnormalizationfactorsbe1/ N.Anormalizationof forboththeDFTand IDFTmakesthetransformsunitary,whichhassometheoreticaladvantages,butitisoftenmore practicalinnumericalcomputationtoperformthescalingallatonceasabove(andaunitscaling canbeconvenientinotherways).(Theconventionofanegativesignintheexponentisoften convenientbecauseitmeansthat Xkistheamplitudeofa"positivefrequency"2π k/ N.

DISCRETE COSINE TRANSFORM

23 Adiscretecosinetransform(DCT)isaFourierrelatedtransformsimilartothediscrete Fouriertransform(DFT),butusingonlyrealnumbers.DCTsareequivalenttoDFTsofroughly twicethelength,operatingonrealdatawithevensymmetry(sincetheFouriertransformofareal andevenfunctionisrealandeven),whereinsomevariantstheinputand/oroutputdataare shiftedbyhalfasample.ThereareeightstandardDCTvariants,ofwhichfourarecommon.The mostcommonvariantofdiscretecosinetransformisthetypeIIDCT,whichisoftencalled simply"theDCT";itsinverse,thetypeIIIDCT,iscorrespondinglyoftencalledsimply"the inverseDCT"or"theIDCT

TheDCT,andinparticulartheDCTII,isoftenusedinsignaland imageprocessing,especiallyforlossydatacompression,becauseithasastrong"energy compaction"property:mostofthesignalinformationtendstobeconcentratedinafewlow frequencycomponentsoftheDCT,approachingtheKarhunenLoèvetransform(whichis optimalinthedecorrelationsense)forsignalsbasedoncertainlimitsofMarkovprocesses

DCT-II

N −1

X k= ∑ xn cos[Π / N(n + )2/1 k]k=0,1…………N n=0

4.2BASIC CORDIC PROCESSOR

AbasicCORDICprocessorshouldcontainfunctionmodules whichrealizetheCORDICiterationsspecified,theangleupdateiterationspecifiedandthe scalingequationspecified.

ThemodulessupportasingleCORDICiteration.Itcontainsdual barriershiftersanddualadderstofacilitatetheupdatingofbothx(i)andy(i)simultneously.The numberofbitstobeshiftediscontrolledbytheshiftsequence[s(m,i)].Theshiftsequencecanbe storedonchipusingROM(readonlymemory)orRAM(randomaccessmemory),orgenerated onchipwithasimpleandadditionalcontroldevices.Theadd/subtractoptionis determinedbythesequence{ i},whichisdeterminedbyeitherthesignofz(i)or–x(i).y(i).

24 Theangleupdatingmoduleperformssimpleoperations. InmanyDSPapplications,thereisnoneedtocomputetherotationangleexplicitly.Inthese casestheangleupdatingmodulecanbeeliminatedcompletely.

Thescalingmodulecansharethesameprocessingunitwiththe CORDICiterationmodule.Bymultiplexingthedatapathsthe,thisscalingmoduleisableto performthescalingiterations.

4.3PARALLEL AND PIPELINED ARRAYS

InaparallelCORDICprocessoreachofthenstages oftheCORDICiterationsandsstagesofscalingoperationsisrealizedwithadedicatedbasic CORDICprocessor.Bycascadingthen+sbasicCORDICprocessors,wewillbeabletoperform theentireCORDICrotationoperationsincludingalltheCOIRDICiterationsandallthescaling operationsinoneclockcycle.

Lett 0bethetimeneededforperformingasingle CORDICiterationorasinglescalingiteration.Thenthetotalcomputationaldelaywillbe

(n+s)t 0.Orequivalently,thesignalprocessingthroughputratewillbeboundedby(1/[(n+s)t 0].To increasethethroughput,onemaychoosetoinsertalatchbetweensuccessivestagesofa CORDICprocessorandconvertitintoapipelinedCORDICprocessorarray.Thelatchisableto storetheintermediateresultafteraCORDICiterationorascalingoperation.Hencethe computationofaCORDICprocessorisisolatedfromthecomputationattheadjacentCORDIC processors.Asaresulttheselatchescanbeclockedataperiodoftimet0timeunitswhichisthe computationaldelaybetweenadjacentstages.Inotherwordsthethroughputrateisnow increased(n+s)foldto1/t0.Howevereachindividualdatawilltaken+sclockcyclestocomplete.

Hencethelatencyis(n+s)t 0timeunits.

4.4ALGORITHM FOR DFT

Initiation(0,k)=0for0 ≤ k ≤ N1

Fork=0,1,……N1Do

Form=0,1,…….N1Do

25 Yr (m + ,1 k) cos 2Πmk / N − sin 2Πmk / N  xr (m)  +      Yi (m ,1 k) sin 2Πmk / N + cos 2Πmk / N xi (m) =K 1(n) +

Yr (m,k)   Y (m, k)  i 

Endmloop

Y(k)=Y(N,k)/K 1(n)/*Scalingoperation*/

Endkloop

HerethesequenceX(n)istakenfromtheleftendoftheprocessorarray.EachX(n),which containstworealnumbersx r(n)andx i(n),willbepropagatedfromthecurrentprocessortothe nearestneighbourprocessorinapipelinedmanner.SinceX(n)isnottobemodifiedduring propagationtheycanbepipedatarateoft 0timeunit(1clockcycle)perstage.EachoftheN CORDICprocessorsinthisprocessorarraywillberesponsibleforevaluatingaparticularY(k). ThisimpliesthatNdifferentrotationanglesmustbestoredineachprocessor.Sinceeachrotation anglerequiresnbitstostore,thetotalstoragerequirement,includingthesscalingiterations,will benN+sbits.

26

Chapter 5 SIMULATION USING MATLAB

27

PROGRAM 1 %MATLABCODEFORCORDICINVECTORMODEFORTANGENTFUNCTIONS clearall x(1)=1; y(1)=1; z(1)=0; A=1; fori=1:25 ify(i)<0 d(i)=+1; else d(i)=1; end x(i+1)=x(i)y(i)*d(i)/2^(i1); y(i+1)=y(i)+x(i)*d(i)/2^(i1); z(i+1)=z(i)d(i)*atan(2^(1i)); A=A*sqrt(1+2^(2*(1i))); ify(i+1)==0 break; end x(i+2)=x(i+1)/A; y(i+2)=y(i+1)/A; end fori=1:30 plot(x,y,'*',x,y,'b'); end

28

FIG5.1(SIMULATIONRESULTRFORCORDICINVECTORMODE)

PROGRAM-2

%MATLABCODEFORCORDICINROTATIONMODEFORSINEANDCOSINE FUNCTIONSl x(1)=1; y(1)=0; z(1)=28; A=1; fori=1:100 A=A*sqrt(1+2^(2*(1i))); end x(2)=A*(x(1)*cos(z(1))y(1)*sin(z(1))); y(2)=A*(y(1)*cos(z(1))+x(1)*sin(z(1))); z(2)=0; plot(x,y,'*',x,y,'b') OUTPUT 29 a=10 a=1.58520.4461

FIG5.2(SIMULATIONRESULTFORCORDICINROTATIONMODEFORSINEAND COSINEFUNCTIONS PROGRAM 3 %MATLABCODEFORCORDICINROTATIONMODE clearall x(1)=1; y(1)=0; z(1)=0.5; fori=1:25 ifz(i)<0 d(i)=1; else d(i)=1; end ifi==4|13|40 30 x(i+1)=x(i)+y(i)*d(i)/2^(i); x(i)=x(i)+y(i)*d(i)/2^(i); y(i+1)=y(i)+x(i)*d(i)/2^(i); y(i)=y(i)+x(i)*d(i)/2^(i); z(i+1)=z(i)d(i)*atanh(2^i); z(i)=z(i)d(i)*atanh(2^i); else x(i+1)=x(i)+y(i)*d(i)/2^(i); y(i+1)=y(i)+x(i)*d(i)/2^(i); z(i+1)=z(i)d(i)*atanh(2^i); end end fori=1:15 a=[x(i),y(i)] plot(x,y,'*',x,y,’b‘) end

FIG5.3(SIMULATIONRESULTFORCORDICINROTATIONALMODE)

31 PROGRAM 4 MATLABCODEFORCORDICINFORHYPERBOLICFUNCTIONS x(1)=1; y(1)=0; z(1)=1; fori=1:20 ifz(i)<0 d(i)=1; else d(i)=1; end x(i+1)=x(i)+y(i)*d(i)/2^(i); y(i+1)=y(i)+x(i)*d(i)/2^(i); z(i+1)=z(i)d(i)*atanh(2^(i)); ifz(i+1)==0.0 break; end end figure plot(x,y,'*',x,y,'b')

FIG5.4(SIMULATIONRESULTFORHYPERBOLICFUNCTIONS) PROGRAM 5

32 MATLABCODEFORROTATINGABOUTTHETHREEAXES clearall %initializationofcoordinatesx1=1,y1=0,z1=3,xn=0.707,yn=0.707,zn=5; x(1)=1; y(1)=0; z(1)=3; u(1)=45; v(1)=45; A1=1; A2=1; %applyingequationsinrotationalmode fori=1:20 ifu(i)<0 d(i)=1; else d(i)=1; end A1=A1*sqrt(1+2^(2*(1i))); x(i+1)=x(i)y(i)*d(i)/2^(i1); y(i+1)=y(i)+x(i)*d(i)/2^(i1); z(i+1)=z(i); u(i+1)=u(i)d(i)*atan(2^(1i)); end %scalingoperationstarts x(22)=x(21)/A1; y(22)=y(21)/A1; z(22)=3; %scalingoperationends fori=22:40 j=i21; ifv(j)<0 d(i)=1; else

33 d(i)=1; end A2=A2*sqrt(1+2^(2*(1j))); y(i+1)=y(i)+z(i)*d(i)/2^(1j); z(i+1)=z(i)y(i)*d(i)/2^(1j); x(i+1)=x(i); v(j+1)=v(j)d(i)*atan(2^(1j)); end y(42)=y(41)/A2; z(42)=z(41)/A2; x(42)=x(41); figure plot3(x,y,z,'*',x,y,z,'b') xlabel('x'); ylabel('y'); zlabel('z'); gridon; figure subplot(1,2,1) plot3(x(1),y(1),z(1),'*',x(1),y(1),z(1),'b') gridon; subplot(1,2,2) plot3(x(42),y(42),z(42),'*',x(42),y(42),z(42),'b') gridon;

34

FIG5.5(SIMULATIONRESULTFORROTATINGABOUTTHREEAXES)

PROGRAM 6 MATLABCODEFORROTATINGABOUTTHREEAXES clearall x(1)=3; y(1)=1; z(1)=3; u(1)=56;%ATAND(YN/XN)ATAND(Y1/X1) v(1)=30;%ATAND(SQRT(XN^2+YN^2)/ZN)ATAND(SQRT(X1^2+Y1^2)/Z1) A=1; fori=1:20 ifu(i)<0

35 d(i)=1; else d(i)=1; end A=A*sqrt(1+2^(2*(1i))); x(i+1)=x(i)y(i)*d(i)/2^(i1); y(i+1)=y(i)+x(i)*d(i)/2^(i1);%CORDICEQUATIONSFORVECTORROTATING AROUNDZAXIS z(i+1)=z(i); u(i+1)=u(i)d(i)*atan(2^(1i)); end i=i+2; x(22)=x(21)/A; y(22)=y(21)/A;%SCALINGOPERATION z(22)=3; B=1; forj=1:22 ifv(j)<0 e(j)=1; else e(j)=1; end B=B*sqrt(1+2^(2*(1j))); x(j+i)=x(j+i1); y(j+i)=y(j+i1)+z(j+i1)*e(j)/2^(j1);%CORDICEQUATIONSFORVECTOR ROTATINGAROUNDXAXIS z(i+j)=z(j+i1)y(j+i1)*e(j)/2^(j1); v(j+1)=v(j)e(j)*atan(2^(1j)); end z(45)=z(44)/B; y(45)=y(44)/B;%SCALINGOPERATION x(45)=x(44); figure

36 plot3(x,y,z,'*',x,y,z,'b') xlabel('x'); ylabel('y'); zlabel('z'); gridon; figure subplot(1,2,1); plot3(x(1),y(1),z(1),'*',x(1),y(1),z(1),'b') xlabel('x'); ylabel('y'); zlabel('z'); gridon; subplot(1,2,2); plot3(x(45),y(45),z(45),'*',x(45),y(45),z(45),'b') xlabel('x'); ylabel('y'); zlabel('z'); gridon;

37 FIG5.6(SIMULATIONRESULTFORROTATINGABOUTTHREEAXES)

PROGRAM 7 MATLABPROGRAMFORCOMPUTING2_DIMENSIONALDCT clc clearall closeall if(input('WANTTOENTERMATRIXFROMCOMMANDLINE(1forY/2forN)')==1); x=input('ENTERTHEORDEROFTHEMATRIX') disp('entertheelementsofthematrix') fori=1:x forj=1:x A(i,j)=input(''); end end else x=input('ENTERTHEORDEROFTHEMATRIX') A=rand(x); end disp('inputmatrix') B=A fori=1:x %implementationof1DDCTrowwise

38 A(1,i)=B(1,i)+B(4,i); A(2,i)=B(2,i)+B(3,i); A(3,i)=B(1,i)B(4,i); A(4,i)=B(3,i)B(2,i); end B=A; fori=1:x [A(3,i),A(1,i)]=cordicdct(B(1,i),B(2,i),45); [A(2,i),A(4,i)]=cordicdct(B(3,i),B(4,i),22.5); end disp('matrixafterapplying1DDCTcolumnwise') B=A fori=1:x %implementationof1DDCTrowwise A(i,1)=B(i,1)+B(i,4); A(i,2)=B(i,2)+B(i,3); A(i,3)=B(i,1)B(i,4); A(i,4)=B(i,3)B(i,2); end B=A; fori=1:x [A(i,3),A(i,1)]=cordicdct(B(i,1),B(i,2),45); [A(i,2),A(i,4)]=cordicdct(B(i,3),B(i,4),22.5); end disp('matrixafterapplying1DDCTROWwise') A function[p,q]=cordicdct(a,b,theta) x(1)=a; y(1)=b; z(1)=theta; A=1; fori=1:25 ifz(i)<0 d(i)=1;

39 else d(i)=1; end x(i+1)=x(i)y(i)*d(i)/2^(i1); y(i+1)=y(i)+x(i)*d(i)/2^(i1); z(i+1)=z(i)d(i)*atand(2^(1i)); A=A*sqrt(1+2^(2*(1i))); end x(27)=x(26)/A; y(27)=y(26)/A; p=x(27); q=y(27); inputmatrix B= 1234 2341 3412 4123 Matrixafterapplying1DDCTcolumnwise B= 7.07117.07117.07117.0711 3.15430.54122.07190.5412 0.00002.82840.00002.8284 0.22421.30662.38901.3066 Matrixafterapplying1DDCTROWwise A= 20.00000.00000.00000.0000 0.00004.00003.69550.0000 0.00003.69554.00001.5307 0.00000.00001.53074.0000 clc clearall closeall

40 if(input('WANTTOENTERMATRIXFROMCOMMANDLINE(1forY/2forN)')==1); x=input('ENTERTHEORDEROFTHEMATRIX') disp('entertheelementsofthematrix') fori=1:x forj=1:x A(i,j)=input(''); end end else x=input('ENTERTHEORDEROFTHEMATRIX') A=rand(x); end disp('matrixafterapplying1DDCTcolumnwise') B=dct(A) C=B'; disp('matrixafterapplying1DDCTrowwise') A=dct(C); A=A' Matrixafterapplying1DDCTcolumnwise B= 5.00005.00005.00005.0000 2.23040.38271.46510.3827 02.000002.0000 0.15850.92391.68920.9239 Matrixafterapplying1DDCTrowwise A=10.0000000 02.00001.84780.0000 01.84782.00000.7654 0.00000.00000.76542.0000 CONCLUSION TheCORDICalgorithmspresentedinthisprojectarewellknownintheresearchandsuper computingcircles.ThetrigonometricCORDICalgorithmswereoriginallydevelopedasadigital 41 solutionforrealtimenavigationproblems.TheoriginalworkiscreditedtoJackVolder.The CORDICalgorithmhasfounditswayintodiverseapplicationsincludingthe8087math coprocessor,theHP35calculator,radarsignalprocessorsandrobotics.CORDICrotationhas alsobeenproposedforcomputingDiscreteFourier[4],DiscreteCosine[4],SingularValue Decomposition[5],andsolvinglinearsystems[1]. HerethebasicCORDICalgorithmandapartiallistofpotentialapplicationssofaCORDIC basedprocessorarraytodigitalsignalprocessingispresented.TheCORDICbasedDCT architectureforlowpowerdesignhasbeenproposed.TheproposedmultiplierlessCORDIC basedDCTarchitectureproduceshighthroughputandiseasytoimplementingVLSI.The proposedarchitecturereducedtheinputdatarangefortheCORDICprocessorbysplitandtheno ofcompensationiterationsinCORDICbasedDCTcomputationbyutilizingthatmostimages havesimilarneighboringpixels.TheprojectalsoshowsthatatoolisavailableforuseinFPGA basedcomputingmachines,whicharethelikelybasisforthenextgenerationDSPsystems.Its basisofapplicationinDSPhasbeenthoroughlyinvestigated. Thedayisnotfarawaywhenmanyofthesoftwarealgorithmswillbereplaced bythehardwareefficientalgorithmspavingwayforreducedcomplexityandfasteroperation.

REFERENCES [1]J.E.Volder.”TheCORDICtrigonometriccomputingtechnique,”IRETrans.Electron.. Comput.Vol.EC8,no3,pp.335339,Sept1959

42 [2]B.G.Lee,”Anewalgorithmtocomputethediscretecosinetransform,”IEEEtransactionson Acoustics,SpeechandSignalProcessing,volASSP32,no.6,pp.12341245,Dec1984 [3]Despain,A.M.,“FourierTransformComputationsUsingCORDICIterations,”IEEE TransactionsOnComputers,Vol.23,1974,pp.9931001 [4]A.PeledandB.Liu,”Anewhardwarerealizationofdigitalfilters,”IEEETrans. Acoust.,Speech,SignalProcessing,vol,ASSP22,PP.456462,Dec.1974 [5]N.WesteandK.Eshraghian,PrinciplesofCMOSVLSIDesignASystemsPerspective,2 nd edReading,MAAddisonWesley,1993 [6]A.P.ChandrakasanandR.W.Brodersen,LowOiwerCMOSDesign.Piscataway.NJ:IEEE Press,1998.Ed.. [7]Chang,L.W.,andS.W.Lee,”SystolicArraysforthediscreteCosineTransform”IEEETrans. OnSignalProcessing,Vol.29,No11,Nov.1991,24112418 [8]Chen,W.h.,C.HSmith,andS.C.Fralik,”Afastcomputationalalgorithmforthediscretecosine transform”,IEEETrans.onCommunications,Vol.COM25,pp.10049,Sept.1977. [9]Andraka,R.J.,“BuildingaHighPerformanceBitSerialprocessorinanFPGA,”Proceedings ofDesignSuperCon’96,Jan1996,pp5.1–5.21 [10]Duh,W.J.,andWu,J.L.,”ImplementingtheDiscreteCosineTransformbyUsingCORDIC Techniques,”ProceedingsTheInternationalSymposiumonVLSITechnology,Systemsand Applications,Taipei,Taiwan,1989,pp.281285 [11]Wang,S.anedPiuri,V.,“AunifiedViewofCORDICProcessorDesign”,Application SpecificProcessors,EditedbyEarlE.Swartzlander,Jr.,Ch.5,pp.121160,KluwerAcademic Press,November1996 [12]Walther,J.s.,“Aunifiedalgorithmforelementaryfunctions,”SpringJointComputer Conf.,1971,proc.,pp.379385

43