flaw 0.6.1

Embedded signal filtering, no-std and no-alloc compatible.
Documentation
//! Butterworth filter of order 3.
//! Region of validity: cutoff ratio from 1.00e-02 to 4.00e-01 .
//! This file is autogenerated.
#![allow(clippy::style)]

use crate::SisoIirFilter;

/// Minimum tabulated cutoff ratio
#[allow(dead_code)]
pub const MIN_CUTOFF_RATIO: f64 = 0.01;

/// Maximum tabulated cutoff ratio
#[allow(dead_code)]
pub const MAX_CUTOFF_RATIO: f64 = 0.4;

/// Initialise a Butterworth filter of order 3 by interpolating the coefficients from stored tables.
/// Cutoff ratio is the dimensionless ratio of the cutoff frequency to the sampling frequency.
/// Region of validity: cutoff ratio from 1.00e-02 to 4.00e-01
pub fn butter3(cutoff_ratio: f64) -> Result<SisoIirFilter<3>, &'static str> {
    let avals = &[&AVALS[0][..], &AVALS[1][..], &AVALS[2][..]];
    let cvals = &[&CVALS[0][..], &CVALS[1][..], &CVALS[2][..]];
    SisoIirFilter::new_interpolated(cutoff_ratio, &LOG10_CUTOFF_RATIOS, avals, cvals, &DVALS)
}

/// [dimensionless] Log base-10 of cutoff ratios, to improve float precision during interpolation
#[rustfmt::skip]
static LOG10_CUTOFF_RATIOS: [f64; 100] = [-2.0, -1.9838175758451722, -1.967635151690344, -1.9514527275355162, -1.9352703033806884, -1.9190878792258605, -1.9029054550710325, -1.8867230309162046, -1.8705406067613768, -1.854358182606549, -1.8381757584517209, -1.821993334296893, -1.8058109101420652, -1.7896284859872371, -1.7734460618324093, -1.7572636376775814, -1.7410812135227536, -1.7248987893679257, -1.7087163652130977, -1.6925339410582698, -1.676351516903442, -1.660169092748614, -1.643986668593786, -1.6278042444389582, -1.6116218202841304, -1.5954393961293023, -1.5792569719744745, -1.5630745478196466, -1.5468921236648185, -1.5307096995099907, -1.5145272753551628, -1.498344851200335, -1.4821624270455072, -1.465980002890679, -1.4497975787358512, -1.4336151545810232, -1.4174327304261953, -1.4012503062713675, -1.3850678821165396, -1.3688854579617118, -1.352703033806884, -1.3365206096520559, -1.320338185497228, -1.3041557613424, -1.2879733371875721, -1.2717909130327443, -1.2556084888779164, -1.2394260647230886, -1.2232436405682605, -1.2070612164134327, -1.1908787922586046, -1.1746963681037768, -1.158513943948949, -1.142331519794121, -1.1261490956392932, -1.1099666714844654, -1.0937842473296373, -1.0776018231748095, -1.0614193990199814, -1.0452369748651535, -1.0290545507103257, -1.0128721265554979, -0.99668970240067, -0.9805072782458419, -0.9643248540910141, -0.9481424299361862, -0.9319600057813582, -0.9157775816265303, -0.8995951574717025, -0.8834127333168746, -0.8672303091620466, -0.8510478850072187, -0.8348654608523909, -0.818683036697563, -0.802500612542735, -0.7863181883879071, -0.7701357642330793, -0.7539533400782514, -0.7377709159234234, -0.7215884917685955, -0.7054060676137677, -0.6892236434589396, -0.6730412193041118, -0.6568587951492839, -0.6406763709944561, -0.624493946839628, -0.6083115226848002, -0.5921290985299723, -0.5759466743751445, -0.5597642502203164, -0.5435818260654885, -0.5273994019106607, -0.5112169777558329, -0.4950345536010048, -0.47885212944617694, -0.4626697052913491, -0.44648728113652103, -0.4303048569816932, -0.41412243282686534, -0.3979400086720376];

