arm_math.h 299 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974
  1. /******************************************************************************
  2. * @file arm_math.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.6.0
  5. * @date 18. March 2019
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2010-2019 Arm Limited or its affiliates. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. /**
  25. \mainpage CMSIS DSP Software Library
  26. *
  27. * Introduction
  28. * ------------
  29. *
  30. * This user manual describes the CMSIS DSP software library,
  31. * a suite of common signal processing functions for use on Cortex-M and Cortex-A processor
  32. * based devices.
  33. *
  34. * The library is divided into a number of functions each covering a specific category:
  35. * - Basic math functions
  36. * - Fast math functions
  37. * - Complex math functions
  38. * - Filtering functions
  39. * - Matrix functions
  40. * - Transform functions
  41. * - Motor control functions
  42. * - Statistical functions
  43. * - Support functions
  44. * - Interpolation functions
  45. * - Support Vector Machine functions (SVM)
  46. * - Bayes classifier functions
  47. * - Distance functions
  48. *
  49. * The library has generally separate functions for operating on 8-bit integers, 16-bit integers,
  50. * 32-bit integer and 32-bit floating-point values.
  51. *
  52. * Using the Library
  53. * ------------
  54. *
  55. * The library installer contains prebuilt versions of the libraries in the <code>Lib</code> folder.
  56. * Pre-built libraries will not be updated to contain new functions.
  57. * So, SVM, Bayes, Distance functions and experimental functions are not included in those libraries.
  58. * If you want to use those functions, you'll have to modify the projects, include the missing
  59. * files and rebuild.
  60. * You can also use the cmake to build the libraries and select what you want to be included.
  61. * Here is the list of pre-built libraries :
  62. * - arm_cortexM7lfdp_math.lib (Cortex-M7, Little endian, Double Precision Floating Point Unit)
  63. * - arm_cortexM7bfdp_math.lib (Cortex-M7, Big endian, Double Precision Floating Point Unit)
  64. * - arm_cortexM7lfsp_math.lib (Cortex-M7, Little endian, Single Precision Floating Point Unit)
  65. * - arm_cortexM7bfsp_math.lib (Cortex-M7, Big endian and Single Precision Floating Point Unit on)
  66. * - arm_cortexM7l_math.lib (Cortex-M7, Little endian)
  67. * - arm_cortexM7b_math.lib (Cortex-M7, Big endian)
  68. * - arm_cortexM4lf_math.lib (Cortex-M4, Little endian, Floating Point Unit)
  69. * - arm_cortexM4bf_math.lib (Cortex-M4, Big endian, Floating Point Unit)
  70. * - arm_cortexM4l_math.lib (Cortex-M4, Little endian)
  71. * - arm_cortexM4b_math.lib (Cortex-M4, Big endian)
  72. * - arm_cortexM3l_math.lib (Cortex-M3, Little endian)
  73. * - arm_cortexM3b_math.lib (Cortex-M3, Big endian)
  74. * - arm_cortexM0l_math.lib (Cortex-M0 / Cortex-M0+, Little endian)
  75. * - arm_cortexM0b_math.lib (Cortex-M0 / Cortex-M0+, Big endian)
  76. * - arm_ARMv8MBLl_math.lib (Armv8-M Baseline, Little endian)
  77. * - arm_ARMv8MMLl_math.lib (Armv8-M Mainline, Little endian)
  78. * - arm_ARMv8MMLlfsp_math.lib (Armv8-M Mainline, Little endian, Single Precision Floating Point Unit)
  79. * - arm_ARMv8MMLld_math.lib (Armv8-M Mainline, Little endian, DSP instructions)
  80. * - arm_ARMv8MMLldfsp_math.lib (Armv8-M Mainline, Little endian, DSP instructions, Single Precision Floating Point Unit)
  81. *
  82. * The library functions are declared in the public file <code>arm_math.h</code> which is placed in the <code>Include</code> folder.
  83. * Simply include this file and link the appropriate library in the application and begin calling the library functions. The Library supports single
  84. * public header file <code> arm_math.h</code> for Cortex-M cores with little endian and big endian. Same header file will be used for floating point unit(FPU) variants.
  85. *
  86. *
  87. * Examples
  88. * --------
  89. *
  90. * The library ships with a number of examples which demonstrate how to use the library functions.
  91. *
  92. * Toolchain Support
  93. * ------------
  94. *
  95. * The library is now tested on Fast Models building with cmake.
  96. * Core M0, M7, A5 are tested.
  97. *
  98. *
  99. *
  100. * Building the Library
  101. * ------------
  102. *
  103. * The library installer contains a project file to rebuild libraries on MDK toolchain in the <code>CMSIS\\DSP\\Projects\\ARM</code> folder.
  104. * - arm_cortexM_math.uvprojx
  105. *
  106. *
  107. * The libraries can be built by opening the arm_cortexM_math.uvprojx project in MDK-ARM, selecting a specific target, and defining the optional preprocessor macros detailed above.
  108. *
  109. * There is also a work in progress cmake build. The README file is giving more details.
  110. *
  111. * Preprocessor Macros
  112. * ------------
  113. *
  114. * Each library project have different preprocessor macros.
  115. *
  116. * - ARM_MATH_BIG_ENDIAN:
  117. *
  118. * Define macro ARM_MATH_BIG_ENDIAN to build the library for big endian targets. By default library builds for little endian targets.
  119. *
  120. * - ARM_MATH_MATRIX_CHECK:
  121. *
  122. * Define macro ARM_MATH_MATRIX_CHECK for checking on the input and output sizes of matrices
  123. *
  124. * - ARM_MATH_ROUNDING:
  125. *
  126. * Define macro ARM_MATH_ROUNDING for rounding on support functions
  127. *
  128. * - ARM_MATH_LOOPUNROLL:
  129. *
  130. * Define macro ARM_MATH_LOOPUNROLL to enable manual loop unrolling in DSP functions
  131. *
  132. * - ARM_MATH_NEON:
  133. *
  134. * Define macro ARM_MATH_NEON to enable Neon versions of the DSP functions.
  135. * It is not enabled by default when Neon is available because performances are
  136. * dependent on the compiler and target architecture.
  137. *
  138. * - ARM_MATH_NEON_EXPERIMENTAL:
  139. *
  140. * Define macro ARM_MATH_NEON_EXPERIMENTAL to enable experimental Neon versions of
  141. * of some DSP functions. Experimental Neon versions currently do not have better
  142. * performances than the scalar versions.
  143. *
  144. * - ARM_MATH_HELIUM:
  145. *
  146. * It implies the flags ARM_MATH_MVEF and ARM_MATH_MVEI and ARM_MATH_FLOAT16.
  147. *
  148. * - ARM_MATH_MVEF:
  149. *
  150. * Select Helium versions of the f32 algorithms.
  151. * It implies ARM_MATH_FLOAT16 and ARM_MATH_MVEI.
  152. *
  153. * - ARM_MATH_MVEI:
  154. *
  155. * Select Helium versions of the int and fixed point algorithms.
  156. *
  157. * - ARM_MATH_FLOAT16:
  158. *
  159. * Float16 implementations of some algorithms (Requires MVE extension).
  160. *
  161. * <hr>
  162. * CMSIS-DSP in ARM::CMSIS Pack
  163. * -----------------------------
  164. *
  165. * The following files relevant to CMSIS-DSP are present in the <b>ARM::CMSIS</b> Pack directories:
  166. * |File/Folder |Content |
  167. * |---------------------------------|------------------------------------------------------------------------|
  168. * |\b CMSIS\\Documentation\\DSP | This documentation |
  169. * |\b CMSIS\\DSP\\DSP_Lib_TestSuite | DSP_Lib test suite |
  170. * |\b CMSIS\\DSP\\Examples | Example projects demonstrating the usage of the library functions |
  171. * |\b CMSIS\\DSP\\Include | DSP_Lib include files |
  172. * |\b CMSIS\\DSP\\Lib | DSP_Lib binaries |
  173. * |\b CMSIS\\DSP\\Projects | Projects to rebuild DSP_Lib binaries |
  174. * |\b CMSIS\\DSP\\Source | DSP_Lib source files |
  175. *
  176. * <hr>
  177. * Revision History of CMSIS-DSP
  178. * ------------
  179. * Please refer to \ref ChangeLog_pg.
  180. */
  181. /**
  182. * @defgroup groupMath Basic Math Functions
  183. */
  184. /**
  185. * @defgroup groupFastMath Fast Math Functions
  186. * This set of functions provides a fast approximation to sine, cosine, and square root.
  187. * As compared to most of the other functions in the CMSIS math library, the fast math functions
  188. * operate on individual values and not arrays.
  189. * There are separate functions for Q15, Q31, and floating-point data.
  190. *
  191. */
  192. /**
  193. * @defgroup groupCmplxMath Complex Math Functions
  194. * This set of functions operates on complex data vectors.
  195. * The data in the complex arrays is stored in an interleaved fashion
  196. * (real, imag, real, imag, ...).
  197. * In the API functions, the number of samples in a complex array refers
  198. * to the number of complex values; the array contains twice this number of
  199. * real values.
  200. */
  201. /**
  202. * @defgroup groupFilters Filtering Functions
  203. */
  204. /**
  205. * @defgroup groupMatrix Matrix Functions
  206. *
  207. * This set of functions provides basic matrix math operations.
  208. * The functions operate on matrix data structures. For example,
  209. * the type
  210. * definition for the floating-point matrix structure is shown
  211. * below:
  212. * <pre>
  213. * typedef struct
  214. * {
  215. * uint16_t numRows; // number of rows of the matrix.
  216. * uint16_t numCols; // number of columns of the matrix.
  217. * float32_t *pData; // points to the data of the matrix.
  218. * } arm_matrix_instance_f32;
  219. * </pre>
  220. * There are similar definitions for Q15 and Q31 data types.
  221. *
  222. * The structure specifies the size of the matrix and then points to
  223. * an array of data. The array is of size <code>numRows X numCols</code>
  224. * and the values are arranged in row order. That is, the
  225. * matrix element (i, j) is stored at:
  226. * <pre>
  227. * pData[i*numCols + j]
  228. * </pre>
  229. *
  230. * \par Init Functions
  231. * There is an associated initialization function for each type of matrix
  232. * data structure.
  233. * The initialization function sets the values of the internal structure fields.
  234. * Refer to \ref arm_mat_init_f32(), \ref arm_mat_init_q31() and \ref arm_mat_init_q15()
  235. * for floating-point, Q31 and Q15 types, respectively.
  236. *
  237. * \par
  238. * Use of the initialization function is optional. However, if initialization function is used
  239. * then the instance structure cannot be placed into a const data section.
  240. * To place the instance structure in a const data
  241. * section, manually initialize the data structure. For example:
  242. * <pre>
  243. * <code>arm_matrix_instance_f32 S = {nRows, nColumns, pData};</code>
  244. * <code>arm_matrix_instance_q31 S = {nRows, nColumns, pData};</code>
  245. * <code>arm_matrix_instance_q15 S = {nRows, nColumns, pData};</code>
  246. * </pre>
  247. * where <code>nRows</code> specifies the number of rows, <code>nColumns</code>
  248. * specifies the number of columns, and <code>pData</code> points to the
  249. * data array.
  250. *
  251. * \par Size Checking
  252. * By default all of the matrix functions perform size checking on the input and
  253. * output matrices. For example, the matrix addition function verifies that the
  254. * two input matrices and the output matrix all have the same number of rows and
  255. * columns. If the size check fails the functions return:
  256. * <pre>
  257. * ARM_MATH_SIZE_MISMATCH
  258. * </pre>
  259. * Otherwise the functions return
  260. * <pre>
  261. * ARM_MATH_SUCCESS
  262. * </pre>
  263. * There is some overhead associated with this matrix size checking.
  264. * The matrix size checking is enabled via the \#define
  265. * <pre>
  266. * ARM_MATH_MATRIX_CHECK
  267. * </pre>
  268. * within the library project settings. By default this macro is defined
  269. * and size checking is enabled. By changing the project settings and
  270. * undefining this macro size checking is eliminated and the functions
  271. * run a bit faster. With size checking disabled the functions always
  272. * return <code>ARM_MATH_SUCCESS</code>.
  273. */
  274. /**
  275. * @defgroup groupTransforms Transform Functions
  276. */
  277. /**
  278. * @defgroup groupController Controller Functions
  279. */
  280. /**
  281. * @defgroup groupStats Statistics Functions
  282. */
  283. /**
  284. * @defgroup groupSupport Support Functions
  285. */
  286. /**
  287. * @defgroup groupInterpolation Interpolation Functions
  288. * These functions perform 1- and 2-dimensional interpolation of data.
  289. * Linear interpolation is used for 1-dimensional data and
  290. * bilinear interpolation is used for 2-dimensional data.
  291. */
  292. /**
  293. * @defgroup groupExamples Examples
  294. */
  295. /**
  296. * @defgroup groupSVM SVM Functions
  297. * This set of functions is implementing SVM classification on 2 classes.
  298. * The training must be done from scikit-learn. The parameters can be easily
  299. * generated from the scikit-learn object. Some examples are given in
  300. * DSP/Testing/PatternGeneration/SVM.py
  301. *
  302. * If more than 2 classes are needed, the functions in this folder
  303. * will have to be used, as building blocks, to do multi-class classification.
  304. *
  305. * No multi-class classification is provided in this SVM folder.
  306. *
  307. */
  308. /**
  309. * @defgroup groupBayes Bayesian estimators
  310. *
  311. * Implement the naive gaussian Bayes estimator.
  312. * The training must be done from scikit-learn.
  313. *
  314. * The parameters can be easily
  315. * generated from the scikit-learn object. Some examples are given in
  316. * DSP/Testing/PatternGeneration/Bayes.py
  317. */
  318. /**
  319. * @defgroup groupDistance Distance functions
  320. *
  321. * Distance functions for use with clustering algorithms.
  322. * There are distance functions for float vectors and boolean vectors.
  323. *
  324. */
  325. #ifndef _ARM_MATH_H
  326. #define _ARM_MATH_H
  327. #ifdef __cplusplus
  328. extern "C"
  329. {
  330. #endif
  331. /* Compiler specific diagnostic adjustment */
  332. #if defined ( __CC_ARM )
  333. #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
  334. #elif defined ( __GNUC__ )
  335. #pragma GCC diagnostic push
  336. #pragma GCC diagnostic ignored "-Wsign-conversion"
  337. #pragma GCC diagnostic ignored "-Wconversion"
  338. #pragma GCC diagnostic ignored "-Wunused-parameter"
  339. #elif defined ( __ICCARM__ )
  340. #elif defined ( __TI_ARM__ )
  341. #elif defined ( __CSMC__ )
  342. #elif defined ( __TASKING__ )
  343. #elif defined ( _MSC_VER )
  344. #else
  345. #error Unknown compiler
  346. #endif
  347. /* Included for instrinsics definitions */
  348. #if defined (_MSC_VER )
  349. #include <stdint.h>
  350. #define __STATIC_FORCEINLINE static __forceinline
  351. #define __STATIC_INLINE static __inline
  352. #define __ALIGNED(x) __declspec(align(x))
  353. #elif defined (__GNUC_PYTHON__)
  354. #include <stdint.h>
  355. #define __ALIGNED(x) __attribute__((aligned(x)))
  356. #define __STATIC_FORCEINLINE static __attribute__((inline))
  357. #define __STATIC_INLINE static __attribute__((inline))
  358. #pragma GCC diagnostic ignored "-Wunused-function"
  359. #pragma GCC diagnostic ignored "-Wattributes"
  360. #else
  361. #include "cmsis_compiler.h"
  362. #endif
  363. #include <string.h>
  364. #include <math.h>
  365. #include <float.h>
  366. #include <limits.h>
  367. #define F64_MAX ((float64_t)DBL_MAX)
  368. #define F32_MAX ((float32_t)FLT_MAX)
  369. #if defined(ARM_MATH_FLOAT16)
  370. #define F16_MAX ((float16_t)FLT_MAX)
  371. #endif
  372. #define F64_MIN (-DBL_MAX)
  373. #define F32_MIN (-FLT_MAX)
  374. #if defined(ARM_MATH_FLOAT16)
  375. #define F16_MIN (-(float16_t)FLT_MAX)
  376. #endif
  377. #define F64_ABSMAX ((float64_t)DBL_MAX)
  378. #define F32_ABSMAX ((float32_t)FLT_MAX)
  379. #if defined(ARM_MATH_FLOAT16)
  380. #define F16_ABSMAX ((float16_t)FLT_MAX)
  381. #endif
  382. #define F64_ABSMIN ((float64_t)0.0)
  383. #define F32_ABSMIN ((float32_t)0.0)
  384. #if defined(ARM_MATH_FLOAT16)
  385. #define F16_ABSMIN ((float16_t)0.0)
  386. #endif
  387. #define Q31_MAX ((q31_t)(0x7FFFFFFFL))
  388. #define Q15_MAX ((q15_t)(0x7FFF))
  389. #define Q7_MAX ((q7_t)(0x7F))
  390. #define Q31_MIN ((q31_t)(0x80000000L))
  391. #define Q15_MIN ((q15_t)(0x8000))
  392. #define Q7_MIN ((q7_t)(0x80))
  393. #define Q31_ABSMAX ((q31_t)(0x7FFFFFFFL))
  394. #define Q15_ABSMAX ((q15_t)(0x7FFF))
  395. #define Q7_ABSMAX ((q7_t)(0x7F))
  396. #define Q31_ABSMIN ((q31_t)0)
  397. #define Q15_ABSMIN ((q15_t)0)
  398. #define Q7_ABSMIN ((q7_t)0)
  399. /* evaluate ARM DSP feature */
  400. #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
  401. #define ARM_MATH_DSP 1
  402. #endif
  403. #if defined(ARM_MATH_NEON)
  404. #include <arm_neon.h>
  405. #endif
  406. #if defined (ARM_MATH_HELIUM)
  407. #define ARM_MATH_MVEF
  408. #define ARM_MATH_FLOAT16
  409. #endif
  410. #if defined (ARM_MATH_MVEF)
  411. #define ARM_MATH_MVEI
  412. #define ARM_MATH_FLOAT16
  413. #endif
  414. #if defined (ARM_MATH_HELIUM) || defined(ARM_MATH_MVEF) || defined(ARM_MATH_MVEI)
  415. #include <arm_mve.h>
  416. #endif
  417. /**
  418. * @brief Macros required for reciprocal calculation in Normalized LMS
  419. */
  420. #define DELTA_Q31 ((q31_t)(0x100))
  421. #define DELTA_Q15 ((q15_t)0x5)
  422. #define INDEX_MASK 0x0000003F
  423. #ifndef PI
  424. #define PI 3.14159265358979f
  425. #endif
  426. /**
  427. * @brief Macros required for SINE and COSINE Fast math approximations
  428. */
  429. #define FAST_MATH_TABLE_SIZE 512
  430. #define FAST_MATH_Q31_SHIFT (32 - 10)
  431. #define FAST_MATH_Q15_SHIFT (16 - 10)
  432. #define CONTROLLER_Q31_SHIFT (32 - 9)
  433. #define TABLE_SPACING_Q31 0x400000
  434. #define TABLE_SPACING_Q15 0x80
  435. /**
  436. * @brief Macros required for SINE and COSINE Controller functions
  437. */
  438. /* 1.31(q31) Fixed value of 2/360 */
  439. /* -1 to +1 is divided into 360 values so total spacing is (2/360) */
  440. #define INPUT_SPACING 0xB60B61
  441. /**
  442. * @brief Macros for complex numbers
  443. */
  444. /* Dimension C vector space */
  445. #define CMPLX_DIM 2
  446. /**
  447. * @brief Error status returned by some functions in the library.
  448. */
  449. typedef enum
  450. {
  451. ARM_MATH_SUCCESS = 0, /**< No error */
  452. ARM_MATH_ARGUMENT_ERROR = -1, /**< One or more arguments are incorrect */
  453. ARM_MATH_LENGTH_ERROR = -2, /**< Length of data buffer is incorrect */
  454. ARM_MATH_SIZE_MISMATCH = -3, /**< Size of matrices is not compatible with the operation */
  455. ARM_MATH_NANINF = -4, /**< Not-a-number (NaN) or infinity is generated */
  456. ARM_MATH_SINGULAR = -5, /**< Input matrix is singular and cannot be inverted */
  457. ARM_MATH_TEST_FAILURE = -6 /**< Test Failed */
  458. } arm_status;
  459. /**
  460. * @brief 8-bit fractional data type in 1.7 format.
  461. */
  462. typedef int8_t q7_t;
  463. /**
  464. * @brief 16-bit fractional data type in 1.15 format.
  465. */
  466. typedef int16_t q15_t;
  467. /**
  468. * @brief 32-bit fractional data type in 1.31 format.
  469. */
  470. typedef int32_t q31_t;
  471. /**
  472. * @brief 64-bit fractional data type in 1.63 format.
  473. */
  474. typedef int64_t q63_t;
  475. /**
  476. * @brief 32-bit floating-point type definition.
  477. */
  478. typedef float float32_t;
  479. /**
  480. * @brief 64-bit floating-point type definition.
  481. */
  482. typedef double float64_t;
  483. /**
  484. * @brief vector types
  485. */
  486. #if defined(ARM_MATH_NEON) || defined (ARM_MATH_MVEI)
  487. /**
  488. * @brief 64-bit fractional 128-bit vector data type in 1.63 format
  489. */
  490. typedef int64x2_t q63x2_t;
  491. /**
  492. * @brief 32-bit fractional 128-bit vector data type in 1.31 format.
  493. */
  494. typedef int32x4_t q31x4_t;
  495. /**
  496. * @brief 16-bit fractional 128-bit vector data type with 16-bit alignement in 1.15 format.
  497. */
  498. typedef __ALIGNED(2) int16x8_t q15x8_t;
  499. /**
  500. * @brief 8-bit fractional 128-bit vector data type with 8-bit alignement in 1.7 format.
  501. */
  502. typedef __ALIGNED(1) int8x16_t q7x16_t;
  503. /**
  504. * @brief 32-bit fractional 128-bit vector pair data type in 1.31 format.
  505. */
  506. typedef int32x4x2_t q31x4x2_t;
  507. /**
  508. * @brief 32-bit fractional 128-bit vector quadruplet data type in 1.31 format.
  509. */
  510. typedef int32x4x4_t q31x4x4_t;
  511. /**
  512. * @brief 16-bit fractional 128-bit vector pair data type in 1.15 format.
  513. */
  514. typedef int16x8x2_t q15x8x2_t;
  515. /**
  516. * @brief 16-bit fractional 128-bit vector quadruplet data type in 1.15 format.
  517. */
  518. typedef int16x8x4_t q15x8x4_t;
  519. /**
  520. * @brief 8-bit fractional 128-bit vector pair data type in 1.7 format.
  521. */
  522. typedef int8x16x2_t q7x16x2_t;
  523. /**
  524. * @brief 8-bit fractional 128-bit vector quadruplet data type in 1.7 format.
  525. */
  526. typedef int8x16x4_t q7x16x4_t;
  527. /**
  528. * @brief 32-bit fractional data type in 9.23 format.
  529. */
  530. typedef int32_t q23_t;
  531. /**
  532. * @brief 32-bit fractional 128-bit vector data type in 9.23 format.
  533. */
  534. typedef int32x4_t q23x4_t;
  535. /**
  536. * @brief 64-bit status 128-bit vector data type.
  537. */
  538. typedef int64x2_t status64x2_t;
  539. /**
  540. * @brief 32-bit status 128-bit vector data type.
  541. */
  542. typedef int32x4_t status32x4_t;
  543. /**
  544. * @brief 16-bit status 128-bit vector data type.
  545. */
  546. typedef int16x8_t status16x8_t;
  547. /**
  548. * @brief 8-bit status 128-bit vector data type.
  549. */
  550. typedef int8x16_t status8x16_t;
  551. #endif
  552. #if defined(ARM_MATH_NEON) || defined(ARM_MATH_MVEF) /* floating point vector*/
  553. /**
  554. * @brief 32-bit floating-point 128-bit vector type
  555. */
  556. typedef float32x4_t f32x4_t;
  557. #if defined(ARM_MATH_FLOAT16)
  558. /**
  559. * @brief 16-bit floating-point 128-bit vector data type
  560. */
  561. typedef __ALIGNED(2) float16x8_t f16x8_t;
  562. #endif
  563. /**
  564. * @brief 32-bit floating-point 128-bit vector pair data type
  565. */
  566. typedef float32x4x2_t f32x4x2_t;
  567. /**
  568. * @brief 32-bit floating-point 128-bit vector quadruplet data type
  569. */
  570. typedef float32x4x4_t f32x4x4_t;
  571. #if defined(ARM_MATH_FLOAT16)
  572. /**
  573. * @brief 16-bit floating-point 128-bit vector pair data type
  574. */
  575. typedef float16x8x2_t f16x8x2_t;
  576. /**
  577. * @brief 16-bit floating-point 128-bit vector quadruplet data type
  578. */
  579. typedef float16x8x4_t f16x8x4_t;
  580. #endif
  581. /**
  582. * @brief 32-bit ubiquitous 128-bit vector data type
  583. */
  584. typedef union _any32x4_t
  585. {
  586. float32x4_t f;
  587. int32x4_t i;
  588. } any32x4_t;
  589. #if defined(ARM_MATH_FLOAT16)
  590. /**
  591. * @brief 16-bit ubiquitous 128-bit vector data type
  592. */
  593. typedef union _any16x8_t
  594. {
  595. float16x8_t f;
  596. int16x8_t i;
  597. } any16x8_t;
  598. #endif
  599. #endif
  600. #if defined(ARM_MATH_NEON)
  601. /**
  602. * @brief 32-bit fractional 64-bit vector data type in 1.31 format.
  603. */
  604. typedef int32x2_t q31x2_t;
  605. /**
  606. * @brief 16-bit fractional 64-bit vector data type in 1.15 format.
  607. */
  608. typedef __ALIGNED(2) int16x4_t q15x4_t;
  609. /**
  610. * @brief 8-bit fractional 64-bit vector data type in 1.7 format.
  611. */
  612. typedef __ALIGNED(1) int8x8_t q7x8_t;
  613. /**
  614. * @brief 32-bit float 64-bit vector data type.
  615. */
  616. typedef float32x2_t f32x2_t;
  617. #if defined(ARM_MATH_FLOAT16)
  618. /**
  619. * @brief 16-bit float 64-bit vector data type.
  620. */
  621. typedef __ALIGNED(2) float16x4_t f16x4_t;
  622. #endif
  623. /**
  624. * @brief 32-bit floating-point 128-bit vector triplet data type
  625. */
  626. typedef float32x4x3_t f32x4x3_t;
  627. #if defined(ARM_MATH_FLOAT16)
  628. /**
  629. * @brief 16-bit floating-point 128-bit vector triplet data type
  630. */
  631. typedef float16x8x3_t f16x8x3_t;
  632. #endif
  633. /**
  634. * @brief 32-bit fractional 128-bit vector triplet data type in 1.31 format
  635. */
  636. typedef int32x4x3_t q31x4x3_t;
  637. /**
  638. * @brief 16-bit fractional 128-bit vector triplet data type in 1.15 format
  639. */
  640. typedef int16x8x3_t q15x8x3_t;
  641. /**
  642. * @brief 8-bit fractional 128-bit vector triplet data type in 1.7 format
  643. */
  644. typedef int8x16x3_t q7x16x3_t;
  645. /**
  646. * @brief 32-bit floating-point 64-bit vector pair data type
  647. */
  648. typedef float32x2x2_t f32x2x2_t;
  649. /**
  650. * @brief 32-bit floating-point 64-bit vector triplet data type
  651. */
  652. typedef float32x2x3_t f32x2x3_t;
  653. /**
  654. * @brief 32-bit floating-point 64-bit vector quadruplet data type
  655. */
  656. typedef float32x2x4_t f32x2x4_t;
  657. #if defined(ARM_MATH_FLOAT16)
  658. /**
  659. * @brief 16-bit floating-point 64-bit vector pair data type
  660. */
  661. typedef float16x4x2_t f16x4x2_t;
  662. /**
  663. * @brief 16-bit floating-point 64-bit vector triplet data type
  664. */
  665. typedef float16x4x3_t f16x4x3_t;
  666. /**
  667. * @brief 16-bit floating-point 64-bit vector quadruplet data type
  668. */
  669. typedef float16x4x4_t f16x4x4_t;
  670. #endif
  671. /**
  672. * @brief 32-bit fractional 64-bit vector pair data type in 1.31 format
  673. */
  674. typedef int32x2x2_t q31x2x2_t;
  675. /**
  676. * @brief 32-bit fractional 64-bit vector triplet data type in 1.31 format
  677. */
  678. typedef int32x2x3_t q31x2x3_t;
  679. /**
  680. * @brief 32-bit fractional 64-bit vector quadruplet data type in 1.31 format
  681. */
  682. typedef int32x4x3_t q31x2x4_t;
  683. /**
  684. * @brief 16-bit fractional 64-bit vector pair data type in 1.15 format
  685. */
  686. typedef int16x4x2_t q15x4x2_t;
  687. /**
  688. * @brief 16-bit fractional 64-bit vector triplet data type in 1.15 format
  689. */
  690. typedef int16x4x2_t q15x4x3_t;
  691. /**
  692. * @brief 16-bit fractional 64-bit vector quadruplet data type in 1.15 format
  693. */
  694. typedef int16x4x3_t q15x4x4_t;
  695. /**
  696. * @brief 8-bit fractional 64-bit vector pair data type in 1.7 format
  697. */
  698. typedef int8x8x2_t q7x8x2_t;
  699. /**
  700. * @brief 8-bit fractional 64-bit vector triplet data type in 1.7 format
  701. */
  702. typedef int8x8x3_t q7x8x3_t;
  703. /**
  704. * @brief 8-bit fractional 64-bit vector quadruplet data type in 1.7 format
  705. */
  706. typedef int8x8x4_t q7x8x4_t;
  707. /**
  708. * @brief 32-bit ubiquitous 64-bit vector data type
  709. */
  710. typedef union _any32x2_t
  711. {
  712. float32x2_t f;
  713. int32x2_t i;
  714. } any32x2_t;
  715. #if defined(ARM_MATH_FLOAT16)
  716. /**
  717. * @brief 16-bit ubiquitous 64-bit vector data type
  718. */
  719. typedef union _any16x4_t
  720. {
  721. float16x4_t f;
  722. int16x4_t i;
  723. } any16x4_t;
  724. #endif
  725. /**
  726. * @brief 32-bit status 64-bit vector data type.
  727. */
  728. typedef int32x4_t status32x2_t;
  729. /**
  730. * @brief 16-bit status 64-bit vector data type.
  731. */
  732. typedef int16x8_t status16x4_t;
  733. /**
  734. * @brief 8-bit status 64-bit vector data type.
  735. */
  736. typedef int8x16_t status8x8_t;
  737. #endif
  738. /**
  739. @brief definition to read/write two 16 bit values.
  740. @deprecated
  741. */
  742. #if defined ( __CC_ARM )
  743. #define __SIMD32_TYPE int32_t __packed
  744. #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
  745. #define __SIMD32_TYPE int32_t
  746. #elif defined ( __GNUC__ )
  747. #define __SIMD32_TYPE int32_t
  748. #elif defined ( __ICCARM__ )
  749. #define __SIMD32_TYPE int32_t __packed
  750. #elif defined ( __TI_ARM__ )
  751. #define __SIMD32_TYPE int32_t
  752. #elif defined ( __CSMC__ )
  753. #define __SIMD32_TYPE int32_t
  754. #elif defined ( __TASKING__ )
  755. #define __SIMD32_TYPE __un(aligned) int32_t
  756. #elif defined(_MSC_VER )
  757. #define __SIMD32_TYPE int32_t
  758. #else
  759. #error Unknown compiler
  760. #endif
  761. #define __SIMD32(addr) (*(__SIMD32_TYPE **) & (addr))
  762. #define __SIMD32_CONST(addr) ( (__SIMD32_TYPE * ) (addr))
  763. #define _SIMD32_OFFSET(addr) (*(__SIMD32_TYPE * ) (addr))
  764. #define __SIMD64(addr) (*( int64_t **) & (addr))
  765. #define STEP(x) (x) <= 0 ? 0 : 1
  766. #define SQ(x) ((x) * (x))
  767. /* SIMD replacement */
  768. /**
  769. @brief Read 2 Q15 from Q15 pointer.
  770. @param[in] pQ15 points to input value
  771. @return Q31 value
  772. */
  773. __STATIC_FORCEINLINE q31_t read_q15x2 (
  774. q15_t * pQ15)
  775. {
  776. q31_t val;
  777. #ifdef __ARM_FEATURE_UNALIGNED
  778. memcpy (&val, pQ15, 4);
  779. #else
  780. val = (pQ15[1] << 16) | (pQ15[0] & 0x0FFFF) ;
  781. #endif
  782. return (val);
  783. }
  784. /**
  785. @brief Read 2 Q15 from Q15 pointer and increment pointer afterwards.
  786. @param[in] pQ15 points to input value
  787. @return Q31 value
  788. */
  789. __STATIC_FORCEINLINE q31_t read_q15x2_ia (
  790. q15_t ** pQ15)
  791. {
  792. q31_t val;
  793. #ifdef __ARM_FEATURE_UNALIGNED
  794. memcpy (&val, *pQ15, 4);
  795. #else
  796. val = ((*pQ15)[1] << 16) | ((*pQ15)[0] & 0x0FFFF);
  797. #endif
  798. *pQ15 += 2;
  799. return (val);
  800. }
  801. /**
  802. @brief Read 2 Q15 from Q15 pointer and decrement pointer afterwards.
  803. @param[in] pQ15 points to input value
  804. @return Q31 value
  805. */
  806. __STATIC_FORCEINLINE q31_t read_q15x2_da (
  807. q15_t ** pQ15)
  808. {
  809. q31_t val;
  810. #ifdef __ARM_FEATURE_UNALIGNED
  811. memcpy (&val, *pQ15, 4);
  812. #else
  813. val = ((*pQ15)[1] << 16) | ((*pQ15)[0] & 0x0FFFF);
  814. #endif
  815. *pQ15 -= 2;
  816. return (val);
  817. }
  818. /**
  819. @brief Write 2 Q15 to Q15 pointer and increment pointer afterwards.
  820. @param[in] pQ15 points to input value
  821. @param[in] value Q31 value
  822. @return none
  823. */
  824. __STATIC_FORCEINLINE void write_q15x2_ia (
  825. q15_t ** pQ15,
  826. q31_t value)
  827. {
  828. q31_t val = value;
  829. #ifdef __ARM_FEATURE_UNALIGNED
  830. memcpy (*pQ15, &val, 4);
  831. #else
  832. (*pQ15)[0] = (val & 0x0FFFF);
  833. (*pQ15)[1] = (val >> 16) & 0x0FFFF;
  834. #endif
  835. *pQ15 += 2;
  836. }
  837. /**
  838. @brief Write 2 Q15 to Q15 pointer.
  839. @param[in] pQ15 points to input value
  840. @param[in] value Q31 value
  841. @return none
  842. */
  843. __STATIC_FORCEINLINE void write_q15x2 (
  844. q15_t * pQ15,
  845. q31_t value)
  846. {
  847. q31_t val = value;
  848. #ifdef __ARM_FEATURE_UNALIGNED
  849. memcpy (pQ15, &val, 4);
  850. #else
  851. pQ15[0] = val & 0x0FFFF;
  852. pQ15[1] = val >> 16;
  853. #endif
  854. }
  855. /**
  856. @brief Read 4 Q7 from Q7 pointer and increment pointer afterwards.
  857. @param[in] pQ7 points to input value
  858. @return Q31 value
  859. */
  860. __STATIC_FORCEINLINE q31_t read_q7x4_ia (
  861. q7_t ** pQ7)
  862. {
  863. q31_t val;
  864. #ifdef __ARM_FEATURE_UNALIGNED
  865. memcpy (&val, *pQ7, 4);
  866. #else
  867. val =(((*pQ7)[3] & 0x0FF) << 24) | (((*pQ7)[2] & 0x0FF) << 16) | (((*pQ7)[1] & 0x0FF) << 8) | ((*pQ7)[0] & 0x0FF);
  868. #endif
  869. *pQ7 += 4;
  870. return (val);
  871. }
  872. /**
  873. @brief Read 4 Q7 from Q7 pointer and decrement pointer afterwards.
  874. @param[in] pQ7 points to input value
  875. @return Q31 value
  876. */
  877. __STATIC_FORCEINLINE q31_t read_q7x4_da (
  878. q7_t ** pQ7)
  879. {
  880. q31_t val;
  881. #ifdef __ARM_FEATURE_UNALIGNED
  882. memcpy (&val, *pQ7, 4);
  883. #else
  884. val = ((((*pQ7)[3]) & 0x0FF) << 24) | ((((*pQ7)[2]) & 0x0FF) << 16) | ((((*pQ7)[1]) & 0x0FF) << 8) | ((*pQ7)[0] & 0x0FF);
  885. #endif
  886. *pQ7 -= 4;
  887. return (val);
  888. }
  889. /**
  890. @brief Write 4 Q7 to Q7 pointer and increment pointer afterwards.
  891. @param[in] pQ7 points to input value
  892. @param[in] value Q31 value
  893. @return none
  894. */
  895. __STATIC_FORCEINLINE void write_q7x4_ia (
  896. q7_t ** pQ7,
  897. q31_t value)
  898. {
  899. q31_t val = value;
  900. #ifdef __ARM_FEATURE_UNALIGNED
  901. memcpy (*pQ7, &val, 4);
  902. #else
  903. (*pQ7)[0] = val & 0x0FF;
  904. (*pQ7)[1] = (val >> 8) & 0x0FF;
  905. (*pQ7)[2] = (val >> 16) & 0x0FF;
  906. (*pQ7)[3] = (val >> 24) & 0x0FF;
  907. #endif
  908. *pQ7 += 4;
  909. }
  910. /*
  911. Normally those kind of definitions are in a compiler file
  912. in Core or Core_A.
  913. But for MSVC compiler it is a bit special. The goal is very specific
  914. to CMSIS-DSP and only to allow the use of this library from other
  915. systems like Python or Matlab.
  916. MSVC is not going to be used to cross-compile to ARM. So, having a MSVC
  917. compiler file in Core or Core_A would not make sense.
  918. */
  919. #if defined ( _MSC_VER ) || defined(__GNUC_PYTHON__)
  920. __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t data)
  921. {
  922. if (data == 0U) { return 32U; }
  923. uint32_t count = 0U;
  924. uint32_t mask = 0x80000000U;
  925. while ((data & mask) == 0U)
  926. {
  927. count += 1U;
  928. mask = mask >> 1U;
  929. }
  930. return count;
  931. }
  932. __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat)
  933. {
  934. if ((sat >= 1U) && (sat <= 32U))
  935. {
  936. const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
  937. const int32_t min = -1 - max ;
  938. if (val > max)
  939. {
  940. return max;
  941. }
  942. else if (val < min)
  943. {
  944. return min;
  945. }
  946. }
  947. return val;
  948. }
  949. __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat)
  950. {
  951. if (sat <= 31U)
  952. {
  953. const uint32_t max = ((1U << sat) - 1U);
  954. if (val > (int32_t)max)
  955. {
  956. return max;
  957. }
  958. else if (val < 0)
  959. {
  960. return 0U;
  961. }
  962. }
  963. return (uint32_t)val;
  964. }
  965. #endif
  966. #ifndef ARM_MATH_DSP
  967. /**
  968. * @brief definition to pack two 16 bit values.
  969. */
  970. #define __PKHBT(ARG1, ARG2, ARG3) ( (((int32_t)(ARG1) << 0) & (int32_t)0x0000FFFF) | \
  971. (((int32_t)(ARG2) << ARG3) & (int32_t)0xFFFF0000) )
  972. #define __PKHTB(ARG1, ARG2, ARG3) ( (((int32_t)(ARG1) << 0) & (int32_t)0xFFFF0000) | \
  973. (((int32_t)(ARG2) >> ARG3) & (int32_t)0x0000FFFF) )
  974. #endif
  975. /**
  976. * @brief definition to pack four 8 bit values.
  977. */
  978. #ifndef ARM_MATH_BIG_ENDIAN
  979. #define __PACKq7(v0,v1,v2,v3) ( (((int32_t)(v0) << 0) & (int32_t)0x000000FF) | \
  980. (((int32_t)(v1) << 8) & (int32_t)0x0000FF00) | \
  981. (((int32_t)(v2) << 16) & (int32_t)0x00FF0000) | \
  982. (((int32_t)(v3) << 24) & (int32_t)0xFF000000) )
  983. #else
  984. #define __PACKq7(v0,v1,v2,v3) ( (((int32_t)(v3) << 0) & (int32_t)0x000000FF) | \
  985. (((int32_t)(v2) << 8) & (int32_t)0x0000FF00) | \
  986. (((int32_t)(v1) << 16) & (int32_t)0x00FF0000) | \
  987. (((int32_t)(v0) << 24) & (int32_t)0xFF000000) )
  988. #endif
  989. /**
  990. * @brief Clips Q63 to Q31 values.
  991. */
  992. __STATIC_FORCEINLINE q31_t clip_q63_to_q31(
  993. q63_t x)
  994. {
  995. return ((q31_t) (x >> 32) != ((q31_t) x >> 31)) ?
  996. ((0x7FFFFFFF ^ ((q31_t) (x >> 63)))) : (q31_t) x;
  997. }
  998. /**
  999. * @brief Clips Q63 to Q15 values.
  1000. */
  1001. __STATIC_FORCEINLINE q15_t clip_q63_to_q15(
  1002. q63_t x)
  1003. {
  1004. return ((q31_t) (x >> 32) != ((q31_t) x >> 31)) ?
  1005. ((0x7FFF ^ ((q15_t) (x >> 63)))) : (q15_t) (x >> 15);
  1006. }
  1007. /**
  1008. * @brief Clips Q31 to Q7 values.
  1009. */
  1010. __STATIC_FORCEINLINE q7_t clip_q31_to_q7(
  1011. q31_t x)
  1012. {
  1013. return ((q31_t) (x >> 24) != ((q31_t) x >> 23)) ?
  1014. ((0x7F ^ ((q7_t) (x >> 31)))) : (q7_t) x;
  1015. }
  1016. /**
  1017. * @brief Clips Q31 to Q15 values.
  1018. */
  1019. __STATIC_FORCEINLINE q15_t clip_q31_to_q15(
  1020. q31_t x)
  1021. {
  1022. return ((q31_t) (x >> 16) != ((q31_t) x >> 15)) ?
  1023. ((0x7FFF ^ ((q15_t) (x >> 31)))) : (q15_t) x;
  1024. }
  1025. /**
  1026. * @brief Multiplies 32 X 64 and returns 32 bit result in 2.30 format.
  1027. */
  1028. __STATIC_FORCEINLINE q63_t mult32x64(
  1029. q63_t x,
  1030. q31_t y)
  1031. {
  1032. return ((((q63_t) (x & 0x00000000FFFFFFFF) * y) >> 32) +
  1033. (((q63_t) (x >> 32) * y) ) );
  1034. }
  1035. /**
  1036. * @brief Function to Calculates 1/in (reciprocal) value of Q31 Data type.
  1037. */
  1038. __STATIC_FORCEINLINE uint32_t arm_recip_q31(
  1039. q31_t in,
  1040. q31_t * dst,
  1041. const q31_t * pRecipTable)
  1042. {
  1043. q31_t out;
  1044. uint32_t tempVal;
  1045. uint32_t index, i;
  1046. uint32_t signBits;
  1047. if (in > 0)
  1048. {
  1049. signBits = ((uint32_t) (__CLZ( in) - 1));
  1050. }
  1051. else
  1052. {
  1053. signBits = ((uint32_t) (__CLZ(-in) - 1));
  1054. }
  1055. /* Convert input sample to 1.31 format */
  1056. in = (in << signBits);
  1057. /* calculation of index for initial approximated Val */
  1058. index = (uint32_t)(in >> 24);
  1059. index = (index & INDEX_MASK);
  1060. /* 1.31 with exp 1 */
  1061. out = pRecipTable[index];
  1062. /* calculation of reciprocal value */
  1063. /* running approximation for two iterations */
  1064. for (i = 0U; i < 2U; i++)
  1065. {
  1066. tempVal = (uint32_t) (((q63_t) in * out) >> 31);
  1067. tempVal = 0x7FFFFFFFu - tempVal;
  1068. /* 1.31 with exp 1 */
  1069. /* out = (q31_t) (((q63_t) out * tempVal) >> 30); */
  1070. out = clip_q63_to_q31(((q63_t) out * tempVal) >> 30);
  1071. }
  1072. /* write output */
  1073. *dst = out;
  1074. /* return num of signbits of out = 1/in value */
  1075. return (signBits + 1U);
  1076. }
  1077. /**
  1078. * @brief Function to Calculates 1/in (reciprocal) value of Q15 Data type.
  1079. */
  1080. __STATIC_FORCEINLINE uint32_t arm_recip_q15(
  1081. q15_t in,
  1082. q15_t * dst,
  1083. const q15_t * pRecipTable)
  1084. {
  1085. q15_t out = 0;
  1086. uint32_t tempVal = 0;
  1087. uint32_t index = 0, i = 0;
  1088. uint32_t signBits = 0;
  1089. if (in > 0)
  1090. {
  1091. signBits = ((uint32_t)(__CLZ( in) - 17));
  1092. }
  1093. else
  1094. {
  1095. signBits = ((uint32_t)(__CLZ(-in) - 17));
  1096. }
  1097. /* Convert input sample to 1.15 format */
  1098. in = (in << signBits);
  1099. /* calculation of index for initial approximated Val */
  1100. index = (uint32_t)(in >> 8);
  1101. index = (index & INDEX_MASK);
  1102. /* 1.15 with exp 1 */
  1103. out = pRecipTable[index];
  1104. /* calculation of reciprocal value */
  1105. /* running approximation for two iterations */
  1106. for (i = 0U; i < 2U; i++)
  1107. {
  1108. tempVal = (uint32_t) (((q31_t) in * out) >> 15);
  1109. tempVal = 0x7FFFu - tempVal;
  1110. /* 1.15 with exp 1 */
  1111. out = (q15_t) (((q31_t) out * tempVal) >> 14);
  1112. /* out = clip_q31_to_q15(((q31_t) out * tempVal) >> 14); */
  1113. }
  1114. /* write output */
  1115. *dst = out;
  1116. /* return num of signbits of out = 1/in value */
  1117. return (signBits + 1);
  1118. }
  1119. /**
  1120. * @brief Integer exponentiation
  1121. * @param[in] x value
  1122. * @param[in] nb integer exponent >= 1
  1123. * @return x^nb
  1124. *
  1125. */
  1126. __STATIC_INLINE float32_t arm_exponent_f32(float32_t x, int32_t nb)
  1127. {
  1128. float32_t r = x;
  1129. nb --;
  1130. while(nb > 0)
  1131. {
  1132. r = r * x;
  1133. nb--;
  1134. }
  1135. return(r);
  1136. }
  1137. /**
  1138. * @brief 64-bit to 32-bit unsigned normalization
  1139. * @param[in] in is input unsigned long long value
  1140. * @param[out] normalized is the 32-bit normalized value
  1141. * @param[out] norm is norm scale
  1142. */
  1143. __STATIC_INLINE void arm_norm_64_to_32u(uint64_t in, int32_t * normalized, int32_t *norm)
  1144. {
  1145. int32_t n1;
  1146. int32_t hi = (int32_t) (in >> 32);
  1147. int32_t lo = (int32_t) ((in << 32) >> 32);
  1148. n1 = __CLZ(hi) - 32;
  1149. if (!n1)
  1150. {
  1151. /*
  1152. * input fits in 32-bit
  1153. */
  1154. n1 = __CLZ(lo);
  1155. if (!n1)
  1156. {
  1157. /*
  1158. * MSB set, need to scale down by 1
  1159. */
  1160. *norm = -1;
  1161. *normalized = (((uint32_t) lo) >> 1);
  1162. } else
  1163. {
  1164. if (n1 == 32)
  1165. {
  1166. /*
  1167. * input is zero
  1168. */
  1169. *norm = 0;
  1170. *normalized = 0;
  1171. } else
  1172. {
  1173. /*
  1174. * 32-bit normalization
  1175. */
  1176. *norm = n1 - 1;
  1177. *normalized = lo << *norm;
  1178. }
  1179. }
  1180. } else
  1181. {
  1182. /*
  1183. * input fits in 64-bit
  1184. */
  1185. n1 = 1 - n1;
  1186. *norm = -n1;
  1187. /*
  1188. * 64 bit normalization
  1189. */
  1190. *normalized = (((uint32_t) lo) >> n1) | (hi << (32 - n1));
  1191. }
  1192. }
  1193. __STATIC_INLINE q31_t arm_div_q63_to_q31(q63_t num, q31_t den)
  1194. {
  1195. q31_t result;
  1196. uint64_t absNum;
  1197. int32_t normalized;
  1198. int32_t norm;
  1199. /*
  1200. * if sum fits in 32bits
  1201. * avoid costly 64-bit division
  1202. */
  1203. absNum = num > 0 ? num : -num;
  1204. arm_norm_64_to_32u(absNum, &normalized, &norm);
  1205. if (norm > 0)
  1206. /*
  1207. * 32-bit division
  1208. */
  1209. result = (q31_t) num / den;
  1210. else
  1211. /*
  1212. * 64-bit division
  1213. */
  1214. result = (q31_t) (num / den);
  1215. return result;
  1216. }
  1217. /*
  1218. * @brief C custom defined intrinsic functions
  1219. */
  1220. #if !defined (ARM_MATH_DSP)
  1221. /*
  1222. * @brief C custom defined QADD8
  1223. */
  1224. __STATIC_FORCEINLINE uint32_t __QADD8(
  1225. uint32_t x,
  1226. uint32_t y)
  1227. {
  1228. q31_t r, s, t, u;
  1229. r = __SSAT(((((q31_t)x << 24) >> 24) + (((q31_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF;
  1230. s = __SSAT(((((q31_t)x << 16) >> 24) + (((q31_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF;
  1231. t = __SSAT(((((q31_t)x << 8) >> 24) + (((q31_t)y << 8) >> 24)), 8) & (int32_t)0x000000FF;
  1232. u = __SSAT(((((q31_t)x ) >> 24) + (((q31_t)y ) >> 24)), 8) & (int32_t)0x000000FF;
  1233. return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r )));
  1234. }
  1235. /*
  1236. * @brief C custom defined QSUB8
  1237. */
  1238. __STATIC_FORCEINLINE uint32_t __QSUB8(
  1239. uint32_t x,
  1240. uint32_t y)
  1241. {
  1242. q31_t r, s, t, u;
  1243. r = __SSAT(((((q31_t)x << 24) >> 24) - (((q31_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF;
  1244. s = __SSAT(((((q31_t)x << 16) >> 24) - (((q31_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF;
  1245. t = __SSAT(((((q31_t)x << 8) >> 24) - (((q31_t)y << 8) >> 24)), 8) & (int32_t)0x000000FF;
  1246. u = __SSAT(((((q31_t)x ) >> 24) - (((q31_t)y ) >> 24)), 8) & (int32_t)0x000000FF;
  1247. return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r )));
  1248. }
  1249. /*
  1250. * @brief C custom defined QADD16
  1251. */
  1252. __STATIC_FORCEINLINE uint32_t __QADD16(
  1253. uint32_t x,
  1254. uint32_t y)
  1255. {
  1256. /* q31_t r, s; without initialisation 'arm_offset_q15 test' fails but 'intrinsic' tests pass! for armCC */
  1257. q31_t r = 0, s = 0;
  1258. r = __SSAT(((((q31_t)x << 16) >> 16) + (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  1259. s = __SSAT(((((q31_t)x ) >> 16) + (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF;
  1260. return ((uint32_t)((s << 16) | (r )));
  1261. }
  1262. /*
  1263. * @brief C custom defined SHADD16
  1264. */
  1265. __STATIC_FORCEINLINE uint32_t __SHADD16(
  1266. uint32_t x,
  1267. uint32_t y)
  1268. {
  1269. q31_t r, s;
  1270. r = (((((q31_t)x << 16) >> 16) + (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1271. s = (((((q31_t)x ) >> 16) + (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1272. return ((uint32_t)((s << 16) | (r )));
  1273. }
  1274. /*
  1275. * @brief C custom defined QSUB16
  1276. */
  1277. __STATIC_FORCEINLINE uint32_t __QSUB16(
  1278. uint32_t x,
  1279. uint32_t y)
  1280. {
  1281. q31_t r, s;
  1282. r = __SSAT(((((q31_t)x << 16) >> 16) - (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  1283. s = __SSAT(((((q31_t)x ) >> 16) - (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF;
  1284. return ((uint32_t)((s << 16) | (r )));
  1285. }
  1286. /*
  1287. * @brief C custom defined SHSUB16
  1288. */
  1289. __STATIC_FORCEINLINE uint32_t __SHSUB16(
  1290. uint32_t x,
  1291. uint32_t y)
  1292. {
  1293. q31_t r, s;
  1294. r = (((((q31_t)x << 16) >> 16) - (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1295. s = (((((q31_t)x ) >> 16) - (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1296. return ((uint32_t)((s << 16) | (r )));
  1297. }
  1298. /*
  1299. * @brief C custom defined QASX
  1300. */
  1301. __STATIC_FORCEINLINE uint32_t __QASX(
  1302. uint32_t x,
  1303. uint32_t y)
  1304. {
  1305. q31_t r, s;
  1306. r = __SSAT(((((q31_t)x << 16) >> 16) - (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF;
  1307. s = __SSAT(((((q31_t)x ) >> 16) + (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  1308. return ((uint32_t)((s << 16) | (r )));
  1309. }
  1310. /*
  1311. * @brief C custom defined SHASX
  1312. */
  1313. __STATIC_FORCEINLINE uint32_t __SHASX(
  1314. uint32_t x,
  1315. uint32_t y)
  1316. {
  1317. q31_t r, s;
  1318. r = (((((q31_t)x << 16) >> 16) - (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1319. s = (((((q31_t)x ) >> 16) + (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1320. return ((uint32_t)((s << 16) | (r )));
  1321. }
  1322. /*
  1323. * @brief C custom defined QSAX
  1324. */
  1325. __STATIC_FORCEINLINE uint32_t __QSAX(
  1326. uint32_t x,
  1327. uint32_t y)
  1328. {
  1329. q31_t r, s;
  1330. r = __SSAT(((((q31_t)x << 16) >> 16) + (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF;
  1331. s = __SSAT(((((q31_t)x ) >> 16) - (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF;
  1332. return ((uint32_t)((s << 16) | (r )));
  1333. }
  1334. /*
  1335. * @brief C custom defined SHSAX
  1336. */
  1337. __STATIC_FORCEINLINE uint32_t __SHSAX(
  1338. uint32_t x,
  1339. uint32_t y)
  1340. {
  1341. q31_t r, s;
  1342. r = (((((q31_t)x << 16) >> 16) + (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1343. s = (((((q31_t)x ) >> 16) - (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF;
  1344. return ((uint32_t)((s << 16) | (r )));
  1345. }
  1346. /*
  1347. * @brief C custom defined SMUSDX
  1348. */
  1349. __STATIC_FORCEINLINE uint32_t __SMUSDX(
  1350. uint32_t x,
  1351. uint32_t y)
  1352. {
  1353. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) -
  1354. ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) ));
  1355. }
  1356. /*
  1357. * @brief C custom defined SMUADX
  1358. */
  1359. __STATIC_FORCEINLINE uint32_t __SMUADX(
  1360. uint32_t x,
  1361. uint32_t y)
  1362. {
  1363. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) +
  1364. ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) ));
  1365. }
  1366. /*
  1367. * @brief C custom defined QADD
  1368. */
  1369. __STATIC_FORCEINLINE int32_t __QADD(
  1370. int32_t x,
  1371. int32_t y)
  1372. {
  1373. return ((int32_t)(clip_q63_to_q31((q63_t)x + (q31_t)y)));
  1374. }
  1375. /*
  1376. * @brief C custom defined QSUB
  1377. */
  1378. __STATIC_FORCEINLINE int32_t __QSUB(
  1379. int32_t x,
  1380. int32_t y)
  1381. {
  1382. return ((int32_t)(clip_q63_to_q31((q63_t)x - (q31_t)y)));
  1383. }
  1384. /*
  1385. * @brief C custom defined SMLAD
  1386. */
  1387. __STATIC_FORCEINLINE uint32_t __SMLAD(
  1388. uint32_t x,
  1389. uint32_t y,
  1390. uint32_t sum)
  1391. {
  1392. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) +
  1393. ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) +
  1394. ( ((q31_t)sum ) ) ));
  1395. }
  1396. /*
  1397. * @brief C custom defined SMLADX
  1398. */
  1399. __STATIC_FORCEINLINE uint32_t __SMLADX(
  1400. uint32_t x,
  1401. uint32_t y,
  1402. uint32_t sum)
  1403. {
  1404. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) +
  1405. ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) +
  1406. ( ((q31_t)sum ) ) ));
  1407. }
  1408. /*
  1409. * @brief C custom defined SMLSDX
  1410. */
  1411. __STATIC_FORCEINLINE uint32_t __SMLSDX(
  1412. uint32_t x,
  1413. uint32_t y,
  1414. uint32_t sum)
  1415. {
  1416. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) -
  1417. ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) +
  1418. ( ((q31_t)sum ) ) ));
  1419. }
  1420. /*
  1421. * @brief C custom defined SMLALD
  1422. */
  1423. __STATIC_FORCEINLINE uint64_t __SMLALD(
  1424. uint32_t x,
  1425. uint32_t y,
  1426. uint64_t sum)
  1427. {
  1428. /* return (sum + ((q15_t) (x >> 16) * (q15_t) (y >> 16)) + ((q15_t) x * (q15_t) y)); */
  1429. return ((uint64_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) +
  1430. ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) +
  1431. ( ((q63_t)sum ) ) ));
  1432. }
  1433. /*
  1434. * @brief C custom defined SMLALDX
  1435. */
  1436. __STATIC_FORCEINLINE uint64_t __SMLALDX(
  1437. uint32_t x,
  1438. uint32_t y,
  1439. uint64_t sum)
  1440. {
  1441. /* return (sum + ((q15_t) (x >> 16) * (q15_t) y)) + ((q15_t) x * (q15_t) (y >> 16)); */
  1442. return ((uint64_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) +
  1443. ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) +
  1444. ( ((q63_t)sum ) ) ));
  1445. }
  1446. /*
  1447. * @brief C custom defined SMUAD
  1448. */
  1449. __STATIC_FORCEINLINE uint32_t __SMUAD(
  1450. uint32_t x,
  1451. uint32_t y)
  1452. {
  1453. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) +
  1454. ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) ));
  1455. }
  1456. /*
  1457. * @brief C custom defined SMUSD
  1458. */
  1459. __STATIC_FORCEINLINE uint32_t __SMUSD(
  1460. uint32_t x,
  1461. uint32_t y)
  1462. {
  1463. return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) -
  1464. ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) ));
  1465. }
  1466. /*
  1467. * @brief C custom defined SXTB16
  1468. */
  1469. __STATIC_FORCEINLINE uint32_t __SXTB16(
  1470. uint32_t x)
  1471. {
  1472. return ((uint32_t)(((((q31_t)x << 24) >> 24) & (q31_t)0x0000FFFF) |
  1473. ((((q31_t)x << 8) >> 8) & (q31_t)0xFFFF0000) ));
  1474. }
  1475. /*
  1476. * @brief C custom defined SMMLA
  1477. */
  1478. __STATIC_FORCEINLINE int32_t __SMMLA(
  1479. int32_t x,
  1480. int32_t y,
  1481. int32_t sum)
  1482. {
  1483. return (sum + (int32_t) (((int64_t) x * y) >> 32));
  1484. }
  1485. #endif /* !defined (ARM_MATH_DSP) */
  1486. /**
  1487. * @brief Instance structure for the Q7 FIR filter.
  1488. */
  1489. typedef struct
  1490. {
  1491. uint16_t numTaps; /**< number of filter coefficients in the filter. */
  1492. q7_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  1493. const q7_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  1494. } arm_fir_instance_q7;
  1495. /**
  1496. * @brief Instance structure for the Q15 FIR filter.
  1497. */
  1498. typedef struct
  1499. {
  1500. uint16_t numTaps; /**< number of filter coefficients in the filter. */
  1501. q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  1502. const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  1503. } arm_fir_instance_q15;
  1504. /**
  1505. * @brief Instance structure for the Q31 FIR filter.
  1506. */
  1507. typedef struct
  1508. {
  1509. uint16_t numTaps; /**< number of filter coefficients in the filter. */
  1510. q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  1511. const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  1512. } arm_fir_instance_q31;
  1513. /**
  1514. * @brief Instance structure for the floating-point FIR filter.
  1515. */
  1516. typedef struct
  1517. {
  1518. uint16_t numTaps; /**< number of filter coefficients in the filter. */
  1519. float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  1520. const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  1521. } arm_fir_instance_f32;
  1522. /**
  1523. * @brief Processing function for the Q7 FIR filter.
  1524. * @param[in] S points to an instance of the Q7 FIR filter structure.
  1525. * @param[in] pSrc points to the block of input data.
  1526. * @param[out] pDst points to the block of output data.
  1527. * @param[in] blockSize number of samples to process.
  1528. */
  1529. void arm_fir_q7(
  1530. const arm_fir_instance_q7 * S,
  1531. const q7_t * pSrc,
  1532. q7_t * pDst,
  1533. uint32_t blockSize);
  1534. /**
  1535. * @brief Initialization function for the Q7 FIR filter.
  1536. * @param[in,out] S points to an instance of the Q7 FIR structure.
  1537. * @param[in] numTaps Number of filter coefficients in the filter.
  1538. * @param[in] pCoeffs points to the filter coefficients.
  1539. * @param[in] pState points to the state buffer.
  1540. * @param[in] blockSize number of samples that are processed.
  1541. */
  1542. void arm_fir_init_q7(
  1543. arm_fir_instance_q7 * S,
  1544. uint16_t numTaps,
  1545. const q7_t * pCoeffs,
  1546. q7_t * pState,
  1547. uint32_t blockSize);
  1548. /**
  1549. * @brief Processing function for the Q15 FIR filter.
  1550. * @param[in] S points to an instance of the Q15 FIR structure.
  1551. * @param[in] pSrc points to the block of input data.
  1552. * @param[out] pDst points to the block of output data.
  1553. * @param[in] blockSize number of samples to process.
  1554. */
  1555. void arm_fir_q15(
  1556. const arm_fir_instance_q15 * S,
  1557. const q15_t * pSrc,
  1558. q15_t * pDst,
  1559. uint32_t blockSize);
  1560. /**
  1561. * @brief Processing function for the fast Q15 FIR filter (fast version).
  1562. * @param[in] S points to an instance of the Q15 FIR filter structure.
  1563. * @param[in] pSrc points to the block of input data.
  1564. * @param[out] pDst points to the block of output data.
  1565. * @param[in] blockSize number of samples to process.
  1566. */
  1567. void arm_fir_fast_q15(
  1568. const arm_fir_instance_q15 * S,
  1569. const q15_t * pSrc,
  1570. q15_t * pDst,
  1571. uint32_t blockSize);
  1572. /**
  1573. * @brief Initialization function for the Q15 FIR filter.
  1574. * @param[in,out] S points to an instance of the Q15 FIR filter structure.
  1575. * @param[in] numTaps Number of filter coefficients in the filter. Must be even and greater than or equal to 4.
  1576. * @param[in] pCoeffs points to the filter coefficients.
  1577. * @param[in] pState points to the state buffer.
  1578. * @param[in] blockSize number of samples that are processed at a time.
  1579. * @return The function returns either
  1580. * <code>ARM_MATH_SUCCESS</code> if initialization was successful or
  1581. * <code>ARM_MATH_ARGUMENT_ERROR</code> if <code>numTaps</code> is not a supported value.
  1582. */
  1583. arm_status arm_fir_init_q15(
  1584. arm_fir_instance_q15 * S,
  1585. uint16_t numTaps,
  1586. const q15_t * pCoeffs,
  1587. q15_t * pState,
  1588. uint32_t blockSize);
  1589. /**
  1590. * @brief Processing function for the Q31 FIR filter.
  1591. * @param[in] S points to an instance of the Q31 FIR filter structure.
  1592. * @param[in] pSrc points to the block of input data.
  1593. * @param[out] pDst points to the block of output data.
  1594. * @param[in] blockSize number of samples to process.
  1595. */
  1596. void arm_fir_q31(
  1597. const arm_fir_instance_q31 * S,
  1598. const q31_t * pSrc,
  1599. q31_t * pDst,
  1600. uint32_t blockSize);
  1601. /**
  1602. * @brief Processing function for the fast Q31 FIR filter (fast version).
  1603. * @param[in] S points to an instance of the Q31 FIR filter structure.
  1604. * @param[in] pSrc points to the block of input data.
  1605. * @param[out] pDst points to the block of output data.
  1606. * @param[in] blockSize number of samples to process.
  1607. */
  1608. void arm_fir_fast_q31(
  1609. const arm_fir_instance_q31 * S,
  1610. const q31_t * pSrc,
  1611. q31_t * pDst,
  1612. uint32_t blockSize);
  1613. /**
  1614. * @brief Initialization function for the Q31 FIR filter.
  1615. * @param[in,out] S points to an instance of the Q31 FIR structure.
  1616. * @param[in] numTaps Number of filter coefficients in the filter.
  1617. * @param[in] pCoeffs points to the filter coefficients.
  1618. * @param[in] pState points to the state buffer.
  1619. * @param[in] blockSize number of samples that are processed at a time.
  1620. */
  1621. void arm_fir_init_q31(
  1622. arm_fir_instance_q31 * S,
  1623. uint16_t numTaps,
  1624. const q31_t * pCoeffs,
  1625. q31_t * pState,
  1626. uint32_t blockSize);
  1627. /**
  1628. * @brief Processing function for the floating-point FIR filter.
  1629. * @param[in] S points to an instance of the floating-point FIR structure.
  1630. * @param[in] pSrc points to the block of input data.
  1631. * @param[out] pDst points to the block of output data.
  1632. * @param[in] blockSize number of samples to process.
  1633. */
  1634. void arm_fir_f32(
  1635. const arm_fir_instance_f32 * S,
  1636. const float32_t * pSrc,
  1637. float32_t * pDst,
  1638. uint32_t blockSize);
  1639. /**
  1640. * @brief Initialization function for the floating-point FIR filter.
  1641. * @param[in,out] S points to an instance of the floating-point FIR filter structure.
  1642. * @param[in] numTaps Number of filter coefficients in the filter.
  1643. * @param[in] pCoeffs points to the filter coefficients.
  1644. * @param[in] pState points to the state buffer.
  1645. * @param[in] blockSize number of samples that are processed at a time.
  1646. */
  1647. void arm_fir_init_f32(
  1648. arm_fir_instance_f32 * S,
  1649. uint16_t numTaps,
  1650. const float32_t * pCoeffs,
  1651. float32_t * pState,
  1652. uint32_t blockSize);
  1653. /**
  1654. * @brief Instance structure for the Q15 Biquad cascade filter.
  1655. */
  1656. typedef struct
  1657. {
  1658. int8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  1659. q15_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */
  1660. const q15_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */
  1661. int8_t postShift; /**< Additional shift, in bits, applied to each output sample. */
  1662. } arm_biquad_casd_df1_inst_q15;
  1663. /**
  1664. * @brief Instance structure for the Q31 Biquad cascade filter.
  1665. */
  1666. typedef struct
  1667. {
  1668. uint32_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  1669. q31_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */
  1670. const q31_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */
  1671. uint8_t postShift; /**< Additional shift, in bits, applied to each output sample. */
  1672. } arm_biquad_casd_df1_inst_q31;
  1673. /**
  1674. * @brief Instance structure for the floating-point Biquad cascade filter.
  1675. */
  1676. typedef struct
  1677. {
  1678. uint32_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  1679. float32_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */
  1680. const float32_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */
  1681. } arm_biquad_casd_df1_inst_f32;
  1682. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  1683. /**
  1684. * @brief Instance structure for the modified Biquad coefs required by vectorized code.
  1685. */
  1686. typedef struct
  1687. {
  1688. float32_t coeffs[8][4]; /**< Points to the array of modified coefficients. The array is of length 32. There is one per stage */
  1689. } arm_biquad_mod_coef_f32;
  1690. #endif
  1691. /**
  1692. * @brief Processing function for the Q15 Biquad cascade filter.
  1693. * @param[in] S points to an instance of the Q15 Biquad cascade structure.
  1694. * @param[in] pSrc points to the block of input data.
  1695. * @param[out] pDst points to the block of output data.
  1696. * @param[in] blockSize number of samples to process.
  1697. */
  1698. void arm_biquad_cascade_df1_q15(
  1699. const arm_biquad_casd_df1_inst_q15 * S,
  1700. const q15_t * pSrc,
  1701. q15_t * pDst,
  1702. uint32_t blockSize);
  1703. /**
  1704. * @brief Initialization function for the Q15 Biquad cascade filter.
  1705. * @param[in,out] S points to an instance of the Q15 Biquad cascade structure.
  1706. * @param[in] numStages number of 2nd order stages in the filter.
  1707. * @param[in] pCoeffs points to the filter coefficients.
  1708. * @param[in] pState points to the state buffer.
  1709. * @param[in] postShift Shift to be applied to the output. Varies according to the coefficients format
  1710. */
  1711. void arm_biquad_cascade_df1_init_q15(
  1712. arm_biquad_casd_df1_inst_q15 * S,
  1713. uint8_t numStages,
  1714. const q15_t * pCoeffs,
  1715. q15_t * pState,
  1716. int8_t postShift);
  1717. /**
  1718. * @brief Fast but less precise processing function for the Q15 Biquad cascade filter for Cortex-M3 and Cortex-M4.
  1719. * @param[in] S points to an instance of the Q15 Biquad cascade structure.
  1720. * @param[in] pSrc points to the block of input data.
  1721. * @param[out] pDst points to the block of output data.
  1722. * @param[in] blockSize number of samples to process.
  1723. */
  1724. void arm_biquad_cascade_df1_fast_q15(
  1725. const arm_biquad_casd_df1_inst_q15 * S,
  1726. const q15_t * pSrc,
  1727. q15_t * pDst,
  1728. uint32_t blockSize);
  1729. /**
  1730. * @brief Processing function for the Q31 Biquad cascade filter
  1731. * @param[in] S points to an instance of the Q31 Biquad cascade structure.
  1732. * @param[in] pSrc points to the block of input data.
  1733. * @param[out] pDst points to the block of output data.
  1734. * @param[in] blockSize number of samples to process.
  1735. */
  1736. void arm_biquad_cascade_df1_q31(
  1737. const arm_biquad_casd_df1_inst_q31 * S,
  1738. const q31_t * pSrc,
  1739. q31_t * pDst,
  1740. uint32_t blockSize);
  1741. /**
  1742. * @brief Fast but less precise processing function for the Q31 Biquad cascade filter for Cortex-M3 and Cortex-M4.
  1743. * @param[in] S points to an instance of the Q31 Biquad cascade structure.
  1744. * @param[in] pSrc points to the block of input data.
  1745. * @param[out] pDst points to the block of output data.
  1746. * @param[in] blockSize number of samples to process.
  1747. */
  1748. void arm_biquad_cascade_df1_fast_q31(
  1749. const arm_biquad_casd_df1_inst_q31 * S,
  1750. const q31_t * pSrc,
  1751. q31_t * pDst,
  1752. uint32_t blockSize);
  1753. /**
  1754. * @brief Initialization function for the Q31 Biquad cascade filter.
  1755. * @param[in,out] S points to an instance of the Q31 Biquad cascade structure.
  1756. * @param[in] numStages number of 2nd order stages in the filter.
  1757. * @param[in] pCoeffs points to the filter coefficients.
  1758. * @param[in] pState points to the state buffer.
  1759. * @param[in] postShift Shift to be applied to the output. Varies according to the coefficients format
  1760. */
  1761. void arm_biquad_cascade_df1_init_q31(
  1762. arm_biquad_casd_df1_inst_q31 * S,
  1763. uint8_t numStages,
  1764. const q31_t * pCoeffs,
  1765. q31_t * pState,
  1766. int8_t postShift);
  1767. /**
  1768. * @brief Processing function for the floating-point Biquad cascade filter.
  1769. * @param[in] S points to an instance of the floating-point Biquad cascade structure.
  1770. * @param[in] pSrc points to the block of input data.
  1771. * @param[out] pDst points to the block of output data.
  1772. * @param[in] blockSize number of samples to process.
  1773. */
  1774. void arm_biquad_cascade_df1_f32(
  1775. const arm_biquad_casd_df1_inst_f32 * S,
  1776. const float32_t * pSrc,
  1777. float32_t * pDst,
  1778. uint32_t blockSize);
  1779. /**
  1780. * @brief Initialization function for the floating-point Biquad cascade filter.
  1781. * @param[in,out] S points to an instance of the floating-point Biquad cascade structure.
  1782. * @param[in] numStages number of 2nd order stages in the filter.
  1783. * @param[in] pCoeffs points to the filter coefficients.
  1784. * @param[in] pCoeffsMod points to the modified filter coefficients (only MVE version).
  1785. * @param[in] pState points to the state buffer.
  1786. */
  1787. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  1788. void arm_biquad_cascade_df1_mve_init_f32(
  1789. arm_biquad_casd_df1_inst_f32 * S,
  1790. uint8_t numStages,
  1791. const float32_t * pCoeffs,
  1792. arm_biquad_mod_coef_f32 * pCoeffsMod,
  1793. float32_t * pState);
  1794. #endif
  1795. void arm_biquad_cascade_df1_init_f32(
  1796. arm_biquad_casd_df1_inst_f32 * S,
  1797. uint8_t numStages,
  1798. const float32_t * pCoeffs,
  1799. float32_t * pState);
  1800. /**
  1801. * @brief Compute the logical bitwise AND of two fixed-point vectors.
  1802. * @param[in] pSrcA points to input vector A
  1803. * @param[in] pSrcB points to input vector B
  1804. * @param[out] pDst points to output vector
  1805. * @param[in] blockSize number of samples in each vector
  1806. * @return none
  1807. */
  1808. void arm_and_u16(
  1809. const uint16_t * pSrcA,
  1810. const uint16_t * pSrcB,
  1811. uint16_t * pDst,
  1812. uint32_t blockSize);
  1813. /**
  1814. * @brief Compute the logical bitwise AND of two fixed-point vectors.
  1815. * @param[in] pSrcA points to input vector A
  1816. * @param[in] pSrcB points to input vector B
  1817. * @param[out] pDst points to output vector
  1818. * @param[in] blockSize number of samples in each vector
  1819. * @return none
  1820. */
  1821. void arm_and_u32(
  1822. const uint32_t * pSrcA,
  1823. const uint32_t * pSrcB,
  1824. uint32_t * pDst,
  1825. uint32_t blockSize);
  1826. /**
  1827. * @brief Compute the logical bitwise AND of two fixed-point vectors.
  1828. * @param[in] pSrcA points to input vector A
  1829. * @param[in] pSrcB points to input vector B
  1830. * @param[out] pDst points to output vector
  1831. * @param[in] blockSize number of samples in each vector
  1832. * @return none
  1833. */
  1834. void arm_and_u8(
  1835. const uint8_t * pSrcA,
  1836. const uint8_t * pSrcB,
  1837. uint8_t * pDst,
  1838. uint32_t blockSize);
  1839. /**
  1840. * @brief Compute the logical bitwise OR of two fixed-point vectors.
  1841. * @param[in] pSrcA points to input vector A
  1842. * @param[in] pSrcB points to input vector B
  1843. * @param[out] pDst points to output vector
  1844. * @param[in] blockSize number of samples in each vector
  1845. * @return none
  1846. */
  1847. void arm_or_u16(
  1848. const uint16_t * pSrcA,
  1849. const uint16_t * pSrcB,
  1850. uint16_t * pDst,
  1851. uint32_t blockSize);
  1852. /**
  1853. * @brief Compute the logical bitwise OR of two fixed-point vectors.
  1854. * @param[in] pSrcA points to input vector A
  1855. * @param[in] pSrcB points to input vector B
  1856. * @param[out] pDst points to output vector
  1857. * @param[in] blockSize number of samples in each vector
  1858. * @return none
  1859. */
  1860. void arm_or_u32(
  1861. const uint32_t * pSrcA,
  1862. const uint32_t * pSrcB,
  1863. uint32_t * pDst,
  1864. uint32_t blockSize);
  1865. /**
  1866. * @brief Compute the logical bitwise OR of two fixed-point vectors.
  1867. * @param[in] pSrcA points to input vector A
  1868. * @param[in] pSrcB points to input vector B
  1869. * @param[out] pDst points to output vector
  1870. * @param[in] blockSize number of samples in each vector
  1871. * @return none
  1872. */
  1873. void arm_or_u8(
  1874. const uint8_t * pSrcA,
  1875. const uint8_t * pSrcB,
  1876. uint8_t * pDst,
  1877. uint32_t blockSize);
  1878. /**
  1879. * @brief Compute the logical bitwise NOT of a fixed-point vector.
  1880. * @param[in] pSrc points to input vector
  1881. * @param[out] pDst points to output vector
  1882. * @param[in] blockSize number of samples in each vector
  1883. * @return none
  1884. */
  1885. void arm_not_u16(
  1886. const uint16_t * pSrc,
  1887. uint16_t * pDst,
  1888. uint32_t blockSize);
  1889. /**
  1890. * @brief Compute the logical bitwise NOT of a fixed-point vector.
  1891. * @param[in] pSrc points to input vector
  1892. * @param[out] pDst points to output vector
  1893. * @param[in] blockSize number of samples in each vector
  1894. * @return none
  1895. */
  1896. void arm_not_u32(
  1897. const uint32_t * pSrc,
  1898. uint32_t * pDst,
  1899. uint32_t blockSize);
  1900. /**
  1901. * @brief Compute the logical bitwise NOT of a fixed-point vector.
  1902. * @param[in] pSrc points to input vector
  1903. * @param[out] pDst points to output vector
  1904. * @param[in] blockSize number of samples in each vector
  1905. * @return none
  1906. */
  1907. void arm_not_u8(
  1908. const uint8_t * pSrc,
  1909. uint8_t * pDst,
  1910. uint32_t blockSize);
  1911. /**
  1912. * @brief Compute the logical bitwise XOR of two fixed-point vectors.
  1913. * @param[in] pSrcA points to input vector A
  1914. * @param[in] pSrcB points to input vector B
  1915. * @param[out] pDst points to output vector
  1916. * @param[in] blockSize number of samples in each vector
  1917. * @return none
  1918. */
  1919. void arm_xor_u16(
  1920. const uint16_t * pSrcA,
  1921. const uint16_t * pSrcB,
  1922. uint16_t * pDst,
  1923. uint32_t blockSize);
  1924. /**
  1925. * @brief Compute the logical bitwise XOR of two fixed-point vectors.
  1926. * @param[in] pSrcA points to input vector A
  1927. * @param[in] pSrcB points to input vector B
  1928. * @param[out] pDst points to output vector
  1929. * @param[in] blockSize number of samples in each vector
  1930. * @return none
  1931. */
  1932. void arm_xor_u32(
  1933. const uint32_t * pSrcA,
  1934. const uint32_t * pSrcB,
  1935. uint32_t * pDst,
  1936. uint32_t blockSize);
  1937. /**
  1938. * @brief Compute the logical bitwise XOR of two fixed-point vectors.
  1939. * @param[in] pSrcA points to input vector A
  1940. * @param[in] pSrcB points to input vector B
  1941. * @param[out] pDst points to output vector
  1942. * @param[in] blockSize number of samples in each vector
  1943. * @return none
  1944. */
  1945. void arm_xor_u8(
  1946. const uint8_t * pSrcA,
  1947. const uint8_t * pSrcB,
  1948. uint8_t * pDst,
  1949. uint32_t blockSize);
  1950. /**
  1951. * @brief Struct for specifying sorting algorithm
  1952. */
  1953. typedef enum
  1954. {
  1955. ARM_SORT_BITONIC = 0,
  1956. /**< Bitonic sort */
  1957. ARM_SORT_BUBBLE = 1,
  1958. /**< Bubble sort */
  1959. ARM_SORT_HEAP = 2,
  1960. /**< Heap sort */
  1961. ARM_SORT_INSERTION = 3,
  1962. /**< Insertion sort */
  1963. ARM_SORT_QUICK = 4,
  1964. /**< Quick sort */
  1965. ARM_SORT_SELECTION = 5
  1966. /**< Selection sort */
  1967. } arm_sort_alg;
  1968. /**
  1969. * @brief Struct for specifying sorting algorithm
  1970. */
  1971. typedef enum
  1972. {
  1973. ARM_SORT_DESCENDING = 0,
  1974. /**< Descending order (9 to 0) */
  1975. ARM_SORT_ASCENDING = 1
  1976. /**< Ascending order (0 to 9) */
  1977. } arm_sort_dir;
  1978. /**
  1979. * @brief Instance structure for the sorting algorithms.
  1980. */
  1981. typedef struct
  1982. {
  1983. arm_sort_alg alg; /**< Sorting algorithm selected */
  1984. arm_sort_dir dir; /**< Sorting order (direction) */
  1985. } arm_sort_instance_f32;
  1986. /**
  1987. * @param[in] S points to an instance of the sorting structure.
  1988. * @param[in] pSrc points to the block of input data.
  1989. * @param[out] pDst points to the block of output data.
  1990. * @param[in] blockSize number of samples to process.
  1991. */
  1992. void arm_sort_f32(
  1993. const arm_sort_instance_f32 * S,
  1994. float32_t * pSrc,
  1995. float32_t * pDst,
  1996. uint32_t blockSize);
  1997. /**
  1998. * @param[in,out] S points to an instance of the sorting structure.
  1999. * @param[in] alg Selected algorithm.
  2000. * @param[in] dir Sorting order.
  2001. */
  2002. void arm_sort_init_f32(
  2003. arm_sort_instance_f32 * S,
  2004. arm_sort_alg alg,
  2005. arm_sort_dir dir);
  2006. /**
  2007. * @brief Instance structure for the sorting algorithms.
  2008. */
  2009. typedef struct
  2010. {
  2011. arm_sort_dir dir; /**< Sorting order (direction) */
  2012. float32_t * buffer; /**< Working buffer */
  2013. } arm_merge_sort_instance_f32;
  2014. /**
  2015. * @param[in] S points to an instance of the sorting structure.
  2016. * @param[in,out] pSrc points to the block of input data.
  2017. * @param[out] pDst points to the block of output data
  2018. * @param[in] blockSize number of samples to process.
  2019. */
  2020. void arm_merge_sort_f32(
  2021. const arm_merge_sort_instance_f32 * S,
  2022. float32_t *pSrc,
  2023. float32_t *pDst,
  2024. uint32_t blockSize);
  2025. /**
  2026. * @param[in,out] S points to an instance of the sorting structure.
  2027. * @param[in] dir Sorting order.
  2028. * @param[in] buffer Working buffer.
  2029. */
  2030. void arm_merge_sort_init_f32(
  2031. arm_merge_sort_instance_f32 * S,
  2032. arm_sort_dir dir,
  2033. float32_t * buffer);
  2034. /**
  2035. * @brief Struct for specifying cubic spline type
  2036. */
  2037. typedef enum
  2038. {
  2039. ARM_SPLINE_NATURAL = 0, /**< Natural spline */
  2040. ARM_SPLINE_PARABOLIC_RUNOUT = 1 /**< Parabolic runout spline */
  2041. } arm_spline_type;
  2042. /**
  2043. * @brief Instance structure for the floating-point cubic spline interpolation.
  2044. */
  2045. typedef struct
  2046. {
  2047. arm_spline_type type; /**< Type (boundary conditions) */
  2048. const float32_t * x; /**< x values */
  2049. const float32_t * y; /**< y values */
  2050. uint32_t n_x; /**< Number of known data points */
  2051. float32_t * coeffs; /**< Coefficients buffer (b,c, and d) */
  2052. } arm_spline_instance_f32;
  2053. /**
  2054. * @brief Processing function for the floating-point cubic spline interpolation.
  2055. * @param[in] S points to an instance of the floating-point spline structure.
  2056. * @param[in] xq points to the x values ot the interpolated data points.
  2057. * @param[out] pDst points to the block of output data.
  2058. * @param[in] blockSize number of samples of output data.
  2059. */
  2060. void arm_spline_f32(
  2061. arm_spline_instance_f32 * S,
  2062. const float32_t * xq,
  2063. float32_t * pDst,
  2064. uint32_t blockSize);
  2065. /**
  2066. * @brief Initialization function for the floating-point cubic spline interpolation.
  2067. * @param[in,out] S points to an instance of the floating-point spline structure.
  2068. * @param[in] type type of cubic spline interpolation (boundary conditions)
  2069. * @param[in] x points to the x values of the known data points.
  2070. * @param[in] y points to the y values of the known data points.
  2071. * @param[in] n number of known data points.
  2072. * @param[in] coeffs coefficients array for b, c, and d
  2073. * @param[in] tempBuffer buffer array for internal computations
  2074. */
  2075. void arm_spline_init_f32(
  2076. arm_spline_instance_f32 * S,
  2077. arm_spline_type type,
  2078. const float32_t * x,
  2079. const float32_t * y,
  2080. uint32_t n,
  2081. float32_t * coeffs,
  2082. float32_t * tempBuffer);
  2083. /**
  2084. * @brief Instance structure for the floating-point matrix structure.
  2085. */
  2086. typedef struct
  2087. {
  2088. uint16_t numRows; /**< number of rows of the matrix. */
  2089. uint16_t numCols; /**< number of columns of the matrix. */
  2090. float32_t *pData; /**< points to the data of the matrix. */
  2091. } arm_matrix_instance_f32;
  2092. /**
  2093. * @brief Instance structure for the floating-point matrix structure.
  2094. */
  2095. typedef struct
  2096. {
  2097. uint16_t numRows; /**< number of rows of the matrix. */
  2098. uint16_t numCols; /**< number of columns of the matrix. */
  2099. float64_t *pData; /**< points to the data of the matrix. */
  2100. } arm_matrix_instance_f64;
  2101. /**
  2102. * @brief Instance structure for the Q15 matrix structure.
  2103. */
  2104. typedef struct
  2105. {
  2106. uint16_t numRows; /**< number of rows of the matrix. */
  2107. uint16_t numCols; /**< number of columns of the matrix. */
  2108. q15_t *pData; /**< points to the data of the matrix. */
  2109. } arm_matrix_instance_q15;
  2110. /**
  2111. * @brief Instance structure for the Q31 matrix structure.
  2112. */
  2113. typedef struct
  2114. {
  2115. uint16_t numRows; /**< number of rows of the matrix. */
  2116. uint16_t numCols; /**< number of columns of the matrix. */
  2117. q31_t *pData; /**< points to the data of the matrix. */
  2118. } arm_matrix_instance_q31;
  2119. /**
  2120. * @brief Floating-point matrix addition.
  2121. * @param[in] pSrcA points to the first input matrix structure
  2122. * @param[in] pSrcB points to the second input matrix structure
  2123. * @param[out] pDst points to output matrix structure
  2124. * @return The function returns either
  2125. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2126. */
  2127. arm_status arm_mat_add_f32(
  2128. const arm_matrix_instance_f32 * pSrcA,
  2129. const arm_matrix_instance_f32 * pSrcB,
  2130. arm_matrix_instance_f32 * pDst);
  2131. /**
  2132. * @brief Q15 matrix addition.
  2133. * @param[in] pSrcA points to the first input matrix structure
  2134. * @param[in] pSrcB points to the second input matrix structure
  2135. * @param[out] pDst points to output matrix structure
  2136. * @return The function returns either
  2137. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2138. */
  2139. arm_status arm_mat_add_q15(
  2140. const arm_matrix_instance_q15 * pSrcA,
  2141. const arm_matrix_instance_q15 * pSrcB,
  2142. arm_matrix_instance_q15 * pDst);
  2143. /**
  2144. * @brief Q31 matrix addition.
  2145. * @param[in] pSrcA points to the first input matrix structure
  2146. * @param[in] pSrcB points to the second input matrix structure
  2147. * @param[out] pDst points to output matrix structure
  2148. * @return The function returns either
  2149. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2150. */
  2151. arm_status arm_mat_add_q31(
  2152. const arm_matrix_instance_q31 * pSrcA,
  2153. const arm_matrix_instance_q31 * pSrcB,
  2154. arm_matrix_instance_q31 * pDst);
  2155. /**
  2156. * @brief Floating-point, complex, matrix multiplication.
  2157. * @param[in] pSrcA points to the first input matrix structure
  2158. * @param[in] pSrcB points to the second input matrix structure
  2159. * @param[out] pDst points to output matrix structure
  2160. * @return The function returns either
  2161. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2162. */
  2163. arm_status arm_mat_cmplx_mult_f32(
  2164. const arm_matrix_instance_f32 * pSrcA,
  2165. const arm_matrix_instance_f32 * pSrcB,
  2166. arm_matrix_instance_f32 * pDst);
  2167. /**
  2168. * @brief Q15, complex, matrix multiplication.
  2169. * @param[in] pSrcA points to the first input matrix structure
  2170. * @param[in] pSrcB points to the second input matrix structure
  2171. * @param[out] pDst points to output matrix structure
  2172. * @return The function returns either
  2173. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2174. */
  2175. arm_status arm_mat_cmplx_mult_q15(
  2176. const arm_matrix_instance_q15 * pSrcA,
  2177. const arm_matrix_instance_q15 * pSrcB,
  2178. arm_matrix_instance_q15 * pDst,
  2179. q15_t * pScratch);
  2180. /**
  2181. * @brief Q31, complex, matrix multiplication.
  2182. * @param[in] pSrcA points to the first input matrix structure
  2183. * @param[in] pSrcB points to the second input matrix structure
  2184. * @param[out] pDst points to output matrix structure
  2185. * @return The function returns either
  2186. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2187. */
  2188. arm_status arm_mat_cmplx_mult_q31(
  2189. const arm_matrix_instance_q31 * pSrcA,
  2190. const arm_matrix_instance_q31 * pSrcB,
  2191. arm_matrix_instance_q31 * pDst);
  2192. /**
  2193. * @brief Floating-point matrix transpose.
  2194. * @param[in] pSrc points to the input matrix
  2195. * @param[out] pDst points to the output matrix
  2196. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  2197. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2198. */
  2199. arm_status arm_mat_trans_f32(
  2200. const arm_matrix_instance_f32 * pSrc,
  2201. arm_matrix_instance_f32 * pDst);
  2202. /**
  2203. * @brief Q15 matrix transpose.
  2204. * @param[in] pSrc points to the input matrix
  2205. * @param[out] pDst points to the output matrix
  2206. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  2207. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2208. */
  2209. arm_status arm_mat_trans_q15(
  2210. const arm_matrix_instance_q15 * pSrc,
  2211. arm_matrix_instance_q15 * pDst);
  2212. /**
  2213. * @brief Q31 matrix transpose.
  2214. * @param[in] pSrc points to the input matrix
  2215. * @param[out] pDst points to the output matrix
  2216. * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code>
  2217. * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2218. */
  2219. arm_status arm_mat_trans_q31(
  2220. const arm_matrix_instance_q31 * pSrc,
  2221. arm_matrix_instance_q31 * pDst);
  2222. /**
  2223. * @brief Floating-point matrix multiplication
  2224. * @param[in] pSrcA points to the first input matrix structure
  2225. * @param[in] pSrcB points to the second input matrix structure
  2226. * @param[out] pDst points to output matrix structure
  2227. * @return The function returns either
  2228. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2229. */
  2230. arm_status arm_mat_mult_f32(
  2231. const arm_matrix_instance_f32 * pSrcA,
  2232. const arm_matrix_instance_f32 * pSrcB,
  2233. arm_matrix_instance_f32 * pDst);
  2234. /**
  2235. * @brief Q15 matrix multiplication
  2236. * @param[in] pSrcA points to the first input matrix structure
  2237. * @param[in] pSrcB points to the second input matrix structure
  2238. * @param[out] pDst points to output matrix structure
  2239. * @param[in] pState points to the array for storing intermediate results
  2240. * @return The function returns either
  2241. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2242. */
  2243. arm_status arm_mat_mult_q15(
  2244. const arm_matrix_instance_q15 * pSrcA,
  2245. const arm_matrix_instance_q15 * pSrcB,
  2246. arm_matrix_instance_q15 * pDst,
  2247. q15_t * pState);
  2248. /**
  2249. * @brief Q15 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4
  2250. * @param[in] pSrcA points to the first input matrix structure
  2251. * @param[in] pSrcB points to the second input matrix structure
  2252. * @param[out] pDst points to output matrix structure
  2253. * @param[in] pState points to the array for storing intermediate results
  2254. * @return The function returns either
  2255. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2256. */
  2257. arm_status arm_mat_mult_fast_q15(
  2258. const arm_matrix_instance_q15 * pSrcA,
  2259. const arm_matrix_instance_q15 * pSrcB,
  2260. arm_matrix_instance_q15 * pDst,
  2261. q15_t * pState);
  2262. /**
  2263. * @brief Q31 matrix multiplication
  2264. * @param[in] pSrcA points to the first input matrix structure
  2265. * @param[in] pSrcB points to the second input matrix structure
  2266. * @param[out] pDst points to output matrix structure
  2267. * @return The function returns either
  2268. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2269. */
  2270. arm_status arm_mat_mult_q31(
  2271. const arm_matrix_instance_q31 * pSrcA,
  2272. const arm_matrix_instance_q31 * pSrcB,
  2273. arm_matrix_instance_q31 * pDst);
  2274. /**
  2275. * @brief Q31 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4
  2276. * @param[in] pSrcA points to the first input matrix structure
  2277. * @param[in] pSrcB points to the second input matrix structure
  2278. * @param[out] pDst points to output matrix structure
  2279. * @return The function returns either
  2280. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2281. */
  2282. arm_status arm_mat_mult_fast_q31(
  2283. const arm_matrix_instance_q31 * pSrcA,
  2284. const arm_matrix_instance_q31 * pSrcB,
  2285. arm_matrix_instance_q31 * pDst);
  2286. /**
  2287. * @brief Floating-point matrix subtraction
  2288. * @param[in] pSrcA points to the first input matrix structure
  2289. * @param[in] pSrcB points to the second input matrix structure
  2290. * @param[out] pDst points to output matrix structure
  2291. * @return The function returns either
  2292. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2293. */
  2294. arm_status arm_mat_sub_f32(
  2295. const arm_matrix_instance_f32 * pSrcA,
  2296. const arm_matrix_instance_f32 * pSrcB,
  2297. arm_matrix_instance_f32 * pDst);
  2298. /**
  2299. * @brief Q15 matrix subtraction
  2300. * @param[in] pSrcA points to the first input matrix structure
  2301. * @param[in] pSrcB points to the second input matrix structure
  2302. * @param[out] pDst points to output matrix structure
  2303. * @return The function returns either
  2304. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2305. */
  2306. arm_status arm_mat_sub_q15(
  2307. const arm_matrix_instance_q15 * pSrcA,
  2308. const arm_matrix_instance_q15 * pSrcB,
  2309. arm_matrix_instance_q15 * pDst);
  2310. /**
  2311. * @brief Q31 matrix subtraction
  2312. * @param[in] pSrcA points to the first input matrix structure
  2313. * @param[in] pSrcB points to the second input matrix structure
  2314. * @param[out] pDst points to output matrix structure
  2315. * @return The function returns either
  2316. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2317. */
  2318. arm_status arm_mat_sub_q31(
  2319. const arm_matrix_instance_q31 * pSrcA,
  2320. const arm_matrix_instance_q31 * pSrcB,
  2321. arm_matrix_instance_q31 * pDst);
  2322. /**
  2323. * @brief Floating-point matrix scaling.
  2324. * @param[in] pSrc points to the input matrix
  2325. * @param[in] scale scale factor
  2326. * @param[out] pDst points to the output matrix
  2327. * @return The function returns either
  2328. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2329. */
  2330. arm_status arm_mat_scale_f32(
  2331. const arm_matrix_instance_f32 * pSrc,
  2332. float32_t scale,
  2333. arm_matrix_instance_f32 * pDst);
  2334. /**
  2335. * @brief Q15 matrix scaling.
  2336. * @param[in] pSrc points to input matrix
  2337. * @param[in] scaleFract fractional portion of the scale factor
  2338. * @param[in] shift number of bits to shift the result by
  2339. * @param[out] pDst points to output matrix
  2340. * @return The function returns either
  2341. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2342. */
  2343. arm_status arm_mat_scale_q15(
  2344. const arm_matrix_instance_q15 * pSrc,
  2345. q15_t scaleFract,
  2346. int32_t shift,
  2347. arm_matrix_instance_q15 * pDst);
  2348. /**
  2349. * @brief Q31 matrix scaling.
  2350. * @param[in] pSrc points to input matrix
  2351. * @param[in] scaleFract fractional portion of the scale factor
  2352. * @param[in] shift number of bits to shift the result by
  2353. * @param[out] pDst points to output matrix structure
  2354. * @return The function returns either
  2355. * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
  2356. */
  2357. arm_status arm_mat_scale_q31(
  2358. const arm_matrix_instance_q31 * pSrc,
  2359. q31_t scaleFract,
  2360. int32_t shift,
  2361. arm_matrix_instance_q31 * pDst);
  2362. /**
  2363. * @brief Q31 matrix initialization.
  2364. * @param[in,out] S points to an instance of the floating-point matrix structure.
  2365. * @param[in] nRows number of rows in the matrix.
  2366. * @param[in] nColumns number of columns in the matrix.
  2367. * @param[in] pData points to the matrix data array.
  2368. */
  2369. void arm_mat_init_q31(
  2370. arm_matrix_instance_q31 * S,
  2371. uint16_t nRows,
  2372. uint16_t nColumns,
  2373. q31_t * pData);
  2374. /**
  2375. * @brief Q15 matrix initialization.
  2376. * @param[in,out] S points to an instance of the floating-point matrix structure.
  2377. * @param[in] nRows number of rows in the matrix.
  2378. * @param[in] nColumns number of columns in the matrix.
  2379. * @param[in] pData points to the matrix data array.
  2380. */
  2381. void arm_mat_init_q15(
  2382. arm_matrix_instance_q15 * S,
  2383. uint16_t nRows,
  2384. uint16_t nColumns,
  2385. q15_t * pData);
  2386. /**
  2387. * @brief Floating-point matrix initialization.
  2388. * @param[in,out] S points to an instance of the floating-point matrix structure.
  2389. * @param[in] nRows number of rows in the matrix.
  2390. * @param[in] nColumns number of columns in the matrix.
  2391. * @param[in] pData points to the matrix data array.
  2392. */
  2393. void arm_mat_init_f32(
  2394. arm_matrix_instance_f32 * S,
  2395. uint16_t nRows,
  2396. uint16_t nColumns,
  2397. float32_t * pData);
  2398. /**
  2399. * @brief Instance structure for the Q15 PID Control.
  2400. */
  2401. typedef struct
  2402. {
  2403. q15_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */
  2404. #if !defined (ARM_MATH_DSP)
  2405. q15_t A1;
  2406. q15_t A2;
  2407. #else
  2408. q31_t A1; /**< The derived gain A1 = -Kp - 2Kd | Kd.*/
  2409. #endif
  2410. q15_t state[3]; /**< The state array of length 3. */
  2411. q15_t Kp; /**< The proportional gain. */
  2412. q15_t Ki; /**< The integral gain. */
  2413. q15_t Kd; /**< The derivative gain. */
  2414. } arm_pid_instance_q15;
  2415. /**
  2416. * @brief Instance structure for the Q31 PID Control.
  2417. */
  2418. typedef struct
  2419. {
  2420. q31_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */
  2421. q31_t A1; /**< The derived gain, A1 = -Kp - 2Kd. */
  2422. q31_t A2; /**< The derived gain, A2 = Kd . */
  2423. q31_t state[3]; /**< The state array of length 3. */
  2424. q31_t Kp; /**< The proportional gain. */
  2425. q31_t Ki; /**< The integral gain. */
  2426. q31_t Kd; /**< The derivative gain. */
  2427. } arm_pid_instance_q31;
  2428. /**
  2429. * @brief Instance structure for the floating-point PID Control.
  2430. */
  2431. typedef struct
  2432. {
  2433. float32_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */
  2434. float32_t A1; /**< The derived gain, A1 = -Kp - 2Kd. */
  2435. float32_t A2; /**< The derived gain, A2 = Kd . */
  2436. float32_t state[3]; /**< The state array of length 3. */
  2437. float32_t Kp; /**< The proportional gain. */
  2438. float32_t Ki; /**< The integral gain. */
  2439. float32_t Kd; /**< The derivative gain. */
  2440. } arm_pid_instance_f32;
  2441. /**
  2442. * @brief Initialization function for the floating-point PID Control.
  2443. * @param[in,out] S points to an instance of the PID structure.
  2444. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state.
  2445. */
  2446. void arm_pid_init_f32(
  2447. arm_pid_instance_f32 * S,
  2448. int32_t resetStateFlag);
  2449. /**
  2450. * @brief Reset function for the floating-point PID Control.
  2451. * @param[in,out] S is an instance of the floating-point PID Control structure
  2452. */
  2453. void arm_pid_reset_f32(
  2454. arm_pid_instance_f32 * S);
  2455. /**
  2456. * @brief Initialization function for the Q31 PID Control.
  2457. * @param[in,out] S points to an instance of the Q15 PID structure.
  2458. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state.
  2459. */
  2460. void arm_pid_init_q31(
  2461. arm_pid_instance_q31 * S,
  2462. int32_t resetStateFlag);
  2463. /**
  2464. * @brief Reset function for the Q31 PID Control.
  2465. * @param[in,out] S points to an instance of the Q31 PID Control structure
  2466. */
  2467. void arm_pid_reset_q31(
  2468. arm_pid_instance_q31 * S);
  2469. /**
  2470. * @brief Initialization function for the Q15 PID Control.
  2471. * @param[in,out] S points to an instance of the Q15 PID structure.
  2472. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state.
  2473. */
  2474. void arm_pid_init_q15(
  2475. arm_pid_instance_q15 * S,
  2476. int32_t resetStateFlag);
  2477. /**
  2478. * @brief Reset function for the Q15 PID Control.
  2479. * @param[in,out] S points to an instance of the q15 PID Control structure
  2480. */
  2481. void arm_pid_reset_q15(
  2482. arm_pid_instance_q15 * S);
  2483. /**
  2484. * @brief Instance structure for the floating-point Linear Interpolate function.
  2485. */
  2486. typedef struct
  2487. {
  2488. uint32_t nValues; /**< nValues */
  2489. float32_t x1; /**< x1 */
  2490. float32_t xSpacing; /**< xSpacing */
  2491. float32_t *pYData; /**< pointer to the table of Y values */
  2492. } arm_linear_interp_instance_f32;
  2493. /**
  2494. * @brief Instance structure for the floating-point bilinear interpolation function.
  2495. */
  2496. typedef struct
  2497. {
  2498. uint16_t numRows; /**< number of rows in the data table. */
  2499. uint16_t numCols; /**< number of columns in the data table. */
  2500. float32_t *pData; /**< points to the data table. */
  2501. } arm_bilinear_interp_instance_f32;
  2502. /**
  2503. * @brief Instance structure for the Q31 bilinear interpolation function.
  2504. */
  2505. typedef struct
  2506. {
  2507. uint16_t numRows; /**< number of rows in the data table. */
  2508. uint16_t numCols; /**< number of columns in the data table. */
  2509. q31_t *pData; /**< points to the data table. */
  2510. } arm_bilinear_interp_instance_q31;
  2511. /**
  2512. * @brief Instance structure for the Q15 bilinear interpolation function.
  2513. */
  2514. typedef struct
  2515. {
  2516. uint16_t numRows; /**< number of rows in the data table. */
  2517. uint16_t numCols; /**< number of columns in the data table. */
  2518. q15_t *pData; /**< points to the data table. */
  2519. } arm_bilinear_interp_instance_q15;
  2520. /**
  2521. * @brief Instance structure for the Q15 bilinear interpolation function.
  2522. */
  2523. typedef struct
  2524. {
  2525. uint16_t numRows; /**< number of rows in the data table. */
  2526. uint16_t numCols; /**< number of columns in the data table. */
  2527. q7_t *pData; /**< points to the data table. */
  2528. } arm_bilinear_interp_instance_q7;
  2529. /**
  2530. * @brief Q7 vector multiplication.
  2531. * @param[in] pSrcA points to the first input vector
  2532. * @param[in] pSrcB points to the second input vector
  2533. * @param[out] pDst points to the output vector
  2534. * @param[in] blockSize number of samples in each vector
  2535. */
  2536. void arm_mult_q7(
  2537. const q7_t * pSrcA,
  2538. const q7_t * pSrcB,
  2539. q7_t * pDst,
  2540. uint32_t blockSize);
  2541. /**
  2542. * @brief Q15 vector multiplication.
  2543. * @param[in] pSrcA points to the first input vector
  2544. * @param[in] pSrcB points to the second input vector
  2545. * @param[out] pDst points to the output vector
  2546. * @param[in] blockSize number of samples in each vector
  2547. */
  2548. void arm_mult_q15(
  2549. const q15_t * pSrcA,
  2550. const q15_t * pSrcB,
  2551. q15_t * pDst,
  2552. uint32_t blockSize);
  2553. /**
  2554. * @brief Q31 vector multiplication.
  2555. * @param[in] pSrcA points to the first input vector
  2556. * @param[in] pSrcB points to the second input vector
  2557. * @param[out] pDst points to the output vector
  2558. * @param[in] blockSize number of samples in each vector
  2559. */
  2560. void arm_mult_q31(
  2561. const q31_t * pSrcA,
  2562. const q31_t * pSrcB,
  2563. q31_t * pDst,
  2564. uint32_t blockSize);
  2565. /**
  2566. * @brief Floating-point vector multiplication.
  2567. * @param[in] pSrcA points to the first input vector
  2568. * @param[in] pSrcB points to the second input vector
  2569. * @param[out] pDst points to the output vector
  2570. * @param[in] blockSize number of samples in each vector
  2571. */
  2572. void arm_mult_f32(
  2573. const float32_t * pSrcA,
  2574. const float32_t * pSrcB,
  2575. float32_t * pDst,
  2576. uint32_t blockSize);
  2577. /**
  2578. * @brief Instance structure for the Q15 CFFT/CIFFT function.
  2579. */
  2580. typedef struct
  2581. {
  2582. uint16_t fftLen; /**< length of the FFT. */
  2583. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2584. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2585. const q15_t *pTwiddle; /**< points to the Sin twiddle factor table. */
  2586. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2587. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2588. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2589. } arm_cfft_radix2_instance_q15;
  2590. /* Deprecated */
  2591. arm_status arm_cfft_radix2_init_q15(
  2592. arm_cfft_radix2_instance_q15 * S,
  2593. uint16_t fftLen,
  2594. uint8_t ifftFlag,
  2595. uint8_t bitReverseFlag);
  2596. /* Deprecated */
  2597. void arm_cfft_radix2_q15(
  2598. const arm_cfft_radix2_instance_q15 * S,
  2599. q15_t * pSrc);
  2600. /**
  2601. * @brief Instance structure for the Q15 CFFT/CIFFT function.
  2602. */
  2603. typedef struct
  2604. {
  2605. uint16_t fftLen; /**< length of the FFT. */
  2606. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2607. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2608. const q15_t *pTwiddle; /**< points to the twiddle factor table. */
  2609. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2610. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2611. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2612. } arm_cfft_radix4_instance_q15;
  2613. /* Deprecated */
  2614. arm_status arm_cfft_radix4_init_q15(
  2615. arm_cfft_radix4_instance_q15 * S,
  2616. uint16_t fftLen,
  2617. uint8_t ifftFlag,
  2618. uint8_t bitReverseFlag);
  2619. /* Deprecated */
  2620. void arm_cfft_radix4_q15(
  2621. const arm_cfft_radix4_instance_q15 * S,
  2622. q15_t * pSrc);
  2623. /**
  2624. * @brief Instance structure for the Radix-2 Q31 CFFT/CIFFT function.
  2625. */
  2626. typedef struct
  2627. {
  2628. uint16_t fftLen; /**< length of the FFT. */
  2629. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2630. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2631. const q31_t *pTwiddle; /**< points to the Twiddle factor table. */
  2632. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2633. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2634. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2635. } arm_cfft_radix2_instance_q31;
  2636. /* Deprecated */
  2637. arm_status arm_cfft_radix2_init_q31(
  2638. arm_cfft_radix2_instance_q31 * S,
  2639. uint16_t fftLen,
  2640. uint8_t ifftFlag,
  2641. uint8_t bitReverseFlag);
  2642. /* Deprecated */
  2643. void arm_cfft_radix2_q31(
  2644. const arm_cfft_radix2_instance_q31 * S,
  2645. q31_t * pSrc);
  2646. /**
  2647. * @brief Instance structure for the Q31 CFFT/CIFFT function.
  2648. */
  2649. typedef struct
  2650. {
  2651. uint16_t fftLen; /**< length of the FFT. */
  2652. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2653. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2654. const q31_t *pTwiddle; /**< points to the twiddle factor table. */
  2655. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2656. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2657. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2658. } arm_cfft_radix4_instance_q31;
  2659. /* Deprecated */
  2660. void arm_cfft_radix4_q31(
  2661. const arm_cfft_radix4_instance_q31 * S,
  2662. q31_t * pSrc);
  2663. /* Deprecated */
  2664. arm_status arm_cfft_radix4_init_q31(
  2665. arm_cfft_radix4_instance_q31 * S,
  2666. uint16_t fftLen,
  2667. uint8_t ifftFlag,
  2668. uint8_t bitReverseFlag);
  2669. /**
  2670. * @brief Instance structure for the floating-point CFFT/CIFFT function.
  2671. */
  2672. typedef struct
  2673. {
  2674. uint16_t fftLen; /**< length of the FFT. */
  2675. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2676. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2677. const float32_t *pTwiddle; /**< points to the Twiddle factor table. */
  2678. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2679. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2680. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2681. float32_t onebyfftLen; /**< value of 1/fftLen. */
  2682. } arm_cfft_radix2_instance_f32;
  2683. /* Deprecated */
  2684. arm_status arm_cfft_radix2_init_f32(
  2685. arm_cfft_radix2_instance_f32 * S,
  2686. uint16_t fftLen,
  2687. uint8_t ifftFlag,
  2688. uint8_t bitReverseFlag);
  2689. /* Deprecated */
  2690. void arm_cfft_radix2_f32(
  2691. const arm_cfft_radix2_instance_f32 * S,
  2692. float32_t * pSrc);
  2693. /**
  2694. * @brief Instance structure for the floating-point CFFT/CIFFT function.
  2695. */
  2696. typedef struct
  2697. {
  2698. uint16_t fftLen; /**< length of the FFT. */
  2699. uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */
  2700. uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */
  2701. const float32_t *pTwiddle; /**< points to the Twiddle factor table. */
  2702. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2703. uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2704. uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */
  2705. float32_t onebyfftLen; /**< value of 1/fftLen. */
  2706. } arm_cfft_radix4_instance_f32;
  2707. /* Deprecated */
  2708. arm_status arm_cfft_radix4_init_f32(
  2709. arm_cfft_radix4_instance_f32 * S,
  2710. uint16_t fftLen,
  2711. uint8_t ifftFlag,
  2712. uint8_t bitReverseFlag);
  2713. /* Deprecated */
  2714. void arm_cfft_radix4_f32(
  2715. const arm_cfft_radix4_instance_f32 * S,
  2716. float32_t * pSrc);
  2717. /**
  2718. * @brief Instance structure for the fixed-point CFFT/CIFFT function.
  2719. */
  2720. typedef struct
  2721. {
  2722. uint16_t fftLen; /**< length of the FFT. */
  2723. const q15_t *pTwiddle; /**< points to the Twiddle factor table. */
  2724. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2725. uint16_t bitRevLength; /**< bit reversal table length. */
  2726. #if defined(ARM_MATH_MVEI)
  2727. const uint32_t *rearranged_twiddle_tab_stride1_arr; /**< Per stage reordered twiddle pointer (offset 1) */ \
  2728. const uint32_t *rearranged_twiddle_tab_stride2_arr; /**< Per stage reordered twiddle pointer (offset 2) */ \
  2729. const uint32_t *rearranged_twiddle_tab_stride3_arr; /**< Per stage reordered twiddle pointer (offset 3) */ \
  2730. const q15_t *rearranged_twiddle_stride1; /**< reordered twiddle offset 1 storage */ \
  2731. const q15_t *rearranged_twiddle_stride2; /**< reordered twiddle offset 2 storage */ \
  2732. const q15_t *rearranged_twiddle_stride3;
  2733. #endif
  2734. } arm_cfft_instance_q15;
  2735. arm_status arm_cfft_init_q15(
  2736. arm_cfft_instance_q15 * S,
  2737. uint16_t fftLen);
  2738. void arm_cfft_q15(
  2739. const arm_cfft_instance_q15 * S,
  2740. q15_t * p1,
  2741. uint8_t ifftFlag,
  2742. uint8_t bitReverseFlag);
  2743. /**
  2744. * @brief Instance structure for the fixed-point CFFT/CIFFT function.
  2745. */
  2746. typedef struct
  2747. {
  2748. uint16_t fftLen; /**< length of the FFT. */
  2749. const q31_t *pTwiddle; /**< points to the Twiddle factor table. */
  2750. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2751. uint16_t bitRevLength; /**< bit reversal table length. */
  2752. #if defined(ARM_MATH_MVEI)
  2753. const uint32_t *rearranged_twiddle_tab_stride1_arr; /**< Per stage reordered twiddle pointer (offset 1) */ \
  2754. const uint32_t *rearranged_twiddle_tab_stride2_arr; /**< Per stage reordered twiddle pointer (offset 2) */ \
  2755. const uint32_t *rearranged_twiddle_tab_stride3_arr; /**< Per stage reordered twiddle pointer (offset 3) */ \
  2756. const q31_t *rearranged_twiddle_stride1; /**< reordered twiddle offset 1 storage */ \
  2757. const q31_t *rearranged_twiddle_stride2; /**< reordered twiddle offset 2 storage */ \
  2758. const q31_t *rearranged_twiddle_stride3;
  2759. #endif
  2760. } arm_cfft_instance_q31;
  2761. arm_status arm_cfft_init_q31(
  2762. arm_cfft_instance_q31 * S,
  2763. uint16_t fftLen);
  2764. void arm_cfft_q31(
  2765. const arm_cfft_instance_q31 * S,
  2766. q31_t * p1,
  2767. uint8_t ifftFlag,
  2768. uint8_t bitReverseFlag);
  2769. /**
  2770. * @brief Instance structure for the floating-point CFFT/CIFFT function.
  2771. */
  2772. typedef struct
  2773. {
  2774. uint16_t fftLen; /**< length of the FFT. */
  2775. const float32_t *pTwiddle; /**< points to the Twiddle factor table. */
  2776. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2777. uint16_t bitRevLength; /**< bit reversal table length. */
  2778. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  2779. const uint32_t *rearranged_twiddle_tab_stride1_arr; /**< Per stage reordered twiddle pointer (offset 1) */ \
  2780. const uint32_t *rearranged_twiddle_tab_stride2_arr; /**< Per stage reordered twiddle pointer (offset 2) */ \
  2781. const uint32_t *rearranged_twiddle_tab_stride3_arr; /**< Per stage reordered twiddle pointer (offset 3) */ \
  2782. const float32_t *rearranged_twiddle_stride1; /**< reordered twiddle offset 1 storage */ \
  2783. const float32_t *rearranged_twiddle_stride2; /**< reordered twiddle offset 2 storage */ \
  2784. const float32_t *rearranged_twiddle_stride3;
  2785. #endif
  2786. } arm_cfft_instance_f32;
  2787. arm_status arm_cfft_init_f32(
  2788. arm_cfft_instance_f32 * S,
  2789. uint16_t fftLen);
  2790. void arm_cfft_f32(
  2791. const arm_cfft_instance_f32 * S,
  2792. float32_t * p1,
  2793. uint8_t ifftFlag,
  2794. uint8_t bitReverseFlag);
  2795. /**
  2796. * @brief Instance structure for the Double Precision Floating-point CFFT/CIFFT function.
  2797. */
  2798. typedef struct
  2799. {
  2800. uint16_t fftLen; /**< length of the FFT. */
  2801. const float64_t *pTwiddle; /**< points to the Twiddle factor table. */
  2802. const uint16_t *pBitRevTable; /**< points to the bit reversal table. */
  2803. uint16_t bitRevLength; /**< bit reversal table length. */
  2804. } arm_cfft_instance_f64;
  2805. void arm_cfft_f64(
  2806. const arm_cfft_instance_f64 * S,
  2807. float64_t * p1,
  2808. uint8_t ifftFlag,
  2809. uint8_t bitReverseFlag);
  2810. /**
  2811. * @brief Instance structure for the Q15 RFFT/RIFFT function.
  2812. */
  2813. typedef struct
  2814. {
  2815. uint32_t fftLenReal; /**< length of the real FFT. */
  2816. uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */
  2817. uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */
  2818. uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2819. const q15_t *pTwiddleAReal; /**< points to the real twiddle factor table. */
  2820. const q15_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */
  2821. #if defined(ARM_MATH_MVEI)
  2822. arm_cfft_instance_q15 cfftInst;
  2823. #else
  2824. const arm_cfft_instance_q15 *pCfft; /**< points to the complex FFT instance. */
  2825. #endif
  2826. } arm_rfft_instance_q15;
  2827. arm_status arm_rfft_init_q15(
  2828. arm_rfft_instance_q15 * S,
  2829. uint32_t fftLenReal,
  2830. uint32_t ifftFlagR,
  2831. uint32_t bitReverseFlag);
  2832. void arm_rfft_q15(
  2833. const arm_rfft_instance_q15 * S,
  2834. q15_t * pSrc,
  2835. q15_t * pDst);
  2836. /**
  2837. * @brief Instance structure for the Q31 RFFT/RIFFT function.
  2838. */
  2839. typedef struct
  2840. {
  2841. uint32_t fftLenReal; /**< length of the real FFT. */
  2842. uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */
  2843. uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */
  2844. uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2845. const q31_t *pTwiddleAReal; /**< points to the real twiddle factor table. */
  2846. const q31_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */
  2847. #if defined(ARM_MATH_MVEI)
  2848. arm_cfft_instance_q31 cfftInst;
  2849. #else
  2850. const arm_cfft_instance_q31 *pCfft; /**< points to the complex FFT instance. */
  2851. #endif
  2852. } arm_rfft_instance_q31;
  2853. arm_status arm_rfft_init_q31(
  2854. arm_rfft_instance_q31 * S,
  2855. uint32_t fftLenReal,
  2856. uint32_t ifftFlagR,
  2857. uint32_t bitReverseFlag);
  2858. void arm_rfft_q31(
  2859. const arm_rfft_instance_q31 * S,
  2860. q31_t * pSrc,
  2861. q31_t * pDst);
  2862. /**
  2863. * @brief Instance structure for the floating-point RFFT/RIFFT function.
  2864. */
  2865. typedef struct
  2866. {
  2867. uint32_t fftLenReal; /**< length of the real FFT. */
  2868. uint16_t fftLenBy2; /**< length of the complex FFT. */
  2869. uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */
  2870. uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */
  2871. uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */
  2872. const float32_t *pTwiddleAReal; /**< points to the real twiddle factor table. */
  2873. const float32_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */
  2874. arm_cfft_radix4_instance_f32 *pCfft; /**< points to the complex FFT instance. */
  2875. } arm_rfft_instance_f32;
  2876. arm_status arm_rfft_init_f32(
  2877. arm_rfft_instance_f32 * S,
  2878. arm_cfft_radix4_instance_f32 * S_CFFT,
  2879. uint32_t fftLenReal,
  2880. uint32_t ifftFlagR,
  2881. uint32_t bitReverseFlag);
  2882. void arm_rfft_f32(
  2883. const arm_rfft_instance_f32 * S,
  2884. float32_t * pSrc,
  2885. float32_t * pDst);
  2886. /**
  2887. * @brief Instance structure for the Double Precision Floating-point RFFT/RIFFT function.
  2888. */
  2889. typedef struct
  2890. {
  2891. arm_cfft_instance_f64 Sint; /**< Internal CFFT structure. */
  2892. uint16_t fftLenRFFT; /**< length of the real sequence */
  2893. const float64_t * pTwiddleRFFT; /**< Twiddle factors real stage */
  2894. } arm_rfft_fast_instance_f64 ;
  2895. arm_status arm_rfft_fast_init_f64 (
  2896. arm_rfft_fast_instance_f64 * S,
  2897. uint16_t fftLen);
  2898. void arm_rfft_fast_f64(
  2899. arm_rfft_fast_instance_f64 * S,
  2900. float64_t * p, float64_t * pOut,
  2901. uint8_t ifftFlag);
  2902. /**
  2903. * @brief Instance structure for the floating-point RFFT/RIFFT function.
  2904. */
  2905. typedef struct
  2906. {
  2907. arm_cfft_instance_f32 Sint; /**< Internal CFFT structure. */
  2908. uint16_t fftLenRFFT; /**< length of the real sequence */
  2909. const float32_t * pTwiddleRFFT; /**< Twiddle factors real stage */
  2910. } arm_rfft_fast_instance_f32 ;
  2911. arm_status arm_rfft_fast_init_f32 (
  2912. arm_rfft_fast_instance_f32 * S,
  2913. uint16_t fftLen);
  2914. void arm_rfft_fast_f32(
  2915. const arm_rfft_fast_instance_f32 * S,
  2916. float32_t * p, float32_t * pOut,
  2917. uint8_t ifftFlag);
  2918. /**
  2919. * @brief Instance structure for the floating-point DCT4/IDCT4 function.
  2920. */
  2921. typedef struct
  2922. {
  2923. uint16_t N; /**< length of the DCT4. */
  2924. uint16_t Nby2; /**< half of the length of the DCT4. */
  2925. float32_t normalize; /**< normalizing factor. */
  2926. const float32_t *pTwiddle; /**< points to the twiddle factor table. */
  2927. const float32_t *pCosFactor; /**< points to the cosFactor table. */
  2928. arm_rfft_instance_f32 *pRfft; /**< points to the real FFT instance. */
  2929. arm_cfft_radix4_instance_f32 *pCfft; /**< points to the complex FFT instance. */
  2930. } arm_dct4_instance_f32;
  2931. /**
  2932. * @brief Initialization function for the floating-point DCT4/IDCT4.
  2933. * @param[in,out] S points to an instance of floating-point DCT4/IDCT4 structure.
  2934. * @param[in] S_RFFT points to an instance of floating-point RFFT/RIFFT structure.
  2935. * @param[in] S_CFFT points to an instance of floating-point CFFT/CIFFT structure.
  2936. * @param[in] N length of the DCT4.
  2937. * @param[in] Nby2 half of the length of the DCT4.
  2938. * @param[in] normalize normalizing factor.
  2939. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLenReal</code> is not a supported transform length.
  2940. */
  2941. arm_status arm_dct4_init_f32(
  2942. arm_dct4_instance_f32 * S,
  2943. arm_rfft_instance_f32 * S_RFFT,
  2944. arm_cfft_radix4_instance_f32 * S_CFFT,
  2945. uint16_t N,
  2946. uint16_t Nby2,
  2947. float32_t normalize);
  2948. /**
  2949. * @brief Processing function for the floating-point DCT4/IDCT4.
  2950. * @param[in] S points to an instance of the floating-point DCT4/IDCT4 structure.
  2951. * @param[in] pState points to state buffer.
  2952. * @param[in,out] pInlineBuffer points to the in-place input and output buffer.
  2953. */
  2954. void arm_dct4_f32(
  2955. const arm_dct4_instance_f32 * S,
  2956. float32_t * pState,
  2957. float32_t * pInlineBuffer);
  2958. /**
  2959. * @brief Instance structure for the Q31 DCT4/IDCT4 function.
  2960. */
  2961. typedef struct
  2962. {
  2963. uint16_t N; /**< length of the DCT4. */
  2964. uint16_t Nby2; /**< half of the length of the DCT4. */
  2965. q31_t normalize; /**< normalizing factor. */
  2966. const q31_t *pTwiddle; /**< points to the twiddle factor table. */
  2967. const q31_t *pCosFactor; /**< points to the cosFactor table. */
  2968. arm_rfft_instance_q31 *pRfft; /**< points to the real FFT instance. */
  2969. arm_cfft_radix4_instance_q31 *pCfft; /**< points to the complex FFT instance. */
  2970. } arm_dct4_instance_q31;
  2971. /**
  2972. * @brief Initialization function for the Q31 DCT4/IDCT4.
  2973. * @param[in,out] S points to an instance of Q31 DCT4/IDCT4 structure.
  2974. * @param[in] S_RFFT points to an instance of Q31 RFFT/RIFFT structure
  2975. * @param[in] S_CFFT points to an instance of Q31 CFFT/CIFFT structure
  2976. * @param[in] N length of the DCT4.
  2977. * @param[in] Nby2 half of the length of the DCT4.
  2978. * @param[in] normalize normalizing factor.
  2979. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>N</code> is not a supported transform length.
  2980. */
  2981. arm_status arm_dct4_init_q31(
  2982. arm_dct4_instance_q31 * S,
  2983. arm_rfft_instance_q31 * S_RFFT,
  2984. arm_cfft_radix4_instance_q31 * S_CFFT,
  2985. uint16_t N,
  2986. uint16_t Nby2,
  2987. q31_t normalize);
  2988. /**
  2989. * @brief Processing function for the Q31 DCT4/IDCT4.
  2990. * @param[in] S points to an instance of the Q31 DCT4 structure.
  2991. * @param[in] pState points to state buffer.
  2992. * @param[in,out] pInlineBuffer points to the in-place input and output buffer.
  2993. */
  2994. void arm_dct4_q31(
  2995. const arm_dct4_instance_q31 * S,
  2996. q31_t * pState,
  2997. q31_t * pInlineBuffer);
  2998. /**
  2999. * @brief Instance structure for the Q15 DCT4/IDCT4 function.
  3000. */
  3001. typedef struct
  3002. {
  3003. uint16_t N; /**< length of the DCT4. */
  3004. uint16_t Nby2; /**< half of the length of the DCT4. */
  3005. q15_t normalize; /**< normalizing factor. */
  3006. const q15_t *pTwiddle; /**< points to the twiddle factor table. */
  3007. const q15_t *pCosFactor; /**< points to the cosFactor table. */
  3008. arm_rfft_instance_q15 *pRfft; /**< points to the real FFT instance. */
  3009. arm_cfft_radix4_instance_q15 *pCfft; /**< points to the complex FFT instance. */
  3010. } arm_dct4_instance_q15;
  3011. /**
  3012. * @brief Initialization function for the Q15 DCT4/IDCT4.
  3013. * @param[in,out] S points to an instance of Q15 DCT4/IDCT4 structure.
  3014. * @param[in] S_RFFT points to an instance of Q15 RFFT/RIFFT structure.
  3015. * @param[in] S_CFFT points to an instance of Q15 CFFT/CIFFT structure.
  3016. * @param[in] N length of the DCT4.
  3017. * @param[in] Nby2 half of the length of the DCT4.
  3018. * @param[in] normalize normalizing factor.
  3019. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>N</code> is not a supported transform length.
  3020. */
  3021. arm_status arm_dct4_init_q15(
  3022. arm_dct4_instance_q15 * S,
  3023. arm_rfft_instance_q15 * S_RFFT,
  3024. arm_cfft_radix4_instance_q15 * S_CFFT,
  3025. uint16_t N,
  3026. uint16_t Nby2,
  3027. q15_t normalize);
  3028. /**
  3029. * @brief Processing function for the Q15 DCT4/IDCT4.
  3030. * @param[in] S points to an instance of the Q15 DCT4 structure.
  3031. * @param[in] pState points to state buffer.
  3032. * @param[in,out] pInlineBuffer points to the in-place input and output buffer.
  3033. */
  3034. void arm_dct4_q15(
  3035. const arm_dct4_instance_q15 * S,
  3036. q15_t * pState,
  3037. q15_t * pInlineBuffer);
  3038. /**
  3039. * @brief Floating-point vector addition.
  3040. * @param[in] pSrcA points to the first input vector
  3041. * @param[in] pSrcB points to the second input vector
  3042. * @param[out] pDst points to the output vector
  3043. * @param[in] blockSize number of samples in each vector
  3044. */
  3045. void arm_add_f32(
  3046. const float32_t * pSrcA,
  3047. const float32_t * pSrcB,
  3048. float32_t * pDst,
  3049. uint32_t blockSize);
  3050. /**
  3051. * @brief Q7 vector addition.
  3052. * @param[in] pSrcA points to the first input vector
  3053. * @param[in] pSrcB points to the second input vector
  3054. * @param[out] pDst points to the output vector
  3055. * @param[in] blockSize number of samples in each vector
  3056. */
  3057. void arm_add_q7(
  3058. const q7_t * pSrcA,
  3059. const q7_t * pSrcB,
  3060. q7_t * pDst,
  3061. uint32_t blockSize);
  3062. /**
  3063. * @brief Q15 vector addition.
  3064. * @param[in] pSrcA points to the first input vector
  3065. * @param[in] pSrcB points to the second input vector
  3066. * @param[out] pDst points to the output vector
  3067. * @param[in] blockSize number of samples in each vector
  3068. */
  3069. void arm_add_q15(
  3070. const q15_t * pSrcA,
  3071. const q15_t * pSrcB,
  3072. q15_t * pDst,
  3073. uint32_t blockSize);
  3074. /**
  3075. * @brief Q31 vector addition.
  3076. * @param[in] pSrcA points to the first input vector
  3077. * @param[in] pSrcB points to the second input vector
  3078. * @param[out] pDst points to the output vector
  3079. * @param[in] blockSize number of samples in each vector
  3080. */
  3081. void arm_add_q31(
  3082. const q31_t * pSrcA,
  3083. const q31_t * pSrcB,
  3084. q31_t * pDst,
  3085. uint32_t blockSize);
  3086. /**
  3087. * @brief Floating-point vector subtraction.
  3088. * @param[in] pSrcA points to the first input vector
  3089. * @param[in] pSrcB points to the second input vector
  3090. * @param[out] pDst points to the output vector
  3091. * @param[in] blockSize number of samples in each vector
  3092. */
  3093. void arm_sub_f32(
  3094. const float32_t * pSrcA,
  3095. const float32_t * pSrcB,
  3096. float32_t * pDst,
  3097. uint32_t blockSize);
  3098. /**
  3099. * @brief Q7 vector subtraction.
  3100. * @param[in] pSrcA points to the first input vector
  3101. * @param[in] pSrcB points to the second input vector
  3102. * @param[out] pDst points to the output vector
  3103. * @param[in] blockSize number of samples in each vector
  3104. */
  3105. void arm_sub_q7(
  3106. const q7_t * pSrcA,
  3107. const q7_t * pSrcB,
  3108. q7_t * pDst,
  3109. uint32_t blockSize);
  3110. /**
  3111. * @brief Q15 vector subtraction.
  3112. * @param[in] pSrcA points to the first input vector
  3113. * @param[in] pSrcB points to the second input vector
  3114. * @param[out] pDst points to the output vector
  3115. * @param[in] blockSize number of samples in each vector
  3116. */
  3117. void arm_sub_q15(
  3118. const q15_t * pSrcA,
  3119. const q15_t * pSrcB,
  3120. q15_t * pDst,
  3121. uint32_t blockSize);
  3122. /**
  3123. * @brief Q31 vector subtraction.
  3124. * @param[in] pSrcA points to the first input vector
  3125. * @param[in] pSrcB points to the second input vector
  3126. * @param[out] pDst points to the output vector
  3127. * @param[in] blockSize number of samples in each vector
  3128. */
  3129. void arm_sub_q31(
  3130. const q31_t * pSrcA,
  3131. const q31_t * pSrcB,
  3132. q31_t * pDst,
  3133. uint32_t blockSize);
  3134. /**
  3135. * @brief Multiplies a floating-point vector by a scalar.
  3136. * @param[in] pSrc points to the input vector
  3137. * @param[in] scale scale factor to be applied
  3138. * @param[out] pDst points to the output vector
  3139. * @param[in] blockSize number of samples in the vector
  3140. */
  3141. void arm_scale_f32(
  3142. const float32_t * pSrc,
  3143. float32_t scale,
  3144. float32_t * pDst,
  3145. uint32_t blockSize);
  3146. /**
  3147. * @brief Multiplies a Q7 vector by a scalar.
  3148. * @param[in] pSrc points to the input vector
  3149. * @param[in] scaleFract fractional portion of the scale value
  3150. * @param[in] shift number of bits to shift the result by
  3151. * @param[out] pDst points to the output vector
  3152. * @param[in] blockSize number of samples in the vector
  3153. */
  3154. void arm_scale_q7(
  3155. const q7_t * pSrc,
  3156. q7_t scaleFract,
  3157. int8_t shift,
  3158. q7_t * pDst,
  3159. uint32_t blockSize);
  3160. /**
  3161. * @brief Multiplies a Q15 vector by a scalar.
  3162. * @param[in] pSrc points to the input vector
  3163. * @param[in] scaleFract fractional portion of the scale value
  3164. * @param[in] shift number of bits to shift the result by
  3165. * @param[out] pDst points to the output vector
  3166. * @param[in] blockSize number of samples in the vector
  3167. */
  3168. void arm_scale_q15(
  3169. const q15_t * pSrc,
  3170. q15_t scaleFract,
  3171. int8_t shift,
  3172. q15_t * pDst,
  3173. uint32_t blockSize);
  3174. /**
  3175. * @brief Multiplies a Q31 vector by a scalar.
  3176. * @param[in] pSrc points to the input vector
  3177. * @param[in] scaleFract fractional portion of the scale value
  3178. * @param[in] shift number of bits to shift the result by
  3179. * @param[out] pDst points to the output vector
  3180. * @param[in] blockSize number of samples in the vector
  3181. */
  3182. void arm_scale_q31(
  3183. const q31_t * pSrc,
  3184. q31_t scaleFract,
  3185. int8_t shift,
  3186. q31_t * pDst,
  3187. uint32_t blockSize);
  3188. /**
  3189. * @brief Q7 vector absolute value.
  3190. * @param[in] pSrc points to the input buffer
  3191. * @param[out] pDst points to the output buffer
  3192. * @param[in] blockSize number of samples in each vector
  3193. */
  3194. void arm_abs_q7(
  3195. const q7_t * pSrc,
  3196. q7_t * pDst,
  3197. uint32_t blockSize);
  3198. /**
  3199. * @brief Floating-point vector absolute value.
  3200. * @param[in] pSrc points to the input buffer
  3201. * @param[out] pDst points to the output buffer
  3202. * @param[in] blockSize number of samples in each vector
  3203. */
  3204. void arm_abs_f32(
  3205. const float32_t * pSrc,
  3206. float32_t * pDst,
  3207. uint32_t blockSize);
  3208. /**
  3209. * @brief Q15 vector absolute value.
  3210. * @param[in] pSrc points to the input buffer
  3211. * @param[out] pDst points to the output buffer
  3212. * @param[in] blockSize number of samples in each vector
  3213. */
  3214. void arm_abs_q15(
  3215. const q15_t * pSrc,
  3216. q15_t * pDst,
  3217. uint32_t blockSize);
  3218. /**
  3219. * @brief Q31 vector absolute value.
  3220. * @param[in] pSrc points to the input buffer
  3221. * @param[out] pDst points to the output buffer
  3222. * @param[in] blockSize number of samples in each vector
  3223. */
  3224. void arm_abs_q31(
  3225. const q31_t * pSrc,
  3226. q31_t * pDst,
  3227. uint32_t blockSize);
  3228. /**
  3229. * @brief Dot product of floating-point vectors.
  3230. * @param[in] pSrcA points to the first input vector
  3231. * @param[in] pSrcB points to the second input vector
  3232. * @param[in] blockSize number of samples in each vector
  3233. * @param[out] result output result returned here
  3234. */
  3235. void arm_dot_prod_f32(
  3236. const float32_t * pSrcA,
  3237. const float32_t * pSrcB,
  3238. uint32_t blockSize,
  3239. float32_t * result);
  3240. /**
  3241. * @brief Dot product of Q7 vectors.
  3242. * @param[in] pSrcA points to the first input vector
  3243. * @param[in] pSrcB points to the second input vector
  3244. * @param[in] blockSize number of samples in each vector
  3245. * @param[out] result output result returned here
  3246. */
  3247. void arm_dot_prod_q7(
  3248. const q7_t * pSrcA,
  3249. const q7_t * pSrcB,
  3250. uint32_t blockSize,
  3251. q31_t * result);
  3252. /**
  3253. * @brief Dot product of Q15 vectors.
  3254. * @param[in] pSrcA points to the first input vector
  3255. * @param[in] pSrcB points to the second input vector
  3256. * @param[in] blockSize number of samples in each vector
  3257. * @param[out] result output result returned here
  3258. */
  3259. void arm_dot_prod_q15(
  3260. const q15_t * pSrcA,
  3261. const q15_t * pSrcB,
  3262. uint32_t blockSize,
  3263. q63_t * result);
  3264. /**
  3265. * @brief Dot product of Q31 vectors.
  3266. * @param[in] pSrcA points to the first input vector
  3267. * @param[in] pSrcB points to the second input vector
  3268. * @param[in] blockSize number of samples in each vector
  3269. * @param[out] result output result returned here
  3270. */
  3271. void arm_dot_prod_q31(
  3272. const q31_t * pSrcA,
  3273. const q31_t * pSrcB,
  3274. uint32_t blockSize,
  3275. q63_t * result);
  3276. /**
  3277. * @brief Shifts the elements of a Q7 vector a specified number of bits.
  3278. * @param[in] pSrc points to the input vector
  3279. * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
  3280. * @param[out] pDst points to the output vector
  3281. * @param[in] blockSize number of samples in the vector
  3282. */
  3283. void arm_shift_q7(
  3284. const q7_t * pSrc,
  3285. int8_t shiftBits,
  3286. q7_t * pDst,
  3287. uint32_t blockSize);
  3288. /**
  3289. * @brief Shifts the elements of a Q15 vector a specified number of bits.
  3290. * @param[in] pSrc points to the input vector
  3291. * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
  3292. * @param[out] pDst points to the output vector
  3293. * @param[in] blockSize number of samples in the vector
  3294. */
  3295. void arm_shift_q15(
  3296. const q15_t * pSrc,
  3297. int8_t shiftBits,
  3298. q15_t * pDst,
  3299. uint32_t blockSize);
  3300. /**
  3301. * @brief Shifts the elements of a Q31 vector a specified number of bits.
  3302. * @param[in] pSrc points to the input vector
  3303. * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right.
  3304. * @param[out] pDst points to the output vector
  3305. * @param[in] blockSize number of samples in the vector
  3306. */
  3307. void arm_shift_q31(
  3308. const q31_t * pSrc,
  3309. int8_t shiftBits,
  3310. q31_t * pDst,
  3311. uint32_t blockSize);
  3312. /**
  3313. * @brief Adds a constant offset to a floating-point vector.
  3314. * @param[in] pSrc points to the input vector
  3315. * @param[in] offset is the offset to be added
  3316. * @param[out] pDst points to the output vector
  3317. * @param[in] blockSize number of samples in the vector
  3318. */
  3319. void arm_offset_f32(
  3320. const float32_t * pSrc,
  3321. float32_t offset,
  3322. float32_t * pDst,
  3323. uint32_t blockSize);
  3324. /**
  3325. * @brief Adds a constant offset to a Q7 vector.
  3326. * @param[in] pSrc points to the input vector
  3327. * @param[in] offset is the offset to be added
  3328. * @param[out] pDst points to the output vector
  3329. * @param[in] blockSize number of samples in the vector
  3330. */
  3331. void arm_offset_q7(
  3332. const q7_t * pSrc,
  3333. q7_t offset,
  3334. q7_t * pDst,
  3335. uint32_t blockSize);
  3336. /**
  3337. * @brief Adds a constant offset to a Q15 vector.
  3338. * @param[in] pSrc points to the input vector
  3339. * @param[in] offset is the offset to be added
  3340. * @param[out] pDst points to the output vector
  3341. * @param[in] blockSize number of samples in the vector
  3342. */
  3343. void arm_offset_q15(
  3344. const q15_t * pSrc,
  3345. q15_t offset,
  3346. q15_t * pDst,
  3347. uint32_t blockSize);
  3348. /**
  3349. * @brief Adds a constant offset to a Q31 vector.
  3350. * @param[in] pSrc points to the input vector
  3351. * @param[in] offset is the offset to be added
  3352. * @param[out] pDst points to the output vector
  3353. * @param[in] blockSize number of samples in the vector
  3354. */
  3355. void arm_offset_q31(
  3356. const q31_t * pSrc,
  3357. q31_t offset,
  3358. q31_t * pDst,
  3359. uint32_t blockSize);
  3360. /**
  3361. * @brief Negates the elements of a floating-point vector.
  3362. * @param[in] pSrc points to the input vector
  3363. * @param[out] pDst points to the output vector
  3364. * @param[in] blockSize number of samples in the vector
  3365. */
  3366. void arm_negate_f32(
  3367. const float32_t * pSrc,
  3368. float32_t * pDst,
  3369. uint32_t blockSize);
  3370. /**
  3371. * @brief Negates the elements of a Q7 vector.
  3372. * @param[in] pSrc points to the input vector
  3373. * @param[out] pDst points to the output vector
  3374. * @param[in] blockSize number of samples in the vector
  3375. */
  3376. void arm_negate_q7(
  3377. const q7_t * pSrc,
  3378. q7_t * pDst,
  3379. uint32_t blockSize);
  3380. /**
  3381. * @brief Negates the elements of a Q15 vector.
  3382. * @param[in] pSrc points to the input vector
  3383. * @param[out] pDst points to the output vector
  3384. * @param[in] blockSize number of samples in the vector
  3385. */
  3386. void arm_negate_q15(
  3387. const q15_t * pSrc,
  3388. q15_t * pDst,
  3389. uint32_t blockSize);
  3390. /**
  3391. * @brief Negates the elements of a Q31 vector.
  3392. * @param[in] pSrc points to the input vector
  3393. * @param[out] pDst points to the output vector
  3394. * @param[in] blockSize number of samples in the vector
  3395. */
  3396. void arm_negate_q31(
  3397. const q31_t * pSrc,
  3398. q31_t * pDst,
  3399. uint32_t blockSize);
  3400. /**
  3401. * @brief Copies the elements of a floating-point vector.
  3402. * @param[in] pSrc input pointer
  3403. * @param[out] pDst output pointer
  3404. * @param[in] blockSize number of samples to process
  3405. */
  3406. void arm_copy_f32(
  3407. const float32_t * pSrc,
  3408. float32_t * pDst,
  3409. uint32_t blockSize);
  3410. /**
  3411. * @brief Copies the elements of a Q7 vector.
  3412. * @param[in] pSrc input pointer
  3413. * @param[out] pDst output pointer
  3414. * @param[in] blockSize number of samples to process
  3415. */
  3416. void arm_copy_q7(
  3417. const q7_t * pSrc,
  3418. q7_t * pDst,
  3419. uint32_t blockSize);
  3420. /**
  3421. * @brief Copies the elements of a Q15 vector.
  3422. * @param[in] pSrc input pointer
  3423. * @param[out] pDst output pointer
  3424. * @param[in] blockSize number of samples to process
  3425. */
  3426. void arm_copy_q15(
  3427. const q15_t * pSrc,
  3428. q15_t * pDst,
  3429. uint32_t blockSize);
  3430. /**
  3431. * @brief Copies the elements of a Q31 vector.
  3432. * @param[in] pSrc input pointer
  3433. * @param[out] pDst output pointer
  3434. * @param[in] blockSize number of samples to process
  3435. */
  3436. void arm_copy_q31(
  3437. const q31_t * pSrc,
  3438. q31_t * pDst,
  3439. uint32_t blockSize);
  3440. /**
  3441. * @brief Fills a constant value into a floating-point vector.
  3442. * @param[in] value input value to be filled
  3443. * @param[out] pDst output pointer
  3444. * @param[in] blockSize number of samples to process
  3445. */
  3446. void arm_fill_f32(
  3447. float32_t value,
  3448. float32_t * pDst,
  3449. uint32_t blockSize);
  3450. /**
  3451. * @brief Fills a constant value into a Q7 vector.
  3452. * @param[in] value input value to be filled
  3453. * @param[out] pDst output pointer
  3454. * @param[in] blockSize number of samples to process
  3455. */
  3456. void arm_fill_q7(
  3457. q7_t value,
  3458. q7_t * pDst,
  3459. uint32_t blockSize);
  3460. /**
  3461. * @brief Fills a constant value into a Q15 vector.
  3462. * @param[in] value input value to be filled
  3463. * @param[out] pDst output pointer
  3464. * @param[in] blockSize number of samples to process
  3465. */
  3466. void arm_fill_q15(
  3467. q15_t value,
  3468. q15_t * pDst,
  3469. uint32_t blockSize);
  3470. /**
  3471. * @brief Fills a constant value into a Q31 vector.
  3472. * @param[in] value input value to be filled
  3473. * @param[out] pDst output pointer
  3474. * @param[in] blockSize number of samples to process
  3475. */
  3476. void arm_fill_q31(
  3477. q31_t value,
  3478. q31_t * pDst,
  3479. uint32_t blockSize);
  3480. /**
  3481. * @brief Convolution of floating-point sequences.
  3482. * @param[in] pSrcA points to the first input sequence.
  3483. * @param[in] srcALen length of the first input sequence.
  3484. * @param[in] pSrcB points to the second input sequence.
  3485. * @param[in] srcBLen length of the second input sequence.
  3486. * @param[out] pDst points to the location where the output result is written. Length srcALen+srcBLen-1.
  3487. */
  3488. void arm_conv_f32(
  3489. const float32_t * pSrcA,
  3490. uint32_t srcALen,
  3491. const float32_t * pSrcB,
  3492. uint32_t srcBLen,
  3493. float32_t * pDst);
  3494. /**
  3495. * @brief Convolution of Q15 sequences.
  3496. * @param[in] pSrcA points to the first input sequence.
  3497. * @param[in] srcALen length of the first input sequence.
  3498. * @param[in] pSrcB points to the second input sequence.
  3499. * @param[in] srcBLen length of the second input sequence.
  3500. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3501. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3502. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen).
  3503. */
  3504. void arm_conv_opt_q15(
  3505. const q15_t * pSrcA,
  3506. uint32_t srcALen,
  3507. const q15_t * pSrcB,
  3508. uint32_t srcBLen,
  3509. q15_t * pDst,
  3510. q15_t * pScratch1,
  3511. q15_t * pScratch2);
  3512. /**
  3513. * @brief Convolution of Q15 sequences.
  3514. * @param[in] pSrcA points to the first input sequence.
  3515. * @param[in] srcALen length of the first input sequence.
  3516. * @param[in] pSrcB points to the second input sequence.
  3517. * @param[in] srcBLen length of the second input sequence.
  3518. * @param[out] pDst points to the location where the output result is written. Length srcALen+srcBLen-1.
  3519. */
  3520. void arm_conv_q15(
  3521. const q15_t * pSrcA,
  3522. uint32_t srcALen,
  3523. const q15_t * pSrcB,
  3524. uint32_t srcBLen,
  3525. q15_t * pDst);
  3526. /**
  3527. * @brief Convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4
  3528. * @param[in] pSrcA points to the first input sequence.
  3529. * @param[in] srcALen length of the first input sequence.
  3530. * @param[in] pSrcB points to the second input sequence.
  3531. * @param[in] srcBLen length of the second input sequence.
  3532. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3533. */
  3534. void arm_conv_fast_q15(
  3535. const q15_t * pSrcA,
  3536. uint32_t srcALen,
  3537. const q15_t * pSrcB,
  3538. uint32_t srcBLen,
  3539. q15_t * pDst);
  3540. /**
  3541. * @brief Convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4
  3542. * @param[in] pSrcA points to the first input sequence.
  3543. * @param[in] srcALen length of the first input sequence.
  3544. * @param[in] pSrcB points to the second input sequence.
  3545. * @param[in] srcBLen length of the second input sequence.
  3546. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3547. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3548. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen).
  3549. */
  3550. void arm_conv_fast_opt_q15(
  3551. const q15_t * pSrcA,
  3552. uint32_t srcALen,
  3553. const q15_t * pSrcB,
  3554. uint32_t srcBLen,
  3555. q15_t * pDst,
  3556. q15_t * pScratch1,
  3557. q15_t * pScratch2);
  3558. /**
  3559. * @brief Convolution of Q31 sequences.
  3560. * @param[in] pSrcA points to the first input sequence.
  3561. * @param[in] srcALen length of the first input sequence.
  3562. * @param[in] pSrcB points to the second input sequence.
  3563. * @param[in] srcBLen length of the second input sequence.
  3564. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3565. */
  3566. void arm_conv_q31(
  3567. const q31_t * pSrcA,
  3568. uint32_t srcALen,
  3569. const q31_t * pSrcB,
  3570. uint32_t srcBLen,
  3571. q31_t * pDst);
  3572. /**
  3573. * @brief Convolution of Q31 sequences (fast version) for Cortex-M3 and Cortex-M4
  3574. * @param[in] pSrcA points to the first input sequence.
  3575. * @param[in] srcALen length of the first input sequence.
  3576. * @param[in] pSrcB points to the second input sequence.
  3577. * @param[in] srcBLen length of the second input sequence.
  3578. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3579. */
  3580. void arm_conv_fast_q31(
  3581. const q31_t * pSrcA,
  3582. uint32_t srcALen,
  3583. const q31_t * pSrcB,
  3584. uint32_t srcBLen,
  3585. q31_t * pDst);
  3586. /**
  3587. * @brief Convolution of Q7 sequences.
  3588. * @param[in] pSrcA points to the first input sequence.
  3589. * @param[in] srcALen length of the first input sequence.
  3590. * @param[in] pSrcB points to the second input sequence.
  3591. * @param[in] srcBLen length of the second input sequence.
  3592. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3593. * @param[in] pScratch1 points to scratch buffer(of type q15_t) of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3594. * @param[in] pScratch2 points to scratch buffer (of type q15_t) of size min(srcALen, srcBLen).
  3595. */
  3596. void arm_conv_opt_q7(
  3597. const q7_t * pSrcA,
  3598. uint32_t srcALen,
  3599. const q7_t * pSrcB,
  3600. uint32_t srcBLen,
  3601. q7_t * pDst,
  3602. q15_t * pScratch1,
  3603. q15_t * pScratch2);
  3604. /**
  3605. * @brief Convolution of Q7 sequences.
  3606. * @param[in] pSrcA points to the first input sequence.
  3607. * @param[in] srcALen length of the first input sequence.
  3608. * @param[in] pSrcB points to the second input sequence.
  3609. * @param[in] srcBLen length of the second input sequence.
  3610. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1.
  3611. */
  3612. void arm_conv_q7(
  3613. const q7_t * pSrcA,
  3614. uint32_t srcALen,
  3615. const q7_t * pSrcB,
  3616. uint32_t srcBLen,
  3617. q7_t * pDst);
  3618. /**
  3619. * @brief Partial convolution of floating-point sequences.
  3620. * @param[in] pSrcA points to the first input sequence.
  3621. * @param[in] srcALen length of the first input sequence.
  3622. * @param[in] pSrcB points to the second input sequence.
  3623. * @param[in] srcBLen length of the second input sequence.
  3624. * @param[out] pDst points to the block of output data
  3625. * @param[in] firstIndex is the first output sample to start with.
  3626. * @param[in] numPoints is the number of output points to be computed.
  3627. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3628. */
  3629. arm_status arm_conv_partial_f32(
  3630. const float32_t * pSrcA,
  3631. uint32_t srcALen,
  3632. const float32_t * pSrcB,
  3633. uint32_t srcBLen,
  3634. float32_t * pDst,
  3635. uint32_t firstIndex,
  3636. uint32_t numPoints);
  3637. /**
  3638. * @brief Partial convolution of Q15 sequences.
  3639. * @param[in] pSrcA points to the first input sequence.
  3640. * @param[in] srcALen length of the first input sequence.
  3641. * @param[in] pSrcB points to the second input sequence.
  3642. * @param[in] srcBLen length of the second input sequence.
  3643. * @param[out] pDst points to the block of output data
  3644. * @param[in] firstIndex is the first output sample to start with.
  3645. * @param[in] numPoints is the number of output points to be computed.
  3646. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3647. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen).
  3648. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3649. */
  3650. arm_status arm_conv_partial_opt_q15(
  3651. const q15_t * pSrcA,
  3652. uint32_t srcALen,
  3653. const q15_t * pSrcB,
  3654. uint32_t srcBLen,
  3655. q15_t * pDst,
  3656. uint32_t firstIndex,
  3657. uint32_t numPoints,
  3658. q15_t * pScratch1,
  3659. q15_t * pScratch2);
  3660. /**
  3661. * @brief Partial convolution of Q15 sequences.
  3662. * @param[in] pSrcA points to the first input sequence.
  3663. * @param[in] srcALen length of the first input sequence.
  3664. * @param[in] pSrcB points to the second input sequence.
  3665. * @param[in] srcBLen length of the second input sequence.
  3666. * @param[out] pDst points to the block of output data
  3667. * @param[in] firstIndex is the first output sample to start with.
  3668. * @param[in] numPoints is the number of output points to be computed.
  3669. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3670. */
  3671. arm_status arm_conv_partial_q15(
  3672. const q15_t * pSrcA,
  3673. uint32_t srcALen,
  3674. const q15_t * pSrcB,
  3675. uint32_t srcBLen,
  3676. q15_t * pDst,
  3677. uint32_t firstIndex,
  3678. uint32_t numPoints);
  3679. /**
  3680. * @brief Partial convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4
  3681. * @param[in] pSrcA points to the first input sequence.
  3682. * @param[in] srcALen length of the first input sequence.
  3683. * @param[in] pSrcB points to the second input sequence.
  3684. * @param[in] srcBLen length of the second input sequence.
  3685. * @param[out] pDst points to the block of output data
  3686. * @param[in] firstIndex is the first output sample to start with.
  3687. * @param[in] numPoints is the number of output points to be computed.
  3688. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3689. */
  3690. arm_status arm_conv_partial_fast_q15(
  3691. const q15_t * pSrcA,
  3692. uint32_t srcALen,
  3693. const q15_t * pSrcB,
  3694. uint32_t srcBLen,
  3695. q15_t * pDst,
  3696. uint32_t firstIndex,
  3697. uint32_t numPoints);
  3698. /**
  3699. * @brief Partial convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4
  3700. * @param[in] pSrcA points to the first input sequence.
  3701. * @param[in] srcALen length of the first input sequence.
  3702. * @param[in] pSrcB points to the second input sequence.
  3703. * @param[in] srcBLen length of the second input sequence.
  3704. * @param[out] pDst points to the block of output data
  3705. * @param[in] firstIndex is the first output sample to start with.
  3706. * @param[in] numPoints is the number of output points to be computed.
  3707. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3708. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen).
  3709. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3710. */
  3711. arm_status arm_conv_partial_fast_opt_q15(
  3712. const q15_t * pSrcA,
  3713. uint32_t srcALen,
  3714. const q15_t * pSrcB,
  3715. uint32_t srcBLen,
  3716. q15_t * pDst,
  3717. uint32_t firstIndex,
  3718. uint32_t numPoints,
  3719. q15_t * pScratch1,
  3720. q15_t * pScratch2);
  3721. /**
  3722. * @brief Partial convolution of Q31 sequences.
  3723. * @param[in] pSrcA points to the first input sequence.
  3724. * @param[in] srcALen length of the first input sequence.
  3725. * @param[in] pSrcB points to the second input sequence.
  3726. * @param[in] srcBLen length of the second input sequence.
  3727. * @param[out] pDst points to the block of output data
  3728. * @param[in] firstIndex is the first output sample to start with.
  3729. * @param[in] numPoints is the number of output points to be computed.
  3730. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3731. */
  3732. arm_status arm_conv_partial_q31(
  3733. const q31_t * pSrcA,
  3734. uint32_t srcALen,
  3735. const q31_t * pSrcB,
  3736. uint32_t srcBLen,
  3737. q31_t * pDst,
  3738. uint32_t firstIndex,
  3739. uint32_t numPoints);
  3740. /**
  3741. * @brief Partial convolution of Q31 sequences (fast version) for Cortex-M3 and Cortex-M4
  3742. * @param[in] pSrcA points to the first input sequence.
  3743. * @param[in] srcALen length of the first input sequence.
  3744. * @param[in] pSrcB points to the second input sequence.
  3745. * @param[in] srcBLen length of the second input sequence.
  3746. * @param[out] pDst points to the block of output data
  3747. * @param[in] firstIndex is the first output sample to start with.
  3748. * @param[in] numPoints is the number of output points to be computed.
  3749. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3750. */
  3751. arm_status arm_conv_partial_fast_q31(
  3752. const q31_t * pSrcA,
  3753. uint32_t srcALen,
  3754. const q31_t * pSrcB,
  3755. uint32_t srcBLen,
  3756. q31_t * pDst,
  3757. uint32_t firstIndex,
  3758. uint32_t numPoints);
  3759. /**
  3760. * @brief Partial convolution of Q7 sequences
  3761. * @param[in] pSrcA points to the first input sequence.
  3762. * @param[in] srcALen length of the first input sequence.
  3763. * @param[in] pSrcB points to the second input sequence.
  3764. * @param[in] srcBLen length of the second input sequence.
  3765. * @param[out] pDst points to the block of output data
  3766. * @param[in] firstIndex is the first output sample to start with.
  3767. * @param[in] numPoints is the number of output points to be computed.
  3768. * @param[in] pScratch1 points to scratch buffer(of type q15_t) of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  3769. * @param[in] pScratch2 points to scratch buffer (of type q15_t) of size min(srcALen, srcBLen).
  3770. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3771. */
  3772. arm_status arm_conv_partial_opt_q7(
  3773. const q7_t * pSrcA,
  3774. uint32_t srcALen,
  3775. const q7_t * pSrcB,
  3776. uint32_t srcBLen,
  3777. q7_t * pDst,
  3778. uint32_t firstIndex,
  3779. uint32_t numPoints,
  3780. q15_t * pScratch1,
  3781. q15_t * pScratch2);
  3782. /**
  3783. * @brief Partial convolution of Q7 sequences.
  3784. * @param[in] pSrcA points to the first input sequence.
  3785. * @param[in] srcALen length of the first input sequence.
  3786. * @param[in] pSrcB points to the second input sequence.
  3787. * @param[in] srcBLen length of the second input sequence.
  3788. * @param[out] pDst points to the block of output data
  3789. * @param[in] firstIndex is the first output sample to start with.
  3790. * @param[in] numPoints is the number of output points to be computed.
  3791. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2].
  3792. */
  3793. arm_status arm_conv_partial_q7(
  3794. const q7_t * pSrcA,
  3795. uint32_t srcALen,
  3796. const q7_t * pSrcB,
  3797. uint32_t srcBLen,
  3798. q7_t * pDst,
  3799. uint32_t firstIndex,
  3800. uint32_t numPoints);
  3801. /**
  3802. * @brief Instance structure for the Q15 FIR decimator.
  3803. */
  3804. typedef struct
  3805. {
  3806. uint8_t M; /**< decimation factor. */
  3807. uint16_t numTaps; /**< number of coefficients in the filter. */
  3808. const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  3809. q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  3810. } arm_fir_decimate_instance_q15;
  3811. /**
  3812. * @brief Instance structure for the Q31 FIR decimator.
  3813. */
  3814. typedef struct
  3815. {
  3816. uint8_t M; /**< decimation factor. */
  3817. uint16_t numTaps; /**< number of coefficients in the filter. */
  3818. const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  3819. q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  3820. } arm_fir_decimate_instance_q31;
  3821. /**
  3822. @brief Instance structure for floating-point FIR decimator.
  3823. */
  3824. typedef struct
  3825. {
  3826. uint8_t M; /**< decimation factor. */
  3827. uint16_t numTaps; /**< number of coefficients in the filter. */
  3828. const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  3829. float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  3830. } arm_fir_decimate_instance_f32;
  3831. /**
  3832. @brief Processing function for floating-point FIR decimator.
  3833. @param[in] S points to an instance of the floating-point FIR decimator structure
  3834. @param[in] pSrc points to the block of input data
  3835. @param[out] pDst points to the block of output data
  3836. @param[in] blockSize number of samples to process
  3837. */
  3838. void arm_fir_decimate_f32(
  3839. const arm_fir_decimate_instance_f32 * S,
  3840. const float32_t * pSrc,
  3841. float32_t * pDst,
  3842. uint32_t blockSize);
  3843. /**
  3844. @brief Initialization function for the floating-point FIR decimator.
  3845. @param[in,out] S points to an instance of the floating-point FIR decimator structure
  3846. @param[in] numTaps number of coefficients in the filter
  3847. @param[in] M decimation factor
  3848. @param[in] pCoeffs points to the filter coefficients
  3849. @param[in] pState points to the state buffer
  3850. @param[in] blockSize number of input samples to process per call
  3851. @return execution status
  3852. - \ref ARM_MATH_SUCCESS : Operation successful
  3853. - \ref ARM_MATH_LENGTH_ERROR : <code>blockSize</code> is not a multiple of <code>M</code>
  3854. */
  3855. arm_status arm_fir_decimate_init_f32(
  3856. arm_fir_decimate_instance_f32 * S,
  3857. uint16_t numTaps,
  3858. uint8_t M,
  3859. const float32_t * pCoeffs,
  3860. float32_t * pState,
  3861. uint32_t blockSize);
  3862. /**
  3863. * @brief Processing function for the Q15 FIR decimator.
  3864. * @param[in] S points to an instance of the Q15 FIR decimator structure.
  3865. * @param[in] pSrc points to the block of input data.
  3866. * @param[out] pDst points to the block of output data
  3867. * @param[in] blockSize number of input samples to process per call.
  3868. */
  3869. void arm_fir_decimate_q15(
  3870. const arm_fir_decimate_instance_q15 * S,
  3871. const q15_t * pSrc,
  3872. q15_t * pDst,
  3873. uint32_t blockSize);
  3874. /**
  3875. * @brief Processing function for the Q15 FIR decimator (fast variant) for Cortex-M3 and Cortex-M4.
  3876. * @param[in] S points to an instance of the Q15 FIR decimator structure.
  3877. * @param[in] pSrc points to the block of input data.
  3878. * @param[out] pDst points to the block of output data
  3879. * @param[in] blockSize number of input samples to process per call.
  3880. */
  3881. void arm_fir_decimate_fast_q15(
  3882. const arm_fir_decimate_instance_q15 * S,
  3883. const q15_t * pSrc,
  3884. q15_t * pDst,
  3885. uint32_t blockSize);
  3886. /**
  3887. * @brief Initialization function for the Q15 FIR decimator.
  3888. * @param[in,out] S points to an instance of the Q15 FIR decimator structure.
  3889. * @param[in] numTaps number of coefficients in the filter.
  3890. * @param[in] M decimation factor.
  3891. * @param[in] pCoeffs points to the filter coefficients.
  3892. * @param[in] pState points to the state buffer.
  3893. * @param[in] blockSize number of input samples to process per call.
  3894. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if
  3895. * <code>blockSize</code> is not a multiple of <code>M</code>.
  3896. */
  3897. arm_status arm_fir_decimate_init_q15(
  3898. arm_fir_decimate_instance_q15 * S,
  3899. uint16_t numTaps,
  3900. uint8_t M,
  3901. const q15_t * pCoeffs,
  3902. q15_t * pState,
  3903. uint32_t blockSize);
  3904. /**
  3905. * @brief Processing function for the Q31 FIR decimator.
  3906. * @param[in] S points to an instance of the Q31 FIR decimator structure.
  3907. * @param[in] pSrc points to the block of input data.
  3908. * @param[out] pDst points to the block of output data
  3909. * @param[in] blockSize number of input samples to process per call.
  3910. */
  3911. void arm_fir_decimate_q31(
  3912. const arm_fir_decimate_instance_q31 * S,
  3913. const q31_t * pSrc,
  3914. q31_t * pDst,
  3915. uint32_t blockSize);
  3916. /**
  3917. * @brief Processing function for the Q31 FIR decimator (fast variant) for Cortex-M3 and Cortex-M4.
  3918. * @param[in] S points to an instance of the Q31 FIR decimator structure.
  3919. * @param[in] pSrc points to the block of input data.
  3920. * @param[out] pDst points to the block of output data
  3921. * @param[in] blockSize number of input samples to process per call.
  3922. */
  3923. void arm_fir_decimate_fast_q31(
  3924. const arm_fir_decimate_instance_q31 * S,
  3925. const q31_t * pSrc,
  3926. q31_t * pDst,
  3927. uint32_t blockSize);
  3928. /**
  3929. * @brief Initialization function for the Q31 FIR decimator.
  3930. * @param[in,out] S points to an instance of the Q31 FIR decimator structure.
  3931. * @param[in] numTaps number of coefficients in the filter.
  3932. * @param[in] M decimation factor.
  3933. * @param[in] pCoeffs points to the filter coefficients.
  3934. * @param[in] pState points to the state buffer.
  3935. * @param[in] blockSize number of input samples to process per call.
  3936. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if
  3937. * <code>blockSize</code> is not a multiple of <code>M</code>.
  3938. */
  3939. arm_status arm_fir_decimate_init_q31(
  3940. arm_fir_decimate_instance_q31 * S,
  3941. uint16_t numTaps,
  3942. uint8_t M,
  3943. const q31_t * pCoeffs,
  3944. q31_t * pState,
  3945. uint32_t blockSize);
  3946. /**
  3947. * @brief Instance structure for the Q15 FIR interpolator.
  3948. */
  3949. typedef struct
  3950. {
  3951. uint8_t L; /**< upsample factor. */
  3952. uint16_t phaseLength; /**< length of each polyphase filter component. */
  3953. const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */
  3954. q15_t *pState; /**< points to the state variable array. The array is of length blockSize+phaseLength-1. */
  3955. } arm_fir_interpolate_instance_q15;
  3956. /**
  3957. * @brief Instance structure for the Q31 FIR interpolator.
  3958. */
  3959. typedef struct
  3960. {
  3961. uint8_t L; /**< upsample factor. */
  3962. uint16_t phaseLength; /**< length of each polyphase filter component. */
  3963. const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */
  3964. q31_t *pState; /**< points to the state variable array. The array is of length blockSize+phaseLength-1. */
  3965. } arm_fir_interpolate_instance_q31;
  3966. /**
  3967. * @brief Instance structure for the floating-point FIR interpolator.
  3968. */
  3969. typedef struct
  3970. {
  3971. uint8_t L; /**< upsample factor. */
  3972. uint16_t phaseLength; /**< length of each polyphase filter component. */
  3973. const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */
  3974. float32_t *pState; /**< points to the state variable array. The array is of length phaseLength+numTaps-1. */
  3975. } arm_fir_interpolate_instance_f32;
  3976. /**
  3977. * @brief Processing function for the Q15 FIR interpolator.
  3978. * @param[in] S points to an instance of the Q15 FIR interpolator structure.
  3979. * @param[in] pSrc points to the block of input data.
  3980. * @param[out] pDst points to the block of output data.
  3981. * @param[in] blockSize number of input samples to process per call.
  3982. */
  3983. void arm_fir_interpolate_q15(
  3984. const arm_fir_interpolate_instance_q15 * S,
  3985. const q15_t * pSrc,
  3986. q15_t * pDst,
  3987. uint32_t blockSize);
  3988. /**
  3989. * @brief Initialization function for the Q15 FIR interpolator.
  3990. * @param[in,out] S points to an instance of the Q15 FIR interpolator structure.
  3991. * @param[in] L upsample factor.
  3992. * @param[in] numTaps number of filter coefficients in the filter.
  3993. * @param[in] pCoeffs points to the filter coefficient buffer.
  3994. * @param[in] pState points to the state buffer.
  3995. * @param[in] blockSize number of input samples to process per call.
  3996. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if
  3997. * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>.
  3998. */
  3999. arm_status arm_fir_interpolate_init_q15(
  4000. arm_fir_interpolate_instance_q15 * S,
  4001. uint8_t L,
  4002. uint16_t numTaps,
  4003. const q15_t * pCoeffs,
  4004. q15_t * pState,
  4005. uint32_t blockSize);
  4006. /**
  4007. * @brief Processing function for the Q31 FIR interpolator.
  4008. * @param[in] S points to an instance of the Q15 FIR interpolator structure.
  4009. * @param[in] pSrc points to the block of input data.
  4010. * @param[out] pDst points to the block of output data.
  4011. * @param[in] blockSize number of input samples to process per call.
  4012. */
  4013. void arm_fir_interpolate_q31(
  4014. const arm_fir_interpolate_instance_q31 * S,
  4015. const q31_t * pSrc,
  4016. q31_t * pDst,
  4017. uint32_t blockSize);
  4018. /**
  4019. * @brief Initialization function for the Q31 FIR interpolator.
  4020. * @param[in,out] S points to an instance of the Q31 FIR interpolator structure.
  4021. * @param[in] L upsample factor.
  4022. * @param[in] numTaps number of filter coefficients in the filter.
  4023. * @param[in] pCoeffs points to the filter coefficient buffer.
  4024. * @param[in] pState points to the state buffer.
  4025. * @param[in] blockSize number of input samples to process per call.
  4026. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if
  4027. * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>.
  4028. */
  4029. arm_status arm_fir_interpolate_init_q31(
  4030. arm_fir_interpolate_instance_q31 * S,
  4031. uint8_t L,
  4032. uint16_t numTaps,
  4033. const q31_t * pCoeffs,
  4034. q31_t * pState,
  4035. uint32_t blockSize);
  4036. /**
  4037. * @brief Processing function for the floating-point FIR interpolator.
  4038. * @param[in] S points to an instance of the floating-point FIR interpolator structure.
  4039. * @param[in] pSrc points to the block of input data.
  4040. * @param[out] pDst points to the block of output data.
  4041. * @param[in] blockSize number of input samples to process per call.
  4042. */
  4043. void arm_fir_interpolate_f32(
  4044. const arm_fir_interpolate_instance_f32 * S,
  4045. const float32_t * pSrc,
  4046. float32_t * pDst,
  4047. uint32_t blockSize);
  4048. /**
  4049. * @brief Initialization function for the floating-point FIR interpolator.
  4050. * @param[in,out] S points to an instance of the floating-point FIR interpolator structure.
  4051. * @param[in] L upsample factor.
  4052. * @param[in] numTaps number of filter coefficients in the filter.
  4053. * @param[in] pCoeffs points to the filter coefficient buffer.
  4054. * @param[in] pState points to the state buffer.
  4055. * @param[in] blockSize number of input samples to process per call.
  4056. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if
  4057. * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>.
  4058. */
  4059. arm_status arm_fir_interpolate_init_f32(
  4060. arm_fir_interpolate_instance_f32 * S,
  4061. uint8_t L,
  4062. uint16_t numTaps,
  4063. const float32_t * pCoeffs,
  4064. float32_t * pState,
  4065. uint32_t blockSize);
  4066. /**
  4067. * @brief Instance structure for the high precision Q31 Biquad cascade filter.
  4068. */
  4069. typedef struct
  4070. {
  4071. uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  4072. q63_t *pState; /**< points to the array of state coefficients. The array is of length 4*numStages. */
  4073. const q31_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */
  4074. uint8_t postShift; /**< additional shift, in bits, applied to each output sample. */
  4075. } arm_biquad_cas_df1_32x64_ins_q31;
  4076. /**
  4077. * @param[in] S points to an instance of the high precision Q31 Biquad cascade filter structure.
  4078. * @param[in] pSrc points to the block of input data.
  4079. * @param[out] pDst points to the block of output data
  4080. * @param[in] blockSize number of samples to process.
  4081. */
  4082. void arm_biquad_cas_df1_32x64_q31(
  4083. const arm_biquad_cas_df1_32x64_ins_q31 * S,
  4084. const q31_t * pSrc,
  4085. q31_t * pDst,
  4086. uint32_t blockSize);
  4087. /**
  4088. * @param[in,out] S points to an instance of the high precision Q31 Biquad cascade filter structure.
  4089. * @param[in] numStages number of 2nd order stages in the filter.
  4090. * @param[in] pCoeffs points to the filter coefficients.
  4091. * @param[in] pState points to the state buffer.
  4092. * @param[in] postShift shift to be applied to the output. Varies according to the coefficients format
  4093. */
  4094. void arm_biquad_cas_df1_32x64_init_q31(
  4095. arm_biquad_cas_df1_32x64_ins_q31 * S,
  4096. uint8_t numStages,
  4097. const q31_t * pCoeffs,
  4098. q63_t * pState,
  4099. uint8_t postShift);
  4100. /**
  4101. * @brief Instance structure for the floating-point transposed direct form II Biquad cascade filter.
  4102. */
  4103. typedef struct
  4104. {
  4105. uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  4106. float32_t *pState; /**< points to the array of state coefficients. The array is of length 2*numStages. */
  4107. const float32_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */
  4108. } arm_biquad_cascade_df2T_instance_f32;
  4109. /**
  4110. * @brief Instance structure for the floating-point transposed direct form II Biquad cascade filter.
  4111. */
  4112. typedef struct
  4113. {
  4114. uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  4115. float32_t *pState; /**< points to the array of state coefficients. The array is of length 4*numStages. */
  4116. const float32_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */
  4117. } arm_biquad_cascade_stereo_df2T_instance_f32;
  4118. /**
  4119. * @brief Instance structure for the floating-point transposed direct form II Biquad cascade filter.
  4120. */
  4121. typedef struct
  4122. {
  4123. uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */
  4124. float64_t *pState; /**< points to the array of state coefficients. The array is of length 2*numStages. */
  4125. const float64_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */
  4126. } arm_biquad_cascade_df2T_instance_f64;
  4127. /**
  4128. * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter.
  4129. * @param[in] S points to an instance of the filter data structure.
  4130. * @param[in] pSrc points to the block of input data.
  4131. * @param[out] pDst points to the block of output data
  4132. * @param[in] blockSize number of samples to process.
  4133. */
  4134. void arm_biquad_cascade_df2T_f32(
  4135. const arm_biquad_cascade_df2T_instance_f32 * S,
  4136. const float32_t * pSrc,
  4137. float32_t * pDst,
  4138. uint32_t blockSize);
  4139. /**
  4140. * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter. 2 channels
  4141. * @param[in] S points to an instance of the filter data structure.
  4142. * @param[in] pSrc points to the block of input data.
  4143. * @param[out] pDst points to the block of output data
  4144. * @param[in] blockSize number of samples to process.
  4145. */
  4146. void arm_biquad_cascade_stereo_df2T_f32(
  4147. const arm_biquad_cascade_stereo_df2T_instance_f32 * S,
  4148. const float32_t * pSrc,
  4149. float32_t * pDst,
  4150. uint32_t blockSize);
  4151. /**
  4152. * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter.
  4153. * @param[in] S points to an instance of the filter data structure.
  4154. * @param[in] pSrc points to the block of input data.
  4155. * @param[out] pDst points to the block of output data
  4156. * @param[in] blockSize number of samples to process.
  4157. */
  4158. void arm_biquad_cascade_df2T_f64(
  4159. const arm_biquad_cascade_df2T_instance_f64 * S,
  4160. const float64_t * pSrc,
  4161. float64_t * pDst,
  4162. uint32_t blockSize);
  4163. #if defined(ARM_MATH_NEON)
  4164. void arm_biquad_cascade_df2T_compute_coefs_f32(
  4165. arm_biquad_cascade_df2T_instance_f32 * S,
  4166. uint8_t numStages,
  4167. float32_t * pCoeffs);
  4168. #endif
  4169. /**
  4170. * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter.
  4171. * @param[in,out] S points to an instance of the filter data structure.
  4172. * @param[in] numStages number of 2nd order stages in the filter.
  4173. * @param[in] pCoeffs points to the filter coefficients.
  4174. * @param[in] pState points to the state buffer.
  4175. */
  4176. void arm_biquad_cascade_df2T_init_f32(
  4177. arm_biquad_cascade_df2T_instance_f32 * S,
  4178. uint8_t numStages,
  4179. const float32_t * pCoeffs,
  4180. float32_t * pState);
  4181. /**
  4182. * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter.
  4183. * @param[in,out] S points to an instance of the filter data structure.
  4184. * @param[in] numStages number of 2nd order stages in the filter.
  4185. * @param[in] pCoeffs points to the filter coefficients.
  4186. * @param[in] pState points to the state buffer.
  4187. */
  4188. void arm_biquad_cascade_stereo_df2T_init_f32(
  4189. arm_biquad_cascade_stereo_df2T_instance_f32 * S,
  4190. uint8_t numStages,
  4191. const float32_t * pCoeffs,
  4192. float32_t * pState);
  4193. /**
  4194. * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter.
  4195. * @param[in,out] S points to an instance of the filter data structure.
  4196. * @param[in] numStages number of 2nd order stages in the filter.
  4197. * @param[in] pCoeffs points to the filter coefficients.
  4198. * @param[in] pState points to the state buffer.
  4199. */
  4200. void arm_biquad_cascade_df2T_init_f64(
  4201. arm_biquad_cascade_df2T_instance_f64 * S,
  4202. uint8_t numStages,
  4203. const float64_t * pCoeffs,
  4204. float64_t * pState);
  4205. /**
  4206. * @brief Instance structure for the Q15 FIR lattice filter.
  4207. */
  4208. typedef struct
  4209. {
  4210. uint16_t numStages; /**< number of filter stages. */
  4211. q15_t *pState; /**< points to the state variable array. The array is of length numStages. */
  4212. const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */
  4213. } arm_fir_lattice_instance_q15;
  4214. /**
  4215. * @brief Instance structure for the Q31 FIR lattice filter.
  4216. */
  4217. typedef struct
  4218. {
  4219. uint16_t numStages; /**< number of filter stages. */
  4220. q31_t *pState; /**< points to the state variable array. The array is of length numStages. */
  4221. const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */
  4222. } arm_fir_lattice_instance_q31;
  4223. /**
  4224. * @brief Instance structure for the floating-point FIR lattice filter.
  4225. */
  4226. typedef struct
  4227. {
  4228. uint16_t numStages; /**< number of filter stages. */
  4229. float32_t *pState; /**< points to the state variable array. The array is of length numStages. */
  4230. const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */
  4231. } arm_fir_lattice_instance_f32;
  4232. /**
  4233. * @brief Initialization function for the Q15 FIR lattice filter.
  4234. * @param[in] S points to an instance of the Q15 FIR lattice structure.
  4235. * @param[in] numStages number of filter stages.
  4236. * @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages.
  4237. * @param[in] pState points to the state buffer. The array is of length numStages.
  4238. */
  4239. void arm_fir_lattice_init_q15(
  4240. arm_fir_lattice_instance_q15 * S,
  4241. uint16_t numStages,
  4242. const q15_t * pCoeffs,
  4243. q15_t * pState);
  4244. /**
  4245. * @brief Processing function for the Q15 FIR lattice filter.
  4246. * @param[in] S points to an instance of the Q15 FIR lattice structure.
  4247. * @param[in] pSrc points to the block of input data.
  4248. * @param[out] pDst points to the block of output data.
  4249. * @param[in] blockSize number of samples to process.
  4250. */
  4251. void arm_fir_lattice_q15(
  4252. const arm_fir_lattice_instance_q15 * S,
  4253. const q15_t * pSrc,
  4254. q15_t * pDst,
  4255. uint32_t blockSize);
  4256. /**
  4257. * @brief Initialization function for the Q31 FIR lattice filter.
  4258. * @param[in] S points to an instance of the Q31 FIR lattice structure.
  4259. * @param[in] numStages number of filter stages.
  4260. * @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages.
  4261. * @param[in] pState points to the state buffer. The array is of length numStages.
  4262. */
  4263. void arm_fir_lattice_init_q31(
  4264. arm_fir_lattice_instance_q31 * S,
  4265. uint16_t numStages,
  4266. const q31_t * pCoeffs,
  4267. q31_t * pState);
  4268. /**
  4269. * @brief Processing function for the Q31 FIR lattice filter.
  4270. * @param[in] S points to an instance of the Q31 FIR lattice structure.
  4271. * @param[in] pSrc points to the block of input data.
  4272. * @param[out] pDst points to the block of output data
  4273. * @param[in] blockSize number of samples to process.
  4274. */
  4275. void arm_fir_lattice_q31(
  4276. const arm_fir_lattice_instance_q31 * S,
  4277. const q31_t * pSrc,
  4278. q31_t * pDst,
  4279. uint32_t blockSize);
  4280. /**
  4281. * @brief Initialization function for the floating-point FIR lattice filter.
  4282. * @param[in] S points to an instance of the floating-point FIR lattice structure.
  4283. * @param[in] numStages number of filter stages.
  4284. * @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages.
  4285. * @param[in] pState points to the state buffer. The array is of length numStages.
  4286. */
  4287. void arm_fir_lattice_init_f32(
  4288. arm_fir_lattice_instance_f32 * S,
  4289. uint16_t numStages,
  4290. const float32_t * pCoeffs,
  4291. float32_t * pState);
  4292. /**
  4293. * @brief Processing function for the floating-point FIR lattice filter.
  4294. * @param[in] S points to an instance of the floating-point FIR lattice structure.
  4295. * @param[in] pSrc points to the block of input data.
  4296. * @param[out] pDst points to the block of output data
  4297. * @param[in] blockSize number of samples to process.
  4298. */
  4299. void arm_fir_lattice_f32(
  4300. const arm_fir_lattice_instance_f32 * S,
  4301. const float32_t * pSrc,
  4302. float32_t * pDst,
  4303. uint32_t blockSize);
  4304. /**
  4305. * @brief Instance structure for the Q15 IIR lattice filter.
  4306. */
  4307. typedef struct
  4308. {
  4309. uint16_t numStages; /**< number of stages in the filter. */
  4310. q15_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */
  4311. q15_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */
  4312. q15_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */
  4313. } arm_iir_lattice_instance_q15;
  4314. /**
  4315. * @brief Instance structure for the Q31 IIR lattice filter.
  4316. */
  4317. typedef struct
  4318. {
  4319. uint16_t numStages; /**< number of stages in the filter. */
  4320. q31_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */
  4321. q31_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */
  4322. q31_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */
  4323. } arm_iir_lattice_instance_q31;
  4324. /**
  4325. * @brief Instance structure for the floating-point IIR lattice filter.
  4326. */
  4327. typedef struct
  4328. {
  4329. uint16_t numStages; /**< number of stages in the filter. */
  4330. float32_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */
  4331. float32_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */
  4332. float32_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */
  4333. } arm_iir_lattice_instance_f32;
  4334. /**
  4335. * @brief Processing function for the floating-point IIR lattice filter.
  4336. * @param[in] S points to an instance of the floating-point IIR lattice structure.
  4337. * @param[in] pSrc points to the block of input data.
  4338. * @param[out] pDst points to the block of output data.
  4339. * @param[in] blockSize number of samples to process.
  4340. */
  4341. void arm_iir_lattice_f32(
  4342. const arm_iir_lattice_instance_f32 * S,
  4343. const float32_t * pSrc,
  4344. float32_t * pDst,
  4345. uint32_t blockSize);
  4346. /**
  4347. * @brief Initialization function for the floating-point IIR lattice filter.
  4348. * @param[in] S points to an instance of the floating-point IIR lattice structure.
  4349. * @param[in] numStages number of stages in the filter.
  4350. * @param[in] pkCoeffs points to the reflection coefficient buffer. The array is of length numStages.
  4351. * @param[in] pvCoeffs points to the ladder coefficient buffer. The array is of length numStages+1.
  4352. * @param[in] pState points to the state buffer. The array is of length numStages+blockSize-1.
  4353. * @param[in] blockSize number of samples to process.
  4354. */
  4355. void arm_iir_lattice_init_f32(
  4356. arm_iir_lattice_instance_f32 * S,
  4357. uint16_t numStages,
  4358. float32_t * pkCoeffs,
  4359. float32_t * pvCoeffs,
  4360. float32_t * pState,
  4361. uint32_t blockSize);
  4362. /**
  4363. * @brief Processing function for the Q31 IIR lattice filter.
  4364. * @param[in] S points to an instance of the Q31 IIR lattice structure.
  4365. * @param[in] pSrc points to the block of input data.
  4366. * @param[out] pDst points to the block of output data.
  4367. * @param[in] blockSize number of samples to process.
  4368. */
  4369. void arm_iir_lattice_q31(
  4370. const arm_iir_lattice_instance_q31 * S,
  4371. const q31_t * pSrc,
  4372. q31_t * pDst,
  4373. uint32_t blockSize);
  4374. /**
  4375. * @brief Initialization function for the Q31 IIR lattice filter.
  4376. * @param[in] S points to an instance of the Q31 IIR lattice structure.
  4377. * @param[in] numStages number of stages in the filter.
  4378. * @param[in] pkCoeffs points to the reflection coefficient buffer. The array is of length numStages.
  4379. * @param[in] pvCoeffs points to the ladder coefficient buffer. The array is of length numStages+1.
  4380. * @param[in] pState points to the state buffer. The array is of length numStages+blockSize.
  4381. * @param[in] blockSize number of samples to process.
  4382. */
  4383. void arm_iir_lattice_init_q31(
  4384. arm_iir_lattice_instance_q31 * S,
  4385. uint16_t numStages,
  4386. q31_t * pkCoeffs,
  4387. q31_t * pvCoeffs,
  4388. q31_t * pState,
  4389. uint32_t blockSize);
  4390. /**
  4391. * @brief Processing function for the Q15 IIR lattice filter.
  4392. * @param[in] S points to an instance of the Q15 IIR lattice structure.
  4393. * @param[in] pSrc points to the block of input data.
  4394. * @param[out] pDst points to the block of output data.
  4395. * @param[in] blockSize number of samples to process.
  4396. */
  4397. void arm_iir_lattice_q15(
  4398. const arm_iir_lattice_instance_q15 * S,
  4399. const q15_t * pSrc,
  4400. q15_t * pDst,
  4401. uint32_t blockSize);
  4402. /**
  4403. * @brief Initialization function for the Q15 IIR lattice filter.
  4404. * @param[in] S points to an instance of the fixed-point Q15 IIR lattice structure.
  4405. * @param[in] numStages number of stages in the filter.
  4406. * @param[in] pkCoeffs points to reflection coefficient buffer. The array is of length numStages.
  4407. * @param[in] pvCoeffs points to ladder coefficient buffer. The array is of length numStages+1.
  4408. * @param[in] pState points to state buffer. The array is of length numStages+blockSize.
  4409. * @param[in] blockSize number of samples to process per call.
  4410. */
  4411. void arm_iir_lattice_init_q15(
  4412. arm_iir_lattice_instance_q15 * S,
  4413. uint16_t numStages,
  4414. q15_t * pkCoeffs,
  4415. q15_t * pvCoeffs,
  4416. q15_t * pState,
  4417. uint32_t blockSize);
  4418. /**
  4419. * @brief Instance structure for the floating-point LMS filter.
  4420. */
  4421. typedef struct
  4422. {
  4423. uint16_t numTaps; /**< number of coefficients in the filter. */
  4424. float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4425. float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4426. float32_t mu; /**< step size that controls filter coefficient updates. */
  4427. } arm_lms_instance_f32;
  4428. /**
  4429. * @brief Processing function for floating-point LMS filter.
  4430. * @param[in] S points to an instance of the floating-point LMS filter structure.
  4431. * @param[in] pSrc points to the block of input data.
  4432. * @param[in] pRef points to the block of reference data.
  4433. * @param[out] pOut points to the block of output data.
  4434. * @param[out] pErr points to the block of error data.
  4435. * @param[in] blockSize number of samples to process.
  4436. */
  4437. void arm_lms_f32(
  4438. const arm_lms_instance_f32 * S,
  4439. const float32_t * pSrc,
  4440. float32_t * pRef,
  4441. float32_t * pOut,
  4442. float32_t * pErr,
  4443. uint32_t blockSize);
  4444. /**
  4445. * @brief Initialization function for floating-point LMS filter.
  4446. * @param[in] S points to an instance of the floating-point LMS filter structure.
  4447. * @param[in] numTaps number of filter coefficients.
  4448. * @param[in] pCoeffs points to the coefficient buffer.
  4449. * @param[in] pState points to state buffer.
  4450. * @param[in] mu step size that controls filter coefficient updates.
  4451. * @param[in] blockSize number of samples to process.
  4452. */
  4453. void arm_lms_init_f32(
  4454. arm_lms_instance_f32 * S,
  4455. uint16_t numTaps,
  4456. float32_t * pCoeffs,
  4457. float32_t * pState,
  4458. float32_t mu,
  4459. uint32_t blockSize);
  4460. /**
  4461. * @brief Instance structure for the Q15 LMS filter.
  4462. */
  4463. typedef struct
  4464. {
  4465. uint16_t numTaps; /**< number of coefficients in the filter. */
  4466. q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4467. q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4468. q15_t mu; /**< step size that controls filter coefficient updates. */
  4469. uint32_t postShift; /**< bit shift applied to coefficients. */
  4470. } arm_lms_instance_q15;
  4471. /**
  4472. * @brief Initialization function for the Q15 LMS filter.
  4473. * @param[in] S points to an instance of the Q15 LMS filter structure.
  4474. * @param[in] numTaps number of filter coefficients.
  4475. * @param[in] pCoeffs points to the coefficient buffer.
  4476. * @param[in] pState points to the state buffer.
  4477. * @param[in] mu step size that controls filter coefficient updates.
  4478. * @param[in] blockSize number of samples to process.
  4479. * @param[in] postShift bit shift applied to coefficients.
  4480. */
  4481. void arm_lms_init_q15(
  4482. arm_lms_instance_q15 * S,
  4483. uint16_t numTaps,
  4484. q15_t * pCoeffs,
  4485. q15_t * pState,
  4486. q15_t mu,
  4487. uint32_t blockSize,
  4488. uint32_t postShift);
  4489. /**
  4490. * @brief Processing function for Q15 LMS filter.
  4491. * @param[in] S points to an instance of the Q15 LMS filter structure.
  4492. * @param[in] pSrc points to the block of input data.
  4493. * @param[in] pRef points to the block of reference data.
  4494. * @param[out] pOut points to the block of output data.
  4495. * @param[out] pErr points to the block of error data.
  4496. * @param[in] blockSize number of samples to process.
  4497. */
  4498. void arm_lms_q15(
  4499. const arm_lms_instance_q15 * S,
  4500. const q15_t * pSrc,
  4501. q15_t * pRef,
  4502. q15_t * pOut,
  4503. q15_t * pErr,
  4504. uint32_t blockSize);
  4505. /**
  4506. * @brief Instance structure for the Q31 LMS filter.
  4507. */
  4508. typedef struct
  4509. {
  4510. uint16_t numTaps; /**< number of coefficients in the filter. */
  4511. q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4512. q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4513. q31_t mu; /**< step size that controls filter coefficient updates. */
  4514. uint32_t postShift; /**< bit shift applied to coefficients. */
  4515. } arm_lms_instance_q31;
  4516. /**
  4517. * @brief Processing function for Q31 LMS filter.
  4518. * @param[in] S points to an instance of the Q15 LMS filter structure.
  4519. * @param[in] pSrc points to the block of input data.
  4520. * @param[in] pRef points to the block of reference data.
  4521. * @param[out] pOut points to the block of output data.
  4522. * @param[out] pErr points to the block of error data.
  4523. * @param[in] blockSize number of samples to process.
  4524. */
  4525. void arm_lms_q31(
  4526. const arm_lms_instance_q31 * S,
  4527. const q31_t * pSrc,
  4528. q31_t * pRef,
  4529. q31_t * pOut,
  4530. q31_t * pErr,
  4531. uint32_t blockSize);
  4532. /**
  4533. * @brief Initialization function for Q31 LMS filter.
  4534. * @param[in] S points to an instance of the Q31 LMS filter structure.
  4535. * @param[in] numTaps number of filter coefficients.
  4536. * @param[in] pCoeffs points to coefficient buffer.
  4537. * @param[in] pState points to state buffer.
  4538. * @param[in] mu step size that controls filter coefficient updates.
  4539. * @param[in] blockSize number of samples to process.
  4540. * @param[in] postShift bit shift applied to coefficients.
  4541. */
  4542. void arm_lms_init_q31(
  4543. arm_lms_instance_q31 * S,
  4544. uint16_t numTaps,
  4545. q31_t * pCoeffs,
  4546. q31_t * pState,
  4547. q31_t mu,
  4548. uint32_t blockSize,
  4549. uint32_t postShift);
  4550. /**
  4551. * @brief Instance structure for the floating-point normalized LMS filter.
  4552. */
  4553. typedef struct
  4554. {
  4555. uint16_t numTaps; /**< number of coefficients in the filter. */
  4556. float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4557. float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4558. float32_t mu; /**< step size that control filter coefficient updates. */
  4559. float32_t energy; /**< saves previous frame energy. */
  4560. float32_t x0; /**< saves previous input sample. */
  4561. } arm_lms_norm_instance_f32;
  4562. /**
  4563. * @brief Processing function for floating-point normalized LMS filter.
  4564. * @param[in] S points to an instance of the floating-point normalized LMS filter structure.
  4565. * @param[in] pSrc points to the block of input data.
  4566. * @param[in] pRef points to the block of reference data.
  4567. * @param[out] pOut points to the block of output data.
  4568. * @param[out] pErr points to the block of error data.
  4569. * @param[in] blockSize number of samples to process.
  4570. */
  4571. void arm_lms_norm_f32(
  4572. arm_lms_norm_instance_f32 * S,
  4573. const float32_t * pSrc,
  4574. float32_t * pRef,
  4575. float32_t * pOut,
  4576. float32_t * pErr,
  4577. uint32_t blockSize);
  4578. /**
  4579. * @brief Initialization function for floating-point normalized LMS filter.
  4580. * @param[in] S points to an instance of the floating-point LMS filter structure.
  4581. * @param[in] numTaps number of filter coefficients.
  4582. * @param[in] pCoeffs points to coefficient buffer.
  4583. * @param[in] pState points to state buffer.
  4584. * @param[in] mu step size that controls filter coefficient updates.
  4585. * @param[in] blockSize number of samples to process.
  4586. */
  4587. void arm_lms_norm_init_f32(
  4588. arm_lms_norm_instance_f32 * S,
  4589. uint16_t numTaps,
  4590. float32_t * pCoeffs,
  4591. float32_t * pState,
  4592. float32_t mu,
  4593. uint32_t blockSize);
  4594. /**
  4595. * @brief Instance structure for the Q31 normalized LMS filter.
  4596. */
  4597. typedef struct
  4598. {
  4599. uint16_t numTaps; /**< number of coefficients in the filter. */
  4600. q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4601. q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4602. q31_t mu; /**< step size that controls filter coefficient updates. */
  4603. uint8_t postShift; /**< bit shift applied to coefficients. */
  4604. const q31_t *recipTable; /**< points to the reciprocal initial value table. */
  4605. q31_t energy; /**< saves previous frame energy. */
  4606. q31_t x0; /**< saves previous input sample. */
  4607. } arm_lms_norm_instance_q31;
  4608. /**
  4609. * @brief Processing function for Q31 normalized LMS filter.
  4610. * @param[in] S points to an instance of the Q31 normalized LMS filter structure.
  4611. * @param[in] pSrc points to the block of input data.
  4612. * @param[in] pRef points to the block of reference data.
  4613. * @param[out] pOut points to the block of output data.
  4614. * @param[out] pErr points to the block of error data.
  4615. * @param[in] blockSize number of samples to process.
  4616. */
  4617. void arm_lms_norm_q31(
  4618. arm_lms_norm_instance_q31 * S,
  4619. const q31_t * pSrc,
  4620. q31_t * pRef,
  4621. q31_t * pOut,
  4622. q31_t * pErr,
  4623. uint32_t blockSize);
  4624. /**
  4625. * @brief Initialization function for Q31 normalized LMS filter.
  4626. * @param[in] S points to an instance of the Q31 normalized LMS filter structure.
  4627. * @param[in] numTaps number of filter coefficients.
  4628. * @param[in] pCoeffs points to coefficient buffer.
  4629. * @param[in] pState points to state buffer.
  4630. * @param[in] mu step size that controls filter coefficient updates.
  4631. * @param[in] blockSize number of samples to process.
  4632. * @param[in] postShift bit shift applied to coefficients.
  4633. */
  4634. void arm_lms_norm_init_q31(
  4635. arm_lms_norm_instance_q31 * S,
  4636. uint16_t numTaps,
  4637. q31_t * pCoeffs,
  4638. q31_t * pState,
  4639. q31_t mu,
  4640. uint32_t blockSize,
  4641. uint8_t postShift);
  4642. /**
  4643. * @brief Instance structure for the Q15 normalized LMS filter.
  4644. */
  4645. typedef struct
  4646. {
  4647. uint16_t numTaps; /**< Number of coefficients in the filter. */
  4648. q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */
  4649. q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */
  4650. q15_t mu; /**< step size that controls filter coefficient updates. */
  4651. uint8_t postShift; /**< bit shift applied to coefficients. */
  4652. const q15_t *recipTable; /**< Points to the reciprocal initial value table. */
  4653. q15_t energy; /**< saves previous frame energy. */
  4654. q15_t x0; /**< saves previous input sample. */
  4655. } arm_lms_norm_instance_q15;
  4656. /**
  4657. * @brief Processing function for Q15 normalized LMS filter.
  4658. * @param[in] S points to an instance of the Q15 normalized LMS filter structure.
  4659. * @param[in] pSrc points to the block of input data.
  4660. * @param[in] pRef points to the block of reference data.
  4661. * @param[out] pOut points to the block of output data.
  4662. * @param[out] pErr points to the block of error data.
  4663. * @param[in] blockSize number of samples to process.
  4664. */
  4665. void arm_lms_norm_q15(
  4666. arm_lms_norm_instance_q15 * S,
  4667. const q15_t * pSrc,
  4668. q15_t * pRef,
  4669. q15_t * pOut,
  4670. q15_t * pErr,
  4671. uint32_t blockSize);
  4672. /**
  4673. * @brief Initialization function for Q15 normalized LMS filter.
  4674. * @param[in] S points to an instance of the Q15 normalized LMS filter structure.
  4675. * @param[in] numTaps number of filter coefficients.
  4676. * @param[in] pCoeffs points to coefficient buffer.
  4677. * @param[in] pState points to state buffer.
  4678. * @param[in] mu step size that controls filter coefficient updates.
  4679. * @param[in] blockSize number of samples to process.
  4680. * @param[in] postShift bit shift applied to coefficients.
  4681. */
  4682. void arm_lms_norm_init_q15(
  4683. arm_lms_norm_instance_q15 * S,
  4684. uint16_t numTaps,
  4685. q15_t * pCoeffs,
  4686. q15_t * pState,
  4687. q15_t mu,
  4688. uint32_t blockSize,
  4689. uint8_t postShift);
  4690. /**
  4691. * @brief Correlation of floating-point sequences.
  4692. * @param[in] pSrcA points to the first input sequence.
  4693. * @param[in] srcALen length of the first input sequence.
  4694. * @param[in] pSrcB points to the second input sequence.
  4695. * @param[in] srcBLen length of the second input sequence.
  4696. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4697. */
  4698. void arm_correlate_f32(
  4699. const float32_t * pSrcA,
  4700. uint32_t srcALen,
  4701. const float32_t * pSrcB,
  4702. uint32_t srcBLen,
  4703. float32_t * pDst);
  4704. /**
  4705. @brief Correlation of Q15 sequences
  4706. @param[in] pSrcA points to the first input sequence
  4707. @param[in] srcALen length of the first input sequence
  4708. @param[in] pSrcB points to the second input sequence
  4709. @param[in] srcBLen length of the second input sequence
  4710. @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4711. @param[in] pScratch points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  4712. */
  4713. void arm_correlate_opt_q15(
  4714. const q15_t * pSrcA,
  4715. uint32_t srcALen,
  4716. const q15_t * pSrcB,
  4717. uint32_t srcBLen,
  4718. q15_t * pDst,
  4719. q15_t * pScratch);
  4720. /**
  4721. @brief Correlation of Q15 sequences.
  4722. @param[in] pSrcA points to the first input sequence
  4723. @param[in] srcALen length of the first input sequence
  4724. @param[in] pSrcB points to the second input sequence
  4725. @param[in] srcBLen length of the second input sequence
  4726. @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4727. */
  4728. void arm_correlate_q15(
  4729. const q15_t * pSrcA,
  4730. uint32_t srcALen,
  4731. const q15_t * pSrcB,
  4732. uint32_t srcBLen,
  4733. q15_t * pDst);
  4734. /**
  4735. @brief Correlation of Q15 sequences (fast version).
  4736. @param[in] pSrcA points to the first input sequence
  4737. @param[in] srcALen length of the first input sequence
  4738. @param[in] pSrcB points to the second input sequence
  4739. @param[in] srcBLen length of the second input sequence
  4740. @param[out] pDst points to the location where the output result is written. Length 2 * max(srcALen, srcBLen) - 1.
  4741. @return none
  4742. */
  4743. void arm_correlate_fast_q15(
  4744. const q15_t * pSrcA,
  4745. uint32_t srcALen,
  4746. const q15_t * pSrcB,
  4747. uint32_t srcBLen,
  4748. q15_t * pDst);
  4749. /**
  4750. @brief Correlation of Q15 sequences (fast version).
  4751. @param[in] pSrcA points to the first input sequence.
  4752. @param[in] srcALen length of the first input sequence.
  4753. @param[in] pSrcB points to the second input sequence.
  4754. @param[in] srcBLen length of the second input sequence.
  4755. @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4756. @param[in] pScratch points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  4757. */
  4758. void arm_correlate_fast_opt_q15(
  4759. const q15_t * pSrcA,
  4760. uint32_t srcALen,
  4761. const q15_t * pSrcB,
  4762. uint32_t srcBLen,
  4763. q15_t * pDst,
  4764. q15_t * pScratch);
  4765. /**
  4766. * @brief Correlation of Q31 sequences.
  4767. * @param[in] pSrcA points to the first input sequence.
  4768. * @param[in] srcALen length of the first input sequence.
  4769. * @param[in] pSrcB points to the second input sequence.
  4770. * @param[in] srcBLen length of the second input sequence.
  4771. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4772. */
  4773. void arm_correlate_q31(
  4774. const q31_t * pSrcA,
  4775. uint32_t srcALen,
  4776. const q31_t * pSrcB,
  4777. uint32_t srcBLen,
  4778. q31_t * pDst);
  4779. /**
  4780. @brief Correlation of Q31 sequences (fast version).
  4781. @param[in] pSrcA points to the first input sequence
  4782. @param[in] srcALen length of the first input sequence
  4783. @param[in] pSrcB points to the second input sequence
  4784. @param[in] srcBLen length of the second input sequence
  4785. @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4786. */
  4787. void arm_correlate_fast_q31(
  4788. const q31_t * pSrcA,
  4789. uint32_t srcALen,
  4790. const q31_t * pSrcB,
  4791. uint32_t srcBLen,
  4792. q31_t * pDst);
  4793. /**
  4794. * @brief Correlation of Q7 sequences.
  4795. * @param[in] pSrcA points to the first input sequence.
  4796. * @param[in] srcALen length of the first input sequence.
  4797. * @param[in] pSrcB points to the second input sequence.
  4798. * @param[in] srcBLen length of the second input sequence.
  4799. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4800. * @param[in] pScratch1 points to scratch buffer(of type q15_t) of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2.
  4801. * @param[in] pScratch2 points to scratch buffer (of type q15_t) of size min(srcALen, srcBLen).
  4802. */
  4803. void arm_correlate_opt_q7(
  4804. const q7_t * pSrcA,
  4805. uint32_t srcALen,
  4806. const q7_t * pSrcB,
  4807. uint32_t srcBLen,
  4808. q7_t * pDst,
  4809. q15_t * pScratch1,
  4810. q15_t * pScratch2);
  4811. /**
  4812. * @brief Correlation of Q7 sequences.
  4813. * @param[in] pSrcA points to the first input sequence.
  4814. * @param[in] srcALen length of the first input sequence.
  4815. * @param[in] pSrcB points to the second input sequence.
  4816. * @param[in] srcBLen length of the second input sequence.
  4817. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1.
  4818. */
  4819. void arm_correlate_q7(
  4820. const q7_t * pSrcA,
  4821. uint32_t srcALen,
  4822. const q7_t * pSrcB,
  4823. uint32_t srcBLen,
  4824. q7_t * pDst);
  4825. /**
  4826. * @brief Instance structure for the floating-point sparse FIR filter.
  4827. */
  4828. typedef struct
  4829. {
  4830. uint16_t numTaps; /**< number of coefficients in the filter. */
  4831. uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */
  4832. float32_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */
  4833. const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  4834. uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */
  4835. int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */
  4836. } arm_fir_sparse_instance_f32;
  4837. /**
  4838. * @brief Instance structure for the Q31 sparse FIR filter.
  4839. */
  4840. typedef struct
  4841. {
  4842. uint16_t numTaps; /**< number of coefficients in the filter. */
  4843. uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */
  4844. q31_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */
  4845. const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  4846. uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */
  4847. int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */
  4848. } arm_fir_sparse_instance_q31;
  4849. /**
  4850. * @brief Instance structure for the Q15 sparse FIR filter.
  4851. */
  4852. typedef struct
  4853. {
  4854. uint16_t numTaps; /**< number of coefficients in the filter. */
  4855. uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */
  4856. q15_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */
  4857. const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  4858. uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */
  4859. int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */
  4860. } arm_fir_sparse_instance_q15;
  4861. /**
  4862. * @brief Instance structure for the Q7 sparse FIR filter.
  4863. */
  4864. typedef struct
  4865. {
  4866. uint16_t numTaps; /**< number of coefficients in the filter. */
  4867. uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */
  4868. q7_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */
  4869. const q7_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/
  4870. uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */
  4871. int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */
  4872. } arm_fir_sparse_instance_q7;
  4873. /**
  4874. * @brief Processing function for the floating-point sparse FIR filter.
  4875. * @param[in] S points to an instance of the floating-point sparse FIR structure.
  4876. * @param[in] pSrc points to the block of input data.
  4877. * @param[out] pDst points to the block of output data
  4878. * @param[in] pScratchIn points to a temporary buffer of size blockSize.
  4879. * @param[in] blockSize number of input samples to process per call.
  4880. */
  4881. void arm_fir_sparse_f32(
  4882. arm_fir_sparse_instance_f32 * S,
  4883. const float32_t * pSrc,
  4884. float32_t * pDst,
  4885. float32_t * pScratchIn,
  4886. uint32_t blockSize);
  4887. /**
  4888. * @brief Initialization function for the floating-point sparse FIR filter.
  4889. * @param[in,out] S points to an instance of the floating-point sparse FIR structure.
  4890. * @param[in] numTaps number of nonzero coefficients in the filter.
  4891. * @param[in] pCoeffs points to the array of filter coefficients.
  4892. * @param[in] pState points to the state buffer.
  4893. * @param[in] pTapDelay points to the array of offset times.
  4894. * @param[in] maxDelay maximum offset time supported.
  4895. * @param[in] blockSize number of samples that will be processed per block.
  4896. */
  4897. void arm_fir_sparse_init_f32(
  4898. arm_fir_sparse_instance_f32 * S,
  4899. uint16_t numTaps,
  4900. const float32_t * pCoeffs,
  4901. float32_t * pState,
  4902. int32_t * pTapDelay,
  4903. uint16_t maxDelay,
  4904. uint32_t blockSize);
  4905. /**
  4906. * @brief Processing function for the Q31 sparse FIR filter.
  4907. * @param[in] S points to an instance of the Q31 sparse FIR structure.
  4908. * @param[in] pSrc points to the block of input data.
  4909. * @param[out] pDst points to the block of output data
  4910. * @param[in] pScratchIn points to a temporary buffer of size blockSize.
  4911. * @param[in] blockSize number of input samples to process per call.
  4912. */
  4913. void arm_fir_sparse_q31(
  4914. arm_fir_sparse_instance_q31 * S,
  4915. const q31_t * pSrc,
  4916. q31_t * pDst,
  4917. q31_t * pScratchIn,
  4918. uint32_t blockSize);
  4919. /**
  4920. * @brief Initialization function for the Q31 sparse FIR filter.
  4921. * @param[in,out] S points to an instance of the Q31 sparse FIR structure.
  4922. * @param[in] numTaps number of nonzero coefficients in the filter.
  4923. * @param[in] pCoeffs points to the array of filter coefficients.
  4924. * @param[in] pState points to the state buffer.
  4925. * @param[in] pTapDelay points to the array of offset times.
  4926. * @param[in] maxDelay maximum offset time supported.
  4927. * @param[in] blockSize number of samples that will be processed per block.
  4928. */
  4929. void arm_fir_sparse_init_q31(
  4930. arm_fir_sparse_instance_q31 * S,
  4931. uint16_t numTaps,
  4932. const q31_t * pCoeffs,
  4933. q31_t * pState,
  4934. int32_t * pTapDelay,
  4935. uint16_t maxDelay,
  4936. uint32_t blockSize);
  4937. /**
  4938. * @brief Processing function for the Q15 sparse FIR filter.
  4939. * @param[in] S points to an instance of the Q15 sparse FIR structure.
  4940. * @param[in] pSrc points to the block of input data.
  4941. * @param[out] pDst points to the block of output data
  4942. * @param[in] pScratchIn points to a temporary buffer of size blockSize.
  4943. * @param[in] pScratchOut points to a temporary buffer of size blockSize.
  4944. * @param[in] blockSize number of input samples to process per call.
  4945. */
  4946. void arm_fir_sparse_q15(
  4947. arm_fir_sparse_instance_q15 * S,
  4948. const q15_t * pSrc,
  4949. q15_t * pDst,
  4950. q15_t * pScratchIn,
  4951. q31_t * pScratchOut,
  4952. uint32_t blockSize);
  4953. /**
  4954. * @brief Initialization function for the Q15 sparse FIR filter.
  4955. * @param[in,out] S points to an instance of the Q15 sparse FIR structure.
  4956. * @param[in] numTaps number of nonzero coefficients in the filter.
  4957. * @param[in] pCoeffs points to the array of filter coefficients.
  4958. * @param[in] pState points to the state buffer.
  4959. * @param[in] pTapDelay points to the array of offset times.
  4960. * @param[in] maxDelay maximum offset time supported.
  4961. * @param[in] blockSize number of samples that will be processed per block.
  4962. */
  4963. void arm_fir_sparse_init_q15(
  4964. arm_fir_sparse_instance_q15 * S,
  4965. uint16_t numTaps,
  4966. const q15_t * pCoeffs,
  4967. q15_t * pState,
  4968. int32_t * pTapDelay,
  4969. uint16_t maxDelay,
  4970. uint32_t blockSize);
  4971. /**
  4972. * @brief Processing function for the Q7 sparse FIR filter.
  4973. * @param[in] S points to an instance of the Q7 sparse FIR structure.
  4974. * @param[in] pSrc points to the block of input data.
  4975. * @param[out] pDst points to the block of output data
  4976. * @param[in] pScratchIn points to a temporary buffer of size blockSize.
  4977. * @param[in] pScratchOut points to a temporary buffer of size blockSize.
  4978. * @param[in] blockSize number of input samples to process per call.
  4979. */
  4980. void arm_fir_sparse_q7(
  4981. arm_fir_sparse_instance_q7 * S,
  4982. const q7_t * pSrc,
  4983. q7_t * pDst,
  4984. q7_t * pScratchIn,
  4985. q31_t * pScratchOut,
  4986. uint32_t blockSize);
  4987. /**
  4988. * @brief Initialization function for the Q7 sparse FIR filter.
  4989. * @param[in,out] S points to an instance of the Q7 sparse FIR structure.
  4990. * @param[in] numTaps number of nonzero coefficients in the filter.
  4991. * @param[in] pCoeffs points to the array of filter coefficients.
  4992. * @param[in] pState points to the state buffer.
  4993. * @param[in] pTapDelay points to the array of offset times.
  4994. * @param[in] maxDelay maximum offset time supported.
  4995. * @param[in] blockSize number of samples that will be processed per block.
  4996. */
  4997. void arm_fir_sparse_init_q7(
  4998. arm_fir_sparse_instance_q7 * S,
  4999. uint16_t numTaps,
  5000. const q7_t * pCoeffs,
  5001. q7_t * pState,
  5002. int32_t * pTapDelay,
  5003. uint16_t maxDelay,
  5004. uint32_t blockSize);
  5005. /**
  5006. * @brief Floating-point sin_cos function.
  5007. * @param[in] theta input value in degrees
  5008. * @param[out] pSinVal points to the processed sine output.
  5009. * @param[out] pCosVal points to the processed cos output.
  5010. */
  5011. void arm_sin_cos_f32(
  5012. float32_t theta,
  5013. float32_t * pSinVal,
  5014. float32_t * pCosVal);
  5015. /**
  5016. * @brief Q31 sin_cos function.
  5017. * @param[in] theta scaled input value in degrees
  5018. * @param[out] pSinVal points to the processed sine output.
  5019. * @param[out] pCosVal points to the processed cosine output.
  5020. */
  5021. void arm_sin_cos_q31(
  5022. q31_t theta,
  5023. q31_t * pSinVal,
  5024. q31_t * pCosVal);
  5025. /**
  5026. * @brief Floating-point complex conjugate.
  5027. * @param[in] pSrc points to the input vector
  5028. * @param[out] pDst points to the output vector
  5029. * @param[in] numSamples number of complex samples in each vector
  5030. */
  5031. void arm_cmplx_conj_f32(
  5032. const float32_t * pSrc,
  5033. float32_t * pDst,
  5034. uint32_t numSamples);
  5035. /**
  5036. * @brief Q31 complex conjugate.
  5037. * @param[in] pSrc points to the input vector
  5038. * @param[out] pDst points to the output vector
  5039. * @param[in] numSamples number of complex samples in each vector
  5040. */
  5041. void arm_cmplx_conj_q31(
  5042. const q31_t * pSrc,
  5043. q31_t * pDst,
  5044. uint32_t numSamples);
  5045. /**
  5046. * @brief Q15 complex conjugate.
  5047. * @param[in] pSrc points to the input vector
  5048. * @param[out] pDst points to the output vector
  5049. * @param[in] numSamples number of complex samples in each vector
  5050. */
  5051. void arm_cmplx_conj_q15(
  5052. const q15_t * pSrc,
  5053. q15_t * pDst,
  5054. uint32_t numSamples);
  5055. /**
  5056. * @brief Floating-point complex magnitude squared
  5057. * @param[in] pSrc points to the complex input vector
  5058. * @param[out] pDst points to the real output vector
  5059. * @param[in] numSamples number of complex samples in the input vector
  5060. */
  5061. void arm_cmplx_mag_squared_f32(
  5062. const float32_t * pSrc,
  5063. float32_t * pDst,
  5064. uint32_t numSamples);
  5065. /**
  5066. * @brief Q31 complex magnitude squared
  5067. * @param[in] pSrc points to the complex input vector
  5068. * @param[out] pDst points to the real output vector
  5069. * @param[in] numSamples number of complex samples in the input vector
  5070. */
  5071. void arm_cmplx_mag_squared_q31(
  5072. const q31_t * pSrc,
  5073. q31_t * pDst,
  5074. uint32_t numSamples);
  5075. /**
  5076. * @brief Q15 complex magnitude squared
  5077. * @param[in] pSrc points to the complex input vector
  5078. * @param[out] pDst points to the real output vector
  5079. * @param[in] numSamples number of complex samples in the input vector
  5080. */
  5081. void arm_cmplx_mag_squared_q15(
  5082. const q15_t * pSrc,
  5083. q15_t * pDst,
  5084. uint32_t numSamples);
  5085. /**
  5086. * @ingroup groupController
  5087. */
  5088. /**
  5089. * @defgroup PID PID Motor Control
  5090. *
  5091. * A Proportional Integral Derivative (PID) controller is a generic feedback control
  5092. * loop mechanism widely used in industrial control systems.
  5093. * A PID controller is the most commonly used type of feedback controller.
  5094. *
  5095. * This set of functions implements (PID) controllers
  5096. * for Q15, Q31, and floating-point data types. The functions operate on a single sample
  5097. * of data and each call to the function returns a single processed value.
  5098. * <code>S</code> points to an instance of the PID control data structure. <code>in</code>
  5099. * is the input sample value. The functions return the output value.
  5100. *
  5101. * \par Algorithm:
  5102. * <pre>
  5103. * y[n] = y[n-1] + A0 * x[n] + A1 * x[n-1] + A2 * x[n-2]
  5104. * A0 = Kp + Ki + Kd
  5105. * A1 = (-Kp ) - (2 * Kd )
  5106. * A2 = Kd
  5107. * </pre>
  5108. *
  5109. * \par
  5110. * where \c Kp is proportional constant, \c Ki is Integral constant and \c Kd is Derivative constant
  5111. *
  5112. * \par
  5113. * \image html PID.gif "Proportional Integral Derivative Controller"
  5114. *
  5115. * \par
  5116. * The PID controller calculates an "error" value as the difference between
  5117. * the measured output and the reference input.
  5118. * The controller attempts to minimize the error by adjusting the process control inputs.
  5119. * The proportional value determines the reaction to the current error,
  5120. * the integral value determines the reaction based on the sum of recent errors,
  5121. * and the derivative value determines the reaction based on the rate at which the error has been changing.
  5122. *
  5123. * \par Instance Structure
  5124. * The Gains A0, A1, A2 and state variables for a PID controller are stored together in an instance data structure.
  5125. * A separate instance structure must be defined for each PID Controller.
  5126. * There are separate instance structure declarations for each of the 3 supported data types.
  5127. *
  5128. * \par Reset Functions
  5129. * There is also an associated reset function for each data type which clears the state array.
  5130. *
  5131. * \par Initialization Functions
  5132. * There is also an associated initialization function for each data type.
  5133. * The initialization function performs the following operations:
  5134. * - Initializes the Gains A0, A1, A2 from Kp,Ki, Kd gains.
  5135. * - Zeros out the values in the state buffer.
  5136. *
  5137. * \par
  5138. * Instance structure cannot be placed into a const data section and it is recommended to use the initialization function.
  5139. *
  5140. * \par Fixed-Point Behavior
  5141. * Care must be taken when using the fixed-point versions of the PID Controller functions.
  5142. * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered.
  5143. * Refer to the function specific documentation below for usage guidelines.
  5144. */
  5145. /**
  5146. * @addtogroup PID
  5147. * @{
  5148. */
  5149. /**
  5150. * @brief Process function for the floating-point PID Control.
  5151. * @param[in,out] S is an instance of the floating-point PID Control structure
  5152. * @param[in] in input sample to process
  5153. * @return processed output sample.
  5154. */
  5155. __STATIC_FORCEINLINE float32_t arm_pid_f32(
  5156. arm_pid_instance_f32 * S,
  5157. float32_t in)
  5158. {
  5159. float32_t out;
  5160. /* y[n] = y[n-1] + A0 * x[n] + A1 * x[n-1] + A2 * x[n-2] */
  5161. out = (S->A0 * in) +
  5162. (S->A1 * S->state[0]) + (S->A2 * S->state[1]) + (S->state[2]);
  5163. /* Update state */
  5164. S->state[1] = S->state[0];
  5165. S->state[0] = in;
  5166. S->state[2] = out;
  5167. /* return to application */
  5168. return (out);
  5169. }
  5170. /**
  5171. @brief Process function for the Q31 PID Control.
  5172. @param[in,out] S points to an instance of the Q31 PID Control structure
  5173. @param[in] in input sample to process
  5174. @return processed output sample.
  5175. \par Scaling and Overflow Behavior
  5176. The function is implemented using an internal 64-bit accumulator.
  5177. The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit.
  5178. Thus, if the accumulator result overflows it wraps around rather than clip.
  5179. In order to avoid overflows completely the input signal must be scaled down by 2 bits as there are four additions.
  5180. After all multiply-accumulates are performed, the 2.62 accumulator is truncated to 1.32 format and then saturated to 1.31 format.
  5181. */
  5182. __STATIC_FORCEINLINE q31_t arm_pid_q31(
  5183. arm_pid_instance_q31 * S,
  5184. q31_t in)
  5185. {
  5186. q63_t acc;
  5187. q31_t out;
  5188. /* acc = A0 * x[n] */
  5189. acc = (q63_t) S->A0 * in;
  5190. /* acc += A1 * x[n-1] */
  5191. acc += (q63_t) S->A1 * S->state[0];
  5192. /* acc += A2 * x[n-2] */
  5193. acc += (q63_t) S->A2 * S->state[1];
  5194. /* convert output to 1.31 format to add y[n-1] */
  5195. out = (q31_t) (acc >> 31U);
  5196. /* out += y[n-1] */
  5197. out += S->state[2];
  5198. /* Update state */
  5199. S->state[1] = S->state[0];
  5200. S->state[0] = in;
  5201. S->state[2] = out;
  5202. /* return to application */
  5203. return (out);
  5204. }
  5205. /**
  5206. @brief Process function for the Q15 PID Control.
  5207. @param[in,out] S points to an instance of the Q15 PID Control structure
  5208. @param[in] in input sample to process
  5209. @return processed output sample.
  5210. \par Scaling and Overflow Behavior
  5211. The function is implemented using a 64-bit internal accumulator.
  5212. Both Gains and state variables are represented in 1.15 format and multiplications yield a 2.30 result.
  5213. The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format.
  5214. There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved.
  5215. After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits.
  5216. Lastly, the accumulator is saturated to yield a result in 1.15 format.
  5217. */
  5218. __STATIC_FORCEINLINE q15_t arm_pid_q15(
  5219. arm_pid_instance_q15 * S,
  5220. q15_t in)
  5221. {
  5222. q63_t acc;
  5223. q15_t out;
  5224. #if defined (ARM_MATH_DSP)
  5225. /* Implementation of PID controller */
  5226. /* acc = A0 * x[n] */
  5227. acc = (q31_t) __SMUAD((uint32_t)S->A0, (uint32_t)in);
  5228. /* acc += A1 * x[n-1] + A2 * x[n-2] */
  5229. acc = (q63_t)__SMLALD((uint32_t)S->A1, (uint32_t)read_q15x2 (S->state), (uint64_t)acc);
  5230. #else
  5231. /* acc = A0 * x[n] */
  5232. acc = ((q31_t) S->A0) * in;
  5233. /* acc += A1 * x[n-1] + A2 * x[n-2] */
  5234. acc += (q31_t) S->A1 * S->state[0];
  5235. acc += (q31_t) S->A2 * S->state[1];
  5236. #endif
  5237. /* acc += y[n-1] */
  5238. acc += (q31_t) S->state[2] << 15;
  5239. /* saturate the output */
  5240. out = (q15_t) (__SSAT((q31_t)(acc >> 15), 16));
  5241. /* Update state */
  5242. S->state[1] = S->state[0];
  5243. S->state[0] = in;
  5244. S->state[2] = out;
  5245. /* return to application */
  5246. return (out);
  5247. }
  5248. /**
  5249. * @} end of PID group
  5250. */
  5251. /**
  5252. * @brief Floating-point matrix inverse.
  5253. * @param[in] src points to the instance of the input floating-point matrix structure.
  5254. * @param[out] dst points to the instance of the output floating-point matrix structure.
  5255. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  5256. * If the input matrix is singular (does not have an inverse), then the algorithm terminates and returns error status ARM_MATH_SINGULAR.
  5257. */
  5258. arm_status arm_mat_inverse_f32(
  5259. const arm_matrix_instance_f32 * src,
  5260. arm_matrix_instance_f32 * dst);
  5261. /**
  5262. * @brief Floating-point matrix inverse.
  5263. * @param[in] src points to the instance of the input floating-point matrix structure.
  5264. * @param[out] dst points to the instance of the output floating-point matrix structure.
  5265. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match.
  5266. * If the input matrix is singular (does not have an inverse), then the algorithm terminates and returns error status ARM_MATH_SINGULAR.
  5267. */
  5268. arm_status arm_mat_inverse_f64(
  5269. const arm_matrix_instance_f64 * src,
  5270. arm_matrix_instance_f64 * dst);
  5271. /**
  5272. * @ingroup groupController
  5273. */
  5274. /**
  5275. * @defgroup clarke Vector Clarke Transform
  5276. * Forward Clarke transform converts the instantaneous stator phases into a two-coordinate time invariant vector.
  5277. * Generally the Clarke transform uses three-phase currents <code>Ia, Ib and Ic</code> to calculate currents
  5278. * in the two-phase orthogonal stator axis <code>Ialpha</code> and <code>Ibeta</code>.
  5279. * When <code>Ialpha</code> is superposed with <code>Ia</code> as shown in the figure below
  5280. * \image html clarke.gif Stator current space vector and its components in (a,b).
  5281. * and <code>Ia + Ib + Ic = 0</code>, in this condition <code>Ialpha</code> and <code>Ibeta</code>
  5282. * can be calculated using only <code>Ia</code> and <code>Ib</code>.
  5283. *
  5284. * The function operates on a single sample of data and each call to the function returns the processed output.
  5285. * The library provides separate functions for Q31 and floating-point data types.
  5286. * \par Algorithm
  5287. * \image html clarkeFormula.gif
  5288. * where <code>Ia</code> and <code>Ib</code> are the instantaneous stator phases and
  5289. * <code>pIalpha</code> and <code>pIbeta</code> are the two coordinates of time invariant vector.
  5290. * \par Fixed-Point Behavior
  5291. * Care must be taken when using the Q31 version of the Clarke transform.
  5292. * In particular, the overflow and saturation behavior of the accumulator used must be considered.
  5293. * Refer to the function specific documentation below for usage guidelines.
  5294. */
  5295. /**
  5296. * @addtogroup clarke
  5297. * @{
  5298. */
  5299. /**
  5300. *
  5301. * @brief Floating-point Clarke transform
  5302. * @param[in] Ia input three-phase coordinate <code>a</code>
  5303. * @param[in] Ib input three-phase coordinate <code>b</code>
  5304. * @param[out] pIalpha points to output two-phase orthogonal vector axis alpha
  5305. * @param[out] pIbeta points to output two-phase orthogonal vector axis beta
  5306. * @return none
  5307. */
  5308. __STATIC_FORCEINLINE void arm_clarke_f32(
  5309. float32_t Ia,
  5310. float32_t Ib,
  5311. float32_t * pIalpha,
  5312. float32_t * pIbeta)
  5313. {
  5314. /* Calculate pIalpha using the equation, pIalpha = Ia */
  5315. *pIalpha = Ia;
  5316. /* Calculate pIbeta using the equation, pIbeta = (1/sqrt(3)) * Ia + (2/sqrt(3)) * Ib */
  5317. *pIbeta = ((float32_t) 0.57735026919 * Ia + (float32_t) 1.15470053838 * Ib);
  5318. }
  5319. /**
  5320. @brief Clarke transform for Q31 version
  5321. @param[in] Ia input three-phase coordinate <code>a</code>
  5322. @param[in] Ib input three-phase coordinate <code>b</code>
  5323. @param[out] pIalpha points to output two-phase orthogonal vector axis alpha
  5324. @param[out] pIbeta points to output two-phase orthogonal vector axis beta
  5325. @return none
  5326. \par Scaling and Overflow Behavior
  5327. The function is implemented using an internal 32-bit accumulator.
  5328. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format.
  5329. There is saturation on the addition, hence there is no risk of overflow.
  5330. */
  5331. __STATIC_FORCEINLINE void arm_clarke_q31(
  5332. q31_t Ia,
  5333. q31_t Ib,
  5334. q31_t * pIalpha,
  5335. q31_t * pIbeta)
  5336. {
  5337. q31_t product1, product2; /* Temporary variables used to store intermediate results */
  5338. /* Calculating pIalpha from Ia by equation pIalpha = Ia */
  5339. *pIalpha = Ia;
  5340. /* Intermediate product is calculated by (1/(sqrt(3)) * Ia) */
  5341. product1 = (q31_t) (((q63_t) Ia * 0x24F34E8B) >> 30);
  5342. /* Intermediate product is calculated by (2/sqrt(3) * Ib) */
  5343. product2 = (q31_t) (((q63_t) Ib * 0x49E69D16) >> 30);
  5344. /* pIbeta is calculated by adding the intermediate products */
  5345. *pIbeta = __QADD(product1, product2);
  5346. }
  5347. /**
  5348. * @} end of clarke group
  5349. */
  5350. /**
  5351. * @ingroup groupController
  5352. */
  5353. /**
  5354. * @defgroup inv_clarke Vector Inverse Clarke Transform
  5355. * Inverse Clarke transform converts the two-coordinate time invariant vector into instantaneous stator phases.
  5356. *
  5357. * The function operates on a single sample of data and each call to the function returns the processed output.
  5358. * The library provides separate functions for Q31 and floating-point data types.
  5359. * \par Algorithm
  5360. * \image html clarkeInvFormula.gif
  5361. * where <code>pIa</code> and <code>pIb</code> are the instantaneous stator phases and
  5362. * <code>Ialpha</code> and <code>Ibeta</code> are the two coordinates of time invariant vector.
  5363. * \par Fixed-Point Behavior
  5364. * Care must be taken when using the Q31 version of the Clarke transform.
  5365. * In particular, the overflow and saturation behavior of the accumulator used must be considered.
  5366. * Refer to the function specific documentation below for usage guidelines.
  5367. */
  5368. /**
  5369. * @addtogroup inv_clarke
  5370. * @{
  5371. */
  5372. /**
  5373. * @brief Floating-point Inverse Clarke transform
  5374. * @param[in] Ialpha input two-phase orthogonal vector axis alpha
  5375. * @param[in] Ibeta input two-phase orthogonal vector axis beta
  5376. * @param[out] pIa points to output three-phase coordinate <code>a</code>
  5377. * @param[out] pIb points to output three-phase coordinate <code>b</code>
  5378. * @return none
  5379. */
  5380. __STATIC_FORCEINLINE void arm_inv_clarke_f32(
  5381. float32_t Ialpha,
  5382. float32_t Ibeta,
  5383. float32_t * pIa,
  5384. float32_t * pIb)
  5385. {
  5386. /* Calculating pIa from Ialpha by equation pIa = Ialpha */
  5387. *pIa = Ialpha;
  5388. /* Calculating pIb from Ialpha and Ibeta by equation pIb = -(1/2) * Ialpha + (sqrt(3)/2) * Ibeta */
  5389. *pIb = -0.5f * Ialpha + 0.8660254039f * Ibeta;
  5390. }
  5391. /**
  5392. @brief Inverse Clarke transform for Q31 version
  5393. @param[in] Ialpha input two-phase orthogonal vector axis alpha
  5394. @param[in] Ibeta input two-phase orthogonal vector axis beta
  5395. @param[out] pIa points to output three-phase coordinate <code>a</code>
  5396. @param[out] pIb points to output three-phase coordinate <code>b</code>
  5397. @return none
  5398. \par Scaling and Overflow Behavior
  5399. The function is implemented using an internal 32-bit accumulator.
  5400. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format.
  5401. There is saturation on the subtraction, hence there is no risk of overflow.
  5402. */
  5403. __STATIC_FORCEINLINE void arm_inv_clarke_q31(
  5404. q31_t Ialpha,
  5405. q31_t Ibeta,
  5406. q31_t * pIa,
  5407. q31_t * pIb)
  5408. {
  5409. q31_t product1, product2; /* Temporary variables used to store intermediate results */
  5410. /* Calculating pIa from Ialpha by equation pIa = Ialpha */
  5411. *pIa = Ialpha;
  5412. /* Intermediate product is calculated by (1/(2*sqrt(3)) * Ia) */
  5413. product1 = (q31_t) (((q63_t) (Ialpha) * (0x40000000)) >> 31);
  5414. /* Intermediate product is calculated by (1/sqrt(3) * pIb) */
  5415. product2 = (q31_t) (((q63_t) (Ibeta) * (0x6ED9EBA1)) >> 31);
  5416. /* pIb is calculated by subtracting the products */
  5417. *pIb = __QSUB(product2, product1);
  5418. }
  5419. /**
  5420. * @} end of inv_clarke group
  5421. */
  5422. /**
  5423. * @ingroup groupController
  5424. */
  5425. /**
  5426. * @defgroup park Vector Park Transform
  5427. *
  5428. * Forward Park transform converts the input two-coordinate vector to flux and torque components.
  5429. * The Park transform can be used to realize the transformation of the <code>Ialpha</code> and the <code>Ibeta</code> currents
  5430. * from the stationary to the moving reference frame and control the spatial relationship between
  5431. * the stator vector current and rotor flux vector.
  5432. * If we consider the d axis aligned with the rotor flux, the diagram below shows the
  5433. * current vector and the relationship from the two reference frames:
  5434. * \image html park.gif "Stator current space vector and its component in (a,b) and in the d,q rotating reference frame"
  5435. *
  5436. * The function operates on a single sample of data and each call to the function returns the processed output.
  5437. * The library provides separate functions for Q31 and floating-point data types.
  5438. * \par Algorithm
  5439. * \image html parkFormula.gif
  5440. * where <code>Ialpha</code> and <code>Ibeta</code> are the stator vector components,
  5441. * <code>pId</code> and <code>pIq</code> are rotor vector components and <code>cosVal</code> and <code>sinVal</code> are the
  5442. * cosine and sine values of theta (rotor flux position).
  5443. * \par Fixed-Point Behavior
  5444. * Care must be taken when using the Q31 version of the Park transform.
  5445. * In particular, the overflow and saturation behavior of the accumulator used must be considered.
  5446. * Refer to the function specific documentation below for usage guidelines.
  5447. */
  5448. /**
  5449. * @addtogroup park
  5450. * @{
  5451. */
  5452. /**
  5453. * @brief Floating-point Park transform
  5454. * @param[in] Ialpha input two-phase vector coordinate alpha
  5455. * @param[in] Ibeta input two-phase vector coordinate beta
  5456. * @param[out] pId points to output rotor reference frame d
  5457. * @param[out] pIq points to output rotor reference frame q
  5458. * @param[in] sinVal sine value of rotation angle theta
  5459. * @param[in] cosVal cosine value of rotation angle theta
  5460. * @return none
  5461. *
  5462. * The function implements the forward Park transform.
  5463. *
  5464. */
  5465. __STATIC_FORCEINLINE void arm_park_f32(
  5466. float32_t Ialpha,
  5467. float32_t Ibeta,
  5468. float32_t * pId,
  5469. float32_t * pIq,
  5470. float32_t sinVal,
  5471. float32_t cosVal)
  5472. {
  5473. /* Calculate pId using the equation, pId = Ialpha * cosVal + Ibeta * sinVal */
  5474. *pId = Ialpha * cosVal + Ibeta * sinVal;
  5475. /* Calculate pIq using the equation, pIq = - Ialpha * sinVal + Ibeta * cosVal */
  5476. *pIq = -Ialpha * sinVal + Ibeta * cosVal;
  5477. }
  5478. /**
  5479. @brief Park transform for Q31 version
  5480. @param[in] Ialpha input two-phase vector coordinate alpha
  5481. @param[in] Ibeta input two-phase vector coordinate beta
  5482. @param[out] pId points to output rotor reference frame d
  5483. @param[out] pIq points to output rotor reference frame q
  5484. @param[in] sinVal sine value of rotation angle theta
  5485. @param[in] cosVal cosine value of rotation angle theta
  5486. @return none
  5487. \par Scaling and Overflow Behavior
  5488. The function is implemented using an internal 32-bit accumulator.
  5489. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format.
  5490. There is saturation on the addition and subtraction, hence there is no risk of overflow.
  5491. */
  5492. __STATIC_FORCEINLINE void arm_park_q31(
  5493. q31_t Ialpha,
  5494. q31_t Ibeta,
  5495. q31_t * pId,
  5496. q31_t * pIq,
  5497. q31_t sinVal,
  5498. q31_t cosVal)
  5499. {
  5500. q31_t product1, product2; /* Temporary variables used to store intermediate results */
  5501. q31_t product3, product4; /* Temporary variables used to store intermediate results */
  5502. /* Intermediate product is calculated by (Ialpha * cosVal) */
  5503. product1 = (q31_t) (((q63_t) (Ialpha) * (cosVal)) >> 31);
  5504. /* Intermediate product is calculated by (Ibeta * sinVal) */
  5505. product2 = (q31_t) (((q63_t) (Ibeta) * (sinVal)) >> 31);
  5506. /* Intermediate product is calculated by (Ialpha * sinVal) */
  5507. product3 = (q31_t) (((q63_t) (Ialpha) * (sinVal)) >> 31);
  5508. /* Intermediate product is calculated by (Ibeta * cosVal) */
  5509. product4 = (q31_t) (((q63_t) (Ibeta) * (cosVal)) >> 31);
  5510. /* Calculate pId by adding the two intermediate products 1 and 2 */
  5511. *pId = __QADD(product1, product2);
  5512. /* Calculate pIq by subtracting the two intermediate products 3 from 4 */
  5513. *pIq = __QSUB(product4, product3);
  5514. }
  5515. /**
  5516. * @} end of park group
  5517. */
  5518. /**
  5519. * @ingroup groupController
  5520. */
  5521. /**
  5522. * @defgroup inv_park Vector Inverse Park transform
  5523. * Inverse Park transform converts the input flux and torque components to two-coordinate vector.
  5524. *
  5525. * The function operates on a single sample of data and each call to the function returns the processed output.
  5526. * The library provides separate functions for Q31 and floating-point data types.
  5527. * \par Algorithm
  5528. * \image html parkInvFormula.gif
  5529. * where <code>pIalpha</code> and <code>pIbeta</code> are the stator vector components,
  5530. * <code>Id</code> and <code>Iq</code> are rotor vector components and <code>cosVal</code> and <code>sinVal</code> are the
  5531. * cosine and sine values of theta (rotor flux position).
  5532. * \par Fixed-Point Behavior
  5533. * Care must be taken when using the Q31 version of the Park transform.
  5534. * In particular, the overflow and saturation behavior of the accumulator used must be considered.
  5535. * Refer to the function specific documentation below for usage guidelines.
  5536. */
  5537. /**
  5538. * @addtogroup inv_park
  5539. * @{
  5540. */
  5541. /**
  5542. * @brief Floating-point Inverse Park transform
  5543. * @param[in] Id input coordinate of rotor reference frame d
  5544. * @param[in] Iq input coordinate of rotor reference frame q
  5545. * @param[out] pIalpha points to output two-phase orthogonal vector axis alpha
  5546. * @param[out] pIbeta points to output two-phase orthogonal vector axis beta
  5547. * @param[in] sinVal sine value of rotation angle theta
  5548. * @param[in] cosVal cosine value of rotation angle theta
  5549. * @return none
  5550. */
  5551. __STATIC_FORCEINLINE void arm_inv_park_f32(
  5552. float32_t Id,
  5553. float32_t Iq,
  5554. float32_t * pIalpha,
  5555. float32_t * pIbeta,
  5556. float32_t sinVal,
  5557. float32_t cosVal)
  5558. {
  5559. /* Calculate pIalpha using the equation, pIalpha = Id * cosVal - Iq * sinVal */
  5560. *pIalpha = Id * cosVal - Iq * sinVal;
  5561. /* Calculate pIbeta using the equation, pIbeta = Id * sinVal + Iq * cosVal */
  5562. *pIbeta = Id * sinVal + Iq * cosVal;
  5563. }
  5564. /**
  5565. @brief Inverse Park transform for Q31 version
  5566. @param[in] Id input coordinate of rotor reference frame d
  5567. @param[in] Iq input coordinate of rotor reference frame q
  5568. @param[out] pIalpha points to output two-phase orthogonal vector axis alpha
  5569. @param[out] pIbeta points to output two-phase orthogonal vector axis beta
  5570. @param[in] sinVal sine value of rotation angle theta
  5571. @param[in] cosVal cosine value of rotation angle theta
  5572. @return none
  5573. @par Scaling and Overflow Behavior
  5574. The function is implemented using an internal 32-bit accumulator.
  5575. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format.
  5576. There is saturation on the addition, hence there is no risk of overflow.
  5577. */
  5578. __STATIC_FORCEINLINE void arm_inv_park_q31(
  5579. q31_t Id,
  5580. q31_t Iq,
  5581. q31_t * pIalpha,
  5582. q31_t * pIbeta,
  5583. q31_t sinVal,
  5584. q31_t cosVal)
  5585. {
  5586. q31_t product1, product2; /* Temporary variables used to store intermediate results */
  5587. q31_t product3, product4; /* Temporary variables used to store intermediate results */
  5588. /* Intermediate product is calculated by (Id * cosVal) */
  5589. product1 = (q31_t) (((q63_t) (Id) * (cosVal)) >> 31);
  5590. /* Intermediate product is calculated by (Iq * sinVal) */
  5591. product2 = (q31_t) (((q63_t) (Iq) * (sinVal)) >> 31);
  5592. /* Intermediate product is calculated by (Id * sinVal) */
  5593. product3 = (q31_t) (((q63_t) (Id) * (sinVal)) >> 31);
  5594. /* Intermediate product is calculated by (Iq * cosVal) */
  5595. product4 = (q31_t) (((q63_t) (Iq) * (cosVal)) >> 31);
  5596. /* Calculate pIalpha by using the two intermediate products 1 and 2 */
  5597. *pIalpha = __QSUB(product1, product2);
  5598. /* Calculate pIbeta by using the two intermediate products 3 and 4 */
  5599. *pIbeta = __QADD(product4, product3);
  5600. }
  5601. /**
  5602. * @} end of Inverse park group
  5603. */
  5604. /**
  5605. * @ingroup groupInterpolation
  5606. */
  5607. /**
  5608. * @defgroup LinearInterpolate Linear Interpolation
  5609. *
  5610. * Linear interpolation is a method of curve fitting using linear polynomials.
  5611. * Linear interpolation works by effectively drawing a straight line between two neighboring samples and returning the appropriate point along that line
  5612. *
  5613. * \par
  5614. * \image html LinearInterp.gif "Linear interpolation"
  5615. *
  5616. * \par
  5617. * A Linear Interpolate function calculates an output value(y), for the input(x)
  5618. * using linear interpolation of the input values x0, x1( nearest input values) and the output values y0 and y1(nearest output values)
  5619. *
  5620. * \par Algorithm:
  5621. * <pre>
  5622. * y = y0 + (x - x0) * ((y1 - y0)/(x1-x0))
  5623. * where x0, x1 are nearest values of input x
  5624. * y0, y1 are nearest values to output y
  5625. * </pre>
  5626. *
  5627. * \par
  5628. * This set of functions implements Linear interpolation process
  5629. * for Q7, Q15, Q31, and floating-point data types. The functions operate on a single
  5630. * sample of data and each call to the function returns a single processed value.
  5631. * <code>S</code> points to an instance of the Linear Interpolate function data structure.
  5632. * <code>x</code> is the input sample value. The functions returns the output value.
  5633. *
  5634. * \par
  5635. * if x is outside of the table boundary, Linear interpolation returns first value of the table
  5636. * if x is below input range and returns last value of table if x is above range.
  5637. */
  5638. /**
  5639. * @addtogroup LinearInterpolate
  5640. * @{
  5641. */
  5642. /**
  5643. * @brief Process function for the floating-point Linear Interpolation Function.
  5644. * @param[in,out] S is an instance of the floating-point Linear Interpolation structure
  5645. * @param[in] x input sample to process
  5646. * @return y processed output sample.
  5647. *
  5648. */
  5649. __STATIC_FORCEINLINE float32_t arm_linear_interp_f32(
  5650. arm_linear_interp_instance_f32 * S,
  5651. float32_t x)
  5652. {
  5653. float32_t y;
  5654. float32_t x0, x1; /* Nearest input values */
  5655. float32_t y0, y1; /* Nearest output values */
  5656. float32_t xSpacing = S->xSpacing; /* spacing between input values */
  5657. int32_t i; /* Index variable */
  5658. float32_t *pYData = S->pYData; /* pointer to output table */
  5659. /* Calculation of index */
  5660. i = (int32_t) ((x - S->x1) / xSpacing);
  5661. if (i < 0)
  5662. {
  5663. /* Iniatilize output for below specified range as least output value of table */
  5664. y = pYData[0];
  5665. }
  5666. else if ((uint32_t)i >= (S->nValues - 1))
  5667. {
  5668. /* Iniatilize output for above specified range as last output value of table */
  5669. y = pYData[S->nValues - 1];
  5670. }
  5671. else
  5672. {
  5673. /* Calculation of nearest input values */
  5674. x0 = S->x1 + i * xSpacing;
  5675. x1 = S->x1 + (i + 1) * xSpacing;
  5676. /* Read of nearest output values */
  5677. y0 = pYData[i];
  5678. y1 = pYData[i + 1];
  5679. /* Calculation of output */
  5680. y = y0 + (x - x0) * ((y1 - y0) / (x1 - x0));
  5681. }
  5682. /* returns output value */
  5683. return (y);
  5684. }
  5685. /**
  5686. *
  5687. * @brief Process function for the Q31 Linear Interpolation Function.
  5688. * @param[in] pYData pointer to Q31 Linear Interpolation table
  5689. * @param[in] x input sample to process
  5690. * @param[in] nValues number of table values
  5691. * @return y processed output sample.
  5692. *
  5693. * \par
  5694. * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part.
  5695. * This function can support maximum of table size 2^12.
  5696. *
  5697. */
  5698. __STATIC_FORCEINLINE q31_t arm_linear_interp_q31(
  5699. q31_t * pYData,
  5700. q31_t x,
  5701. uint32_t nValues)
  5702. {
  5703. q31_t y; /* output */
  5704. q31_t y0, y1; /* Nearest output values */
  5705. q31_t fract; /* fractional part */
  5706. int32_t index; /* Index to read nearest output values */
  5707. /* Input is in 12.20 format */
  5708. /* 12 bits for the table index */
  5709. /* Index value calculation */
  5710. index = ((x & (q31_t)0xFFF00000) >> 20);
  5711. if (index >= (int32_t)(nValues - 1))
  5712. {
  5713. return (pYData[nValues - 1]);
  5714. }
  5715. else if (index < 0)
  5716. {
  5717. return (pYData[0]);
  5718. }
  5719. else
  5720. {
  5721. /* 20 bits for the fractional part */
  5722. /* shift left by 11 to keep fract in 1.31 format */
  5723. fract = (x & 0x000FFFFF) << 11;
  5724. /* Read two nearest output values from the index in 1.31(q31) format */
  5725. y0 = pYData[index];
  5726. y1 = pYData[index + 1];
  5727. /* Calculation of y0 * (1-fract) and y is in 2.30 format */
  5728. y = ((q31_t) ((q63_t) y0 * (0x7FFFFFFF - fract) >> 32));
  5729. /* Calculation of y0 * (1-fract) + y1 *fract and y is in 2.30 format */
  5730. y += ((q31_t) (((q63_t) y1 * fract) >> 32));
  5731. /* Convert y to 1.31 format */
  5732. return (y << 1U);
  5733. }
  5734. }
  5735. /**
  5736. *
  5737. * @brief Process function for the Q15 Linear Interpolation Function.
  5738. * @param[in] pYData pointer to Q15 Linear Interpolation table
  5739. * @param[in] x input sample to process
  5740. * @param[in] nValues number of table values
  5741. * @return y processed output sample.
  5742. *
  5743. * \par
  5744. * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part.
  5745. * This function can support maximum of table size 2^12.
  5746. *
  5747. */
  5748. __STATIC_FORCEINLINE q15_t arm_linear_interp_q15(
  5749. q15_t * pYData,
  5750. q31_t x,
  5751. uint32_t nValues)
  5752. {
  5753. q63_t y; /* output */
  5754. q15_t y0, y1; /* Nearest output values */
  5755. q31_t fract; /* fractional part */
  5756. int32_t index; /* Index to read nearest output values */
  5757. /* Input is in 12.20 format */
  5758. /* 12 bits for the table index */
  5759. /* Index value calculation */
  5760. index = ((x & (int32_t)0xFFF00000) >> 20);
  5761. if (index >= (int32_t)(nValues - 1))
  5762. {
  5763. return (pYData[nValues - 1]);
  5764. }
  5765. else if (index < 0)
  5766. {
  5767. return (pYData[0]);
  5768. }
  5769. else
  5770. {
  5771. /* 20 bits for the fractional part */
  5772. /* fract is in 12.20 format */
  5773. fract = (x & 0x000FFFFF);
  5774. /* Read two nearest output values from the index */
  5775. y0 = pYData[index];
  5776. y1 = pYData[index + 1];
  5777. /* Calculation of y0 * (1-fract) and y is in 13.35 format */
  5778. y = ((q63_t) y0 * (0xFFFFF - fract));
  5779. /* Calculation of (y0 * (1-fract) + y1 * fract) and y is in 13.35 format */
  5780. y += ((q63_t) y1 * (fract));
  5781. /* convert y to 1.15 format */
  5782. return (q15_t) (y >> 20);
  5783. }
  5784. }
  5785. /**
  5786. *
  5787. * @brief Process function for the Q7 Linear Interpolation Function.
  5788. * @param[in] pYData pointer to Q7 Linear Interpolation table
  5789. * @param[in] x input sample to process
  5790. * @param[in] nValues number of table values
  5791. * @return y processed output sample.
  5792. *
  5793. * \par
  5794. * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part.
  5795. * This function can support maximum of table size 2^12.
  5796. */
  5797. __STATIC_FORCEINLINE q7_t arm_linear_interp_q7(
  5798. q7_t * pYData,
  5799. q31_t x,
  5800. uint32_t nValues)
  5801. {
  5802. q31_t y; /* output */
  5803. q7_t y0, y1; /* Nearest output values */
  5804. q31_t fract; /* fractional part */
  5805. uint32_t index; /* Index to read nearest output values */
  5806. /* Input is in 12.20 format */
  5807. /* 12 bits for the table index */
  5808. /* Index value calculation */
  5809. if (x < 0)
  5810. {
  5811. return (pYData[0]);
  5812. }
  5813. index = (x >> 20) & 0xfff;
  5814. if (index >= (nValues - 1))
  5815. {
  5816. return (pYData[nValues - 1]);
  5817. }
  5818. else
  5819. {
  5820. /* 20 bits for the fractional part */
  5821. /* fract is in 12.20 format */
  5822. fract = (x & 0x000FFFFF);
  5823. /* Read two nearest output values from the index and are in 1.7(q7) format */
  5824. y0 = pYData[index];
  5825. y1 = pYData[index + 1];
  5826. /* Calculation of y0 * (1-fract ) and y is in 13.27(q27) format */
  5827. y = ((y0 * (0xFFFFF - fract)));
  5828. /* Calculation of y1 * fract + y0 * (1-fract) and y is in 13.27(q27) format */
  5829. y += (y1 * fract);
  5830. /* convert y to 1.7(q7) format */
  5831. return (q7_t) (y >> 20);
  5832. }
  5833. }
  5834. /**
  5835. * @} end of LinearInterpolate group
  5836. */
  5837. /**
  5838. * @brief Fast approximation to the trigonometric sine function for floating-point data.
  5839. * @param[in] x input value in radians.
  5840. * @return sin(x).
  5841. */
  5842. float32_t arm_sin_f32(
  5843. float32_t x);
  5844. /**
  5845. * @brief Fast approximation to the trigonometric sine function for Q31 data.
  5846. * @param[in] x Scaled input value in radians.
  5847. * @return sin(x).
  5848. */
  5849. q31_t arm_sin_q31(
  5850. q31_t x);
  5851. /**
  5852. * @brief Fast approximation to the trigonometric sine function for Q15 data.
  5853. * @param[in] x Scaled input value in radians.
  5854. * @return sin(x).
  5855. */
  5856. q15_t arm_sin_q15(
  5857. q15_t x);
  5858. /**
  5859. * @brief Fast approximation to the trigonometric cosine function for floating-point data.
  5860. * @param[in] x input value in radians.
  5861. * @return cos(x).
  5862. */
  5863. float32_t arm_cos_f32(
  5864. float32_t x);
  5865. /**
  5866. * @brief Fast approximation to the trigonometric cosine function for Q31 data.
  5867. * @param[in] x Scaled input value in radians.
  5868. * @return cos(x).
  5869. */
  5870. q31_t arm_cos_q31(
  5871. q31_t x);
  5872. /**
  5873. * @brief Fast approximation to the trigonometric cosine function for Q15 data.
  5874. * @param[in] x Scaled input value in radians.
  5875. * @return cos(x).
  5876. */
  5877. q15_t arm_cos_q15(
  5878. q15_t x);
  5879. /**
  5880. @brief Floating-point vector of log values.
  5881. @param[in] pSrc points to the input vector
  5882. @param[out] pDst points to the output vector
  5883. @param[in] blockSize number of samples in each vector
  5884. @return none
  5885. */
  5886. void arm_vlog_f32(
  5887. const float32_t * pSrc,
  5888. float32_t * pDst,
  5889. uint32_t blockSize);
  5890. /**
  5891. @brief Floating-point vector of exp values.
  5892. @param[in] pSrc points to the input vector
  5893. @param[out] pDst points to the output vector
  5894. @param[in] blockSize number of samples in each vector
  5895. @return none
  5896. */
  5897. void arm_vexp_f32(
  5898. const float32_t * pSrc,
  5899. float32_t * pDst,
  5900. uint32_t blockSize);
  5901. /**
  5902. * @ingroup groupFastMath
  5903. */
  5904. /**
  5905. * @defgroup SQRT Square Root
  5906. *
  5907. * Computes the square root of a number.
  5908. * There are separate functions for Q15, Q31, and floating-point data types.
  5909. * The square root function is computed using the Newton-Raphson algorithm.
  5910. * This is an iterative algorithm of the form:
  5911. * <pre>
  5912. * x1 = x0 - f(x0)/f'(x0)
  5913. * </pre>
  5914. * where <code>x1</code> is the current estimate,
  5915. * <code>x0</code> is the previous estimate, and
  5916. * <code>f'(x0)</code> is the derivative of <code>f()</code> evaluated at <code>x0</code>.
  5917. * For the square root function, the algorithm reduces to:
  5918. * <pre>
  5919. * x0 = in/2 [initial guess]
  5920. * x1 = 1/2 * ( x0 + in / x0) [each iteration]
  5921. * </pre>
  5922. */
  5923. /**
  5924. * @addtogroup SQRT
  5925. * @{
  5926. */
  5927. /**
  5928. @brief Floating-point square root function.
  5929. @param[in] in input value
  5930. @param[out] pOut square root of input value
  5931. @return execution status
  5932. - \ref ARM_MATH_SUCCESS : input value is positive
  5933. - \ref ARM_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0
  5934. */
  5935. __STATIC_FORCEINLINE arm_status arm_sqrt_f32(
  5936. float32_t in,
  5937. float32_t * pOut)
  5938. {
  5939. if (in >= 0.0f)
  5940. {
  5941. #if defined ( __CC_ARM )
  5942. #if defined __TARGET_FPU_VFP
  5943. *pOut = __sqrtf(in);
  5944. #else
  5945. *pOut = sqrtf(in);
  5946. #endif
  5947. #elif defined ( __ICCARM__ )
  5948. #if defined __ARMVFP__
  5949. __ASM("VSQRT.F32 %0,%1" : "=t"(*pOut) : "t"(in));
  5950. #else
  5951. *pOut = sqrtf(in);
  5952. #endif
  5953. #else
  5954. *pOut = sqrtf(in);
  5955. #endif
  5956. return (ARM_MATH_SUCCESS);
  5957. }
  5958. else
  5959. {
  5960. *pOut = 0.0f;
  5961. return (ARM_MATH_ARGUMENT_ERROR);
  5962. }
  5963. }
  5964. /**
  5965. @brief Q31 square root function.
  5966. @param[in] in input value. The range of the input value is [0 +1) or 0x00000000 to 0x7FFFFFFF
  5967. @param[out] pOut points to square root of input value
  5968. @return execution status
  5969. - \ref ARM_MATH_SUCCESS : input value is positive
  5970. - \ref ARM_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0
  5971. */
  5972. arm_status arm_sqrt_q31(
  5973. q31_t in,
  5974. q31_t * pOut);
  5975. /**
  5976. @brief Q15 square root function.
  5977. @param[in] in input value. The range of the input value is [0 +1) or 0x0000 to 0x7FFF
  5978. @param[out] pOut points to square root of input value
  5979. @return execution status
  5980. - \ref ARM_MATH_SUCCESS : input value is positive
  5981. - \ref ARM_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0
  5982. */
  5983. arm_status arm_sqrt_q15(
  5984. q15_t in,
  5985. q15_t * pOut);
  5986. /**
  5987. * @brief Vector Floating-point square root function.
  5988. * @param[in] pIn input vector.
  5989. * @param[out] pOut vector of square roots of input elements.
  5990. * @param[in] len length of input vector.
  5991. * @return The function returns ARM_MATH_SUCCESS if input value is positive value or ARM_MATH_ARGUMENT_ERROR if
  5992. * <code>in</code> is negative value and returns zero output for negative values.
  5993. */
  5994. void arm_vsqrt_f32(
  5995. float32_t * pIn,
  5996. float32_t * pOut,
  5997. uint16_t len);
  5998. void arm_vsqrt_q31(
  5999. q31_t * pIn,
  6000. q31_t * pOut,
  6001. uint16_t len);
  6002. void arm_vsqrt_q15(
  6003. q15_t * pIn,
  6004. q15_t * pOut,
  6005. uint16_t len);
  6006. /**
  6007. * @} end of SQRT group
  6008. */
  6009. /**
  6010. * @brief floating-point Circular write function.
  6011. */
  6012. __STATIC_FORCEINLINE void arm_circularWrite_f32(
  6013. int32_t * circBuffer,
  6014. int32_t L,
  6015. uint16_t * writeOffset,
  6016. int32_t bufferInc,
  6017. const int32_t * src,
  6018. int32_t srcInc,
  6019. uint32_t blockSize)
  6020. {
  6021. uint32_t i = 0U;
  6022. int32_t wOffset;
  6023. /* Copy the value of Index pointer that points
  6024. * to the current location where the input samples to be copied */
  6025. wOffset = *writeOffset;
  6026. /* Loop over the blockSize */
  6027. i = blockSize;
  6028. while (i > 0U)
  6029. {
  6030. /* copy the input sample to the circular buffer */
  6031. circBuffer[wOffset] = *src;
  6032. /* Update the input pointer */
  6033. src += srcInc;
  6034. /* Circularly update wOffset. Watch out for positive and negative value */
  6035. wOffset += bufferInc;
  6036. if (wOffset >= L)
  6037. wOffset -= L;
  6038. /* Decrement the loop counter */
  6039. i--;
  6040. }
  6041. /* Update the index pointer */
  6042. *writeOffset = (uint16_t)wOffset;
  6043. }
  6044. /**
  6045. * @brief floating-point Circular Read function.
  6046. */
  6047. __STATIC_FORCEINLINE void arm_circularRead_f32(
  6048. int32_t * circBuffer,
  6049. int32_t L,
  6050. int32_t * readOffset,
  6051. int32_t bufferInc,
  6052. int32_t * dst,
  6053. int32_t * dst_base,
  6054. int32_t dst_length,
  6055. int32_t dstInc,
  6056. uint32_t blockSize)
  6057. {
  6058. uint32_t i = 0U;
  6059. int32_t rOffset;
  6060. int32_t* dst_end;
  6061. /* Copy the value of Index pointer that points
  6062. * to the current location from where the input samples to be read */
  6063. rOffset = *readOffset;
  6064. dst_end = dst_base + dst_length;
  6065. /* Loop over the blockSize */
  6066. i = blockSize;
  6067. while (i > 0U)
  6068. {
  6069. /* copy the sample from the circular buffer to the destination buffer */
  6070. *dst = circBuffer[rOffset];
  6071. /* Update the input pointer */
  6072. dst += dstInc;
  6073. if (dst == dst_end)
  6074. {
  6075. dst = dst_base;
  6076. }
  6077. /* Circularly update rOffset. Watch out for positive and negative value */
  6078. rOffset += bufferInc;
  6079. if (rOffset >= L)
  6080. {
  6081. rOffset -= L;
  6082. }
  6083. /* Decrement the loop counter */
  6084. i--;
  6085. }
  6086. /* Update the index pointer */
  6087. *readOffset = rOffset;
  6088. }
  6089. /**
  6090. * @brief Q15 Circular write function.
  6091. */
  6092. __STATIC_FORCEINLINE void arm_circularWrite_q15(
  6093. q15_t * circBuffer,
  6094. int32_t L,
  6095. uint16_t * writeOffset,
  6096. int32_t bufferInc,
  6097. const q15_t * src,
  6098. int32_t srcInc,
  6099. uint32_t blockSize)
  6100. {
  6101. uint32_t i = 0U;
  6102. int32_t wOffset;
  6103. /* Copy the value of Index pointer that points
  6104. * to the current location where the input samples to be copied */
  6105. wOffset = *writeOffset;
  6106. /* Loop over the blockSize */
  6107. i = blockSize;
  6108. while (i > 0U)
  6109. {
  6110. /* copy the input sample to the circular buffer */
  6111. circBuffer[wOffset] = *src;
  6112. /* Update the input pointer */
  6113. src += srcInc;
  6114. /* Circularly update wOffset. Watch out for positive and negative value */
  6115. wOffset += bufferInc;
  6116. if (wOffset >= L)
  6117. wOffset -= L;
  6118. /* Decrement the loop counter */
  6119. i--;
  6120. }
  6121. /* Update the index pointer */
  6122. *writeOffset = (uint16_t)wOffset;
  6123. }
  6124. /**
  6125. * @brief Q15 Circular Read function.
  6126. */
  6127. __STATIC_FORCEINLINE void arm_circularRead_q15(
  6128. q15_t * circBuffer,
  6129. int32_t L,
  6130. int32_t * readOffset,
  6131. int32_t bufferInc,
  6132. q15_t * dst,
  6133. q15_t * dst_base,
  6134. int32_t dst_length,
  6135. int32_t dstInc,
  6136. uint32_t blockSize)
  6137. {
  6138. uint32_t i = 0;
  6139. int32_t rOffset;
  6140. q15_t* dst_end;
  6141. /* Copy the value of Index pointer that points
  6142. * to the current location from where the input samples to be read */
  6143. rOffset = *readOffset;
  6144. dst_end = dst_base + dst_length;
  6145. /* Loop over the blockSize */
  6146. i = blockSize;
  6147. while (i > 0U)
  6148. {
  6149. /* copy the sample from the circular buffer to the destination buffer */
  6150. *dst = circBuffer[rOffset];
  6151. /* Update the input pointer */
  6152. dst += dstInc;
  6153. if (dst == dst_end)
  6154. {
  6155. dst = dst_base;
  6156. }
  6157. /* Circularly update wOffset. Watch out for positive and negative value */
  6158. rOffset += bufferInc;
  6159. if (rOffset >= L)
  6160. {
  6161. rOffset -= L;
  6162. }
  6163. /* Decrement the loop counter */
  6164. i--;
  6165. }
  6166. /* Update the index pointer */
  6167. *readOffset = rOffset;
  6168. }
  6169. /**
  6170. * @brief Q7 Circular write function.
  6171. */
  6172. __STATIC_FORCEINLINE void arm_circularWrite_q7(
  6173. q7_t * circBuffer,
  6174. int32_t L,
  6175. uint16_t * writeOffset,
  6176. int32_t bufferInc,
  6177. const q7_t * src,
  6178. int32_t srcInc,
  6179. uint32_t blockSize)
  6180. {
  6181. uint32_t i = 0U;
  6182. int32_t wOffset;
  6183. /* Copy the value of Index pointer that points
  6184. * to the current location where the input samples to be copied */
  6185. wOffset = *writeOffset;
  6186. /* Loop over the blockSize */
  6187. i = blockSize;
  6188. while (i > 0U)
  6189. {
  6190. /* copy the input sample to the circular buffer */
  6191. circBuffer[wOffset] = *src;
  6192. /* Update the input pointer */
  6193. src += srcInc;
  6194. /* Circularly update wOffset. Watch out for positive and negative value */
  6195. wOffset += bufferInc;
  6196. if (wOffset >= L)
  6197. wOffset -= L;
  6198. /* Decrement the loop counter */
  6199. i--;
  6200. }
  6201. /* Update the index pointer */
  6202. *writeOffset = (uint16_t)wOffset;
  6203. }
  6204. /**
  6205. * @brief Q7 Circular Read function.
  6206. */
  6207. __STATIC_FORCEINLINE void arm_circularRead_q7(
  6208. q7_t * circBuffer,
  6209. int32_t L,
  6210. int32_t * readOffset,
  6211. int32_t bufferInc,
  6212. q7_t * dst,
  6213. q7_t * dst_base,
  6214. int32_t dst_length,
  6215. int32_t dstInc,
  6216. uint32_t blockSize)
  6217. {
  6218. uint32_t i = 0;
  6219. int32_t rOffset;
  6220. q7_t* dst_end;
  6221. /* Copy the value of Index pointer that points
  6222. * to the current location from where the input samples to be read */
  6223. rOffset = *readOffset;
  6224. dst_end = dst_base + dst_length;
  6225. /* Loop over the blockSize */
  6226. i = blockSize;
  6227. while (i > 0U)
  6228. {
  6229. /* copy the sample from the circular buffer to the destination buffer */
  6230. *dst = circBuffer[rOffset];
  6231. /* Update the input pointer */
  6232. dst += dstInc;
  6233. if (dst == dst_end)
  6234. {
  6235. dst = dst_base;
  6236. }
  6237. /* Circularly update rOffset. Watch out for positive and negative value */
  6238. rOffset += bufferInc;
  6239. if (rOffset >= L)
  6240. {
  6241. rOffset -= L;
  6242. }
  6243. /* Decrement the loop counter */
  6244. i--;
  6245. }
  6246. /* Update the index pointer */
  6247. *readOffset = rOffset;
  6248. }
  6249. /**
  6250. * @brief Sum of the squares of the elements of a Q31 vector.
  6251. * @param[in] pSrc is input pointer
  6252. * @param[in] blockSize is the number of samples to process
  6253. * @param[out] pResult is output value.
  6254. */
  6255. void arm_power_q31(
  6256. const q31_t * pSrc,
  6257. uint32_t blockSize,
  6258. q63_t * pResult);
  6259. /**
  6260. * @brief Sum of the squares of the elements of a floating-point vector.
  6261. * @param[in] pSrc is input pointer
  6262. * @param[in] blockSize is the number of samples to process
  6263. * @param[out] pResult is output value.
  6264. */
  6265. void arm_power_f32(
  6266. const float32_t * pSrc,
  6267. uint32_t blockSize,
  6268. float32_t * pResult);
  6269. /**
  6270. * @brief Sum of the squares of the elements of a Q15 vector.
  6271. * @param[in] pSrc is input pointer
  6272. * @param[in] blockSize is the number of samples to process
  6273. * @param[out] pResult is output value.
  6274. */
  6275. void arm_power_q15(
  6276. const q15_t * pSrc,
  6277. uint32_t blockSize,
  6278. q63_t * pResult);
  6279. /**
  6280. * @brief Sum of the squares of the elements of a Q7 vector.
  6281. * @param[in] pSrc is input pointer
  6282. * @param[in] blockSize is the number of samples to process
  6283. * @param[out] pResult is output value.
  6284. */
  6285. void arm_power_q7(
  6286. const q7_t * pSrc,
  6287. uint32_t blockSize,
  6288. q31_t * pResult);
  6289. /**
  6290. * @brief Mean value of a Q7 vector.
  6291. * @param[in] pSrc is input pointer
  6292. * @param[in] blockSize is the number of samples to process
  6293. * @param[out] pResult is output value.
  6294. */
  6295. void arm_mean_q7(
  6296. const q7_t * pSrc,
  6297. uint32_t blockSize,
  6298. q7_t * pResult);
  6299. /**
  6300. * @brief Mean value of a Q15 vector.
  6301. * @param[in] pSrc is input pointer
  6302. * @param[in] blockSize is the number of samples to process
  6303. * @param[out] pResult is output value.
  6304. */
  6305. void arm_mean_q15(
  6306. const q15_t * pSrc,
  6307. uint32_t blockSize,
  6308. q15_t * pResult);
  6309. /**
  6310. * @brief Mean value of a Q31 vector.
  6311. * @param[in] pSrc is input pointer
  6312. * @param[in] blockSize is the number of samples to process
  6313. * @param[out] pResult is output value.
  6314. */
  6315. void arm_mean_q31(
  6316. const q31_t * pSrc,
  6317. uint32_t blockSize,
  6318. q31_t * pResult);
  6319. /**
  6320. * @brief Mean value of a floating-point vector.
  6321. * @param[in] pSrc is input pointer
  6322. * @param[in] blockSize is the number of samples to process
  6323. * @param[out] pResult is output value.
  6324. */
  6325. void arm_mean_f32(
  6326. const float32_t * pSrc,
  6327. uint32_t blockSize,
  6328. float32_t * pResult);
  6329. /**
  6330. * @brief Variance of the elements of a floating-point vector.
  6331. * @param[in] pSrc is input pointer
  6332. * @param[in] blockSize is the number of samples to process
  6333. * @param[out] pResult is output value.
  6334. */
  6335. void arm_var_f32(
  6336. const float32_t * pSrc,
  6337. uint32_t blockSize,
  6338. float32_t * pResult);
  6339. /**
  6340. * @brief Variance of the elements of a Q31 vector.
  6341. * @param[in] pSrc is input pointer
  6342. * @param[in] blockSize is the number of samples to process
  6343. * @param[out] pResult is output value.
  6344. */
  6345. void arm_var_q31(
  6346. const q31_t * pSrc,
  6347. uint32_t blockSize,
  6348. q31_t * pResult);
  6349. /**
  6350. * @brief Variance of the elements of a Q15 vector.
  6351. * @param[in] pSrc is input pointer
  6352. * @param[in] blockSize is the number of samples to process
  6353. * @param[out] pResult is output value.
  6354. */
  6355. void arm_var_q15(
  6356. const q15_t * pSrc,
  6357. uint32_t blockSize,
  6358. q15_t * pResult);
  6359. /**
  6360. * @brief Root Mean Square of the elements of a floating-point vector.
  6361. * @param[in] pSrc is input pointer
  6362. * @param[in] blockSize is the number of samples to process
  6363. * @param[out] pResult is output value.
  6364. */
  6365. void arm_rms_f32(
  6366. const float32_t * pSrc,
  6367. uint32_t blockSize,
  6368. float32_t * pResult);
  6369. /**
  6370. * @brief Root Mean Square of the elements of a Q31 vector.
  6371. * @param[in] pSrc is input pointer
  6372. * @param[in] blockSize is the number of samples to process
  6373. * @param[out] pResult is output value.
  6374. */
  6375. void arm_rms_q31(
  6376. const q31_t * pSrc,
  6377. uint32_t blockSize,
  6378. q31_t * pResult);
  6379. /**
  6380. * @brief Root Mean Square of the elements of a Q15 vector.
  6381. * @param[in] pSrc is input pointer
  6382. * @param[in] blockSize is the number of samples to process
  6383. * @param[out] pResult is output value.
  6384. */
  6385. void arm_rms_q15(
  6386. const q15_t * pSrc,
  6387. uint32_t blockSize,
  6388. q15_t * pResult);
  6389. /**
  6390. * @brief Standard deviation of the elements of a floating-point vector.
  6391. * @param[in] pSrc is input pointer
  6392. * @param[in] blockSize is the number of samples to process
  6393. * @param[out] pResult is output value.
  6394. */
  6395. void arm_std_f32(
  6396. const float32_t * pSrc,
  6397. uint32_t blockSize,
  6398. float32_t * pResult);
  6399. /**
  6400. * @brief Standard deviation of the elements of a Q31 vector.
  6401. * @param[in] pSrc is input pointer
  6402. * @param[in] blockSize is the number of samples to process
  6403. * @param[out] pResult is output value.
  6404. */
  6405. void arm_std_q31(
  6406. const q31_t * pSrc,
  6407. uint32_t blockSize,
  6408. q31_t * pResult);
  6409. /**
  6410. * @brief Standard deviation of the elements of a Q15 vector.
  6411. * @param[in] pSrc is input pointer
  6412. * @param[in] blockSize is the number of samples to process
  6413. * @param[out] pResult is output value.
  6414. */
  6415. void arm_std_q15(
  6416. const q15_t * pSrc,
  6417. uint32_t blockSize,
  6418. q15_t * pResult);
  6419. /**
  6420. * @brief Floating-point complex magnitude
  6421. * @param[in] pSrc points to the complex input vector
  6422. * @param[out] pDst points to the real output vector
  6423. * @param[in] numSamples number of complex samples in the input vector
  6424. */
  6425. void arm_cmplx_mag_f32(
  6426. const float32_t * pSrc,
  6427. float32_t * pDst,
  6428. uint32_t numSamples);
  6429. /**
  6430. * @brief Q31 complex magnitude
  6431. * @param[in] pSrc points to the complex input vector
  6432. * @param[out] pDst points to the real output vector
  6433. * @param[in] numSamples number of complex samples in the input vector
  6434. */
  6435. void arm_cmplx_mag_q31(
  6436. const q31_t * pSrc,
  6437. q31_t * pDst,
  6438. uint32_t numSamples);
  6439. /**
  6440. * @brief Q15 complex magnitude
  6441. * @param[in] pSrc points to the complex input vector
  6442. * @param[out] pDst points to the real output vector
  6443. * @param[in] numSamples number of complex samples in the input vector
  6444. */
  6445. void arm_cmplx_mag_q15(
  6446. const q15_t * pSrc,
  6447. q15_t * pDst,
  6448. uint32_t numSamples);
  6449. /**
  6450. * @brief Q15 complex dot product
  6451. * @param[in] pSrcA points to the first input vector
  6452. * @param[in] pSrcB points to the second input vector
  6453. * @param[in] numSamples number of complex samples in each vector
  6454. * @param[out] realResult real part of the result returned here
  6455. * @param[out] imagResult imaginary part of the result returned here
  6456. */
  6457. void arm_cmplx_dot_prod_q15(
  6458. const q15_t * pSrcA,
  6459. const q15_t * pSrcB,
  6460. uint32_t numSamples,
  6461. q31_t * realResult,
  6462. q31_t * imagResult);
  6463. /**
  6464. * @brief Q31 complex dot product
  6465. * @param[in] pSrcA points to the first input vector
  6466. * @param[in] pSrcB points to the second input vector
  6467. * @param[in] numSamples number of complex samples in each vector
  6468. * @param[out] realResult real part of the result returned here
  6469. * @param[out] imagResult imaginary part of the result returned here
  6470. */
  6471. void arm_cmplx_dot_prod_q31(
  6472. const q31_t * pSrcA,
  6473. const q31_t * pSrcB,
  6474. uint32_t numSamples,
  6475. q63_t * realResult,
  6476. q63_t * imagResult);
  6477. /**
  6478. * @brief Floating-point complex dot product
  6479. * @param[in] pSrcA points to the first input vector
  6480. * @param[in] pSrcB points to the second input vector
  6481. * @param[in] numSamples number of complex samples in each vector
  6482. * @param[out] realResult real part of the result returned here
  6483. * @param[out] imagResult imaginary part of the result returned here
  6484. */
  6485. void arm_cmplx_dot_prod_f32(
  6486. const float32_t * pSrcA,
  6487. const float32_t * pSrcB,
  6488. uint32_t numSamples,
  6489. float32_t * realResult,
  6490. float32_t * imagResult);
  6491. /**
  6492. * @brief Q15 complex-by-real multiplication
  6493. * @param[in] pSrcCmplx points to the complex input vector
  6494. * @param[in] pSrcReal points to the real input vector
  6495. * @param[out] pCmplxDst points to the complex output vector
  6496. * @param[in] numSamples number of samples in each vector
  6497. */
  6498. void arm_cmplx_mult_real_q15(
  6499. const q15_t * pSrcCmplx,
  6500. const q15_t * pSrcReal,
  6501. q15_t * pCmplxDst,
  6502. uint32_t numSamples);
  6503. /**
  6504. * @brief Q31 complex-by-real multiplication
  6505. * @param[in] pSrcCmplx points to the complex input vector
  6506. * @param[in] pSrcReal points to the real input vector
  6507. * @param[out] pCmplxDst points to the complex output vector
  6508. * @param[in] numSamples number of samples in each vector
  6509. */
  6510. void arm_cmplx_mult_real_q31(
  6511. const q31_t * pSrcCmplx,
  6512. const q31_t * pSrcReal,
  6513. q31_t * pCmplxDst,
  6514. uint32_t numSamples);
  6515. /**
  6516. * @brief Floating-point complex-by-real multiplication
  6517. * @param[in] pSrcCmplx points to the complex input vector
  6518. * @param[in] pSrcReal points to the real input vector
  6519. * @param[out] pCmplxDst points to the complex output vector
  6520. * @param[in] numSamples number of samples in each vector
  6521. */
  6522. void arm_cmplx_mult_real_f32(
  6523. const float32_t * pSrcCmplx,
  6524. const float32_t * pSrcReal,
  6525. float32_t * pCmplxDst,
  6526. uint32_t numSamples);
  6527. /**
  6528. * @brief Minimum value of a Q7 vector.
  6529. * @param[in] pSrc is input pointer
  6530. * @param[in] blockSize is the number of samples to process
  6531. * @param[out] result is output pointer
  6532. * @param[in] index is the array index of the minimum value in the input buffer.
  6533. */
  6534. void arm_min_q7(
  6535. const q7_t * pSrc,
  6536. uint32_t blockSize,
  6537. q7_t * result,
  6538. uint32_t * index);
  6539. /**
  6540. * @brief Minimum value of a Q15 vector.
  6541. * @param[in] pSrc is input pointer
  6542. * @param[in] blockSize is the number of samples to process
  6543. * @param[out] pResult is output pointer
  6544. * @param[in] pIndex is the array index of the minimum value in the input buffer.
  6545. */
  6546. void arm_min_q15(
  6547. const q15_t * pSrc,
  6548. uint32_t blockSize,
  6549. q15_t * pResult,
  6550. uint32_t * pIndex);
  6551. /**
  6552. * @brief Minimum value of a Q31 vector.
  6553. * @param[in] pSrc is input pointer
  6554. * @param[in] blockSize is the number of samples to process
  6555. * @param[out] pResult is output pointer
  6556. * @param[out] pIndex is the array index of the minimum value in the input buffer.
  6557. */
  6558. void arm_min_q31(
  6559. const q31_t * pSrc,
  6560. uint32_t blockSize,
  6561. q31_t * pResult,
  6562. uint32_t * pIndex);
  6563. /**
  6564. * @brief Minimum value of a floating-point vector.
  6565. * @param[in] pSrc is input pointer
  6566. * @param[in] blockSize is the number of samples to process
  6567. * @param[out] pResult is output pointer
  6568. * @param[out] pIndex is the array index of the minimum value in the input buffer.
  6569. */
  6570. void arm_min_f32(
  6571. const float32_t * pSrc,
  6572. uint32_t blockSize,
  6573. float32_t * pResult,
  6574. uint32_t * pIndex);
  6575. /**
  6576. * @brief Maximum value of a Q7 vector.
  6577. * @param[in] pSrc points to the input buffer
  6578. * @param[in] blockSize length of the input vector
  6579. * @param[out] pResult maximum value returned here
  6580. * @param[out] pIndex index of maximum value returned here
  6581. */
  6582. void arm_max_q7(
  6583. const q7_t * pSrc,
  6584. uint32_t blockSize,
  6585. q7_t * pResult,
  6586. uint32_t * pIndex);
  6587. /**
  6588. * @brief Maximum value of a Q15 vector.
  6589. * @param[in] pSrc points to the input buffer
  6590. * @param[in] blockSize length of the input vector
  6591. * @param[out] pResult maximum value returned here
  6592. * @param[out] pIndex index of maximum value returned here
  6593. */
  6594. void arm_max_q15(
  6595. const q15_t * pSrc,
  6596. uint32_t blockSize,
  6597. q15_t * pResult,
  6598. uint32_t * pIndex);
  6599. /**
  6600. * @brief Maximum value of a Q31 vector.
  6601. * @param[in] pSrc points to the input buffer
  6602. * @param[in] blockSize length of the input vector
  6603. * @param[out] pResult maximum value returned here
  6604. * @param[out] pIndex index of maximum value returned here
  6605. */
  6606. void arm_max_q31(
  6607. const q31_t * pSrc,
  6608. uint32_t blockSize,
  6609. q31_t * pResult,
  6610. uint32_t * pIndex);
  6611. /**
  6612. * @brief Maximum value of a floating-point vector.
  6613. * @param[in] pSrc points to the input buffer
  6614. * @param[in] blockSize length of the input vector
  6615. * @param[out] pResult maximum value returned here
  6616. * @param[out] pIndex index of maximum value returned here
  6617. */
  6618. void arm_max_f32(
  6619. const float32_t * pSrc,
  6620. uint32_t blockSize,
  6621. float32_t * pResult,
  6622. uint32_t * pIndex);
  6623. /**
  6624. @brief Maximum value of a floating-point vector.
  6625. @param[in] pSrc points to the input vector
  6626. @param[in] blockSize number of samples in input vector
  6627. @param[out] pResult maximum value returned here
  6628. @return none
  6629. */
  6630. void arm_max_no_idx_f32(
  6631. const float32_t *pSrc,
  6632. uint32_t blockSize,
  6633. float32_t *pResult);
  6634. /**
  6635. * @brief Q15 complex-by-complex multiplication
  6636. * @param[in] pSrcA points to the first input vector
  6637. * @param[in] pSrcB points to the second input vector
  6638. * @param[out] pDst points to the output vector
  6639. * @param[in] numSamples number of complex samples in each vector
  6640. */
  6641. void arm_cmplx_mult_cmplx_q15(
  6642. const q15_t * pSrcA,
  6643. const q15_t * pSrcB,
  6644. q15_t * pDst,
  6645. uint32_t numSamples);
  6646. /**
  6647. * @brief Q31 complex-by-complex multiplication
  6648. * @param[in] pSrcA points to the first input vector
  6649. * @param[in] pSrcB points to the second input vector
  6650. * @param[out] pDst points to the output vector
  6651. * @param[in] numSamples number of complex samples in each vector
  6652. */
  6653. void arm_cmplx_mult_cmplx_q31(
  6654. const q31_t * pSrcA,
  6655. const q31_t * pSrcB,
  6656. q31_t * pDst,
  6657. uint32_t numSamples);
  6658. /**
  6659. * @brief Floating-point complex-by-complex multiplication
  6660. * @param[in] pSrcA points to the first input vector
  6661. * @param[in] pSrcB points to the second input vector
  6662. * @param[out] pDst points to the output vector
  6663. * @param[in] numSamples number of complex samples in each vector
  6664. */
  6665. void arm_cmplx_mult_cmplx_f32(
  6666. const float32_t * pSrcA,
  6667. const float32_t * pSrcB,
  6668. float32_t * pDst,
  6669. uint32_t numSamples);
  6670. /**
  6671. * @brief Converts the elements of the floating-point vector to Q31 vector.
  6672. * @param[in] pSrc points to the floating-point input vector
  6673. * @param[out] pDst points to the Q31 output vector
  6674. * @param[in] blockSize length of the input vector
  6675. */
  6676. void arm_float_to_q31(
  6677. const float32_t * pSrc,
  6678. q31_t * pDst,
  6679. uint32_t blockSize);
  6680. /**
  6681. * @brief Converts the elements of the floating-point vector to Q15 vector.
  6682. * @param[in] pSrc points to the floating-point input vector
  6683. * @param[out] pDst points to the Q15 output vector
  6684. * @param[in] blockSize length of the input vector
  6685. */
  6686. void arm_float_to_q15(
  6687. const float32_t * pSrc,
  6688. q15_t * pDst,
  6689. uint32_t blockSize);
  6690. /**
  6691. * @brief Converts the elements of the floating-point vector to Q7 vector.
  6692. * @param[in] pSrc points to the floating-point input vector
  6693. * @param[out] pDst points to the Q7 output vector
  6694. * @param[in] blockSize length of the input vector
  6695. */
  6696. void arm_float_to_q7(
  6697. const float32_t * pSrc,
  6698. q7_t * pDst,
  6699. uint32_t blockSize);
  6700. /**
  6701. * @brief Converts the elements of the Q31 vector to floating-point vector.
  6702. * @param[in] pSrc is input pointer
  6703. * @param[out] pDst is output pointer
  6704. * @param[in] blockSize is the number of samples to process
  6705. */
  6706. void arm_q31_to_float(
  6707. const q31_t * pSrc,
  6708. float32_t * pDst,
  6709. uint32_t blockSize);
  6710. /**
  6711. * @brief Converts the elements of the Q31 vector to Q15 vector.
  6712. * @param[in] pSrc is input pointer
  6713. * @param[out] pDst is output pointer
  6714. * @param[in] blockSize is the number of samples to process
  6715. */
  6716. void arm_q31_to_q15(
  6717. const q31_t * pSrc,
  6718. q15_t * pDst,
  6719. uint32_t blockSize);
  6720. /**
  6721. * @brief Converts the elements of the Q31 vector to Q7 vector.
  6722. * @param[in] pSrc is input pointer
  6723. * @param[out] pDst is output pointer
  6724. * @param[in] blockSize is the number of samples to process
  6725. */
  6726. void arm_q31_to_q7(
  6727. const q31_t * pSrc,
  6728. q7_t * pDst,
  6729. uint32_t blockSize);
  6730. /**
  6731. * @brief Converts the elements of the Q15 vector to floating-point vector.
  6732. * @param[in] pSrc is input pointer
  6733. * @param[out] pDst is output pointer
  6734. * @param[in] blockSize is the number of samples to process
  6735. */
  6736. void arm_q15_to_float(
  6737. const q15_t * pSrc,
  6738. float32_t * pDst,
  6739. uint32_t blockSize);
  6740. /**
  6741. * @brief Converts the elements of the Q15 vector to Q31 vector.
  6742. * @param[in] pSrc is input pointer
  6743. * @param[out] pDst is output pointer
  6744. * @param[in] blockSize is the number of samples to process
  6745. */
  6746. void arm_q15_to_q31(
  6747. const q15_t * pSrc,
  6748. q31_t * pDst,
  6749. uint32_t blockSize);
  6750. /**
  6751. * @brief Converts the elements of the Q15 vector to Q7 vector.
  6752. * @param[in] pSrc is input pointer
  6753. * @param[out] pDst is output pointer
  6754. * @param[in] blockSize is the number of samples to process
  6755. */
  6756. void arm_q15_to_q7(
  6757. const q15_t * pSrc,
  6758. q7_t * pDst,
  6759. uint32_t blockSize);
  6760. /**
  6761. * @brief Converts the elements of the Q7 vector to floating-point vector.
  6762. * @param[in] pSrc is input pointer
  6763. * @param[out] pDst is output pointer
  6764. * @param[in] blockSize is the number of samples to process
  6765. */
  6766. void arm_q7_to_float(
  6767. const q7_t * pSrc,
  6768. float32_t * pDst,
  6769. uint32_t blockSize);
  6770. /**
  6771. * @brief Converts the elements of the Q7 vector to Q31 vector.
  6772. * @param[in] pSrc input pointer
  6773. * @param[out] pDst output pointer
  6774. * @param[in] blockSize number of samples to process
  6775. */
  6776. void arm_q7_to_q31(
  6777. const q7_t * pSrc,
  6778. q31_t * pDst,
  6779. uint32_t blockSize);
  6780. /**
  6781. * @brief Converts the elements of the Q7 vector to Q15 vector.
  6782. * @param[in] pSrc input pointer
  6783. * @param[out] pDst output pointer
  6784. * @param[in] blockSize number of samples to process
  6785. */
  6786. void arm_q7_to_q15(
  6787. const q7_t * pSrc,
  6788. q15_t * pDst,
  6789. uint32_t blockSize);
  6790. /**
  6791. * @brief Struct for specifying SVM Kernel
  6792. */
  6793. typedef enum
  6794. {
  6795. ARM_ML_KERNEL_LINEAR = 0,
  6796. /**< Linear kernel */
  6797. ARM_ML_KERNEL_POLYNOMIAL = 1,
  6798. /**< Polynomial kernel */
  6799. ARM_ML_KERNEL_RBF = 2,
  6800. /**< Radial Basis Function kernel */
  6801. ARM_ML_KERNEL_SIGMOID = 3
  6802. /**< Sigmoid kernel */
  6803. } arm_ml_kernel_type;
  6804. /**
  6805. * @brief Instance structure for linear SVM prediction function.
  6806. */
  6807. typedef struct
  6808. {
  6809. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  6810. uint32_t vectorDimension; /**< Dimension of vector space */
  6811. float32_t intercept; /**< Intercept */
  6812. const float32_t *dualCoefficients; /**< Dual coefficients */
  6813. const float32_t *supportVectors; /**< Support vectors */
  6814. const int32_t *classes; /**< The two SVM classes */
  6815. } arm_svm_linear_instance_f32;
  6816. /**
  6817. * @brief Instance structure for polynomial SVM prediction function.
  6818. */
  6819. typedef struct
  6820. {
  6821. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  6822. uint32_t vectorDimension; /**< Dimension of vector space */
  6823. float32_t intercept; /**< Intercept */
  6824. const float32_t *dualCoefficients; /**< Dual coefficients */
  6825. const float32_t *supportVectors; /**< Support vectors */
  6826. const int32_t *classes; /**< The two SVM classes */
  6827. int32_t degree; /**< Polynomial degree */
  6828. float32_t coef0; /**< Polynomial constant */
  6829. float32_t gamma; /**< Gamma factor */
  6830. } arm_svm_polynomial_instance_f32;
  6831. /**
  6832. * @brief Instance structure for rbf SVM prediction function.
  6833. */
  6834. typedef struct
  6835. {
  6836. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  6837. uint32_t vectorDimension; /**< Dimension of vector space */
  6838. float32_t intercept; /**< Intercept */
  6839. const float32_t *dualCoefficients; /**< Dual coefficients */
  6840. const float32_t *supportVectors; /**< Support vectors */
  6841. const int32_t *classes; /**< The two SVM classes */
  6842. float32_t gamma; /**< Gamma factor */
  6843. } arm_svm_rbf_instance_f32;
  6844. /**
  6845. * @brief Instance structure for sigmoid SVM prediction function.
  6846. */
  6847. typedef struct
  6848. {
  6849. uint32_t nbOfSupportVectors; /**< Number of support vectors */
  6850. uint32_t vectorDimension; /**< Dimension of vector space */
  6851. float32_t intercept; /**< Intercept */
  6852. const float32_t *dualCoefficients; /**< Dual coefficients */
  6853. const float32_t *supportVectors; /**< Support vectors */
  6854. const int32_t *classes; /**< The two SVM classes */
  6855. float32_t coef0; /**< Independant constant */
  6856. float32_t gamma; /**< Gamma factor */
  6857. } arm_svm_sigmoid_instance_f32;
  6858. /**
  6859. * @brief SVM linear instance init function
  6860. * @param[in] S Parameters for SVM functions
  6861. * @param[in] nbOfSupportVectors Number of support vectors
  6862. * @param[in] vectorDimension Dimension of vector space
  6863. * @param[in] intercept Intercept
  6864. * @param[in] dualCoefficients Array of dual coefficients
  6865. * @param[in] supportVectors Array of support vectors
  6866. * @param[in] classes Array of 2 classes ID
  6867. * @return none.
  6868. *
  6869. */
  6870. void arm_svm_linear_init_f32(arm_svm_linear_instance_f32 *S,
  6871. uint32_t nbOfSupportVectors,
  6872. uint32_t vectorDimension,
  6873. float32_t intercept,
  6874. const float32_t *dualCoefficients,
  6875. const float32_t *supportVectors,
  6876. const int32_t *classes);
  6877. /**
  6878. * @brief SVM linear prediction
  6879. * @param[in] S Pointer to an instance of the linear SVM structure.
  6880. * @param[in] in Pointer to input vector
  6881. * @param[out] pResult Decision value
  6882. * @return none.
  6883. *
  6884. */
  6885. void arm_svm_linear_predict_f32(const arm_svm_linear_instance_f32 *S,
  6886. const float32_t * in,
  6887. int32_t * pResult);
  6888. /**
  6889. * @brief SVM polynomial instance init function
  6890. * @param[in] S points to an instance of the polynomial SVM structure.
  6891. * @param[in] nbOfSupportVectors Number of support vectors
  6892. * @param[in] vectorDimension Dimension of vector space
  6893. * @param[in] intercept Intercept
  6894. * @param[in] dualCoefficients Array of dual coefficients
  6895. * @param[in] supportVectors Array of support vectors
  6896. * @param[in] classes Array of 2 classes ID
  6897. * @param[in] degree Polynomial degree
  6898. * @param[in] coef0 coeff0 (scikit-learn terminology)
  6899. * @param[in] gamma gamma (scikit-learn terminology)
  6900. * @return none.
  6901. *
  6902. */
  6903. void arm_svm_polynomial_init_f32(arm_svm_polynomial_instance_f32 *S,
  6904. uint32_t nbOfSupportVectors,
  6905. uint32_t vectorDimension,
  6906. float32_t intercept,
  6907. const float32_t *dualCoefficients,
  6908. const float32_t *supportVectors,
  6909. const int32_t *classes,
  6910. int32_t degree,
  6911. float32_t coef0,
  6912. float32_t gamma
  6913. );
  6914. /**
  6915. * @brief SVM polynomial prediction
  6916. * @param[in] S Pointer to an instance of the polynomial SVM structure.
  6917. * @param[in] in Pointer to input vector
  6918. * @param[out] pResult Decision value
  6919. * @return none.
  6920. *
  6921. */
  6922. void arm_svm_polynomial_predict_f32(const arm_svm_polynomial_instance_f32 *S,
  6923. const float32_t * in,
  6924. int32_t * pResult);
  6925. /**
  6926. * @brief SVM radial basis function instance init function
  6927. * @param[in] S points to an instance of the polynomial SVM structure.
  6928. * @param[in] nbOfSupportVectors Number of support vectors
  6929. * @param[in] vectorDimension Dimension of vector space
  6930. * @param[in] intercept Intercept
  6931. * @param[in] dualCoefficients Array of dual coefficients
  6932. * @param[in] supportVectors Array of support vectors
  6933. * @param[in] classes Array of 2 classes ID
  6934. * @param[in] gamma gamma (scikit-learn terminology)
  6935. * @return none.
  6936. *
  6937. */
  6938. void arm_svm_rbf_init_f32(arm_svm_rbf_instance_f32 *S,
  6939. uint32_t nbOfSupportVectors,
  6940. uint32_t vectorDimension,
  6941. float32_t intercept,
  6942. const float32_t *dualCoefficients,
  6943. const float32_t *supportVectors,
  6944. const int32_t *classes,
  6945. float32_t gamma
  6946. );
  6947. /**
  6948. * @brief SVM rbf prediction
  6949. * @param[in] S Pointer to an instance of the rbf SVM structure.
  6950. * @param[in] in Pointer to input vector
  6951. * @param[out] pResult decision value
  6952. * @return none.
  6953. *
  6954. */
  6955. void arm_svm_rbf_predict_f32(const arm_svm_rbf_instance_f32 *S,
  6956. const float32_t * in,
  6957. int32_t * pResult);
  6958. /**
  6959. * @brief SVM sigmoid instance init function
  6960. * @param[in] S points to an instance of the rbf SVM structure.
  6961. * @param[in] nbOfSupportVectors Number of support vectors
  6962. * @param[in] vectorDimension Dimension of vector space
  6963. * @param[in] intercept Intercept
  6964. * @param[in] dualCoefficients Array of dual coefficients
  6965. * @param[in] supportVectors Array of support vectors
  6966. * @param[in] classes Array of 2 classes ID
  6967. * @param[in] coef0 coeff0 (scikit-learn terminology)
  6968. * @param[in] gamma gamma (scikit-learn terminology)
  6969. * @return none.
  6970. *
  6971. */
  6972. void arm_svm_sigmoid_init_f32(arm_svm_sigmoid_instance_f32 *S,
  6973. uint32_t nbOfSupportVectors,
  6974. uint32_t vectorDimension,
  6975. float32_t intercept,
  6976. const float32_t *dualCoefficients,
  6977. const float32_t *supportVectors,
  6978. const int32_t *classes,
  6979. float32_t coef0,
  6980. float32_t gamma
  6981. );
  6982. /**
  6983. * @brief SVM sigmoid prediction
  6984. * @param[in] S Pointer to an instance of the rbf SVM structure.
  6985. * @param[in] in Pointer to input vector
  6986. * @param[out] pResult Decision value
  6987. * @return none.
  6988. *
  6989. */
  6990. void arm_svm_sigmoid_predict_f32(const arm_svm_sigmoid_instance_f32 *S,
  6991. const float32_t * in,
  6992. int32_t * pResult);
  6993. /**
  6994. * @brief Instance structure for Naive Gaussian Bayesian estimator.
  6995. */
  6996. typedef struct
  6997. {
  6998. uint32_t vectorDimension; /**< Dimension of vector space */
  6999. uint32_t numberOfClasses; /**< Number of different classes */
  7000. const float32_t *theta; /**< Mean values for the Gaussians */
  7001. const float32_t *sigma; /**< Variances for the Gaussians */
  7002. const float32_t *classPriors; /**< Class prior probabilities */
  7003. float32_t epsilon; /**< Additive value to variances */
  7004. } arm_gaussian_naive_bayes_instance_f32;
  7005. /**
  7006. * @brief Naive Gaussian Bayesian Estimator
  7007. *
  7008. * @param[in] S points to a naive bayes instance structure
  7009. * @param[in] in points to the elements of the input vector.
  7010. * @param[in] pBuffer points to a buffer of length numberOfClasses
  7011. * @return The predicted class
  7012. *
  7013. */
  7014. uint32_t arm_gaussian_naive_bayes_predict_f32(const arm_gaussian_naive_bayes_instance_f32 *S,
  7015. const float32_t * in,
  7016. float32_t *pBuffer);
  7017. /**
  7018. * @brief Computation of the LogSumExp
  7019. *
  7020. * In probabilistic computations, the dynamic of the probability values can be very
  7021. * wide because they come from gaussian functions.
  7022. * To avoid underflow and overflow issues, the values are represented by their log.
  7023. * In this representation, multiplying the original exp values is easy : their logs are added.
  7024. * But adding the original exp values is requiring some special handling and it is the
  7025. * goal of the LogSumExp function.
  7026. *
  7027. * If the values are x1...xn, the function is computing:
  7028. *
  7029. * ln(exp(x1) + ... + exp(xn)) and the computation is done in such a way that
  7030. * rounding issues are minimised.
  7031. *
  7032. * The max xm of the values is extracted and the function is computing:
  7033. * xm + ln(exp(x1 - xm) + ... + exp(xn - xm))
  7034. *
  7035. * @param[in] *in Pointer to an array of input values.
  7036. * @param[in] blockSize Number of samples in the input array.
  7037. * @return LogSumExp
  7038. *
  7039. */
  7040. float32_t arm_logsumexp_f32(const float32_t *in, uint32_t blockSize);
  7041. /**
  7042. * @brief Dot product with log arithmetic
  7043. *
  7044. * Vectors are containing the log of the samples
  7045. *
  7046. * @param[in] pSrcA points to the first input vector
  7047. * @param[in] pSrcB points to the second input vector
  7048. * @param[in] blockSize number of samples in each vector
  7049. * @param[in] pTmpBuffer temporary buffer of length blockSize
  7050. * @return The log of the dot product .
  7051. *
  7052. */
  7053. float32_t arm_logsumexp_dot_prod_f32(const float32_t * pSrcA,
  7054. const float32_t * pSrcB,
  7055. uint32_t blockSize,
  7056. float32_t *pTmpBuffer);
  7057. /**
  7058. * @brief Entropy
  7059. *
  7060. * @param[in] pSrcA Array of input values.
  7061. * @param[in] blockSize Number of samples in the input array.
  7062. * @return Entropy -Sum(p ln p)
  7063. *
  7064. */
  7065. float32_t arm_entropy_f32(const float32_t * pSrcA,uint32_t blockSize);
  7066. /**
  7067. * @brief Entropy
  7068. *
  7069. * @param[in] pSrcA Array of input values.
  7070. * @param[in] blockSize Number of samples in the input array.
  7071. * @return Entropy -Sum(p ln p)
  7072. *
  7073. */
  7074. float64_t arm_entropy_f64(const float64_t * pSrcA, uint32_t blockSize);
  7075. /**
  7076. * @brief Kullback-Leibler
  7077. *
  7078. * @param[in] pSrcA Pointer to an array of input values for probability distribution A.
  7079. * @param[in] pSrcB Pointer to an array of input values for probability distribution B.
  7080. * @param[in] blockSize Number of samples in the input array.
  7081. * @return Kullback-Leibler Divergence D(A || B)
  7082. *
  7083. */
  7084. float32_t arm_kullback_leibler_f32(const float32_t * pSrcA
  7085. ,const float32_t * pSrcB
  7086. ,uint32_t blockSize);
  7087. /**
  7088. * @brief Kullback-Leibler
  7089. *
  7090. * @param[in] pSrcA Pointer to an array of input values for probability distribution A.
  7091. * @param[in] pSrcB Pointer to an array of input values for probability distribution B.
  7092. * @param[in] blockSize Number of samples in the input array.
  7093. * @return Kullback-Leibler Divergence D(A || B)
  7094. *
  7095. */
  7096. float64_t arm_kullback_leibler_f64(const float64_t * pSrcA,
  7097. const float64_t * pSrcB,
  7098. uint32_t blockSize);
  7099. /**
  7100. * @brief Weighted sum
  7101. *
  7102. *
  7103. * @param[in] *in Array of input values.
  7104. * @param[in] *weigths Weights
  7105. * @param[in] blockSize Number of samples in the input array.
  7106. * @return Weighted sum
  7107. *
  7108. */
  7109. float32_t arm_weighted_sum_f32(const float32_t *in
  7110. , const float32_t *weigths
  7111. , uint32_t blockSize);
  7112. /**
  7113. * @brief Barycenter
  7114. *
  7115. *
  7116. * @param[in] in List of vectors
  7117. * @param[in] weights Weights of the vectors
  7118. * @param[out] out Barycenter
  7119. * @param[in] nbVectors Number of vectors
  7120. * @param[in] vecDim Dimension of space (vector dimension)
  7121. * @return None
  7122. *
  7123. */
  7124. void arm_barycenter_f32(const float32_t *in
  7125. , const float32_t *weights
  7126. , float32_t *out
  7127. , uint32_t nbVectors
  7128. , uint32_t vecDim);
  7129. /**
  7130. * @brief Euclidean distance between two vectors
  7131. * @param[in] pA First vector
  7132. * @param[in] pB Second vector
  7133. * @param[in] blockSize vector length
  7134. * @return distance
  7135. *
  7136. */
  7137. float32_t arm_euclidean_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7138. /**
  7139. * @brief Bray-Curtis distance between two vectors
  7140. * @param[in] pA First vector
  7141. * @param[in] pB Second vector
  7142. * @param[in] blockSize vector length
  7143. * @return distance
  7144. *
  7145. */
  7146. float32_t arm_braycurtis_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7147. /**
  7148. * @brief Canberra distance between two vectors
  7149. *
  7150. * This function may divide by zero when samples pA[i] and pB[i] are both zero.
  7151. * The result of the computation will be correct. So the division per zero may be
  7152. * ignored.
  7153. *
  7154. * @param[in] pA First vector
  7155. * @param[in] pB Second vector
  7156. * @param[in] blockSize vector length
  7157. * @return distance
  7158. *
  7159. */
  7160. float32_t arm_canberra_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7161. /**
  7162. * @brief Chebyshev distance between two vectors
  7163. * @param[in] pA First vector
  7164. * @param[in] pB Second vector
  7165. * @param[in] blockSize vector length
  7166. * @return distance
  7167. *
  7168. */
  7169. float32_t arm_chebyshev_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7170. /**
  7171. * @brief Cityblock (Manhattan) distance between two vectors
  7172. * @param[in] pA First vector
  7173. * @param[in] pB Second vector
  7174. * @param[in] blockSize vector length
  7175. * @return distance
  7176. *
  7177. */
  7178. float32_t arm_cityblock_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7179. /**
  7180. * @brief Correlation distance between two vectors
  7181. *
  7182. * The input vectors are modified in place !
  7183. *
  7184. * @param[in] pA First vector
  7185. * @param[in] pB Second vector
  7186. * @param[in] blockSize vector length
  7187. * @return distance
  7188. *
  7189. */
  7190. float32_t arm_correlation_distance_f32(float32_t *pA,float32_t *pB, uint32_t blockSize);
  7191. /**
  7192. * @brief Cosine distance between two vectors
  7193. *
  7194. * @param[in] pA First vector
  7195. * @param[in] pB Second vector
  7196. * @param[in] blockSize vector length
  7197. * @return distance
  7198. *
  7199. */
  7200. float32_t arm_cosine_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize);
  7201. /**
  7202. * @brief Jensen-Shannon distance between two vectors
  7203. *
  7204. * This function is assuming that elements of second vector are > 0
  7205. * and 0 only when the corresponding element of first vector is 0.
  7206. * Otherwise the result of the computation does not make sense
  7207. * and for speed reasons, the cases returning NaN or Infinity are not
  7208. * managed.
  7209. *
  7210. * When the function is computing x log (x / y) with x 0 and y 0,
  7211. * it will compute the right value (0) but a division per zero will occur
  7212. * and shoudl be ignored in client code.
  7213. *
  7214. * @param[in] pA First vector
  7215. * @param[in] pB Second vector
  7216. * @param[in] blockSize vector length
  7217. * @return distance
  7218. *
  7219. */
  7220. float32_t arm_jensenshannon_distance_f32(const float32_t *pA,const float32_t *pB,uint32_t blockSize);
  7221. /**
  7222. * @brief Minkowski distance between two vectors
  7223. *
  7224. * @param[in] pA First vector
  7225. * @param[in] pB Second vector
  7226. * @param[in] n Norm order (>= 2)
  7227. * @param[in] blockSize vector length
  7228. * @return distance
  7229. *
  7230. */
  7231. float32_t arm_minkowski_distance_f32(const float32_t *pA,const float32_t *pB, int32_t order, uint32_t blockSize);
  7232. /**
  7233. * @brief Dice distance between two vectors
  7234. *
  7235. * @param[in] pA First vector of packed booleans
  7236. * @param[in] pB Second vector of packed booleans
  7237. * @param[in] order Distance order
  7238. * @param[in] blockSize Number of samples
  7239. * @return distance
  7240. *
  7241. */
  7242. float32_t arm_dice_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7243. /**
  7244. * @brief Hamming distance between two vectors
  7245. *
  7246. * @param[in] pA First vector of packed booleans
  7247. * @param[in] pB Second vector of packed booleans
  7248. * @param[in] numberOfBools Number of booleans
  7249. * @return distance
  7250. *
  7251. */
  7252. float32_t arm_hamming_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7253. /**
  7254. * @brief Jaccard distance between two vectors
  7255. *
  7256. * @param[in] pA First vector of packed booleans
  7257. * @param[in] pB Second vector of packed booleans
  7258. * @param[in] numberOfBools Number of booleans
  7259. * @return distance
  7260. *
  7261. */
  7262. float32_t arm_jaccard_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7263. /**
  7264. * @brief Kulsinski distance between two vectors
  7265. *
  7266. * @param[in] pA First vector of packed booleans
  7267. * @param[in] pB Second vector of packed booleans
  7268. * @param[in] numberOfBools Number of booleans
  7269. * @return distance
  7270. *
  7271. */
  7272. float32_t arm_kulsinski_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7273. /**
  7274. * @brief Roger Stanimoto distance between two vectors
  7275. *
  7276. * @param[in] pA First vector of packed booleans
  7277. * @param[in] pB Second vector of packed booleans
  7278. * @param[in] numberOfBools Number of booleans
  7279. * @return distance
  7280. *
  7281. */
  7282. float32_t arm_rogerstanimoto_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7283. /**
  7284. * @brief Russell-Rao distance between two vectors
  7285. *
  7286. * @param[in] pA First vector of packed booleans
  7287. * @param[in] pB Second vector of packed booleans
  7288. * @param[in] numberOfBools Number of booleans
  7289. * @return distance
  7290. *
  7291. */
  7292. float32_t arm_russellrao_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7293. /**
  7294. * @brief Sokal-Michener distance between two vectors
  7295. *
  7296. * @param[in] pA First vector of packed booleans
  7297. * @param[in] pB Second vector of packed booleans
  7298. * @param[in] numberOfBools Number of booleans
  7299. * @return distance
  7300. *
  7301. */
  7302. float32_t arm_sokalmichener_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7303. /**
  7304. * @brief Sokal-Sneath distance between two vectors
  7305. *
  7306. * @param[in] pA First vector of packed booleans
  7307. * @param[in] pB Second vector of packed booleans
  7308. * @param[in] numberOfBools Number of booleans
  7309. * @return distance
  7310. *
  7311. */
  7312. float32_t arm_sokalsneath_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7313. /**
  7314. * @brief Yule distance between two vectors
  7315. *
  7316. * @param[in] pA First vector of packed booleans
  7317. * @param[in] pB Second vector of packed booleans
  7318. * @param[in] numberOfBools Number of booleans
  7319. * @return distance
  7320. *
  7321. */
  7322. float32_t arm_yule_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools);
  7323. /**
  7324. * @ingroup groupInterpolation
  7325. */
  7326. /**
  7327. * @defgroup BilinearInterpolate Bilinear Interpolation
  7328. *
  7329. * Bilinear interpolation is an extension of linear interpolation applied to a two dimensional grid.
  7330. * The underlying function <code>f(x, y)</code> is sampled on a regular grid and the interpolation process
  7331. * determines values between the grid points.
  7332. * Bilinear interpolation is equivalent to two step linear interpolation, first in the x-dimension and then in the y-dimension.
  7333. * Bilinear interpolation is often used in image processing to rescale images.
  7334. * The CMSIS DSP library provides bilinear interpolation functions for Q7, Q15, Q31, and floating-point data types.
  7335. *
  7336. * <b>Algorithm</b>
  7337. * \par
  7338. * The instance structure used by the bilinear interpolation functions describes a two dimensional data table.
  7339. * For floating-point, the instance structure is defined as:
  7340. * <pre>
  7341. * typedef struct
  7342. * {
  7343. * uint16_t numRows;
  7344. * uint16_t numCols;
  7345. * float32_t *pData;
  7346. * } arm_bilinear_interp_instance_f32;
  7347. * </pre>
  7348. *
  7349. * \par
  7350. * where <code>numRows</code> specifies the number of rows in the table;
  7351. * <code>numCols</code> specifies the number of columns in the table;
  7352. * and <code>pData</code> points to an array of size <code>numRows*numCols</code> values.
  7353. * The data table <code>pTable</code> is organized in row order and the supplied data values fall on integer indexes.
  7354. * That is, table element (x,y) is located at <code>pTable[x + y*numCols]</code> where x and y are integers.
  7355. *
  7356. * \par
  7357. * Let <code>(x, y)</code> specify the desired interpolation point. Then define:
  7358. * <pre>
  7359. * XF = floor(x)
  7360. * YF = floor(y)
  7361. * </pre>
  7362. * \par
  7363. * The interpolated output point is computed as:
  7364. * <pre>
  7365. * f(x, y) = f(XF, YF) * (1-(x-XF)) * (1-(y-YF))
  7366. * + f(XF+1, YF) * (x-XF)*(1-(y-YF))
  7367. * + f(XF, YF+1) * (1-(x-XF))*(y-YF)
  7368. * + f(XF+1, YF+1) * (x-XF)*(y-YF)
  7369. * </pre>
  7370. * Note that the coordinates (x, y) contain integer and fractional components.
  7371. * The integer components specify which portion of the table to use while the
  7372. * fractional components control the interpolation processor.
  7373. *
  7374. * \par
  7375. * if (x,y) are outside of the table boundary, Bilinear interpolation returns zero output.
  7376. */
  7377. /**
  7378. * @addtogroup BilinearInterpolate
  7379. * @{
  7380. */
  7381. /**
  7382. * @brief Floating-point bilinear interpolation.
  7383. * @param[in,out] S points to an instance of the interpolation structure.
  7384. * @param[in] X interpolation coordinate.
  7385. * @param[in] Y interpolation coordinate.
  7386. * @return out interpolated value.
  7387. */
  7388. __STATIC_FORCEINLINE float32_t arm_bilinear_interp_f32(
  7389. const arm_bilinear_interp_instance_f32 * S,
  7390. float32_t X,
  7391. float32_t Y)
  7392. {
  7393. float32_t out;
  7394. float32_t f00, f01, f10, f11;
  7395. float32_t *pData = S->pData;
  7396. int32_t xIndex, yIndex, index;
  7397. float32_t xdiff, ydiff;
  7398. float32_t b1, b2, b3, b4;
  7399. xIndex = (int32_t) X;
  7400. yIndex = (int32_t) Y;
  7401. /* Care taken for table outside boundary */
  7402. /* Returns zero output when values are outside table boundary */
  7403. if (xIndex < 0 || xIndex > (S->numCols - 2) || yIndex < 0 || yIndex > (S->numRows - 2))
  7404. {
  7405. return (0);
  7406. }
  7407. /* Calculation of index for two nearest points in X-direction */
  7408. index = (xIndex ) + (yIndex ) * S->numCols;
  7409. /* Read two nearest points in X-direction */
  7410. f00 = pData[index];
  7411. f01 = pData[index + 1];
  7412. /* Calculation of index for two nearest points in Y-direction */
  7413. index = (xIndex ) + (yIndex+1) * S->numCols;
  7414. /* Read two nearest points in Y-direction */
  7415. f10 = pData[index];
  7416. f11 = pData[index + 1];
  7417. /* Calculation of intermediate values */
  7418. b1 = f00;
  7419. b2 = f01 - f00;
  7420. b3 = f10 - f00;
  7421. b4 = f00 - f01 - f10 + f11;
  7422. /* Calculation of fractional part in X */
  7423. xdiff = X - xIndex;
  7424. /* Calculation of fractional part in Y */
  7425. ydiff = Y - yIndex;
  7426. /* Calculation of bi-linear interpolated output */
  7427. out = b1 + b2 * xdiff + b3 * ydiff + b4 * xdiff * ydiff;
  7428. /* return to application */
  7429. return (out);
  7430. }
  7431. /**
  7432. * @brief Q31 bilinear interpolation.
  7433. * @param[in,out] S points to an instance of the interpolation structure.
  7434. * @param[in] X interpolation coordinate in 12.20 format.
  7435. * @param[in] Y interpolation coordinate in 12.20 format.
  7436. * @return out interpolated value.
  7437. */
  7438. __STATIC_FORCEINLINE q31_t arm_bilinear_interp_q31(
  7439. arm_bilinear_interp_instance_q31 * S,
  7440. q31_t X,
  7441. q31_t Y)
  7442. {
  7443. q31_t out; /* Temporary output */
  7444. q31_t acc = 0; /* output */
  7445. q31_t xfract, yfract; /* X, Y fractional parts */
  7446. q31_t x1, x2, y1, y2; /* Nearest output values */
  7447. int32_t rI, cI; /* Row and column indices */
  7448. q31_t *pYData = S->pData; /* pointer to output table values */
  7449. uint32_t nCols = S->numCols; /* num of rows */
  7450. /* Input is in 12.20 format */
  7451. /* 12 bits for the table index */
  7452. /* Index value calculation */
  7453. rI = ((X & (q31_t)0xFFF00000) >> 20);
  7454. /* Input is in 12.20 format */
  7455. /* 12 bits for the table index */
  7456. /* Index value calculation */
  7457. cI = ((Y & (q31_t)0xFFF00000) >> 20);
  7458. /* Care taken for table outside boundary */
  7459. /* Returns zero output when values are outside table boundary */
  7460. if (rI < 0 || rI > (S->numCols - 2) || cI < 0 || cI > (S->numRows - 2))
  7461. {
  7462. return (0);
  7463. }
  7464. /* 20 bits for the fractional part */
  7465. /* shift left xfract by 11 to keep 1.31 format */
  7466. xfract = (X & 0x000FFFFF) << 11U;
  7467. /* Read two nearest output values from the index */
  7468. x1 = pYData[(rI) + (int32_t)nCols * (cI) ];
  7469. x2 = pYData[(rI) + (int32_t)nCols * (cI) + 1];
  7470. /* 20 bits for the fractional part */
  7471. /* shift left yfract by 11 to keep 1.31 format */
  7472. yfract = (Y & 0x000FFFFF) << 11U;
  7473. /* Read two nearest output values from the index */
  7474. y1 = pYData[(rI) + (int32_t)nCols * (cI + 1) ];
  7475. y2 = pYData[(rI) + (int32_t)nCols * (cI + 1) + 1];
  7476. /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 3.29(q29) format */
  7477. out = ((q31_t) (((q63_t) x1 * (0x7FFFFFFF - xfract)) >> 32));
  7478. acc = ((q31_t) (((q63_t) out * (0x7FFFFFFF - yfract)) >> 32));
  7479. /* x2 * (xfract) * (1-yfract) in 3.29(q29) and adding to acc */
  7480. out = ((q31_t) ((q63_t) x2 * (0x7FFFFFFF - yfract) >> 32));
  7481. acc += ((q31_t) ((q63_t) out * (xfract) >> 32));
  7482. /* y1 * (1 - xfract) * (yfract) in 3.29(q29) and adding to acc */
  7483. out = ((q31_t) ((q63_t) y1 * (0x7FFFFFFF - xfract) >> 32));
  7484. acc += ((q31_t) ((q63_t) out * (yfract) >> 32));
  7485. /* y2 * (xfract) * (yfract) in 3.29(q29) and adding to acc */
  7486. out = ((q31_t) ((q63_t) y2 * (xfract) >> 32));
  7487. acc += ((q31_t) ((q63_t) out * (yfract) >> 32));
  7488. /* Convert acc to 1.31(q31) format */
  7489. return ((q31_t)(acc << 2));
  7490. }
  7491. /**
  7492. * @brief Q15 bilinear interpolation.
  7493. * @param[in,out] S points to an instance of the interpolation structure.
  7494. * @param[in] X interpolation coordinate in 12.20 format.
  7495. * @param[in] Y interpolation coordinate in 12.20 format.
  7496. * @return out interpolated value.
  7497. */
  7498. __STATIC_FORCEINLINE q15_t arm_bilinear_interp_q15(
  7499. arm_bilinear_interp_instance_q15 * S,
  7500. q31_t X,
  7501. q31_t Y)
  7502. {
  7503. q63_t acc = 0; /* output */
  7504. q31_t out; /* Temporary output */
  7505. q15_t x1, x2, y1, y2; /* Nearest output values */
  7506. q31_t xfract, yfract; /* X, Y fractional parts */
  7507. int32_t rI, cI; /* Row and column indices */
  7508. q15_t *pYData = S->pData; /* pointer to output table values */
  7509. uint32_t nCols = S->numCols; /* num of rows */
  7510. /* Input is in 12.20 format */
  7511. /* 12 bits for the table index */
  7512. /* Index value calculation */
  7513. rI = ((X & (q31_t)0xFFF00000) >> 20);
  7514. /* Input is in 12.20 format */
  7515. /* 12 bits for the table index */
  7516. /* Index value calculation */
  7517. cI = ((Y & (q31_t)0xFFF00000) >> 20);
  7518. /* Care taken for table outside boundary */
  7519. /* Returns zero output when values are outside table boundary */
  7520. if (rI < 0 || rI > (S->numCols - 2) || cI < 0 || cI > (S->numRows - 2))
  7521. {
  7522. return (0);
  7523. }
  7524. /* 20 bits for the fractional part */
  7525. /* xfract should be in 12.20 format */
  7526. xfract = (X & 0x000FFFFF);
  7527. /* Read two nearest output values from the index */
  7528. x1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) ];
  7529. x2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) + 1];
  7530. /* 20 bits for the fractional part */
  7531. /* yfract should be in 12.20 format */
  7532. yfract = (Y & 0x000FFFFF);
  7533. /* Read two nearest output values from the index */
  7534. y1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) ];
  7535. y2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) + 1];
  7536. /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 13.51 format */
  7537. /* x1 is in 1.15(q15), xfract in 12.20 format and out is in 13.35 format */
  7538. /* convert 13.35 to 13.31 by right shifting and out is in 1.31 */
  7539. out = (q31_t) (((q63_t) x1 * (0x0FFFFF - xfract)) >> 4U);
  7540. acc = ((q63_t) out * (0x0FFFFF - yfract));
  7541. /* x2 * (xfract) * (1-yfract) in 1.51 and adding to acc */
  7542. out = (q31_t) (((q63_t) x2 * (0x0FFFFF - yfract)) >> 4U);
  7543. acc += ((q63_t) out * (xfract));
  7544. /* y1 * (1 - xfract) * (yfract) in 1.51 and adding to acc */
  7545. out = (q31_t) (((q63_t) y1 * (0x0FFFFF - xfract)) >> 4U);
  7546. acc += ((q63_t) out * (yfract));
  7547. /* y2 * (xfract) * (yfract) in 1.51 and adding to acc */
  7548. out = (q31_t) (((q63_t) y2 * (xfract)) >> 4U);
  7549. acc += ((q63_t) out * (yfract));
  7550. /* acc is in 13.51 format and down shift acc by 36 times */
  7551. /* Convert out to 1.15 format */
  7552. return ((q15_t)(acc >> 36));
  7553. }
  7554. /**
  7555. * @brief Q7 bilinear interpolation.
  7556. * @param[in,out] S points to an instance of the interpolation structure.
  7557. * @param[in] X interpolation coordinate in 12.20 format.
  7558. * @param[in] Y interpolation coordinate in 12.20 format.
  7559. * @return out interpolated value.
  7560. */
  7561. __STATIC_FORCEINLINE q7_t arm_bilinear_interp_q7(
  7562. arm_bilinear_interp_instance_q7 * S,
  7563. q31_t X,
  7564. q31_t Y)
  7565. {
  7566. q63_t acc = 0; /* output */
  7567. q31_t out; /* Temporary output */
  7568. q31_t xfract, yfract; /* X, Y fractional parts */
  7569. q7_t x1, x2, y1, y2; /* Nearest output values */
  7570. int32_t rI, cI; /* Row and column indices */
  7571. q7_t *pYData = S->pData; /* pointer to output table values */
  7572. uint32_t nCols = S->numCols; /* num of rows */
  7573. /* Input is in 12.20 format */
  7574. /* 12 bits for the table index */
  7575. /* Index value calculation */
  7576. rI = ((X & (q31_t)0xFFF00000) >> 20);
  7577. /* Input is in 12.20 format */
  7578. /* 12 bits for the table index */
  7579. /* Index value calculation */
  7580. cI = ((Y & (q31_t)0xFFF00000) >> 20);
  7581. /* Care taken for table outside boundary */
  7582. /* Returns zero output when values are outside table boundary */
  7583. if (rI < 0 || rI > (S->numCols - 2) || cI < 0 || cI > (S->numRows - 2))
  7584. {
  7585. return (0);
  7586. }
  7587. /* 20 bits for the fractional part */
  7588. /* xfract should be in 12.20 format */
  7589. xfract = (X & (q31_t)0x000FFFFF);
  7590. /* Read two nearest output values from the index */
  7591. x1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) ];
  7592. x2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) + 1];
  7593. /* 20 bits for the fractional part */
  7594. /* yfract should be in 12.20 format */
  7595. yfract = (Y & (q31_t)0x000FFFFF);
  7596. /* Read two nearest output values from the index */
  7597. y1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) ];
  7598. y2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) + 1];
  7599. /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 16.47 format */
  7600. out = ((x1 * (0xFFFFF - xfract)));
  7601. acc = (((q63_t) out * (0xFFFFF - yfract)));
  7602. /* x2 * (xfract) * (1-yfract) in 2.22 and adding to acc */
  7603. out = ((x2 * (0xFFFFF - yfract)));
  7604. acc += (((q63_t) out * (xfract)));
  7605. /* y1 * (1 - xfract) * (yfract) in 2.22 and adding to acc */
  7606. out = ((y1 * (0xFFFFF - xfract)));
  7607. acc += (((q63_t) out * (yfract)));
  7608. /* y2 * (xfract) * (yfract) in 2.22 and adding to acc */
  7609. out = ((y2 * (yfract)));
  7610. acc += (((q63_t) out * (xfract)));
  7611. /* acc in 16.47 format and down shift by 40 to convert to 1.7 format */
  7612. return ((q7_t)(acc >> 40));
  7613. }
  7614. /**
  7615. * @} end of BilinearInterpolate group
  7616. */
  7617. /* SMMLAR */
  7618. #define multAcc_32x32_keep32_R(a, x, y) \
  7619. a = (q31_t) (((((q63_t) a) << 32) + ((q63_t) x * y) + 0x80000000LL ) >> 32)
  7620. /* SMMLSR */
  7621. #define multSub_32x32_keep32_R(a, x, y) \
  7622. a = (q31_t) (((((q63_t) a) << 32) - ((q63_t) x * y) + 0x80000000LL ) >> 32)
  7623. /* SMMULR */
  7624. #define mult_32x32_keep32_R(a, x, y) \
  7625. a = (q31_t) (((q63_t) x * y + 0x80000000LL ) >> 32)
  7626. /* SMMLA */
  7627. #define multAcc_32x32_keep32(a, x, y) \
  7628. a += (q31_t) (((q63_t) x * y) >> 32)
  7629. /* SMMLS */
  7630. #define multSub_32x32_keep32(a, x, y) \
  7631. a -= (q31_t) (((q63_t) x * y) >> 32)
  7632. /* SMMUL */
  7633. #define mult_32x32_keep32(a, x, y) \
  7634. a = (q31_t) (((q63_t) x * y ) >> 32)
  7635. #if defined ( __CC_ARM )
  7636. /* Enter low optimization region - place directly above function definition */
  7637. #if defined( __ARM_ARCH_7EM__ )
  7638. #define LOW_OPTIMIZATION_ENTER \
  7639. _Pragma ("push") \
  7640. _Pragma ("O1")
  7641. #else
  7642. #define LOW_OPTIMIZATION_ENTER
  7643. #endif
  7644. /* Exit low optimization region - place directly after end of function definition */
  7645. #if defined ( __ARM_ARCH_7EM__ )
  7646. #define LOW_OPTIMIZATION_EXIT \
  7647. _Pragma ("pop")
  7648. #else
  7649. #define LOW_OPTIMIZATION_EXIT
  7650. #endif
  7651. /* Enter low optimization region - place directly above function definition */
  7652. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7653. /* Exit low optimization region - place directly after end of function definition */
  7654. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7655. #elif defined (__ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
  7656. #define LOW_OPTIMIZATION_ENTER
  7657. #define LOW_OPTIMIZATION_EXIT
  7658. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7659. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7660. #elif defined ( __GNUC__ )
  7661. #define LOW_OPTIMIZATION_ENTER \
  7662. __attribute__(( optimize("-O1") ))
  7663. #define LOW_OPTIMIZATION_EXIT
  7664. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7665. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7666. #elif defined ( __ICCARM__ )
  7667. /* Enter low optimization region - place directly above function definition */
  7668. #if defined ( __ARM_ARCH_7EM__ )
  7669. #define LOW_OPTIMIZATION_ENTER \
  7670. _Pragma ("optimize=low")
  7671. #else
  7672. #define LOW_OPTIMIZATION_ENTER
  7673. #endif
  7674. /* Exit low optimization region - place directly after end of function definition */
  7675. #define LOW_OPTIMIZATION_EXIT
  7676. /* Enter low optimization region - place directly above function definition */
  7677. #if defined ( __ARM_ARCH_7EM__ )
  7678. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER \
  7679. _Pragma ("optimize=low")
  7680. #else
  7681. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7682. #endif
  7683. /* Exit low optimization region - place directly after end of function definition */
  7684. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7685. #elif defined ( __TI_ARM__ )
  7686. #define LOW_OPTIMIZATION_ENTER
  7687. #define LOW_OPTIMIZATION_EXIT
  7688. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7689. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7690. #elif defined ( __CSMC__ )
  7691. #define LOW_OPTIMIZATION_ENTER
  7692. #define LOW_OPTIMIZATION_EXIT
  7693. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7694. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7695. #elif defined ( __TASKING__ )
  7696. #define LOW_OPTIMIZATION_ENTER
  7697. #define LOW_OPTIMIZATION_EXIT
  7698. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7699. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7700. #elif defined ( _MSC_VER ) || defined(__GNUC_PYTHON__)
  7701. #define LOW_OPTIMIZATION_ENTER
  7702. #define LOW_OPTIMIZATION_EXIT
  7703. #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
  7704. #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
  7705. #endif
  7706. /* Compiler specific diagnostic adjustment */
  7707. #if defined ( __CC_ARM )
  7708. #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
  7709. #elif defined ( __GNUC__ )
  7710. #pragma GCC diagnostic pop
  7711. #elif defined ( __ICCARM__ )
  7712. #elif defined ( __TI_ARM__ )
  7713. #elif defined ( __CSMC__ )
  7714. #elif defined ( __TASKING__ )
  7715. #elif defined ( _MSC_VER )
  7716. #else
  7717. #error Unknown compiler
  7718. #endif
  7719. #ifdef __cplusplus
  7720. }
  7721. #endif
  7722. #endif /* _ARM_MATH_H */
  7723. /**
  7724. *
  7725. * End of file.
  7726. */