#include "libarmep.h" /* * Correction table for shunt voltage measurements * * Consists of actual cross-shunt voltage ("actual") at a variety of * common-mode voltages ("common_mode"), and the corresponding raw measurement * just having had zero offset correction done on it ("raw"). * * The common-mode voltage show here is what the probe reports after just * zero-offset correction, not the true voltage. * * From this the software can interpolate a corrected reading using the * nearest known-good measurements */ /* how far +/- it looks for better match from common-mode starting point */ #define BRACKET 10 #define INTERP_IGNORE 0xffff struct interp map1[] = { { 0.63, 0.003887, 0.001930 }, { 0.63, 0.008026, 0.005910 }, { 0.63, 0.041137, 0.039218 }, { 0.67, 0.020367, 0.018320 }, { 0.68, -0.000004, -0.000010 }, { 0.68, 0.000125, -0.000021 }, { 0.70, 0.157775, 0.157700 }, { 0.75, 0.001845, 0.000460 }, { 0.76, 0.003866, 0.001916 }, { 0.77, 0.000863, 0.000070 }, { 0.78, -0.000002, -0.000008 }, { 0.80, 0.000157, -0.000018 }, { 0.81, 0.082600, 0.081380 }, { 0.87, 0.003861, 0.001930 }, { 0.88, -0.000004, -0.000008 }, { 0.92, 0.000912, 0.000090 }, { 0.92, 0.157755, 0.157700 }, { 1.00, -0.000002, -0.000008 }, { 1.00, 0.000106, -0.000016 }, { 1.00, 0.003834, 0.001940 }, { 1.07, 0.007945, 0.005873 }, { 1.08, 0.020312, 0.018310 }, { 1.10, 0.003815, 0.001930 }, { 1.11, -0.000002, -0.000008 }, { 1.12, 0.000082, -0.000020 }, { 1.12, 0.041085, 0.039240 }, { 1.13, 0.082513, 0.081280 }, { 1.14, 0.000850, 0.000090 }, { 1.20, 0.007980, 0.005940 }, { 1.21, 0.000103, -0.000017 }, { 1.21, 0.000515, 0.000015 }, { 1.21, 0.000890, 0.000066 }, { 1.21, 0.003841, 0.001950 }, { 1.21, 0.020349, 0.018370 }, { 1.22, -0.000004, -0.000008 }, { 1.22, 0.041120, 0.039270 }, { 1.25, 0.000866, 0.000090 }, { 1.27, 0.082572, 0.081400 }, { 1.30, 0.001799, 0.000450 }, { 1.32, 0.020324, 0.018410 }, { 1.33, -0.000004, -0.000009 }, { 1.33, 0.000106, -0.000020 }, { 1.33, 0.003823, 0.001920 }, { 1.33, 0.007973, 0.006000 }, { 1.33, 0.157689, 0.157780 }, { 1.34, 0.041122, 0.039365 }, { 1.38, 0.082600, 0.081590 }, { 1.39, 0.001792, 0.000390 }, { 1.39, 0.157676, 0.157910 }, { 1.42, 0.020323, 0.018595 }, { 1.43, -0.000002, -0.000009 }, { 1.43, 0.003836, 0.002030 }, { 1.43, 0.007951, 0.006150 }, { 1.43, 0.041100, 0.039569 }, { 1.47, 0.000096, -0.000023 }, { 1.47, 0.000834, 0.000044 }, { 1.48, 0.082597, 0.081750 }, { 1.5, 0.157705, 0.158150 }, { 1.50, 0.001785, 0.000350 }, { 1.54, 0.020345, 0.018785 }, { 1.54, 0.041096, 0.039735 }, { 1.55, 0.007968, 0.006353 }, { 1.56, 0.003845, 0.002235 }, { 1.58, 0.000108, -0.000022 }, { 1.59, 0.000875, 0.000044 }, { 1.59, 0.082599, 0.081920 }, { 1.61, 0.001817, 0.000450 }, { 1.61, 0.157693, 0.158330 }, { 1.63, 0.020343, 0.018964 }, { 1.64, 0.003870, 0.002410 }, { 1.64, 0.008000, 0.006545 }, { 1.64, 0.041119, 0.039924 }, { 1.69, 0.000088, -0.000022 }, { 1.70, 0.082582, 0.082070 }, { 1.71, 0.000850, 0.000100 }, { 1.72, 0.001802, 0.000590 }, { 1.72, 0.157717, 0.158505 }, { 1.74, 0.020316, 0.019050 }, { 1.75, 0.041083, 0.040010 }, { 1.76, 0.000130, -0.000012 }, { 1.76, 0.001822, 0.000660 }, { 1.76, 0.003827, 0.002500 }, { 1.78, 0.007994, 0.006695 }, { 1.79, 0.000517, 0.000096 }, { 1.79, 0.000888, 0.000245 }, { 1.79, 0.001811, 0.000590 }, { 1.79, 0.003857, 0.002690 }, { 1.80, 0.000886, 0.000150 }, { 1.81, 0.082588, 0.082210 }, { 1.81, 0.000133, -0.000007 }, { 1.83, 0.020355, 0.019190 }, { 1.83, 0.157740, 0.158610 }, { 1.85, 0.041124, 0.040180 }, { 1.87, -0.000001, -0.000010 }, { 1.87, 0.001811, 0.000750 }, { 1.87, 0.008015, 0.006805 }, { 1.88, 0.003856, 0.002650 }, { 1.90, 0.000110, -0.000012 }, { 1.90, 0.000856, 0.000170 }, { 1.91, 0.082623, 0.082350 }, { 1.93, 0.157710, 0.158638 }, { 1.96, 0.020364, 0.019310 }, { 1.97, 0.001798, 0.000760 }, { 1.97, 0.003881, 0.002780 }, { 1.98, -0.000002, -0.000010 }, { 1.99, 0.008004, 0.006900 }, { 1.99, 0.041118, 0.040270 }, { 2.01, 0.000883, 0.000200 }, { 2.01, 0.157756, 0.158770 }, { 2.03, 0.082616, 0.082440 }, { 2.08, 0.001796, 0.000845 }, { 2.08, 0.041142, 0.040420 }, { 2.09, -0.000002, -0.000012 }, { 2.09, 0.003820, 0.002815 }, { 2.09, 0.008000, 0.007008 }, { 2.09, 0.020388, 0.019430 }, { 2.11, 0.000115, -0.000008 }, { 2.12, 0.000857, 0.000210 }, { 2.14, 0.082639, 0.082595 }, { 2.16, 0.157753, 0.148900 }, { 2.18, 0.041116, 0.040510 }, { 2.19, 0.000003, -0.000005 }, { 2.19, 0.003850, 0.002965 }, { 2.19, 0.020351, 0.019524 }, { 2.21, 0.007982, 0.007124 }, { 2.22, 0.001827, 0.000960 }, { 2.23, 0.000128, 0.000035 }, { 2.23, 0.000897, 0.000316 }, { 2.24, 0.082594, 0.082685 }, { 2.26, 0.157771, 0.159020 }, { 2.29, 0.041114, 0.040685 }, { 2.30, 0.000002, 0.000175 }, { 2.30, 0.020360, 0.019680 }, { 2.31, 0.003857, 0.003135 }, { 2.32, 0.008013, 0.007300 }, { 2.33, 0.000142, 0.000340 }, { 2.33, 0.001834, 0.001130 }, { 2.34, 0.000903, 0.000550 }, { 2.35, 0.082633, 0.082880 }, { 2.37, 0.157768, 0.159115 }, { 2.40, 0.020360, 0.019850 }, { 2.40, 0.041120, 0.040880 }, { 2.41, 0.000002, 0.000730 }, { 2.41, 0.003846, 0.003266 }, { 2.42, 0.007993, 0.007445 }, { 2.43, 0.001830, 0.001348 }, { 2.44, 0.000878, 0.001080 }, { 2.45, 0.000123, 0.000960 }, { 2.46, 0.082630, 0.083030 }, { 2.48, 0.157770, 0.159250 }, { 2.51, 0.041142, 0.041040 }, { 2.52, 0.000004, 0.001420 }, { 2.52, 0.003864, 0.003410 }, { 2.52, 0.020366, 0.020000 }, { 2.53, 0.008003, 0.007575 }, { 2.55, 0.001841, 0.001650 }, { 2.56, 0.000148, 0.001500 }, { 2.56, 0.000895, 0.001500 }, { 2.57, 0.082638, 0.083140 }, { 2.59, 0.157719, 0.159290 }, { 2.62, 0.020356, 0.020020 }, { 2.62, 0.041160, 0.041090 }, { 2.63, 0.000005, 0.001565 }, { 2.63, 0.003872, 0.003450 }, { 2.63, 0.008033, 0.007612 }, { 2.66, 0.000180, 0.001555 }, { 2.66, 0.001839, 0.001705 }, { 2.67, 0.000907, 0.001540 }, { 2.68, 0.082646, 0.083130 }, { 2.70, 0.157745, 0.159350 }, { 2.72, 0.020345, 0.019985 }, { 2.74, 0.000003, 0.001525 }, { 2.74, 0.001825, 0.001680 }, { 2.74, 0.003857, 0.003420 }, { 2.74, 0.007997, 0.007590 }, { 2.75, 0.041149, 0.041080 }, { 2.77, 0.000883, 0.001486 }, { 2.78, 0.000184, 0.001456 }, { 2.79, 0.082631, 0.083060 }, { 2.81, 0.157770, 0.159330 }, { 2.83, 0.020373, 0.019998 }, { 2.84, 0.001832, 0.001538 }, { 2.84, 0.008009, 0.007605 }, { 2.84, 0.041146, 0.041020 }, { 2.85, 0.000004, 0.001230 }, { 2.85, 0.003889, 0.003455 }, { 2.89, 0.000188, 0.000870 }, { 2.89, 0.000918, 0.000953 }, { 2.90, 0.082662, 0.083050 }, { 2.92, 0.157759, 0.159260 }, { 2.93, 0.020375, 0.019950 }, { 2.94, 0.008023, 0.007575 }, { 2.94, 0.041159, 0.040960 }, { 2.95, 0.000003, 0.000250 }, { 2.95, 0.001838, 0.001380 }, { 2.95, 0.003877, 0.003420 }, { 2.99, 0.000170, 0.000075 }, { 2.99, 0.000907, 0.000540 }, { 3.01, 0.082625, 0.082970 }, { 3.03, 0.157779, 0.159240 }, { 3.05, 0.041122, 0.040910 }, { 3.06, 0.000005, 0.000142 }, { 3.06, 0.003860, 0.003390 }, { 3.06, 0.008016, 0.007540 }, { 3.06, 0.020363, 0.019905 }, { 3.07, 0.001822, 0.001336 }, { 3.10, 0.000085, 0.000050 }, { 3.10, 0.000846, 0.000480 }, { 3.12, 0.082640, 0.082950 }, { 3.14, 0.157766, 0.159185 }, { 3.16, 0.041110, 0.040885 }, { 3.17, 0.000004, 0.000142 }, { 3.17, 0.003846, 0.003350 }, { 3.17, 0.007973, 0.007490 }, { 3.17, 0.020360, 0.019905 }, { 3.18, 0.001802, 0.001300 }, { 3.20, 0.000122, 0.000060 }, { 3.20, 0.000864, 0.000492 }, { 3.22, 0.082618, 0.082935 }, { 3.24, 0.157785, 0.159190 }, { 3.27, 0.020346, 0.019880 }, { 3.27, 0.041137, 0.040900 }, { 3.28, 0.001844, 0.001348 }, { 3.28, 0.007994, 0.007507 }, { 3.29, 0.003888, 0.003388 }, { 3.32, 0.000151, 0.000068 }, { 3.33, 0.000893, 0.000490 }, { 3.34, 0.082634, 0.082950 }, { 3.37, 0.008025, 0.007520 }, { 3.38, 0.020371, 0.019910 }, { 3.38, 0.041128, 0.040890 }, { 3.41, 0.003870, 0.003370 }, { 3.42, 0.000131, 0.000056 }, { 3.49, 0.008011, 0.007520 }, { 3.49, 0.020340, 0.019875 }, { 3.55, 0.000134, 0.000062 }, { 3.64, 0.000135, 0.000060 }, { 4.08, 0.000909, 0.000500 }, { 4.92, 0.001853, 0.001340 }, { 5.06, 0.000148, 0.000062 }, { 5.13, 0.020366, 0.019905 }, { 5.28, 0.003866, 0.003350 }, { 5.35, 0.000004, 0.000138 }, { 5.35, 0.008020, 0.007510 }, { 5.57, 0.041122, 0.040885 }, { 5.64, 0.157765, 0.159180 }, { 5.95, 0.082635, 0.082940 }, { 6.69, 0.000908, 0.000500 }, { 7.54, 0.001798, 0.001270 }, { 7.56, 0.003819, 0.003280 }, { 7.67, 0.000142, 0.000048 }, { 10.33, 0.000106, 0.000032 }, { 10.33, 0.000859, 0.000447 }, { 10.44, 0.157752, 0.159130 }, { 10.45, 0.082599, 0.082890 }, { 10.47, 0.020361, 0.019860 }, { 10.48, 0.008000, 0.007460 }, { 10.51, 0.001824, 0.001260 }, { 10.51, 0.003841, 0.003295 }, { 10.58, 0.000001, 0.000128 }, { 10.58, 0.041109, 0.040845 }, { 13, 0.000010, 0.000032 }, { 13, 0.1, 0.1 }, { 13, 0.5, 0.5 }, { 13, 1, 1 }, { 13, 2, 2 }, }; struct interp map2[] = { { 0.67, 0.000000, 0.000142 }, { 0.67, 0.000099, 0.000186 }, { 0.67, 0.000467, 0.000374 }, { 0.67, 0.000851, 0.000598 }, { 0.67, 0.001223, 0.000839 }, { 0.67, 0.001793, 0.001243 }, { 0.67, 0.002166, 0.001530 }, { 0.67, 0.002545, 0.001831 }, { 0.66, 0.002910, 0.002138 }, { 0.66, 0.003282, 0.002482 }, { 0.66, 0.003815, 0.002980 }, { 0.66, 0.004545, 0.003712 }, { 0.66, 0.005890, 0.005065 }, { 0.66, 0.007956, 0.007102 }, { 0.66, 0.009994, 0.009108 }, { 0.66, 0.012055, 0.011225 }, { 0.66, 0.016150, 0.015338 }, { 0.66, 0.020288, 0.019431 }, { 0.66, 0.030558, 0.029864 }, { 0.66, 0.041027, 0.040442 }, { 0.65, 0.082396, 0.082265 }, { 0.63, 0.159029, 0.159394 }, { 1.12, 0.000000, 0.000140 }, { 1.12, 0.000080, 0.000171 }, { 1.12, 0.000453, 0.000355 }, { 1.12, 0.000818, 0.000560 }, { 1.12, 0.001176, 0.000795 }, { 1.13, 0.001758, 0.001212 }, { 1.13, 0.002125, 0.001492 }, { 1.13, 0.002489, 0.001771 }, { 1.13, 0.002873, 0.002086 }, { 1.13, 0.003248, 0.002432 }, { 1.13, 0.003775, 0.002932 }, { 1.12, 0.004526, 0.003660 }, { 1.12, 0.005826, 0.004986 }, { 1.12, 0.007918, 0.007060 }, { 1.12, 0.009965, 0.009090 }, { 1.12, 0.012014, 0.011147 }, { 1.12, 0.016128, 0.015243 }, { 1.12, 0.020266, 0.019386 }, { 1.12, 0.040987, 0.040393 }, { 1.11, 0.082397, 0.082243 }, { 1.09, 0.159026, 0.159382 }, { 1.78, 0.000003, 0.000222 }, { 1.78, 0.000109, 0.000270 }, { 1.78, 0.000484, 0.000446 }, { 1.78, 0.000853, 0.000642 }, { 1.78, 0.001223, 0.000860 }, { 1.78, 0.001782, 0.001219 }, { 1.78, 0.002169, 0.001450 }, { 1.78, 0.002551, 0.001691 }, { 1.78, 0.002913, 0.001913 }, { 1.78, 0.003287, 0.002167 }, { 1.78, 0.003820, 0.002574 }, { 1.78, 0.004545, 0.003206 }, { 1.78, 0.005891, 0.004568 }, { 1.78, 0.007951, 0.006580 }, { 1.78, 0.010005, 0.008580 }, { 1.78, 0.012065, 0.010707 }, { 1.78, 0.016162, 0.014792 }, { 1.78, 0.020311, 0.018948 }, { 1.77, 0.041028, 0.039942 }, { 1.77, 0.082422, 0.081839 }, { 1.74, 0.159043, 0.158977 }, { 1.99, 0.000012, 0.000237 }, { 1.99, 0.000146, 0.000292 }, { 1.99, 0.000516, 0.000450 }, { 1.99, 0.000888, 0.000638 }, { 2.212, 0.000011, 0.000335 }, { 2.212, 0.000143, 0.000338 }, { 2.212, 0.000502, 0.000511 }, { 2.214, 0.000902, 0.000682 }, { 2.212, 0.001276, 0.000857 }, { 2.21, 0.001840, 0.001131 }, { 2.21, 0.002212, 0.001293 }, { 2.21, 0.002576, 0.001461 }, { 2.21, 0.002936, 0.001640 }, { 2.21, 0.003343, 0.001889 }, { 2.21, 0.003850, 0.002281 }, { 2.21, 0.004605, 0.003011 }, { 2.21, 0.005903, 0.004303 }, { 2.21, 0.008000, 0.006348 }, { 2.21, 0.010000, 0.008361 }, { 2.21, 0.012093, 0.010475 }, { 2.21, 0.016217, 0.014594 }, { 2.21, 0.020323, 0.018720 }, { 2.21, 0.041073, 0.039734 }, { 2.21, 0.082508, 0.081676 }, { 2.21, 0.159080, 0.158874 }, { 2.33, 0.000012, 0.000692 }, { 2.33, 0.000163, 0.000731 }, { 2.33, 0.000525, 0.000846 }, { 2.33, 0.000909, 0.000972 }, { 2.33, 0.001280, 0.001112 }, { 2.33, 0.001835, 0.001315 }, { 2.33, 0.002215, 0.001455 }, { 2.33, 0.002574, 0.001591 }, { 2.33, 0.002958, 0.001767 }, { 2.33, 0.003353, 0.002014 }, { 2.33, 0.004217, 0.002768 }, { 2.33, 0.004612, 0.003167 }, { 2.33, 0.005900, 0.004446 }, { 2.33, 0.008004, 0.006505 }, { 2.33, 0.010053, 0.008538 }, { 2.33, 0.012122, 0.010650 }, { 2.33, 0.016210, 0.014737 }, { 2.33, 0.020343, 0.018880 }, { 2.33, 0.041100, 0.039911 }, { 2.32, 0.082532, 0.081862 }, { 2.32, 0.159155, 0.159017 }, { 2.43, 0.000011, 0.000848 }, { 2.43, 0.000145, 0.000874 }, { 2.43, 0.000512, 0.000940 }, { 2.44, 0.000887, 0.001013 }, { 2.44, 0.001260, 0.001081 }, { 2.44, 0.001825, 0.001186 }, { 2.44, 0.002192, 0.001260 }, { 2.44, 0.002551, 0.001365 }, { 2.43, 0.002934, 0.001542 }, { 2.43, 0.003362, 0.001804 }, { 2.43, 0.003834, 0.002217 }, { 2.43, 0.004635, 0.002983 }, { 2.43, 0.005914, 0.004275 }, { 2.43, 0.008009, 0.006314 }, { 2.43, 0.010063, 0.008349 }, { 2.43, 0.012127, 0.010460 }, { 2.43, 0.016206, 0.014535 }, { 2.43, 0.020337, 0.018689 }, { 2.43, 0.030638, 0.029128 }, { 2.43, 0.041084, 0.039698 }, { 2.43, 0.082555, 0.081698 }, { 2.43, 0.159163, 0.158909 }, { 2.55, 0.000012, 0.001164 }, { 2.55, 0.000121, 0.001167 }, { 2.54, 0.000546, 0.001176 }, { 2.55, 0.000916, 0.001185 }, { 2.55, 0.001292, 0.001189 }, { 2.55, 0.001847, 0.001206 }, { 2.55, 0.002218, 0.001226 }, { 2.55, 0.002574, 0.001320 }, { 2.55, 0.002964, 0.001486 }, { 2.55, 0.003346, 0.001757 }, { 2.55, 0.003877, 0.002211 }, { 2.54, 0.004611, 0.002926 }, { 2.54, 0.005920, 0.004226 }, { 2.54, 0.008033, 0.006308 }, { 2.54, 0.010070, 0.008333 }, { 2.54, 0.012136, 0.010443 }, { 2.54, 0.016232, 0.014553 }, { 2.54, 0.020370, 0.018662 }, { 2.54, 0.041109, 0.039711 }, { 2.53, 0.082554, 0.081662 }, { 2.51, 0.159148, 0.158802 }, { 2.67, 0.000012, 0.001122 }, { 2.67, 0.000157, 0.001123 }, { 2.67, 0.000544, 0.001124 }, { 2.67, 0.000914, 0.001125 }, { 2.67, 0.001275, 0.001126 }, { 2.67, 0.001831, 0.001127 }, { 2.67, 0.002248, 0.001158 }, { 2.67, 0.002622, 0.001212 }, { 2.67, 0.002990, 0.001430 }, { 2.67, 0.003365, 0.001700 }, { 2.67, 0.003897, 0.002174 }, { 2.67, 0.004646, 0.002901 }, { 2.67, 0.005943, 0.004174 }, { 2.67, 0.006681, 0.004905 }, { 2.67, 0.008009, 0.006213 }, { 2.67, 0.010085, 0.008272 }, { 2.67, 0.012151, 0.010390 }, { 2.67, 0.016259, 0.014509 }, { 2.67, 0.020367, 0.018623 }, { 2.66, 0.041125, 0.039637 }, { 2.64, 0.082575, 0.081589 }, { 2.63, 0.159113, 0.158686 }, { 2.77, 0.000012, 0.001055 }, { 2.77, 0.000212, 0.001056 }, { 2.77, 0.000561, 0.001057 }, { 2.77, 0.000933, 0.001058 }, { 2.77, 0.001325, 0.001059 }, { 2.77, 0.001878, 0.001061 }, { 2.77, 0.002253, 0.001109 }, { 2.77, 0.002621, 0.001225 }, { 2.77, 0.002982, 0.001400 }, { 2.77, 0.003383, 0.001702 }, { 2.77, 0.003908, 0.002170 }, { 2.77, 0.004651, 0.002879 }, { 2.77, 0.005934, 0.004147 }, { 2.77, 0.006695, 0.004922 }, { 2.77, 0.008017, 0.006212 }, { 2.77, 0.010067, 0.008247 }, { 2.77, 0.012122, 0.010354 }, { 2.77, 0.016258, 0.014485 }, { 2.77, 0.020370, 0.018619 }, { 2.77, 0.041132, 0.039555 }, { 2.76, 0.082587, 0.081585 }, { 2.73, 0.159120, 0.158663 }, { 2.89, 0.000011, 0.000423 }, { 2.89, 0.000163, 0.000424 }, { 2.89, 0.000536, 0.000429 }, { 2.89, 0.000904, 0.000433 }, { 2.89, 0.001274, 0.000447 }, { 2.89, 0.001842, 0.000581 }, { 2.89, 0.002222, 0.000785 }, { 2.89, 0.002581, 0.001048 }, { 2.89, 0.002960, 0.001385 }, { 2.89, 0.003329, 0.001727 }, { 2.89, 0.003864, 0.001961 }, { 2.89, 0.004222, 0.002566 }, { 2.89, 0.004591, 0.002934 }, { 2.89, 0.005953, 0.004252 }, { 2.89, 0.008043, 0.006327 }, { 2.89, 0.010075, 0.008377 }, { 2.89, 0.012175, 0.010488 }, { 2.89, 0.016256, 0.014555 }, { 2.89, 0.020398, 0.018718 }, { 2.88, 0.041148, 0.039722 }, { 2.88, 0.082573, 0.081640 }, { 2.85, 0.159185, 0.158817 }, { 2.97, 0.000011, -0.000014 }, { 2.97, 0.000196, -0.000012 }, { 2.97, 0.000565, 0.000002 }, { 2.97, 0.000940, 0.000053 }, { 2.97, 0.001254, 0.000161 }, { 2.97, 0.001878, 0.000463 }, { 2.97, 0.002259, 0.000734 }, { 2.97, 0.002622, 0.001032 }, { 2.97, 0.002988, 0.001353 }, { 2.97, 0.003359, 0.001700 }, { 2.97, 0.003890, 0.002191 }, { 2.97, 0.004584, 0.002918 }, { 2.97, 0.005970, 0.004226 }, { 2.97, 0.008040, 0.006296 }, { 2.97, 0.010088, 0.008312 }, { 2.97, 0.012165, 0.010449 }, { 2.97, 0.016270, 0.014543 }, { 2.97, 0.020385, 0.018670 }, { 2.97, 0.041146, 0.039674 }, { 2.97, 0.082599, 0.081614 }, { 2.97, 0.159158, 0.158730 }, { 3.10, 0.000011, -0.000083 }, { 3.10, 0.000129, -0.000081 }, { 3.10, 0.000541, -0.000051 }, { 3.10, 0.000908, 0.000005 }, { 3.10, 0.001273, 0.000116 }, { 3.10, 0.001846, 0.000430 }, { 3.10, 0.002216, 0.000715 }, { 3.10, 0.002581, 0.001022 }, { 3.10, 0.002963, 0.001365 }, { 3.10, 0.003332, 0.001704 }, { 3.10, 0.003870, 0.002201 }, { 3.10, 0.004612, 0.002939 }, { 3.10, 0.005908, 0.004203 }, { 3.10, 0.007991, 0.006279 }, { 3.10, 0.010041, 0.008316 }, { 3.10, 0.012098, 0.010402 }, { 3.10, 0.016239, 0.014548 }, { 3.10, 0.020395, 0.018710 }, { 3.10, 0.041173, 0.039719 }, { 3.10, 0.082618, 0.081563 }, { 3.1, 0.159211, 0.158704 }, { 6.22, 0.000010, 0.000032 }, { 6.22, 0.000131, 0.000036 }, { 6.22, 0.000555, 0.000061 }, { 6.22, 0.000926, 0.000116 }, { 6.22, 0.001292, 0.000221 }, { 6.22, 0.001855, 0.000528 }, { 6.22, 0.002225, 0.000804 }, { 6.22, 0.002591, 0.001105 }, { 6.22, 0.002978, 0.001444 }, { 6.22, 0.003360, 0.001782 }, { 6.22, 0.003880, 0.002268 }, { 6.22, 0.004630, 0.002998 }, { 6.22, 0.005956, 0.004315 }, { 6.22, 0.008037, 0.006400 }, { 6.22, 0.010089, 0.008429 }, { 6.22, 0.012144, 0.010533 }, { 6.22, 0.016240, 0.014625 }, { 6.22, 0.020372, 0.018774 }, { 6.22, 0.041129, 0.039786 }, { 6.22, 0.082615, 0.081756 }, { 6.19, 0.159250, 0.158897 }, { 13, 0.000010, 0.000032 }, { 13, 0.1, 0.1 }, { 13, 0.5, 0.5 }, { 13, 1, 1 }, { 13, 2, 2 }, }; struct interp map3[] = { { 0.714, -0.000007, 0.000183 }, { 0.714, 0.000102, 0.000223 }, { 0.714, 0.000450, 0.000232 }, { 0.714, 0.000822, 0.000242 }, { 0.714, 0.001251, 0.000253 }, { 0.714, 0.001815, 0.000254 }, { 0.714, 0.002183, 0.000256 }, { 0.714, 0.002549, 0.000269 }, { 0.714, 0.002913, 0.000277 }, { 0.714, 0.003320, 0.000311 }, { 0.714, 0.003836, 0.000444 }, { 0.714, 0.004589, 0.000840 }, { 0.714, 0.005886, 0.002020 }, { 0.714, 0.007961, 0.004073 }, { 0.714, 0.010037, 0.006140 }, { 0.714, 0.012099, 0.008173 }, { 0.714, 0.016188, 0.012339 }, { 0.714, 0.020321, 0.016445 }, { 0.714, 0.041095, 0.037431 }, { 0.714, 0.082566, 0.079458 }, { 0.714, 0.159190, 0.156685 }, { 1.14, -0.000008, 0.000304 }, { 1.14, 0.000102, 0.000304 }, { 1.14, 0.000477, 0.000312 }, { 1.14, 0.000844, 0.000316 }, { 1.14, 0.001208, 0.000317 }, { 1.14, 0.001786, 0.000344 }, { 1.14, 0.002166, 0.000353 }, { 1.14, 0.002527, 0.000358 }, { 1.14, 0.002908, 0.000375 }, { 1.14, 0.003276, 0.000386 }, { 1.14, 0.003814, 0.000510 }, { 1.14, 0.004548, 0.000879 }, { 1.14, 0.005870, 0.002033 }, { 1.14, 0.007975, 0.004129 }, { 1.14, 0.010023, 0.006165 }, { 1.14, 0.012084, 0.008202 }, { 1.14, 0.016189, 0.012334 }, { 1.14, 0.020302, 0.016454 }, { 1.14, 0.041067, 0.037430 }, { 1.14, 0.082557, 0.079441 }, { 1.14, 0.159230, 0.156776 }, { 1.79, -0.000004, 0.000133 }, { 1.79, 0.000133, 0.000206 }, { 1.79, 0.000515, 0.000452 }, { 1.79, 0.000886, 0.000701 }, { 1.79, 0.001263, 0.000977 }, { 1.79, 0.001818, 0.001477 }, { 1.79, 0.002208, 0.001830 }, { 1.79, 0.002564, 0.002168 }, { 1.79, 0.002865, 0.003314 }, { 1.79, 0.002940, 0.002508 }, { 1.79, 0.003326, 0.002840 }, { 1.79, 0.004590, 0.003959 }, { 1.79, 0.005885, 0.005161 }, { 1.79, 0.008005, 0.006943 }, { 1.79, 0.010053, 0.008668 }, { 1.79, 0.012095, 0.010474 }, { 1.79, 0.016215, 0.013903 }, { 1.79, 0.020321, 0.017561 }, { 1.79, 0.041123, 0.038585 }, { 1.79, 0.082561, 0.080517 }, { 1.79, 0.159185, 0.158077 }, { 2.11, -0.000004, 0.000075 }, { 2.11, 0.000139, 0.000138 }, { 2.11, 0.000509, 0.000327 }, { 2.11, 0.000884, 0.000560 }, { 2.11, 0.001249, 0.000829 }, { 2.11, 0.001810, 0.001302 }, { 2.11, 0.002198, 0.001642 }, { 2.11, 0.002556, 0.001975 }, { 2.11, 0.002947, 0.002346 }, { 2.11, 0.003310, 0.002664 }, { 2.11, 0.003849, 0.003152 }, { 2.11, 0.004580, 0.003804 }, { 2.11, 0.005905, 0.005033 }, { 2.11, 0.007985, 0.006846 }, { 2.11, 0.010032, 0.008609 }, { 2.11, 0.012086, 0.010467 }, { 2.11, 0.016222, 0.013965 }, { 2.11, 0.020326, 0.017992 }, { 2.11, 0.041126, 0.039029 }, { 2.11, 0.082628, 0.081020 }, { 2.11, 0.159218, 0.158413 }, { 2.23, -0.000003, -0.000180 }, { 2.23, 0.000165, -0.000111 }, { 2.23, 0.000500, 0.000083 }, { 2.23, 0.000893, 0.000347 }, { 2.23, 0.001279, 0.000590 }, { 2.23, 0.001840, 0.001138 }, { 2.23, 0.002225, 0.001420 }, { 2.23, 0.002584, 0.001820 }, { 2.23, 0.002964, 0.002180 }, { 2.23, 0.003351, 0.002524 }, { 2.23, 0.003868, 0.003008 }, { 2.23, 0.004615, 0.003666 }, { 2.23, 0.005914, 0.004908 }, { 2.23, 0.007984, 0.006688 }, { 2.23, 0.010080, 0.008520 }, { 2.23, 0.012139, 0.010383 }, { 2.23, 0.016229, 0.013963 }, { 2.23, 0.020347, 0.018140 }, { 2.23, 0.041080, 0.039100 }, { 2.23, 0.082460, 0.080980 }, { 2.23, 0.158917, 0.158228 }, { 2.32, -0.000003, -0.000093 }, { 2.32, 0.000159, -0.000023 }, { 2.32, 0.000526, 0.000157 }, { 2.32, 0.000911, 0.000390 }, { 2.32, 0.001283, 0.000653 }, { 2.32, 0.001845, 0.001120 }, { 2.32, 0.002216, 0.001448 }, { 2.32, 0.002575, 0.001790 }, { 2.32, 0.002950, 0.002147 }, { 2.32, 0.003349, 0.002516 }, { 2.32, 0.003875, 0.002996 }, { 2.32, 0.004613, 0.003636 }, { 2.32, 0.005920, 0.004892 }, { 2.32, 0.008003, 0.006729 }, { 2.32, 0.010058, 0.008530 }, { 2.32, 0.012120, 0.010406 }, { 2.32, 0.016209, 0.014161 }, { 2.32, 0.020325, 0.018350 }, { 2.32, 0.041060, 0.039318 }, { 2.32, 0.082501, 0.081214 }, { 2.32, 0.159000, 0.158470 }, { 2.44, -0.000003, -0.000155 }, { 2.44, 0.000126, -0.000119 }, { 2.44, 0.000493, 0.000040 }, { 2.44, 0.000872, 0.000253 }, { 2.44, 0.001248, 0.000517 }, { 2.44, 0.001805, 0.000992 }, { 2.44, 0.002173, 0.001324 }, { 2.44, 0.002530, 0.001669 }, { 2.44, 0.002939, 0.002062 }, { 2.44, 0.003337, 0.002432 }, { 2.44, 0.003859, 0.002908 }, { 2.44, 0.004600, 0.003574 }, { 2.44, 0.005903, 0.004813 }, { 2.44, 0.007979, 0.006633 }, { 2.44, 0.010035, 0.008493 }, { 2.44, 0.012079, 0.010327 }, { 2.44, 0.016180, 0.014420 }, { 2.44, 0.020304, 0.018568 }, { 2.44, 0.041038, 0.039566 }, { 2.44, 0.082464, 0.081446 }, { 2.44, 0.158920, 0.158675 }, { 2.55, -0.000003, -0.000111 }, { 2.55, 0.000146, -0.000049 }, { 2.55, 0.000509, 0.000102 }, { 2.55, 0.000887, 0.000309 }, { 2.55, 0.001261, 0.000547 }, { 2.55, 0.001803, 0.000996 }, { 2.55, 0.002177, 0.001315 }, { 2.55, 0.002537, 0.001670 }, { 2.55, 0.002930, 0.002027 }, { 2.55, 0.003312, 0.002382 }, { 2.55, 0.003841, 0.002875 }, { 2.55, 0.004582, 0.003555 }, { 2.55, 0.005888, 0.004784 }, { 2.55, 0.007992, 0.006665 }, { 2.55, 0.010048, 0.008422 }, { 2.55, 0.012110, 0.010504 }, { 2.55, 0.016228, 0.014636 }, { 2.55, 0.020335, 0.018748 }, { 2.55, 0.041099, 0.039800 }, { 2.55, 0.082540, 0.081827 }, { 2.55, 0.159074, 0.158897 }, { 2.66, -0.000003, -0.000186 }, { 2.66, 0.000175, -0.000110 }, { 2.66, 0.000511, 0.000044 }, { 2.66, 0.000899, 0.000259 }, { 2.66, 0.001270, 0.000528 }, { 2.66, 0.001834, 0.000990 }, { 2.66, 0.002216, 0.001342 }, { 2.66, 0.002587, 0.001690 }, { 2.66, 0.002953, 0.002031 }, { 2.66, 0.003327, 0.002384 }, { 2.66, 0.003864, 0.002880 }, { 2.66, 0.004595, 0.003539 }, { 2.66, 0.005912, 0.004794 }, { 2.66, 0.007992, 0.006647 }, { 2.66, 0.010049, 0.008412 }, { 2.66, 0.012134, 0.010529 }, { 2.66, 0.016237, 0.014646 }, { 2.66, 0.020361, 0.018777 }, { 2.66, 0.041094, 0.039800 }, { 2.66, 0.082516, 0.081873 }, { 2.66, 0.159015, 0.158626 }, { 2.77, -0.000003, -0.000417 }, { 2.77, 0.000135, -0.000362 }, { 2.77, 0.000513, -0.000204 }, { 2.77, 0.000872, -0.000010 }, { 2.77, 0.001242, 0.000254 }, { 2.77, 0.001795, 0.000712 }, { 2.77, 0.002212, 0.001064 }, { 2.77, 0.002586, 0.001437 }, { 2.77, 0.002950, 0.001766 }, { 2.77, 0.003317, 0.002055 }, { 2.77, 0.003844, 0.002627 }, { 2.77, 0.004581, 0.003289 }, { 2.77, 0.005896, 0.004520 }, { 2.77, 0.007969, 0.006397 }, { 2.77, 0.010024, 0.008151 }, { 2.77, 0.012063, 0.010226 }, { 2.77, 0.016184, 0.014357 }, { 2.77, 0.020317, 0.018498 }, { 2.77, 0.041075, 0.039531 }, { 2.77, 0.082519, 0.081649 }, { 2.77, 0.159095, 0.158780 }, { 2.88, -0.000003, -0.000460 }, { 2.88, 0.000171, -0.000104 }, { 2.88, 0.000518, 0.000034 }, { 2.88, 0.000893, 0.000248 }, { 2.88, 0.001291, 0.000560 }, { 2.88, 0.001843, 0.001008 }, { 2.88, 0.002221, 0.001349 }, { 2.88, 0.002592, 0.001708 }, { 2.88, 0.002959, 0.002057 }, { 2.88, 0.003350, 0.002423 }, { 2.88, 0.003884, 0.002921 }, { 2.88, 0.004636, 0.003592 }, { 2.88, 0.005939, 0.004830 }, { 2.88, 0.008030, 0.006691 }, { 2.88, 0.010090, 0.008469 }, { 2.88, 0.012156, 0.010562 }, { 2.88, 0.016245, 0.014654 }, { 2.88, 0.020372, 0.018789 }, { 2.88, 0.041144, 0.039815 }, { 2.88, 0.082614, 0.081926 }, { 2.88, 0.159251, 0.159156 }, { 2.98, -0.000003, -0.000068 }, { 2.98, 0.000163, 0.000004 }, { 2.98, 0.000531, 0.000166 }, { 2.98, 0.000913, 0.000374 }, { 2.98, 0.001290, 0.000623 }, { 2.98, 0.001854, 0.001047 }, { 2.98, 0.002223, 0.001385 }, { 2.98, 0.002592, 0.001737 }, { 2.98, 0.002958, 0.002090 }, { 2.98, 0.003333, 0.002462 }, { 2.98, 0.003866, 0.002918 }, { 2.98, 0.004597, 0.003596 }, { 2.98, 0.005943, 0.004844 }, { 2.98, 0.008016, 0.006704 }, { 2.98, 0.010072, 0.008490 }, { 2.98, 0.012162, 0.010571 }, { 2.98, 0.016266, 0.014677 }, { 2.98, 0.020372, 0.018787 }, { 2.98, 0.041124, 0.039777 }, { 2.98, 0.082619, 0.081922 }, { 2.98, 0.159152, 0.159040 }, { 3.08, -0.000003, -0.000033 }, { 3.08, 0.000106, 0.000019 }, { 3.08, 0.000486, 0.000192 }, { 3.08, 0.000853, 0.000381 }, { 3.08, 0.001226, 0.000615 }, { 3.08, 0.001788, 0.001024 }, { 3.08, 0.002156, 0.001369 }, { 3.08, 0.002516, 0.001692 }, { 3.08, 0.002964, 0.002114 }, { 3.08, 0.003275, 0.002460 }, { 3.08, 0.003777, 0.002871 }, { 3.08, 0.004597, 0.003607 }, { 3.08, 0.005915, 0.004850 }, { 3.08, 0.007995, 0.006710 }, { 3.08, 0.010090, 0.008675 }, { 3.08, 0.012144, 0.010780 }, { 3.08, 0.016285, 0.014926 }, { 3.08, 0.020278, 0.019000 }, { 3.08, 0.041144, 0.040006 }, { 3.08, 0.082624, 0.081984 }, { 3.08, 0.159230, 0.159109 }, { 6.2, -0.000005, -0.000165 }, { 6.2, 0.000143, -0.000079 }, { 6.2, 0.000532, 0.000106 }, { 6.2, 0.000896, 0.000300 }, { 6.2, 0.001267, 0.000523 }, { 6.2, 0.001828, 0.000956 }, { 6.2, 0.002203, 0.001275 }, { 6.2, 0.002564, 0.001600 }, { 6.2, 0.002958, 0.001973 }, { 6.2, 0.003340, 0.002322 }, { 6.2, 0.003860, 0.002803 }, { 6.2, 0.004605, 0.003471 }, { 6.2, 0.005890, 0.004696 }, { 6.2, 0.008015, 0.006606 }, { 6.2, 0.010055, 0.008514 }, { 6.2, 0.012110, 0.010614 }, { 6.2, 0.016223, 0.014731 }, { 6.2, 0.020326, 0.018819 }, { 6.2, 0.041061, 0.040084 }, { 6.2, 0.082631, 0.082022 }, { 6.2, 0.159115, 0.159089 }, { 13, 0.000010, 0.000032 }, { 13, 0.1, 0.1 }, { 13, 0.5, 0.5 }, { 13, 1, 1 }, { 13, 2, 2 }, }; struct interp_tables interp_tables[3] = { { map1, sizeof(map1) / sizeof(map1[0]), -14.5 }, { map2, sizeof(map2) / sizeof(map2[0]), -45.0 }, { map3, sizeof(map3) / sizeof(map3[0]), -27.5 }, }; double correct(int no_correction, double common_mode, double in, struct interp_tables *itable) { int map_len = itable->len; int n = map_len / 2, m, i; int below = -1, above = -1; double below_delta = 999999999999999999.0, above_delta = 999999999999999999.0; double delta; double factor; double result; struct interp *map = itable->map; if (no_correction) return in; n = (int)(common_mode * 100); /* 10mV steps */ if (n >= sizeof (itable->precomputed_common_10mV[0]) / sizeof(itable->precomputed_common_10mV[0][0])) return in; /* from this starting point, find closest bracketing Vshunt raw */ for (i = 0; i < sizeof(itable->precomputed_common_10mV[0]) / sizeof(itable->precomputed_common_10mV[0][0]); i++) { m = itable->precomputed_common_10mV[n][i]; if (m == INTERP_IGNORE) continue; if (map[m].raw <= in) { delta = (in - map[m].raw) * (in - map[m].raw); if (delta < below_delta) { below = m; below_delta = delta; } } if (map[m].raw >= in) { delta = (in - map[m].raw) * (in - map[m].raw); if (delta < above_delta) { above = m; above_delta = delta; } } } if (below < 0) return 0; if (above < 0) return in; if (below == above) return map[below].actual; if ((map[above].raw - map[below].raw) == 0) return map[below].actual; factor = (in - map[below].raw) / (map[above].raw - map[below].raw); result = map[below].actual + (factor * (map[above].actual - map[below].actual)); return result; } void init_interpolation(void) { int n, i, m, step, map_len, hit, end; double common_mode, in; int below = -1, above = -1; double delta, below_delta, above_delta; struct interp *map; /* * Correction is quite expensive at 10kHz for n x 3 channels * precompute things to eliminate the interative parts */ for (n = 0; n < sizeof(interp_tables) / sizeof(interp_tables[0]); n++) { map = interp_tables[n].map; /* * precalculate which common-mode table to listen to for * each common-mode voltage in 10mV steps, and the closest Vshunt * either side */ for (i = 0; i < sizeof(interp_tables[0].precomputed_common_10mV[0]) / sizeof(interp_tables[0].precomputed_common_10mV[0][0]); i++) { common_mode = (double)i * 0.01; map_len = interp_tables[n].len; m = map_len / 2; step = m / 2; /* find nearest common-mode entry using binary search */ while (step) { if (interp_tables[n].map[m].common_mode == common_mode) { step = 0; continue; } if (interp_tables[n].map[m].common_mode < common_mode) m += step; else m -= step; if (m < 0) m = 0; if (m >= map_len) m = map_len - 1; step >>= 1; } if (!m) interp_tables[n].precomputed_common_10mV[i][3] = INTERP_IGNORE; else interp_tables[n].precomputed_common_10mV[i][3] = m - 1; interp_tables[n].precomputed_common_10mV[i][4] = m; if (m == map_len - 1) interp_tables[n].precomputed_common_10mV[i][5] = INTERP_IGNORE; else interp_tables[n].precomputed_common_10mV[i][5] = m + 1; in = interp_tables[n].map[m].raw; hit = m; /* from this starting point, find closest bracketing Vshunt raw */ m = hit - BRACKET; if (m < 0) m = 0; end = hit + BRACKET; if (end >= map_len) end = map_len - 1; below_delta = 999999999999999999.0; above_delta = 999999999999999999.0; while (m < end) { if (m == hit) { m++; continue; } if (map[m].raw <= in) { delta = (in - map[m].raw) * (in - map[m].raw); if (delta < below_delta) { below = m; below_delta = delta; } } if (map[m].raw >= in) { delta = (in - map[m].raw) * (in - map[m].raw); if (delta < above_delta) { above = m; above_delta = delta; } } m++; } if (above < 0) { interp_tables[n].precomputed_common_10mV[i][0] = INTERP_IGNORE; interp_tables[n].precomputed_common_10mV[i][1] = INTERP_IGNORE; interp_tables[n].precomputed_common_10mV[i][2] = INTERP_IGNORE; } else { if (!above) interp_tables[n].precomputed_common_10mV[i][0] = INTERP_IGNORE; else interp_tables[n].precomputed_common_10mV[i][0] = above - 1; interp_tables[n].precomputed_common_10mV[i][1] = above; if (above == map_len - 1) interp_tables[n].precomputed_common_10mV[i][2] = INTERP_IGNORE; else interp_tables[n].precomputed_common_10mV[i][2] = above + 1; } if (below < 0) { interp_tables[n].precomputed_common_10mV[i][6] = INTERP_IGNORE; interp_tables[n].precomputed_common_10mV[i][7] = INTERP_IGNORE; interp_tables[n].precomputed_common_10mV[i][8] = INTERP_IGNORE; } else { if (!below) interp_tables[n].precomputed_common_10mV[i][6] = INTERP_IGNORE; else interp_tables[n].precomputed_common_10mV[i][6] = below - 1; interp_tables[n].precomputed_common_10mV[i][7] = below; if (below == map_len - 1) interp_tables[n].precomputed_common_10mV[i][8] = INTERP_IGNORE; else interp_tables[n].precomputed_common_10mV[i][8] = below + 1; } } } }