/// State-Space `D` 1x1 matrix
#[rustfmt::skip]
static DVALS: [f64; 100] = [2.914649446569766e-05, 3.251848437821954e-05, 3.6277507404170416e-05, 4.046750766077423e-05, 4.513734463387047e-05, 5.034133162750553e-05, 5.6139831474123425e-05, 6.259991533643825e-05, 6.979609098775842e-05, 7.781110756063919e-05, 8.673684440753126e-05, 9.667529242492606e-05, 0.00010773963695785043, 0.00012005545222797126, 0.00013376201811966047, 0.00014901377111777974, 0.00016598190222234202, 0.00018485611577225472, 0.0002058465642966358, 0.0002291859757812482, 0.00025513199109283494, 0.0002839697307487856, 0.000316014611756695, 0.00035161543688083576, 0.0003911577804228617, 0.0004350676964345895, 0.00048381577721333673, 0.000537921591966876, 0.0005979585376768859, 0.000664559136438213, 0.0007384208159073479, 0.0008203122119583076, 0.000911080035219143, 0.0010116565458491071, 0.0011230676837179232, 0.0012464419040684777, 0.0013830197717882428, 0.001534164370591563, 0.0017013725867360556, 0.0018862873303789453, 0.0020907107613453374, 0.0023166185899610474, 0.002566175527737556, 0.0028417519671385385, 0.0031459419744733846, 0.003481582685239452, 0.0038517751970793433, 0.004259907062068185, 0.004709676487466613, 0.005205118362575076, 0.005750632239158143, 0.00635101240438218, 0.0070114801987008184, 0.007737718747080882, 0.008535910290929628, 0.009412776330710951, 0.010375620816299193, 0.011432376654537143, 0.012591655842338286, 0.013862803580304991, 0.015255956777774183, 0.016782107427284667, 0.0184531714068708, 0.020282063364919365, 0.022282778457671654, 0.02447048184750516, 0.02686160703530615, 0.02947396429786152, 0.03232686073766006, 0.0354412337355576, 0.03883979993586827, 0.042547222300126045, 0.04659029825418223, 0.050998172540940676, 0.055802579099557104, 0.06103811714834631, 0.06674256768676746, 0.07295725789423617, 0.07972748244393474, 0.08710299263654896, 0.0951385665791189, 0.10389467649962565, 0.11343827284237423, 0.12384370921864828, 0.13519383783314592, 0.14758131198472535, 0.1611101410634679, 0.17589755467964674, 0.19207624688461503, 0.20979708983726159, 0.2292324300129111, 0.2505801108635695, 0.2740684060393581, 0.2999621000195065, 0.32857002257660506, 0.36025443582388467, 0.395442795883987, 0.43464257702139447, 0.47846007096142695, 0.5276243825019431];

