flaw/generated/butter/
butter6.rs

1//! Butterworth filter of order 6.
2//! Region of validity: cutoff ratio from 1.00e-01 to 4.00e-01 .
3//! This file is autogenerated.
4#![allow(clippy::style)]
5
6use crate::SisoIirFilter;
7
8/// Minimum tabulated cutoff ratio
9#[allow(dead_code)]
10pub const MIN_CUTOFF_RATIO: f64 = 0.1;
11
12/// Maximum tabulated cutoff ratio
13#[allow(dead_code)]
14pub const MAX_CUTOFF_RATIO: f64 = 0.4;
15
16/// Initialise a Butterworth filter of order 6 by interpolating the coefficients from stored tables.
17/// Cutoff ratio is the dimensionless ratio of the cutoff frequency to the sampling frequency.
18/// Region of validity: cutoff ratio from 1.00e-01 to 4.00e-01
19pub fn butter6(cutoff_ratio: f64) -> Result<SisoIirFilter<6>, &'static str> {
20    let avals = &[
21        &AVALS[0][..],
22        &AVALS[1][..],
23        &AVALS[2][..],
24        &AVALS[3][..],
25        &AVALS[4][..],
26        &AVALS[5][..],
27    ];
28    let cvals = &[
29        &CVALS[0][..],
30        &CVALS[1][..],
31        &CVALS[2][..],
32        &CVALS[3][..],
33        &CVALS[4][..],
34        &CVALS[5][..],
35    ];
36    SisoIirFilter::new_interpolated(cutoff_ratio, &LOG10_CUTOFF_RATIOS, avals, cvals, &DVALS)
37}
38
39/// [dimensionless] Log base-10 of cutoff ratios, to improve float precision during interpolation
40#[rustfmt::skip]
41static LOG10_CUTOFF_RATIOS: [f64; 100] = [-1.0, -0.9939185859461822, -0.9878371718923644, -0.9817557578385466, -0.9756743437847288, -0.9695929297309109, -0.9635115156770931, -0.9574301016232754, -0.9513486875694576, -0.9452672735156398, -0.939185859461822, -0.9331044454080042, -0.9270230313541864, -0.9209416173003686, -0.9148602032465508, -0.908778789192733, -0.9026973751389151, -0.8966159610850974, -0.8905345470312795, -0.8844531329774619, -0.878371718923644, -0.8722903048698262, -0.8662088908160084, -0.8601274767621907, -0.8540460627083728, -0.8479646486545549, -0.8418832346007371, -0.8358018205469193, -0.8297204064931015, -0.8236389924392837, -0.8175575783854659, -0.8114761643316482, -0.8053947502778304, -0.7993133362240126, -0.7932319221701947, -0.787150508116377, -0.7810690940625591, -0.7749876800087413, -0.7689062659549235, -0.7628248519011057, -0.7567434378472879, -0.7506620237934701, -0.7445806097396523, -0.7384991956858344, -0.7324177816320168, -0.7263363675781989, -0.7202549535243812, -0.7141735394705633, -0.7080921254167455, -0.7020107113629277, -0.6959292973091099, -0.6898478832552921, -0.6837664692014742, -0.6776850551476565, -0.6716036410938386, -0.665522227040021, -0.659440812986203, -0.6533593989323853, -0.6472779848785675, -0.6411965708247497, -0.6351151567709319, -0.6290337427171141, -0.6229523286632963, -0.6168709146094784, -0.6107895005556607, -0.6047080865018428, -0.5986266724480251, -0.5925452583942072, -0.5864638443403895, -0.5803824302865717, -0.5743010162327539, -0.5682196021789361, -0.5621381881251182, -0.5560567740713005, -0.5499753600174826, -0.5438939459636649, -0.537812531909847, -0.5317311178560292, -0.5256497038022114, -0.5195682897483936, -0.5134868756945759, -0.5074054616407581, -0.5013240475869403, -0.4952426335331225, -0.48916121947930463, -0.4830798054254868, -0.476998391371669, -0.4709169773178512, -0.4648355632640334, -0.4587541492102156, -0.45267273515639783, -0.44659132110258004, -0.44050990704876225, -0.43442849299494446, -0.42834707894112656, -0.42226566488730877, -0.416184250833491, -0.4101028367796732, -0.4040214227258554, -0.3979400086720376];
42
43/// State-Space `D` 1x1 matrix
44#[rustfmt::skip]
45static DVALS: [f64; 100] = [0.0003405376527201276, 0.0003658278081625552, 0.0003929502160461965, 0.00042203404531198784, 0.00045321731150327435, 0.0004866474659431454, 0.0005224820233207184, 0.0005608892301808209, 0.0006020487769785166, 0.0006461525565390653, 0.0006934054719560695, 0.0007440262971669096, 0.0007982485936662123, 0.0008563216870563829, 0.0009185117073904487, 0.0009851026975382575, 0.0010563977941040672, 0.0011327204857435368, 0.001214415954073224, 0.0013018525027379494, 0.001395423080603393, 0.0014955469054754589, 0.0016026711952175673, 0.0017172730136447868, 0.0018398612391236923, 0.0019709786644024397, 0.002111204236841269, 0.0022611554489142894, 0.002421490889613674, 0.0025929129682137637, 0.002776170822750558, 0.0029720634265491463, 0.003181442907195453, 0.003405218093507388, 0.0036443583073240524, 0.003899897418310062, 0.004172938181477217, 0.004464656878769986, 0.0047763082878599025, 0.005109231003261142, 0.005464853137034654, 0.005844698428709634, 0.006250392796640863, 0.00668367136586333, 0.007146386010628006, 0.007640513453235384, 0.00816816396455947, 0.008731590715814162, 0.009333199835694665, 0.009975561232081702, 0.010661420243073027, 0.011393710188269703, 0.012175565898057693, 0.013010338306164855, 0.013901610199125208, 0.01485321322553978, 0.01586924627829713, 0.0169540953743251, 0.018112455169131635, 0.019349352257504466, 0.020670170427463667, 0.0220806780520887, 0.023587057823407847, 0.025195939054396092, 0.02691443279957739, 0.028750170072102017, 0.030711343465853375, 0.032806752525574766, 0.03504585324668887, 0.037438812130000394, 0.03999656526546998, 0.042730882974505294, 0.04565444060258876, 0.048780896124578484, 0.052124975304831504, 0.05570256524476399, 0.05953081725314374, 0.06362826009111311, 0.068014924776788, 0.07271248228570955, 0.07774439565632293, 0.08313608820735928, 0.08891512980042991, 0.09511144334090857, 0.10175753400869526, 0.10888874405408108, 0.11654353639022554, 0.12476381067158303, 0.13359525607756947, 0.14308774563536414, 0.15329577762996457, 0.1642789704812893, 0.17610261843863526, 0.18883831657777536, 0.20256466491629083, 0.21736806302558295, 0.23334360835844914, 0.2505961136837356, 0.2692412615908916, 0.28940691707833444];
46
47/// State-Space `A` matrix, first row
48#[rustfmt::skip]
49static AVALS: [[f64; 100]; 6] = [[3.5794347983311923, 3.5454842714320973, 3.5110617377928177, 3.476160758516154, 3.440774808684749, 3.4048972760856007, 3.3685214598996165, 3.331640569354368, 3.294247722338083, 3.256335943972836, 3.2178981651447294, 3.1789272209888213, 3.1394158493263893, 3.0993566890519975, 3.0587422784677476, 3.017565053561927, 2.9758173462291637, 2.9334913824290476, 2.8905792802800443, 2.847073048085401, 2.802964582287569, 2.7582456653475793, 2.7129079635455895, 2.666943024698746, 2.6203422757923014, 2.5730970205198274, 2.525198436728174, 2.476637573762718, 2.4274053497082946, 2.37749254852105, 2.3268898170463586, 2.275587661917788, 2.22357644633201, 2.170846386694427, 2.1173875491302074, 2.0631898458553435, 2.0082430314022646, 1.9525366986945347, 1.8960602749650857, 1.8388030175125145, 1.7807540092899439, 1.7219021543210513, 1.6622361729379698, 1.6017445968359076, 1.5404157639395328, 1.4782378130764064, 1.4151986784531236, 1.3512860839300687, 1.286487537091314, 1.2207903231065695, 1.1541814983828458, 1.0866478840041502, 1.0181760589584243, 0.948752353151912, 0.8783628402122214, 0.8069933300827006, 0.7346293614120882, 0.6612561937451761, 0.5868587995218814, 0.5114218558944004, 0.4349297363742759, 0.35736650232391476, 0.2787158943099154, 0.19896132333886174, 0.11808586199976571, 0.036072235541315875, -0.04709718708345628, -0.13144040216776554, -0.2169757801540923, -0.3037220744411484, -0.39169843003968086, -0.480924392015172, -0.571419913647716, -0.6632053642311136, -0.7563015364241803, -0.8507296530575229, -0.9465113732885948, -1.043668797986566, -1.1422244742166352, -1.242201398680641, -1.3436230199575057, -1.4465132393730515, -1.5508964103141936, -1.6567973357876848, -1.764241264008561, -1.8732538817884672, -1.9838613054796184, -2.0960900692164297, -2.209967110184685, -2.325519750637884, -2.442775676373199, -2.561762911375941, -2.682509788343187, -2.8050449148052277, -2.929397134579738, -3.055595484319813, -3.1836691449554673, -3.3136473878812898, -3.4455595158135894, -3.5794347983311914], [-5.658667165933626, -5.564657569260978, -5.470327800632602, -5.375699210216937, -5.280794082772603, -5.185635665771899, -5.090248198315312, -4.994656940865225, -4.898888205828585, -4.8029693890200305, -4.706929002038701, -4.61079670559398, -4.514603343817498, -4.418380979600861, -4.322162931001063, -4.225983808758, -4.1298795549712795, -4.033887482986404, -3.938046318543505, -3.842396242245196, -3.746978933403549, -3.6518376153301597, -3.55701710213713, -3.4625638471213054, -3.3685259928085904, -3.2749534227401984, -3.181897815087859, -3.0894126981907144, -2.997553508112557, -2.9063776483244546, -2.8159445516246553, -2.726315744414812, -2.6375549134594185, -2.549727975263427, -2.4629031482118813, -2.3771510276246515, -2.292544663889254, -2.2091596438453216, -2.1270741756054186, -2.0463691770088737, -1.9671283679178737, -1.8894383665785353, -1.813388790283903, -1.739072360590951, -1.6665850133596911, -1.596026013899494, -1.5274980775258018, -1.461107495849356, -1.3969642691404225, -1.3351822451317086, -1.2758792646463384, -1.2191773144610472, -1.165202687839944, -1.1140861532007267, -1.065963131403175, -1.0209738821792085, -0.979263700254658, -0.9409831217454666, -0.906288141444936, -0.8753404416544048, -0.8483076332468394, -0.8253635096916994, -0.8066883148097606, -0.7924690250684929, -0.7828996472718945, -0.7781815325433693, -0.7785237075461244, -0.7841432239324445, -0.7952655270609383, -0.8121248450690262, -0.8349645994363117, -0.8640378382225277, -0.8996076932109479, -0.9419478622339169, -0.991343118000604, -1.0480898447874019, -1.1124966043874338, -1.1848847327461312, -1.2655889687333328, -1.3549581165170532, -1.4533557430080237, -1.5611609118349614, -1.6787689552856477, -1.8065922856052343, -1.945061246977418, -2.0946250094222245, -2.2557525057220094, -2.4289334123299033, -2.614679175017336, -2.813524079773461, -3.0260263691736027, -3.2527694040791806, -3.4943628701122402, -3.7514440278561074, -4.02467900516442, -4.314764129307498, -4.622427295943813, -4.9484293710720975, -5.293565621197209, -5.658667165933624], [4.96541522877857, 4.853531731527794, 4.742124069755846, 4.631228577778235, 4.520881974432013, 4.411121335453064, 4.301984063745095, 4.193507857440379, 4.085730675647706, 3.978690701778035, 3.8724263043328913, 3.7669759950351276, 3.6623783841754842, 3.5586721330419433, 3.4558959032920296, 3.3540883031207405, 3.2532878300689, 3.1535328103081546, 3.054861334229691, 2.9573111881539127, 2.8609197819676053, 2.7657240724838306, 2.6717604823072505, 2.579064813974439, 2.4876721591242186, 2.397616802437592, 2.308932120069945, 2.2216504722800514, 2.1358030899406875, 2.051419954594273, 1.9685296716939051, 1.8871593366449386, 1.8073343932351942, 1.7290784840121898, 1.6524132921338486, 1.5773583741842536, 1.5039309834081571, 1.4321458827769122, 1.3620151472536879, 1.293547954577309, 1.226750363831097, 1.1616250810055821, 1.0981712107012895, 1.0363839930496193, 0.97625452485553, 0.9177694638848284, 0.8609107151307345, 0.8056550977981669, 0.7519739916395506, 0.699832961161555, 0.6491913560975908, 0.6000018864048511, 0.5522101698962307, 0.5057542504554332, 0.46056408460655585, 0.4165609940162207, 0.3736570812950594, 0.3317546062346728, 0.2907453193637967, 0.2505097494317066, 0.2109164411251373, 0.1718211389950835, 0.13306591320875777, 0.09447822234690176, 0.05586990803411296, 0.01703611571634112, -0.022245864618760262, -0.0622178445508587, -0.10314207755947895, -0.14530270165563483, -0.1890072931344873, -0.23458854108884203, -0.28240605321920753, -0.33284830445776603, -0.38633474099888626, -0.44331805350660025, -0.5042866345592814, -0.5697672368038224, -0.6403278498370639, -0.7165808155227998, -0.7991862033011913, -0.8888554690671455, -0.9863554233994023, -1.092512537327479, -1.2082176164446468, -1.3344308770273134, -1.4721874609204868, -1.6226034293106824, -1.7868822791468049, -1.9663220298993624, -2.1623229325807514, -2.376395857492187, -2.610171422021092, -2.8654099249842666, -3.144012159488488, -3.448031182042214, -3.7796851216687823, -4.141371118995512, -4.535680491658502, -4.965415228778568], [-2.529494905841447, -2.4597413357572795, -2.3907277612451807, -2.322475619300766, -2.255006092296556, -2.1883400810354314, -2.1224981774150056, -2.057500636747891, -1.9933673497873439, -1.9301178145125175, -1.8677711077324917, -1.806345856573767, -1.7458602099215408, -1.6863318098912152, -1.6277777634131403, -1.570214614020543, -1.513658313938092, -1.4581241965764924, -1.4036269495471099, -1.3501805883198161, -1.2977984306570836, -1.2464930719680565, -1.1962763617376773, -1.1471593811983654, -1.099152422425006, -1.0522649690484571, -1.0065056787983147, -0.9618823681026278, -0.9184019989905579, -0.8760706685638968, -0.8348936013250865, -0.7948751446729349, -0.7560187679030681, -0.718327065078237, -0.6818017621644286, -0.6464437288624046, -0.6122529956012217, -0.5792287762008468, -0.5473694967554749, -0.5166728313381681, -0.48713574518129743, -0.4587545460467172, -0.43152494456510176, -0.40544212439624927, -0.38050082314209877, -0.3566954250326582, -0.33402006650298366, -0.3124687558877893, -0.2920355085806599, -0.2727144991383179, -0.25450023195876476, -0.23738773232698845, -0.22137275980536938, -0.20645204615015084, -0.1926235601628696, -0.17988680213937908, -0.16824313086217274, -0.1576961263978759, -0.14825199231500158, -0.13992000133216032, -0.13271298884899868, -0.1266478993073003, -0.12174639088461381, -0.11803550464519498, -0.11554840497167913, -0.11432519888563945, -0.11441384274736041, -0.1158711458175496, -0.11876388128101943, -0.12317001659123583, -0.12918007641411886, -0.13689865305133225, -0.14644608103235612, -0.1579602946093486, -0.17159888920167649, -0.18754141045531675, -0.20599189754881614, -0.22718171074112462, -0.2513726769736602, -0.27886059167396055, -0.3099791198355123, -0.345104145053119, -0.3846586215736877, -0.4291179916915545, -0.47901623910558516, -0.5349526583120304, -0.5975994309052235, -0.6677101119963846, -0.7461291440683098, -0.833802531724307, -0.9317898292674776, -1.0412776142108167, -1.1635946440721896, -1.3002289216128293, -1.4528469255640237, -1.623315300461238, -1.8137253411620176, -2.0264206557541167, -2.2640284457614133, -2.529494905841446], [0.7052741145099006, 0.6827227379680586, 0.6605323238967634, 0.6387077485413082, 0.6172536599418444, 0.596174469805244, 0.5754743455235682, 0.5551572023567695, 0.5352266957973433, 0.5156862141346222, 0.49653887123628243, 0.47778749956447614, 0.4594346434436775, 0.4414825525969235, 0.4239331759666044, 0.40678815583527117, 0.3900488222611176, 0.37371618784179217, 0.3577909428190263, 0.3422734505352069, 0.327163743251403, 0.312461518334558, 0.29816613481942844, 0.28427661034848095, 0.2707916184902319, 0.2577094864334499, 0.24502819305116613, 0.2327453673245447, 0.22085828711227257, 0.20936387824620128, 0.19825871392846622, 0.18753901439910603, 0.17720064683630268, 0.16723912544359698, 0.15764961166978145, 0.14842691449746587, 0.13956549072545818, 0.13105944515796533, 0.12290253060000925, 0.11508814754323288, 0.10760934340919026, 0.10045881119807795, 0.09362888736937991, 0.08711154875677657, 0.08089840829255497, 0.07498070928626197, 0.06934931796802059, 0.06399471396823361, 0.058906978361795106, 0.054075778855672, 0.049490351643090534, 0.045139479384631136, 0.041011464705299455, 0.03709409851591741, 0.03337462237560492, 0.02983968400815658, 0.026475284966935474, 0.023266719308459943, 0.020198501981718443, 0.01725428546567395, 0.014416762988166623, 0.011667556431799939, 0.008987086772063762, 0.006354424594908687, 0.003747117899400711, 0.0011409939991729315, -0.0014900681137526635, -0.004174399096814124, -0.006942839026314821, -0.009829081044978547, -0.012870065116561307, -0.0161064290316911, -0.019583024867637612, -0.023349510330445186, -0.02746102582894499, -0.031978969779811434, -0.03697188656025911, -0.04251648375656427, -0.04869879795727342, -0.05561553137487535, -0.06337558512627298, -0.0721018191526823, -0.08193307362335857, -0.09302649237580245, -0.10556019565445104, -0.11973635730785606, -0.13578475091599124, -0.15396684031491834, -0.17458050299097827, -0.19796549022323034, -0.2245097461348909, -0.25465672954522156, -0.28891390838755027, -0.3278626273203351, -0.3721695860323877, -0.4226002098804016, -0.4800342474221201, -0.5454839929862405, -0.6201156089333634, -0.7052741145099004], [-0.08375647961867896, -0.08075281563209652, -0.0778113833946007, -0.0749324342179604, -0.07211617592565622, -0.06936277235694015, -0.06667234293048802, -0.06404496226997185, -0.061480659893829046, -0.05897941997144496, -0.05654118114789891, -0.05416583643936077, -0.05185323320115, -0.04960317317039649, -0.04741541258516713, -0.04528966238184473, -0.04322558847247028, -0.04122281210368453, -0.03928091029883346, -0.03739941638473747, -0.035577820604562035, -0.03381557081818135, -0.03211207329138563, -0.03046669357526173, -0.028878757477071384, -0.027347552123970047, -0.025872327120952186, -0.024452295804486303, -0.02308663659341531, -0.021774494438853927, -0.020514982375023715, -0.019307183173230956, -0.018150151101529344, -0.017042913793022387, -0.015984474226266976, -0.01497381282185056, -0.014009889659946166, -0.013091646824523179, -0.01221801088092288, -0.011387895494727244, -0.01060020420127768, -0.009853833336875494, -0.009147675144649798, -0.008480621070356454, -0.007851565266020178, -0.007259408322408827, -0.00670306125489921, -0.00618144977143033, -0.0056935188560360075, -0.005238237706999054, -0.004814605075097868, -0.004421655054857593, -0.004058463390333951, -0.0037241543669357794, -0.0034179083723508566, -0.003138970223036288, -0.002886658368268443, -0.002660375101772813, -0.0024596179318830923, -0.002283992285501103, -0.002133225749416379, -0.002007184085475529, -0.0019058892944650956, -0.0018295400483345832, -0.0017785348626588025, -0.00175349844235014, -0.001755311705161858, -0.0017851460713518752, -0.001844502706243706, -0.001935257518000634, -0.0020597128489187213, -0.0022206569587731213, -0.002421432587814734, -0.002666016110432926, -0.0029591090549227674, -0.003306244078242843, -0.003713907856814409, -0.0041896837970316686, -0.004742417996467278, -0.0053824125160803595, -0.006121650776161715, -0.006974060790038242, -0.007955823031223134, -0.009085731030394735, -0.01038561436583363, -0.011880835603298258, -0.013600875031107252, -0.015580019812994873, -0.017858177556336126, -0.020481838405057552, -0.023505214787810844, -0.026991594099169097, -0.031014947136396957, -0.03566184439886151, -0.04103374381355673, -0.04724972762613963, -0.05444978378854791, -0.06279874906981332, -0.07249105845298848, -0.08375647961867891]];
50
51/// State-Space `C` vector
52#[rustfmt::skip]
53static CVALS: [[f64; 100]; 6] = [[0.003262158240609213, 0.0034920035888681496, 0.0037373737646944007, 0.003999262458943288, 0.004278722577299942, 0.004576869426862648, 0.004894884047891922, 0.0052340166952692885, 0.005595590474169005, 0.00598100513438249, 0.0063917410276451685, 0.006829363232196865, 0.007295525848655482, 0.007791976471096789, 0.008320560837005456, 0.008883227659490575, 0.00948203364483751, 0.01011914869809073, 0.010796861318924928, 0.011517584189555438, 0.012283859955858279, 0.013098367202204423, 0.013963926619756269, 0.01488350736711208, 0.015860233621209575, 0.016897391315296707, 0.017998435059533083, 0.019166995238385172, 0.020406885277400172, 0.021722109070174404, 0.02311686855434283, 0.024595571423187218, 0.02616283895696256, 0.027823513955241325, 0.029582668748441503, 0.03144561326319516, 0.033417903112287366, 0.03550534767549731, 0.03771401813275708, 0.040050255405531934, 0.042520677956163114, 0.045132189388009794, 0.047891985781492535, 0.050807562692478436, 0.05388672172973636, 0.05713757661730384, 0.060568558635389805, 0.06418842131973763, 0.06800624428397187, 0.0720314360121726, 0.0762737354494774, 0.08074321219665802, 0.08545026509001913, 0.0904056189202655, 0.09562031901277804, 0.10110572335654544, 0.10687349192929936, 0.11293557282156952, 0.11930418471174029, 0.12599179518691425, 0.13301109433961014, 0.14037496299694757, 0.14809643485583787, 0.15618865170340449, 0.1646648107948372, 0.17353810333930586, 0.1828216429063247, 0.19252838240766867, 0.20267101813076707, 0.21326187909526623, 0.22431279977135565, 0.23583497393224637, 0.2478387871087665, 0.2603336247656497, 0.2733276529198725, 0.2868275674634918, 0.30083830792759697, 0.31536273081941, 0.33040123696867735, 0.34595134651740755, 0.3620072142614178, 0.3785590769825246, 0.3955926231724721, 0.4130882741153127, 0.43102036363027696, 0.44935620184210817, 0.46805500609302897, 0.48706667948319415, 0.5063304144572875, 0.5257730952628958, 0.5453074688945951, 0.564830049189746, 0.584218712917307, 0.6033299398297837, 0.6219956405248578, 0.6400195063371819, 0.6571728040473276, 0.6731895245811004, 0.6877607786211971, 0.7005283126020667], [0.0031810755565904207, 0.003451710640700412, 0.0037446867495908517, 0.004061782595611506, 0.004404912375752516, 0.00477613553309489, 0.005177667171950351, 0.005611889166133123, 0.0060813620018041695, 0.006588837398391814, 0.007137271753218686, 0.00772984045765117, 0.008369953134830087, 0.0090612698513361, 0.009807718357483237, 0.010613512413313356, 0.01148317125977386, 0.01242154029698992, 0.013433813033979804, 0.014525554376591442, 0.015702725322844897, 0.016971709137225982, 0.01833933907777207, 0.019812927751988313, 0.021400298179706206, 0.02310981664290392, 0.024950427404209573, 0.02693168937725541, 0.029063814833181045, 0.03135771022833936, 0.0338250192385546, 0.03647816808503682, 0.039330413236167816, 0.04239589156772183, 0.04568967306154025, 0.049227816119084444, 0.05302742556147293, 0.057106713381354715, 0.0614850623040616, 0.0661830922056254, 0.07122272942315395, 0.07662727897835925, 0.08242149971731316, 0.08863168234830386, 0.0952857303344241, 0.10241324356761804, 0.11004560471561192, 0.11821606809164771, 0.12695985084820727, 0.13631422623892583, 0.1463186186262778, 0.1570146998349634, 0.16844648636047624, 0.18066043683711758, 0.1937055490474723, 0.20763345561338178, 0.2224985173437192, 0.2383579130231737, 0.2552717242047375, 0.2733030133117564, 0.2925178930578245, 0.31298558484788613, 0.33477846342423245, 0.3579720845578189, 0.38264519204834857, 0.4088796996739394, 0.43676064300904205, 0.46637609519146345, 0.4978170397468048, 0.5311771924493609, 0.5665527628863382, 0.604042144866948, 0.6437455230435003, 0.6857643810462758, 0.7302008940280764, 0.777157185709815, 0.8267344267466249, 0.8790317474135367, 0.9341449331450896, 0.9921648662405187, 1.0531756709310391, 1.1172525118381964, 1.1844589874422933, 1.2548440503011637, 1.328438374142129, 1.4052500742709624, 1.4852596716154274, 1.5684141716839353, 1.654620107216413, 1.7437353666648652, 1.8355595990582232, 1.929822948304175, 2.0261728253780187, 2.124158373710534, 2.223212219667601, 2.3226290241839074, 2.421540260766619, 2.5188845360269143, 2.613372637698066, 2.7034463369097703], [0.008501663901191581, 0.009092113038443327, 0.009722422998652357, 0.01039521703768399, 0.011113288204141179, 0.011879610338728884, 0.012697349804333392, 0.013569877997533375, 0.014500784695907641, 0.01549389229941339, 0.016553271028292436, 0.017683255144440815, 0.018888460267965864, 0.02017380186577467, 0.021544514994505395, 0.02300617538595091, 0.024564721969351735, 0.02622648093157117, 0.027998191423234432, 0.0298870330264321, 0.03190065510758028, 0.034047208187511356, 0.03633537746986577, 0.038774418678374854, 0.04137419636369364, 0.04414522485106609, 0.047098712011295944, 0.05024660604926483, 0.05360164551657359, 0.057177412767795255, 0.06098839109328651, 0.0650500257754961, 0.06937878933019757, 0.0739922512090004, 0.07890915225480173, 0.08414948421743218, 0.08973457465251482, 0.09568717754234177, 0.10203156999321657, 0.10879365537895425, 0.11600107331483385, 0.12368331685989571, 0.131871857357663, 0.14060027733565142, 0.14990441189179995, 0.15982249900048834, 0.17039533917122338, 0.18166646488836607, 0.19368232024911022, 0.2064924511979302, 0.22014970672698742, 0.23471045137150606, 0.2502347892743031, 0.2667868000215031, 0.28443478635842145, 0.3032515337763613, 0.32331458181264355, 0.34470650672147635, 0.36751521494524436, 0.3918342465357826, 0.417763087333284, 0.44540748829446764, 0.4748797898573365, 0.5062992486201421, 0.5397923628768504, 0.5754931926662531, 0.6135436689280659, 0.6540938850826407, 0.6973023628200694, 0.7433362820507411, 0.7923716627738961, 0.8445934839936786, 0.9001957216692674, 0.9593812839265733, 1.0223618172626645, 1.0893573520956465, 1.1605957495777233, 1.2363119038875137, 1.3167466449966096, 1.4021452758592101, 1.4927556647339364, 1.5888257974672257, 1.6906006755076826, 1.7983184225249167, 1.9122054349786346, 2.0324703788551317, 2.1592967948794906, 2.292834026382081, 2.433186125888301, 2.5803983262558297, 2.73444057716222, 2.8951875447009687, 3.062394346781095, 3.2356671450162287, 3.4144275287462875, 3.5978694012193313, 3.784906802420045, 3.974110765932373, 4.163632894070502, 4.351112828192071], [0.004246676532999148, 0.004587575340931407, 0.004954816250404014, 0.005350346898927851, 0.005776251873974966, 0.006234761834089471, 0.006728263207580448, 0.00725930850447024, 0.00783062727966937, 0.008445137787817122, 0.009105959372877883, 0.009816425638434276, 0.010580098447685517, 0.011400782805462854, 0.012282542678131923, 0.013229717811088232, 0.014246941607689525, 0.015339160137932524, 0.016511652350001217, 0.017770051563016892, 0.01912036832494114, 0.020569014725653458, 0.022122830261786863, 0.0237891093569904, 0.025575630648946707, 0.02749068816274399, 0.029543124499135237, 0.031742366175864505, 0.03409846127064649, 0.03662211952561543, 0.03932475508515853, 0.0422185320520818, 0.04531641306107993, 0.04863221108355034, 0.05218064469396867, 0.055977397045377714, 0.06003917882009011, 0.06438379544150315, 0.06903021885402365, 0.07399866420050144, 0.07931067175030408, 0.08498919445620187, 0.09105869154453239, 0.09754522857060793, 0.10447658439988496, 0.11188236560486123, 0.11979412879774262, 0.12824551144932061, 0.13727237177471796, 0.14691293829619473, 0.15720796972122342, 0.16820092579966128, 0.17993814984582024, 0.1924690636280594, 0.20584637533832617, 0.22012630135446, 0.2353688024961733, 0.2516378354477653, 0.2690016199724346, 0.28753292246892054, 0.3073093563145081, 0.3284136992907527, 0.35093422818953107, 0.37496507043464616, 0.4006065722129522, 0.4279656821700412, 0.45715634916593834, 0.48829993187793036, 0.5215256171459514, 0.5569708428387976, 0.5947817196247539, 0.6351134442946755, 0.6781306951308579, 0.7240079971455308, 0.7729300417104986, 0.8250919410194775, 0.8806993927885493, 0.9399687243877163, 1.0031267779365165, 1.070410588453368, 1.1420667955071533, 1.2183507144665278, 1.29952497574037, 1.3858576185602927, 1.477619498888925, 1.5750808377192271, 1.678506694830902, 1.788151102077127, 1.9042495270947986, 2.027009259960972, 2.1565972179842188, 2.293124542771573, 2.4366272129572444, 2.5870417079435275, 2.744174523092823, 2.9076640428426925, 3.076932909698833, 3.251128564235605, 3.4290490488489063, 3.6090504337100917], [0.0022833983078002335, 0.0024447258117889247, 0.0026172576156579083, 0.002801760686760927, 0.002999053913294045, 0.0032100115906495926, 0.0034355671403426304, 0.003676717076944152, 0.003934525239482142, 0.004210127304869429, 0.004504735602090545, 0.004819644247135052, 0.0051562346200077274, 0.005515981206584053, 0.005900457829619234, 0.006311344294869484, 0.006750433480053938, 0.007219638896283598, 0.0077210027536216705, 0.00825670456462771, 0.008829070322089969, 0.009440582289678165, 0.010093889446969859, 0.01079181863323058, 0.011537386437481903, 0.01233381188578908, 0.013184529980362797, 0.014093206149021188, 0.015063751667820093, 0.016100340124262685, 0.017207424993467606, 0.018389758405041534, 0.019652411184200518, 0.021000794256947217, 0.022440681515879492, 0.023978234250516768, 0.025620027253928174, 0.027373076725972202, 0.029244870102663193, 0.03124339795110263, 0.03337718808011188, 0.035655342028217255, 0.03808757410301625, 0.04068425315924166, 0.04345644731707202, 0.04641597183744712, 0.04957544038734998, 0.052948319945231186, 0.05654898961493556, 0.060392803635637475, 0.06449615889528261, 0.06887656727577607, 0.0735527331794414, 0.07854463660784343, 0.0838736221855599, 0.08956249454239457, 0.09563562048721118, 0.10211903842415389, 0.1090405754764173, 0.11642997279245366, 0.12431901951275977, 0.13274169586975734, 0.14173432587580373, 0.15133574002119562, 0.16158744835035985, 0.1725338242041396, 0.1842222988014913, 0.19670356667533642, 0.2100318017625016, 0.2242648836613489, 0.23946463319341446, 0.2556970559129414, 0.27303259156989396, 0.2915463667094817, 0.3113184465358099, 0.33243408081796366, 0.35498393689653973, 0.3790643106600564, 0.40477730358094405, 0.4322309503743514, 0.46153927737292966, 0.49282226604716717, 0.5262056889264103, 0.5618207760866467, 0.5998036588528993, 0.6402945227596233, 0.6834363832817377, 0.7293733743147458, 0.7782484094621862, 0.8302000381025431, 0.8853582696605333, 0.9438390775319148, 1.0057372148614239, 1.0711168728547136, 1.1399995820110596, 1.21234858909759, 1.2880487267215848, 1.3668805133833755, 1.448486860663927, 1.5323302952945441], [0.00031201541775068145, 0.0003362861826169104, 0.0003623742161304347, 0.00039041000697390756, 0.0004205330121343513, 0.0004528922485448492, 0.00048764692268686425, 0.0005249671005962567, 0.0005650344208816047, 0.0006080428535413249, 0.000654199507557257, 0.0007037254904479835, 0.0007568568231863482, 0.000813845414123759, 0.0008749600958202243, 0.0009404877289553052, 0.0010107343777928993, 0.0010860265619937366, 0.0011667125899158014, 0.0012531639789165403, 0.00134577696857422, 0.0014449741331814415, 0.0015512061003347482, 0.0016649533829530049, 0.0017867283326075752, 0.0019170772226424612, 0.0020565824702065715, 0.002205865007017511, 0.002365586809430897, 0.0025364535992069607, 0.002719217727251775, 0.0029146812535703016, 0.003123699237708967, 0.003347183255093301, 0.003586105155889349, 0.003841501084343869, 0.004114475777996945, 0.004406207167720451, 0.004717951301228188, 0.0050510476145375835, 0.005406924577852094, 0.0057871057444888315, 0.0061932162338107334, 0.006626989681650651, 0.007090275694449386, 0.007585047846285491, 0.008113412261164967, 0.00867761682637967, 0.009280061086442986, 0.009923306871087334, 0.010610089715062975, 0.011343331132022159, 0.012126151809603828, 0.01296188579794664, 0.01385409576923646, 0.014806589431508402, 0.015823437185729768, 0.016908991121118166, 0.01806790544960721, 0.019305158486218884, 0.020626076287662977, 0.02203635806650604, 0.023542103502414286, 0.025149842074840677, 0.02686656454253465, 0.028699756693663286, 0.030657435485186516, 0.03274818768018992, 0.03498121107553274, 0.0373663583873608, 0.03991418382608007, 0.04263599234187344, 0.0455438914523352, 0.048650845469629, 0.05197073181841935, 0.05551839896828055, 0.05930972528322471, 0.06336167780077606, 0.0676923695734982, 0.07232111371097967, 0.07726847161631119, 0.08255629207435518, 0.08820773676293946, 0.09424728634880045, 0.10070071950166275, 0.10759505478692492, 0.11495844231609878, 0.12281998802937502, 0.13120948827385204, 0.14015704555151662, 0.14969252745070777, 0.15984481919102897, 0.1706408050371799, 0.18210399391543577, 0.19425267835043677, 0.2070974812530026, 0.22063809933489198, 0.23485899122264026, 0.24972367755894995, 0.2651672125265582]];
54
55#[cfg(feature = "std")]
56#[cfg(test)]
57#[rustfmt::skip]
58mod test {
59    use super::*;
60    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];
61    static CUTOFF_TEST_OUTPUT: [f32; 101] = [0.0, 0.1701091177700757, 0.13651787661258524, -0.2758226226829054, 0.12500969241519752, 0.15993667325805636, -0.3602533858437855, 0.34143187081754334, -0.11084618772932286, -0.20661827917658687, 0.4441181378398668, -0.47774028965057586, 0.2831445488985754, 0.0568645745964646, -0.39249299021776074, 0.5743786037576771, -0.5184536662684498, 0.24144523512230154, 0.1464797119002651, -0.4875905989378341, 0.6414096217167659, -0.5419553416347214, 0.2245992662842411, 0.18776834826675143, -0.5333498583158058, 0.6753476535674541, -0.5559404854843433, 0.21923792169314876, 0.2056187518729427, -0.5544955516701243, 0.6919214627279588, -0.5636612562518688, 0.21788545432784068, 0.21320079162966254, -0.5641499158491021, 0.6999016130363559, -0.5677646708790703, 0.21777606568813518, 0.21637396542279558, -0.5685257545253696, 0.7037118564388389, -0.5698955587112364, 0.21796470610644691, 0.2176771500498399, -0.5704947287718536, 0.7055180140251524, -0.5709831024229058, 0.2181628615749145, 0.21819919906352375, -0.5713737089154732, 0.7063682547820161, -0.5715303120408437, 0.21830564924917123, 0.21840136992412867, -0.5717627139912993, 0.7067657868108418, -0.5718023251266388, 0.21839511038161225, 0.21847591065112804, -0.571933233668492, 0.7069504064043827, -0.5719361140605321, 0.21844713716513225, 0.21850130233741272, -0.5720071806723879, 0.7070355703324718, -0.5720012982704562, 0.21847600745570694, 0.21850872738857274, -0.572038854387965, 0.7070745882123497, -0.572032785223078, 0.21849151340569173, 0.21851012279353532, -0.5720522251377365, 0.7070923389916302, -0.5720478744114467, 0.21849964136572597, 0.2185098123722063, -0.5720577706759963, 0.7071003555055215, -0.5720550516365588, 0.2185038214779259, 0.21850922371477993, -0.5720600201824793, 0.7071039478804474, -0.5720584412675841, 0.218505938141203, 0.21850874558577987, -0.5720609063899827, 0.7071055443192572, -0.5720600311086159, 0.21850699604633844, 0.2185084298680003, -0.5720612415291775, 0.7071062473251172, -0.572060771765471, 0.2185075188609064, 0.21850824069573715, -0.5720613606056578, 0.7071065537691201];
62    const STEP_TEST_MIN_OUTPUT: f32 = 0.9999998285690135;
63    const STEP_TEST_MAX_OUTPUT: f32 = 0.9899352296804012;
64
65    #[test]
66    fn test() {
67        let order = 6;
68        println!("order {order}");
69        let mut filter = butter6(0.4).unwrap();
70        let out = (0..CUTOFF_TEST_INPUT.len()).map(|i| {filter.update(CUTOFF_TEST_INPUT[i])}).collect::<Vec<f32>>();
71        // Check overall match to reference output to catch phase error, etc
72        (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); });
73        // Check approximate attenuation at cutoff frequency; should be -3dB or 1/sqrt(2) magnitude
74        let maxmag = out.iter().fold(0.0_f32, |a, b| a.abs().max(b.abs()));
75        let attenuation_rel_err = (maxmag - 0.707).abs() / 0.707;
76        println!("order {order} attenuation rel err {attenuation_rel_err}");
77        assert!(attenuation_rel_err < 0.05);
78        // Check convergence of step responses at min and max tabulated cutoff
79        let mut filtermin = butter6(MIN_CUTOFF_RATIO).unwrap();
80        (0..99).for_each(|_| {filtermin.update(1.0);});
81        let step_min_final = filtermin.update(1.0);
82        let step_min_rel_err = (step_min_final - STEP_TEST_MIN_OUTPUT).abs() / STEP_TEST_MIN_OUTPUT;
83        println!("order {order} step min rel err {step_min_rel_err}");
84        assert!(step_min_rel_err < 1e-4);
85        let mut filtermax = butter6(MAX_CUTOFF_RATIO).unwrap();
86        (0..1).for_each(|_| {filtermax.update(1.0);});
87        let step_max_final = filtermax.update(1.0);
88        let step_max_rel_err = (step_max_final - STEP_TEST_MAX_OUTPUT).abs() / STEP_TEST_MAX_OUTPUT;
89        println!("order {order} step max rel err {step_max_rel_err}");
90        assert!(step_max_rel_err < 1e-6);
91    }
92}