/// State-Space `A` matrix, first row
#[rustfmt::skip]
static AVALS: [[f64; 100]; 3] = [[2.874356892677484, 2.8695885860117767, 2.864639447805153, 2.85950263566043, 2.854171050066194, 2.848637324941998, 2.842893817859415, 2.8369325999305053, 2.830745445355309, 2.82432382062012, 2.817658873338455, 2.8107414207268757, 2.8035619377080643, 2.796110544633935, 2.788376994621937, 2.7803506604981987, 2.7720205213417177, 2.7633751486244327, 2.754402691942754, 2.7450908643369245, 2.735426927195517, 2.7253976747433803, 2.714989418112453, 2.7041879689960813, 2.692978622888807, 2.6813461419149633, 2.6692747372509498, 2.6567480511475967, 2.643749138560691, 2.630260448399377, 2.616263804403851, 2.60174038566542, 2.586670706803579, 2.571034597816254, 2.5548111836206076, 2.5379788633028477, 2.520515289096105, 2.502397345105627, 2.48360112580008, 2.4641019142865277, 2.4438741603845076, 2.42289145851124, 2.4011265253852985, 2.3785511775495936, 2.3551363087061, 2.3308518668439318, 2.305666831128822, 2.2795491885052597, 2.2524659099420634, 2.2243829262274204, 2.1952651031897843, 2.1650762161859114, 2.1337789236558615, 2.1013347394963935, 2.0677040039478207, 2.0328458526242987, 1.996718183242622, 1.9592776195189634, 1.92047947160545, 1.880277692327943, 1.8386248283616184, 1.7954719653407727, 1.7507686657422794, 1.7044628982070886, 1.6565009567695845, 1.606827368249153, 1.5553847858204781, 1.5021138665174052, 1.4469531301382519, 1.389838796706826, 1.3307045993017772, 1.2694815686963203, 1.2060977858500166, 1.140478097864314, 1.072543792554778, 1.0022122263081, 0.9293963993860448, 0.854004472320339, 0.7759392165263292, 0.695097391771859, 0.6113690427057861, 0.524636706330685, 0.4347745221750002, 0.3416472370976151, 0.24510909731354522, 0.14500262161316477, 0.04115725222322342, -0.06661211614597663, -0.1785067220423588, -0.2947456208112527, -0.4155674339039148, -0.54123210955516, -0.6720226074994964, -0.8082463723663458, -0.9502363909600777, -1.0983515292280421, -1.252975704171895, -1.414515250696413, -1.583393579392736, -1.7600418803431688], [-2.7564831952256954, -2.747542454883604, -2.7382855281451306, -2.7287021739613073, -2.7187818945599482, -2.7085139353926997, -2.6978872857661043, -2.68689068022797, -2.6755126007856247, -2.6637412800381894, -2.651564705310879, -2.6389706238855584, -2.6259465494281757, -2.612479769720576, -2.5985573558112165, -2.5841661727067438, -2.5692928917340825, -2.5539240047106357, -2.538045840068504, -2.521644581087095, -2.504706286397273, -2.487216912929153, -2.469162341484787, -2.450528405126255, -2.431300920579096, -2.4114657228603984, -2.391008703350343, -2.3699158515353185, -2.348173300660018, -2.3257673775348806, -2.3026846567540686, -2.2789120195874917, -2.254436717818358, -2.229246442805137, -2.2033294000535735, -2.176674389590538, -2.1492708924367783, -2.1211091634801917, -2.092180331054887, -2.06247650353412, -2.0319908832472016, -2.0007178880316934, -1.9686532807329156, -1.9357943069630184, -1.9021398414321498, -1.8676905431647925, -1.8324490199159214, -1.796420002104809, -1.7596105265901814, -1.7220301306200456, -1.6836910563044019, -1.6446084659810412, -1.6048006688757466, -1.5642893595012823, -1.5230998682975216, -1.4812614250918261, -1.4388074360587115, -1.395775774986203, -1.3522090898193388, -1.3081551256562995, -1.263667065628167, -1.2188038914095896, -1.1736307654962623, -1.1282194378602683, -1.082648680172168, -1.0370047514786982, -0.9913819000698387, -0.9458829072859385, -0.9006196802368793, -0.8557139018695371, -0.8112977485734949, -0.7675146876142553, -0.7245203691961136, -0.6824836309665727, -0.6415876363824184, -0.602031172689758, -0.5640301394813183, -0.5278192650764117, -0.4936540955614289, -0.4618133105304254, -0.4326014307500534, -0.40635199660948557, -0.3834313128918425, -0.3642428758565389, -0.3492326237760814, -0.3388951830812757, -0.3337813205726062, -0.3345068595269766, -0.34176337613286295, -0.35633106511562984, -0.3790942526810332, -0.4110601443352654, -0.45338152806603915, -0.5073843124281578, -0.5746009647719281, -0.6568111227456563, -0.7560908675992016, -0.8748723358889003, -1.0160154338744787, -1.1828932620378305], [0.8818931305924855, 0.8776937209968013, 0.8733558602807443, 0.8688757982395916, 0.8642497457366832, 0.8594738797976821, 0.8545443492548963, 0.8494572809747729, 0.8442087867024136, 0.8387949705575843, 0.8332119372171637, 0.827455800819283, 0.8215226946244489, 0.8154087814688177, 0.8091102650443219, 0.8026234020396028, 0.7959445151745862, 0.7890700071600248, 0.7819963756113765, 0.7747202289439208, 0.7672383032730133, 0.7595474803397823, 0.7516448064782805, 0.7435275126351271, 0.7351930354469061, 0.7266390393739587, 0.7178634398816865, 0.7088644276519871, 0.6996404937979116, 0.6901904560439978, 0.6805134858229589, 0.6706091362264055, 0.6604773707330264, 0.6501185926220899, 0.6395336749632222, 0.6287239910551427, 0.6176914451663678, 0.6064385034098324, 0.5949682245609188, 0.5832842906045607, 0.5713910367719311, 0.5592934808007652, 0.5469973511257167, 0.5345091136763161, 0.5218359969302624, 0.5089860148389452, 0.4959679872104645, 0.48279155710300364, 0.469467204748385, 0.45600625749202484, 0.44242089520135264, 0.42872415056007235, 0.41492990363027854, 0.40105287002824197, 0.3871085820222637, 0.37311336182183974, 0.3590842862856961, 0.34503914223094245, 0.33099637147518274, 0.3169750046859167, 0.3029945830443551, 0.2890750666505396, 0.2752367284990165, 0.26150003273382477, 0.24788549574121016, 0.23441352844950397, 0.22110425796691136, 0.20797732638564112, 0.19505166419734674, 0.18234523527825042, 0.16987474978477168, 0.15765534051692665, 0.145700197312639, 0.13402015277473311, 0.12262321103118351, 0.11151400919488752, 0.10069319860113388, 0.0901567296021831, 0.07989501948362186, 0.06989197766617467, 0.06012385541131628, 0.050557878281795324, 0.04115060797784854, 0.03184596500973764, 0.02257282379736879, 0.013242065590308329, 0.003742939841639807, -0.006061461764220391, -0.01633987690169905, -0.027300032771210053, -0.03919775351834031, -0.05234863301813141, -0.06714311274932955, -0.08406611536154815, -0.10372282488083538, -0.12687283461737903, -0.15447579530080013, -0.18775302958584272, -0.22827155442420116, -0.2780599176345464]];

/// State-Space `C` vector
#[rustfmt::skip]
static CVALS: [[f64; 100]; 3] = [[0.00017121691066195722, 0.00019087012474079966, 0.00021275450099054132, 0.00023711946779691524, 0.0002642417362324652, 0.0002944281911439119, 0.00032801907425582515, 0.00036539148658014603, 0.0004069632396304771, 0.0004531970872742652, 0.0005046053725128512, 0.000561755126054401, 0.0006252736562310658, 0.0006958546725993398, 0.0007742649884380454, 0.0008613518503039855, 0.0009580509457986926, 0.0010653951437130538, 0.0011845240237157283, 0.0013166942556949927, 0.0014632908917028523, 0.001625839636126601, 0.001806020162158427, 0.0020056805447689645, 0.0022268528821239855, 0.0024717701786104856, 0.0027428845632390033, 0.003042886917028839, 0.0033747279819089353, 0.0037416410215105156, 0.004147166100798798, 0.004595176046581384, 0.00508990414431236, 0.005635973618032661, 0.006238428929479211, 0.006902768919066185, 0.0076349817952792, 0.008441581959698661, 0.009329648632031229, 0.010306866212818018, 0.011381566290525703, 0.012562771164128116, 0.013860238711657931, 0.015284508389156858, 0.016846948092584982, 0.01855980155718024, 0.020436235904108552, 0.02249038887264991, 0.024737415197274067, 0.027193531502430056, 0.029876058993376434, 0.0328034631185761, 0.035995389267720675, 0.03947269344893621, 0.043257466758683485, 0.047373052317698776, 0.05184405319523284, 0.056696329680757135, 0.06195698408574636, 0.06765433106608638, 0.07381785124534988, 0.08047812568688077, 0.08766674850333317, 0.09541621459934838, 0.10375977920763274, 0.11273128548933085, 0.12236495601132194, 0.1326951433666413, 0.14375603454488076, 0.15558130285550553, 0.1682037002182256, 0.1816545814096132, 0.19596335032900777, 0.21115681643687012, 0.2272584471204483, 0.2442874987219377, 0.2622580051541635, 0.28117759821261457, 0.3010461275949676, 0.32185404090683545, 0.3435804741112333, 0.36619099038293257, 0.38963488939852325, 0.41384198874241646, 0.438718753053074, 0.4641436130930716, 0.489961273901872, 0.5159757556968263, 0.5419418394402736, 0.5675544960233069, 0.5924357573307091, 0.616118330575453, 0.6380250532582742, 0.6574430208703624, 0.6734908752989508, 0.6850772969733048, 0.6908481720195194, 0.6891191772654307, 0.6777896085281644, 0.6542321372122061], [7.097661202658655e-06, 8.209536737031179e-06, 9.49434869049358e-06, 1.097874685357218e-05, 1.2693438542531725e-05, 1.4673796643192589e-05, 1.6960556863280938e-05, 1.960061690877885e-05, 2.2647952039947652e-05, 2.6164663427151284e-05, 3.0222177941542573e-05, 3.4902620509852226e-05, 4.030038296743961e-05, 4.6523916493683816e-05, 5.3697778245984486e-05, 6.196496676330761e-05, 7.14895851306612e-05, 8.245987582843452e-05, 9.509167668443706e-05, 0.00010963235345380195, 0.00012636527132722797, 0.00014561487516803957, 0.00016775245656151805, 0.00019320269488514146, 0.00022245106963480555, 0.0002560522522279227, 0.0002946395975047115, 0.00033893586821521506, 0.00038976533995608697, 0.0004480674493438912, 0.0005149121647043732, 0.0005915172762287332, 0.0006792678213881501, 0.0007797378813726675, 0.0008947150053680015, 0.0010262275415071115, 0.0011765751761957026, 0.0013483630070281042, 0.001544539498443017, 0.0017684386933161595, 0.002023827077475471, 0.002314955517201316, 0.002646616711595608, 0.0030242086216278738, 0.003453804354940605, 0.003942228999250346, 0.004497143906413531, 0.0051271389327977365, 0.005841833138219317, 0.006651984433927272, 0.007569608648308107, 0.008608108445348999, 0.009782412483418327, 0.011109125138370429, 0.012606687032874509, 0.014295546510433342, 0.016198342064680744, 0.018340095578690676, 0.020748416041128242, 0.023453713181372498, 0.026489420198602506, 0.02989222444342567, 0.033702304536532876, 0.03796357196654243, 0.04272391468524793, 0.04803543959567939, 0.053954710084327284, 0.06054297385428135, 0.06786637523236665, 0.07599614479974852, 0.08500875756458992, 0.09498604886784262, 0.10601527467046953, 0.11818909965442106, 0.13160549247014353, 0.14636750219944517, 0.16258288329859363, 0.1803635274389825, 0.1998246490945539, 0.22108365652305492, 0.24425861971572066, 0.26946622026615746, 0.2968190326389881, 0.3264219388534034, 0.35836741479461015, 0.3927293402097377, 0.42955486754860056, 0.46885372542457693, 0.5105841140436298, 0.5546340490319138, 0.6007965932927315, 0.6487368360515829, 0.6979476653933265, 0.7476902361856159, 0.7969134157621637, 0.8441441870040653, 0.8873377010261834, 0.9236709644287049, 0.9492573962947927, 0.9587498205574098], [5.4850587715848324e-05, 6.10597539333154e-05, 6.796068109198074e-05, 7.562874568229623e-05, 8.414728325692206e-05, 9.360839123557947e-05, 0.00010411380722845777, 0.00011577586920738007, 0.0001287185642771052, 0.00014307867323601857, 0.00015900701856443408, 0.00017666982393783163, 0.00019625019382932358, 0.00021794972223786917, 0.00024199024005332236, 0.00026861571104308285, 0.0002980942869144596, 0.0003307205323682421, 0.00036681783150865915, 0.00040674098740923266, 0.0004508790270495672, 0.0004996582242317921, 0.0005535453534548649, 0.0006130511880689571, 0.0006787342563506197, 0.0007512048694344607, 0.0008311294353127343, 0.0009192350733781213, 0.0010163145442478195, 0.0011232315098847084, 0.0012409261393446906, 0.0013704210758556403, 0.0015128277814080355, 0.0016693532756534533, 0.0018413072867184803, 0.002030109832612782, 0.0022372992533177824, 0.002464540715477798, 0.0027136352139830247, 0.002986529097755399, 0.0032853241508606834, 0.003612288264828122, 0.003969866743933637, 0.004360694292381687, 0.004787607741007461, 0.005253659581531754, 0.005762132388761975, 0.006316554225678166, 0.006920715143306756, 0.007578684906895953, 0.008294832102380249, 0.009073844802647413, 0.009920753001853355, 0.010840953058069001, 0.011840234419920645, 0.012924808951539555, 0.014101343211891, 0.01537699408907969, 0.016759448237016545, 0.018256965810132107, 0.019878429040598576, 0.0216333962503635, 0.02353216193532951, 0.02558582359875529, 0.02780635604214315, 0.03020669384023838, 0.03280082272664628, 0.0356038805905166, 0.03863226872281652, 0.04190377383961931, 0.04543770123166449, 0.049255019119901794, 0.05337851390267129, 0.05783295541610974, 0.06264527053256641, 0.06784472230526563, 0.07346309031000076, 0.07953484566672356, 0.08609731120717302, 0.09319079305255962, 0.10085866400016173, 0.10914737090822023, 0.118106326737795, 0.12778763164910148, 0.13824554451304358, 0.14953559339793085, 0.16171316662934657, 0.1748313583775362, 0.18893774465478005, 0.20406962240939985, 0.2202470337228548, 0.23746258459832983, 0.25566660015162845, 0.27474545151517443, 0.2944898116637997, 0.3145479343674238, 0.33435645549383614, 0.35303711639862967, 0.3692412468331484, 0.3809131901614744]];

#[cfg(feature = "std")]
#[cfg(test)]
#[rustfmt::skip]
mod test {
    use super::*;
    static CUTOFF_TEST_INPUT: [f32; 101] = [0.0, 0.5877852522924732, -0.9510565162951536, 0.9510565162951535, -0.5877852522924728, -4.898587196589413e-16, 0.5877852522924736, -0.9510565162951538, 0.9510565162951533, -0.5877852522924725, -9.797174393178826e-16, 0.587785252292474, -0.951056516295154, 0.9510565162951532, -0.587785252292472, -1.4695761589768238e-15, 0.5877852522924744, -0.9510565162951541, 0.951056516295153, -0.5877852522924716, -1.959434878635765e-15, 0.5877852522924748, -0.9510565162951542, 0.9510565162951529, -0.5877852522924712, -2.4492935982947065e-15, 0.5877852522924751, -0.9510565162951544, 0.9510565162951528, -0.5877852522924708, -2.9391523179536475e-15, 0.5877852522924756, -0.9510565162951545, 0.9510565162951525, -0.5877852522924705, -3.429011037612589e-15, 0.587785252292476, -0.9510565162951546, 0.9510565162951524, -0.58778525229247, -3.91886975727153e-15, 0.5877852522924764, -0.9510565162951549, 0.9510565162951523, -0.5877852522924697, -4.408728476930472e-15, 0.5877852522924768, -0.951056516295155, 0.9510565162951521, -0.5877852522924693, -4.898587196589413e-15, 0.5877852522924887, -0.9510565162951552, 0.9510565162951563, -0.5877852522924688, -1.9599300631450357e-14, 0.5877852522924776, -0.9510565162951509, 0.9510565162951519, -0.5877852522924569, -5.878304635907295e-15, 0.5877852522924665, -0.9510565162951554, 0.9510565162951473, -0.587785252292468, 7.842691359635767e-15, 0.5877852522924784, -0.95105651629516, 0.9510565162951515, -0.5877852522924791, -6.858022075225178e-15, 0.5877852522924902, -0.9510565162951558, 0.9510565162951558, -0.5877852522924673, -2.1558735510086122e-14, 0.5877852522924791, -0.9510565162951515, 0.9510565162951512, -0.5877852522924554, -7.83773951454306e-15, 0.587785252292468, -0.9510565162951561, 0.9510565162951466, -0.5877852522924665, 5.883256481000002e-15, 0.5877852522924799, -0.9510565162951606, 0.9510565162951509, -0.5877852522924776, -8.817456953860943e-15, 0.5877852522924918, -0.9510565162951563, 0.9510565162951552, -0.5877852522924657, -2.3518170388721888e-14, 0.5877852522924807, -0.9510565162951521, 0.9510565162951506, -0.5877852522924538, -9.797174393178826e-15];
    static CUTOFF_TEST_OUTPUT: [f32; 101] = [0.0, 0.310129830784565, -0.11725260530555914, -0.2336927131905271, 0.4637716039147073, -0.4340089382940309, 0.16180312459268492, 0.21810873356737814, -0.5278075636855191, 0.6259731020226973, -0.4648344393675273, 0.10597178936395202, 0.3077357641200965, -0.6109410445269183, 0.6817967559001239, -0.48967005850185574, 0.1067661839661142, 0.32019316228409034, -0.6269004808270591, 0.6949293705266857, -0.49736960368507127, 0.10922090413658253, 0.32132883835613946, -0.6296620553267345, 0.6977639144399008, -0.49940765781077556, 0.11022288503425548, 0.32118793745885477, -0.6300325991367549, 0.6983041470601736, -0.49988099717952666, 0.11051997800171254, 0.32107473430583044, -0.6300531694099611, 0.6983916492033998, -0.4999791949192437, 0.11059502420900807, 0.32103447644394945, -0.630043780684572, 0.6984018780648554, -0.499997109906036, 0.11061184505654764, 0.3210232183286109, -0.6300388817575467, 0.6984018956934174, -0.49999980541019035, 0.11061520620879295, 0.3210204861517958, -0.6300372993846088, 0.6984014079226056, -0.5000000589825591, 0.11061578949310619, 0.32101989512555307, -0.6300368786084212, 0.6984012042718774, -0.5000000339413576, 0.11061586931560013, 0.32101978164062084, -0.6300367802546508, 0.6984011432102497, -0.5000000112567159, 0.1106158742708575, 0.3210197630644467, -0.630036759729059, 0.6984011276800934, -0.5000000030373063, 0.1106158724675333, 0.32101976083403616, -0.6300367559557689, 0.6984011241787147, -0.5000000007179651, 0.11061587147792118, 0.3210197608058474, -0.6300367553804465, 0.6984011234746637, -0.5000000001514942, 0.11061587115374205, 0.32101976090207684, -0.6300367553238782, 0.698401123351415, -0.5000000000282208, 0.11061587106686915, 0.3210197609434359, -0.6300367553282087, 0.6984011233342422, -0.500000000004394, 0.11061587104645865, 0.32101976095598095, -0.6300367553327508, 0.6984011233330718, -0.5000000000004703, 0.11061587104216797, 0.32101976095920937, -0.6300367553344276, 0.6984011233334237, -0.49999999999998335, 0.11061587104135423, 0.32101976095993723, -0.6300367553349008, 0.6984011233336229, -0.49999999999995554];
    const STEP_TEST_MIN_OUTPUT: f32 = 0.9999999999989908;
    const STEP_TEST_MAX_OUTPUT: f32 = 1.1818565197141493;

    #[test]
    fn test() {
        let order = 3;
        println!("order {order}");
        let mut filter = butter3(0.4).unwrap();
        let out = (0..CUTOFF_TEST_INPUT.len()).map(|i| {filter.update(CUTOFF_TEST_INPUT[i])}).collect::<Vec<f32>>();
        // Check overall match to reference output to catch phase error, etc
        (0..CUTOFF_TEST_INPUT.len()).for_each(|i| { let expected = CUTOFF_TEST_OUTPUT[i]; let rel_err = (out[i] - expected).abs() / expected.abs().max(1e-4); assert!(rel_err < 0.05); });
        // Check approximate attenuation at cutoff frequency; should be -3dB or 1/sqrt(2) magnitude
        let maxmag = out.iter().fold(0.0_f32, |a, b| a.abs().max(b.abs()));
        let attenuation_rel_err = (maxmag - 0.707).abs() / 0.707;
        println!("order {order} attenuation rel err {attenuation_rel_err}");
        assert!(attenuation_rel_err < 0.05);
        // Check convergence of step responses at min and max tabulated cutoff
        let mut filtermin = butter3(MIN_CUTOFF_RATIO).unwrap();
        (0..999).for_each(|_| {filtermin.update(1.0);});
        let step_min_final = filtermin.update(1.0);
        let step_min_rel_err = (step_min_final - STEP_TEST_MIN_OUTPUT).abs() / STEP_TEST_MIN_OUTPUT;
        println!("order {order} step min rel err {step_min_rel_err}");
        assert!(step_min_rel_err < 1e-4);
        let mut filtermax = butter3(MAX_CUTOFF_RATIO).unwrap();
        (0..1).for_each(|_| {filtermax.update(1.0);});
        let step_max_final = filtermax.update(1.0);
        let step_max_rel_err = (step_max_final - STEP_TEST_MAX_OUTPUT).abs() / STEP_TEST_MAX_OUTPUT;
        println!("order {order} step max rel err {step_max_rel_err}");
        assert!(step_max_rel_err < 1e-6);
    }
}