2
0

make_line_models.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. /*
  2. * SpanDSP - a series of DSP components for telephony
  3. *
  4. * make_line_models.c
  5. *
  6. * Written by Steve Underwood <steveu@coppice.org>
  7. *
  8. * Copyright (C) 2004 Steve Underwood
  9. *
  10. * All rights reserved.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2, as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*! \page make_line_models_page Telephony line model construction
  26. \section make_line_models_page_sec_1 What does it do?
  27. ???.
  28. \section make_line_models_page_sec_2 How does it work?
  29. ???.
  30. */
  31. #if defined(HAVE_CONFIG_H)
  32. #include "config.h"
  33. #endif
  34. #include <stdlib.h>
  35. #include <unistd.h>
  36. #include <inttypes.h>
  37. #include <string.h>
  38. #include <stdio.h>
  39. #if defined(HAVE_FFTW3_H)
  40. #include <fftw3.h>
  41. #else
  42. #include <fftw.h>
  43. #endif
  44. #include <math.h>
  45. #if defined(HAVE_STDBOOL_H)
  46. #include <stdbool.h>
  47. #else
  48. #include "spandsp/stdbool.h"
  49. #endif
  50. #include "spandsp.h"
  51. #if !defined(M_PI)
  52. # define M_PI 3.14159265358979323846 /* pi */
  53. #endif
  54. #define LINE_MODEL_FILE_NAME "line_models.c"
  55. #define SAMPLE_RATE 8000
  56. #define LINE_FILTER_SIZE 129
  57. #define FFT_SIZE 1024
  58. /* Tabulated medium range telephone line response
  59. (from p 537, Digital Communication, John G. Proakis */
  60. /*
  61. amp 1.0 -> 2.15, freq = 3000 Hz -> 3.2, by 0.2 increments
  62. delay = 4 ms -> 2.2
  63. */
  64. struct
  65. {
  66. int frequency;
  67. float amp;
  68. float delay;
  69. } proakis[] =
  70. {
  71. { 0, 0.00, 4.80},
  72. { 200, 0.90, 3.50},
  73. { 400, 1.40, 2.20},
  74. { 600, 1.80, 0.90},
  75. { 800, 2.00, 0.50},
  76. {1000, 2.10, 0.25},
  77. {1200, 2.30, 0.10},
  78. {1400, 2.30, 0.05},
  79. {1600, 2.20, 0.00},
  80. {1800, 2.10, 0.00},
  81. {2000, 2.00, 0.00},
  82. {2200, 1.85, 0.05},
  83. {2400, 1.75, 0.10},
  84. {2600, 1.55, 0.20},
  85. {2800, 1.30, 0.40},
  86. {3000, 1.10, 0.50},
  87. {3200, 0.80, 0.90},
  88. {3400, 0.55, 1.20},
  89. {3600, 0.25, 2.20},
  90. {3800, 0.05, 3.20},
  91. {4000, 0.05, 4.20},
  92. {4200, 0.05, 5.20}
  93. };
  94. #define CPE_TO_CO_ATTENUATION 0 /* In dB */
  95. #define CPE_TO_CO_DELAY 1 /* In us */
  96. #define CPE_TO_CO_IMPEDANCE 2 /* In ohms */
  97. #define CPE_TO_CO_PHASE 3 /* In degrees */
  98. #define CO_TO_CPE_IMPEDANCE 4 /* In ohms */
  99. #define CO_TO_CPE_PHASE 5 /* In degrees */
  100. #define CO_TO_CPE_ATTENUATION 6 /* In dB */
  101. #define CO_TO_CPE_DELAY 7 /* In us */
  102. /* Terms used, for V.56bis:
  103. AD = attenuation distortion
  104. EDD = envelope delay distortion */
  105. /* V.56bis EIA LL-1, non-loaded loop */
  106. struct
  107. {
  108. int freq;
  109. float ad[8];
  110. } eia_ll1[] =
  111. {
  112. { 200, {0.0, 0.4, 767, -1.4, 767, -1.4, 0.0, 0.4}},
  113. { 300, {0.0, 0.7, 766, -2.0, 766, -2.0, 0.0, 0.7}},
  114. { 400, {0.0, 0.5, 763, -2.8, 763, -2.8, 0.0, 0.5}},
  115. { 500, {0.0, 0.6, 765, -3.4, 765, -3.4, 0.0, 0.6}},
  116. { 600, {0.0, 0.2, 764, -4.1, 764, -4.1, 0.0, 0.2}},
  117. { 700, {0.0, 0.4, 764, -4.7, 764, -4.7, 0.0, 0.4}},
  118. { 800, {0.0, 0.4, 762, -5.4, 762, -5.4, 0.0, 0.4}},
  119. { 900, {0.0, 0.2, 762, -6.0, 762, -6.0, 0.0, 0.2}},
  120. {1000, {1.2, 0.5, 761, -6.7, 761, -6.7, 1.2, 0.5}},
  121. {1100, {0.0, 0.6, 759, -7.4, 759, -7.4, 0.0, 0.6}},
  122. {1200, {0.0, 0.4, 757, -8.1, 757, -8.1, 0.0, 0.4}},
  123. {1300, {0.0, 0.1, 757, -8.6, 757, -8.6, 0.0, 0.1}},
  124. {1400, {0.0, 0.3, 755, -9.3, 755, -9.3, 0.0, 0.3}},
  125. {1500, {0.0, 0.4, 753, -10.0, 753, -10.0, 0.0, 0.4}},
  126. {1600, {0.0, 0.3, 751, -10.7, 751, -10.7, 0.0, 0.3}},
  127. {1700, {0.0, 0.1, 748, -11.3, 748, -11.3, 0.0, 0.1}},
  128. {1800, {0.0, 11.0, 748, -11.9, 748, -11.9, 0.0, 11.0}},
  129. {1900, {0.1, 0.1, 745, -12.5, 745, -12.5, 0.1, 0.1}},
  130. {2000, {0.1, 0.3, 743, -13.9, 743, -13.9, 0.1, 0.3}},
  131. {2100, {0.1, 0.3, 740, -13.9, 740, -13.9, 0.1, 0.3}},
  132. {2200, {0.1, 0.3, 737, -14.5, 737, -14.5, 0.1, 0.3}},
  133. {2300, {0.1, 0.3, 734, -15.2, 734, -15.2, 0.1, 0.3}},
  134. {2400, {0.1, 0.2, 731, -15.8, 731, -15.8, 0.1, 0.2}},
  135. {2500, {0.1, 0.0, 728, -16.4, 728, -16.4, 0.1, 0.0}},
  136. {2600, {0.1, 0.0, 729, -16.8, 729, -16.8, 0.1, 0.0}},
  137. {2700, {0.2, 0.1, 726, -17.4, 726, -17.4, 0.2, 0.1}},
  138. {2800, {0.2, 0.2, 722, -18.0, 722, -18.0, 0.2, 0.2}},
  139. {2900, {0.2, 0.3, 719, -18.6, 719, -18.6, 0.2, 0.3}},
  140. {3000, {0.2, 0.4, 715, -19.3, 715, -19.3, 0.2, 0.4}},
  141. {3100, {0.2, 0.4, 712, -19.9, 712, -19.9, 0.2, 0.4}},
  142. {3200, {0.2, 0.5, 708, -20.5, 708, -20.5, 0.2, 0.5}},
  143. {3300, {0.2, 0.5, 704, -21.1, 704, -21.1, 0.2, 0.5}},
  144. {3400, {0.2, 0.5, 700, -21.7, 700, -21.7, 0.2, 0.5}},
  145. {3500, {0.2, 0.5, 696, -22.3, 696, -22.3, 0.2, 0.5}},
  146. {3600, {0.2, 0.4, 692, -22.9, 692, -22.9, 0.2, 0.4}},
  147. {3700, {0.2, 0.3, 688, -23.5, 688, -23.5, 0.2, 0.3}},
  148. {3800, {0.2, 0.2, 684, -24.1, 684, -24.1, 0.2, 0.2}},
  149. {3900, {0.2, 0.1, 680, -24.7, 680, -24.7, 0.2, 0.1}},
  150. {4000, {0.2, -0.1, 676, -25.2, 676, -25.2, 0.2, -0.1}}
  151. };
  152. /* V.56bis EIA LL-2, non-loaded loop */
  153. struct
  154. {
  155. int freq;
  156. float ad[8];
  157. } eia_ll2[] =
  158. {
  159. { 200, {-0.2, 6.6, 1086, -4.9, 1085, -5.6, -0.2, 6.6}},
  160. { 300, {-0.2, 7.7, 1079, -7.3, 1077, -8.3, -0.2, 7.7}},
  161. { 400, {-0.2, 6.7, 1062, -9.9, 1058, -11.2, -0.2, 6.7}},
  162. { 500, {-0.2, 7.1, 1059, -12.0, 1053, -13.6, -0.2, 7.1}},
  163. { 600, {-0.1, 5.2, 1041, -14.4, 1034, -16.3, -0.1, 5.2}},
  164. { 700, {-0.1, 5.8, 1030, -16.5, 1020, -18.6, -0.1, 5.8}},
  165. { 800, {-0.1, 5.4, 1010, -18.7, 998, -21.0, -0.1, 5.4}},
  166. { 900, { 0.0, 4.5, 997, -20.5, 982, -23.1, 0.0, 4.5}},
  167. {1000, { 3.2, 5.1, 976, -22.5, 959, -25.3, 3.2, 5.1}},
  168. {1100, { 0.1, 5.0, 954, -24.5, 934, -27.4, 0.1, 5.0}},
  169. {1200, { 0.1, 4.0, 931, -26.2, 909, -29.4, 0.1, 4.0}},
  170. {1300, { 0.2, 2.7, 918, -27.6, 894, -30.9, 0.2, 2.7}},
  171. {1400, { 0.2, 2.8, 897, -29.2, 871, -32.6, 0.2, 2.8}},
  172. {1500, { 0.3, 2.6, 874, -30.7, 847, -34.3, 0.3, 2.6}},
  173. {1600, { 0.3, 2.0, 852, -32.1, 823, -35.8, 0.3, 2.0}},
  174. {1700, { 0.4, 0.9, 831, -33.4, 800, -37.2, 0.4, 0.9}},
  175. {1800, { 0.5, 40.8, 816, -34.4, 783, -38.4, 0.5, 40.8}},
  176. {1900, { 0.6, 0.0, 796, -35.6, 762, -39.6, 0.6, 0.0}},
  177. {2000, { 0.6, -0.2, 776, -36.6, 741, -40.7, 0.6, -0.2}},
  178. {2100, { 0.7, -0.6, 756, -37.6, 720, -41.8, 0.7, -0.6}},
  179. {2200, { 0.8, -1.1, 737, -38.6, 700, -42.9, 0.8, -1.1}},
  180. {2300, { 0.9, -1.8, 719, -39.4, 681, -43.8, 0.9, -1.8}},
  181. {2400, { 1.0, -2.6, 701, -40.2, 663, -44.7, 1.0, -2.6}},
  182. {2500, { 1.0, -3.7, 684, -41.0, 646, -45.5, 1.0, -3.7}},
  183. {2600, { 1.1, -4.1, 678, -41.3, 639, -45.9, 1.1, -4.1}},
  184. {2700, { 1.2, -4.3, 663, -42.0, 623, -46.6, 1.2, -4.3}},
  185. {2800, { 1.3, -4.5, 647, -42.6, 607, -47.3, 1.3, -4.5}},
  186. {2900, { 1.4, -4.8, 632, -43.1, 591, -47.9, 1.4, -4.8}},
  187. {3000, { 1.5, -5.2, 617, -43.6, 576, -48.4, 1.5, -5.2}},
  188. {3100, { 1.6, -5.6, 603, -44.1, 562, -49.0, 1.6, -5.6}},
  189. {3200, { 1.7, -6.0, 589, -44.5, 548, -49.5, 1.7, -6.0}},
  190. {3300, { 1.8, -6.5, 576, -44.9, 535, -49.9, 1.8, -6.5}},
  191. {3400, { 1.9, -7.1, 563, -45.3, 522, -50.3, 1.9, -7.1}},
  192. {3500, { 2.0, -7.7, 551, -45.6, 509, -50.7, 2.0, -7.7}},
  193. {3600, { 2.1, -8.4, 539, -45.9, 498, -51.0, 2.1, -8.4}},
  194. {3700, { 2.2, -9.1, 528, -46.2, 486, -51.3, 2.2, -9.1}},
  195. {3800, { 2.3, -9.9, 518, -46.4, 476, -51.6, 2.3, -9.9}},
  196. {3900, { 2.4, -10.6, 507, -46.6, 466, -51.9, 2.4, -10.6}},
  197. {4000, { 2.5, -11.5, 498, -46.8, 456, -52.1, 2.5, -11.5}}
  198. };
  199. /* V.56bis EIA LL-3, non-loaded loop */
  200. struct
  201. {
  202. int freq;
  203. float ad[8];
  204. } eia_ll3[] =
  205. {
  206. { 200, {-0.3, 10.5, 1176, -5.9, 1173, -7.4, -0.3, 10.5}},
  207. { 300, {-0.3, 11.5, 1165, -8.8, 1159, -11.0, -0.3, 11.5}},
  208. { 400, {-0.3, 10.6, 1140, -11.8, 1130, -14.7, -0.3, 10.6}},
  209. { 500, {-0.3, 11.0, 1133, -14.3, 1117, -17.8, -0.3, 11.0}},
  210. { 600, {-0.2, 8.5, 1108, -17.1, 1086, -21.2, -0.2, 8.5}},
  211. { 700, {-0.2, 8.5, 1090, -19.4, 1062, -24.0, -0.2, 8.5}},
  212. { 800, {-0.1, 8.4, 1062, -21.9, 1029, -27.0, -0.1, 8.4}},
  213. { 900, { 0.0, 7.1, 1042, -23.9, 1003, -29.4, 0.0, 7.1}},
  214. {1000, { 3.8, 7.7, 1013, -23.0, 969, -31.9, 3.8, 7.7}},
  215. {1100, { 0.1, 7.4, 982, -28.1, 934, -34.3, 0.1, 7.4}},
  216. {1200, { 0.1, 6.0, 953, -29.9, 900, -36.5, 0.1, 6.0}},
  217. {1300, { 0.2, 4.2, 935, -31.3, 878, -38.1, 0.2, 4.2}},
  218. {1400, { 0.3, 4.2, 907, -32.8, 847, -40.0, 0.3, 4.2}},
  219. {1500, { 0.4, 3.7, 880, -34.3, 817, -41.7, 0.4, 3.7}},
  220. {1600, { 0.5, 2.7, 853, -35.6, 787, -43.2, 0.5, 2.7}},
  221. {1700, { 0.6, 1.2, 827, -36.8, 760, -44.6, 0.6, 1.2}},
  222. {1800, { 0.7, 48.7, 809, -37.8, 739, -45.8, 0.7, 48.7}},
  223. {1900, { 0.8, -0.2, 785, -38.8, 715, -47.0, 0.8, -0.2}},
  224. {2000, { 0.9, -0.7, 763, -39.7, 691, -48.0, 0.9, -0.7}},
  225. {2100, { 1.0, -1.3, 741, -40.5, 668, -49.1, 1.0, -1.3}},
  226. {2200, { 1.1, -2.1, 719, -41.3, 647, -50.0, 1.1, -2.1}},
  227. {2300, { 1.2, -2.1, 699, -42.0, 625, -50.8, 1.2, -2.1}},
  228. {2400, { 1.2, -4.3, 680, -42.6, 606, -51.6, 1.2, -4.3}},
  229. {2500, { 1.3, -5.6, 663, -43.2, 588, -52.3, 1.3, -5.6}},
  230. {2600, { 1.6, -6.2, 656, -43.4, 581, -52.7, 1.6, -6.2}},
  231. {2700, { 1.7, -6.6, 640, -43.9, 564, -53.3, 1.7, -6.6}},
  232. {2800, { 1.8, -7.0, 624, -44.3, 548, -53.9, 1.8, -7.0}},
  233. {2900, { 1.9, -7.5, 609, -44.7, 533, -54.4, 1.9, -7.5}},
  234. {3000, { 2.0, -8.0, 594, -45.0, 518, -54.8, 2.0, -8.0}},
  235. {3100, { 2.2, -8.6, 580, -45.3, 504, -55.3, 2.2, -8.6}},
  236. {3200, { 2.3, -9.2, 566, -45.6, 490, -55.7, 2.3, -9.2}},
  237. {3300, { 2.4, -9.9, 553, -45.8, 477, -56.0, 2.4, -9.9}},
  238. {3400, { 2.6, -10.7, 540, -46.0, 465, -56.3, 2.6, -10.7}},
  239. {3500, { 2.7, -11.4, 529, -46.2, 454, -56.6, 2.7, -11.4}},
  240. {3600, { 2.8, -12.3, 517, -46.3, 443, -56.9, 2.8, -12.3}},
  241. {3700, { 3.0, -13.1, 507, -46.4, 432, -57.1, 3.0, -13.1}},
  242. {3800, { 3.1, -14.0, 497, -46.5, 422, -57.3, 3.1, -14.0}},
  243. {3900, { 3.2, -14.9, 487, -46.6, 413, -57.5, 3.2, -14.9}},
  244. {4000, { 3.3, -15.9, 478, -46.6, 404, -57.7, 3.3, -15.9}}
  245. };
  246. /* V.56bis EIA LL-4, non-loaded loop */
  247. struct
  248. {
  249. int freq;
  250. float ad[8];
  251. } eia_ll4[] =
  252. {
  253. { 200, {-0.8, 31.0, 1564, -10.7, 1564, -10.7, -0.8, 31.0}},
  254. { 300, {-0.8, 32.6, 1520, -15.6, 1520, -15.6, -0.8, 32.6}},
  255. { 400, {-0.8, 29.8, 1447, -20.5, 1447, -20.5, -0.8, 29.8}},
  256. { 500, {-0.6, 29.7, 1402, -24.3, 1402, -24.3, -0.6, 29.7}},
  257. { 600, {-0.5, 24.9, 1328, -28.1, 1328, -28.1, -0.5, 24.9}},
  258. { 700, {-0.4, 24.8, 1270, -31.2, 1270, -31.2, -0.4, 24.8}},
  259. { 800, {-0.3, 22.7, 1200, -34.0, 1200, -34.0, -0.3, 22.7}},
  260. { 900, {-0.1, 19.8, 1148, -36.2, 1148, -36.2, -0.1, 19.8}},
  261. {1000, { 6.1, 19.3, 1086, -38.3, 1086, -38.3, 6.1, 19.3}},
  262. {1100, { 0.1, 17.5, 1027, -40.1, 1027, -40.1, 0.1, 17.5}},
  263. {1200, { 0.3, 14.3, 974, -41.6, 974, -41.6, 0.3, 14.3}},
  264. {1300, { 0.5, 10.9, 941, -42.6, 941, -42.6, 0.5, 10.9}},
  265. {1400, { 0.7, 9.6, 897, -43.7, 897, -43.7, 0.7, 9.6}},
  266. {1500, { 0.9, 7.7, 856, -44.6, 856, -44.6, 0.9, 7.7}},
  267. {1600, { 1.1, 5.3, 818, -45.3, 818, -45.3, 1.1, 5.3}},
  268. {1700, { 1.3, 2.4, 784, -45.9, 784, -45.9, 1.3, 2.4}},
  269. {1800, { 1.4, 69.1, 761, -46.3, 761, -46.3, 1.4, 69.1}},
  270. {1900, { 1.7, -1.3, 732, -46.6, 732, -46.6, 1.7, -1.3}},
  271. {2000, { 1.9, -2.7, 706, -46.9, 706, -46.9, 1.9, -2.7}},
  272. {2100, { 2.1, -4.3, 682, -47.1, 682, -47.1, 2.1, -4.3}},
  273. {2200, { 2.3, -6.0, 659, -47.3, 659, -47.3, 2.3, -6.0}},
  274. {2300, { 2.5, -7.9, 638, -47.4, 638, -47.4, 2.5, -7.9}},
  275. {2400, { 2.7, -9.9, 619, -47.4, 619, -47.4, 2.7, -9.9}},
  276. {2500, { 2.9, -12.0, 602, -47.5, 602, -47.5, 2.9, -12.0}},
  277. {2600, { 3.1, -13.0, 596, -47.4, 596, -47.4, 3.1, -13.0}},
  278. {2700, { 3.3, -13.9, 580, -47.4, 580, -47.4, 3.3, -13.9}},
  279. {2800, { 3.5, -14.8, 566, -47.3, 566, -47.3, 3.5, -14.8}},
  280. {2900, { 3.7, -15.7, 552, -47.2, 552, -47.2, 3.7, -15.7}},
  281. {3000, { 3.9, -16.7, 539, -47.1, 539, -47.1, 3.9, -16.7}},
  282. {3100, { 4.1, -17.7, 526, -47.0, 526, -47.0, 4.1, -17.7}},
  283. {3200, { 4.3, -18.7, 515, -46.8, 515, -46.8, 4.3, -18.7}},
  284. {3300, { 4.5, -19.8, 504, -46.7, 504, -46.7, 4.5, -19.8}},
  285. {3400, { 4.7, -20.8, 493, -46.5, 493, -46.5, 4.7, -20.8}},
  286. {3500, { 4.9, -21.8, 484, -46.4, 484, -46.4, 4.9, -21.8}},
  287. {3600, { 5.1, -22.9, 475, -46.2, 475, -46.2, 5.1, -22.9}},
  288. {3700, { 5.3, -23.9, 466, -46.0, 466, -46.0, 5.3, -23.9}},
  289. {3800, { 5.5, -25.0, 458, -45.9, 458, -45.9, 5.5, -25.0}},
  290. {3900, { 5.6, -26.1, 451, -45.7, 451, -45.7, 5.6, -26.1}},
  291. {4000, { 5.8, -27.2, 444, -45.5, 444, -45.5, 5.8, -27.2}}
  292. };
  293. /* V.56bis EIA LL-5, non-loaded loop */
  294. struct
  295. {
  296. int freq;
  297. float ad[8];
  298. } eia_ll5[] =
  299. {
  300. { 200, {-1.4, 55.8, 1607, -12.7, 1574, -17.4, -1.4, 55.8}},
  301. { 300, {-1.3, 57.2, 1541, -18.3, 1478, -24.8, -1.3, 57.2}},
  302. { 400, {-1.2, 52.2, 1443, -23.6, 1350, -31.5, -1.2, 52.2}},
  303. { 500, {-1.0, 51.0, 1379, -27.5, 1261, -36.4, -1.0, 51.0}},
  304. { 600, {-0.9, 43.2, 1287, -31.2, 1150, -40.7, -0.9, 43.2}},
  305. { 700, {-0.7, 41.8, 1216, -34.0, 1066, -44.0, -0.7, 41.8}},
  306. { 800, {-0.5, 37.4, 1137, -36.5, 979, -46.9, -0.5, 37.4}},
  307. { 900, {-0.2, 32.4, 1080, -38.3, 915, -48.9, -0.2, 32.4}},
  308. {1000, { 7.0, 30.5, 1015, -39.8, 848, -50.7, 7.0, 30.5}},
  309. {1100, { 0.3, 26.8, 956, -41.1, 788, -52.2, 0.3, 26.8}},
  310. {1200, { 0.5, 21.5, 904, -42.1, 736, -53.3, 0.5, 21.5}},
  311. {1300, { 0.8, 16.6, 873, -42.7, 703, -54.1, 0.8, 16.6}},
  312. {1400, { 1.0, 14.1, 832, -43.2, 663, -54.8, 1.0, 14.1}},
  313. {1500, { 1.3, 10.9, 795, -43.7, 627, -55.3, 1.3, 10.9}},
  314. {1600, { 1.6, 7.3, 762, -44.0, 595, -55.7, 1.6, 7.3}},
  315. {1700, { 1.9, 3.2, 733, -44.2, 567, -56.0, 1.9, 3.2}},
  316. {1800, { 2.2, 81.5, 713, -44.3, 547, -56.2, 2.2, 81.5}},
  317. {1900, { 2.4, -1.9, 689, -44.4, 524, -56.4, 2.4, -1.9}},
  318. {2000, { 2.7, -3.9, 667, -44.4, 503, -56.5, 2.7, -3.9}},
  319. {2100, { 3.0, -6.1, 646, -44.4, 485, -56.5, 3.0, -6.1}},
  320. {2200, { 3.3, -8.3, 628, -44.4, 466, -56.5, 3.3, -8.3}},
  321. {2300, { 3.6, -10.7, 610, -44.3, 450, -56.5, 3.6, -10.7}},
  322. {2400, { 3.8, -13.1, 595, -44.2, 436, -56.4, 3.8, -13.1}},
  323. {2500, { 4.1, -15.5, 581, -44.1, 422, -56.3, 4.1, -15.5}},
  324. {2600, { 4.3, -16.7, 577, -44.0, 417, -56.2, 4.3, -16.7}},
  325. {2700, { 4.6, -17.7, 565, -43.9, 406, -56.1, 4.6, -17.7}},
  326. {2800, { 4.8, -18.8, 553, -43.8, 395, -56.0, 4.8, -18.8}},
  327. {2900, { 5.1, -19.9, 542, -43.7, 395, -55.9, 5.1, -19.9}},
  328. {3000, { 5.4, -21.0, 531, -43.6, 375, -55.7, 5.4, -21.0}},
  329. {3100, { 5.6, -22.1, 521, -43.5, 366, -55.6, 5.6, -22.1}},
  330. {3200, { 5.9, -23.2, 511, -43.4, 357, -55.4, 5.9, -23.2}},
  331. {3300, { 6.1, -24.3, 502, -43.3, 349, -55.3, 6.1, -24.3}},
  332. {3400, { 6.4, -25.4, 494, -43.2, 341, -55.1, 6.4, -25.4}},
  333. {3500, { 6.6, -26.5, 486, -43.1, 334, -55.0, 6.6, -26.5}},
  334. {3600, { 6.9, -27.6, 478, -43.0, 327, -54.8, 6.9, -27.6}},
  335. {3700, { 7.1, -28.7, 471, -42.9, 321, -54.7, 7.1, -28.7}},
  336. {3800, { 7.3, -29.9, 464, -42.8, 315, -54.6, 7.3, -29.9}},
  337. {3900, { 7.5, -31.0, 458, -42.7, 310, -54.4, 7.5, -31.0}},
  338. {4000, { 7.8, -32.1, 452, -42.7, 304, -54.3, 7.8, -32.1}}
  339. };
  340. /* V.56bis EIA LL-6, non-loaded loop */
  341. struct
  342. {
  343. int freq;
  344. float ad[8];
  345. } eia_ll6[] =
  346. {
  347. { 200, {-0.2, -39.3, 1756, -12.0, 1748, -19.8, -0.2, -39.3}},
  348. { 300, {-0.2, -31.7, 1642, -15.9, 1689, -26.9, -0.2, -31.7}},
  349. { 400, {-0.2, -37.5, 1506, -18.4, 1427, -33.4, -0.2, -37.5}},
  350. { 500, {-0.1, -34.7, 1442, -19.5, 1301, -37.7, -0.1, -34.7}},
  351. { 600, {-0.1, -46.0, 1363, -20.1, 1153, -40.7, -0.1, -46.0}},
  352. { 700, { 0.0, -40.8, 1320, -20.7, 1045, -42.2, 0.0, -40.8}},
  353. { 800, { 0.0, -40.1, 1269, -21.5, 943, -42.3, 0.0, -40.1}},
  354. { 900, { 0.0, -40.6, 1227, -22.5, 878, -41.3, 0.0, -40.6}},
  355. {1000, { 6.6, -28.0, 1161, -23.4, 825, -39.3, 6.6, -28.0}},
  356. {1100, { 0.0, -16.5, 1082, -23.5, 797, -36.8, 0.0, -16.5}},
  357. {1200, {-0.1, 0.3, 1000, -22.2, 798, -34.4, -0.1, 0.3}},
  358. {1300, { 0.0, -2.3, 943, -19.3, 826, -33.2, 0.0, -2.3}},
  359. {1400, { 0.0, 13.5, 896, -14.0, 870, -33.8, 0.0, 13.5}},
  360. {1500, { 0.1, 22.6, 890, -7.2, 916, -36.8, 0.1, 22.6}},
  361. {1600, { 0.3, 30.3, 940, -0.3, 938, -42.0, 0.3, 30.3}},
  362. {1700, { 0.5, 12.5, 1052, 4.6, 929, -48.0, 0.5, 12.5}},
  363. {1800, { 0.8, 458.6, 1212, 6.9, 880, -52.8, 0.8, 458.6}},
  364. {1900, { 1.1, -5.1, 1410, 3.5, 814, -56.5, 1.1, -5.1}},
  365. {2000, { 1.4, -5.0, 1579, -3.6, 747, -58.5, 1.4, -5.0}},
  366. {2100, { 1.5, 6.1, 1618, -13.2, 688, -58.8, 1.5, 6.1}},
  367. {2200, { 1.5, 33.5, 1491, -21.5, 646, -57.7, 1.5, 33.5}},
  368. {2300, { 1.4, 80.5, 1275, -24.9, 625, -55.6, 1.4, 80.5}},
  369. {2400, { 1.3, 142.3, 1078, -20.8, 633, -53.8, 1.3, 142.3}},
  370. {2500, { 1.4, 196.5, 985, -9.3, 664, -54.5, 1.4, 196.5}},
  371. {2600, { 1.6, 214.5, 1045, 2.4, 692, -57.6, 1.6, 214.5}},
  372. {2700, { 2.4, 196.8, 1326, 13.7, 684, -63.5, 2.4, 196.8}},
  373. {2800, { 3.4, 150.4, 1887, 14.7, 637, -68.3, 3.4, 150.4}},
  374. {2900, { 4.3, 125.3, 2608, 1.3, 501, -70.7, 4.3, 125.3}},
  375. {3000, { 4.9, 174.6, 2730, -21.8, 533, -70.6, 4.9, 174.6}},
  376. {3100, { 4.9, 380.0, 2094, -33.7, 506, -68.5, 4.9, 380.0}},
  377. {3200, { 5.2, 759.3, 1642, -21.3, 522, -67.0, 5.2, 759.3}},
  378. {3300, { 8.0, 680.1, 2348, 0.5, 531, -72.9, 8.0, 680.1}},
  379. {3400, {13.1, 237.8, 4510, -20.9, 482, -77.3, 13.1, 237.8}},
  380. {3500, {18.2, -18.8, 4116, -59.6, 439, -78.0, 18.2, -18.8}},
  381. {3600, {22.7, -145.4, 3041, -74.4, 487, -77.7, 22.7, -145.4}},
  382. {3700, {26.8, -214.5, 2427, -80.1, 383, -77.1, 26.8, -214.5}},
  383. {3800, {30.4, -257.0, 2054, -82.7, 364, -76.4, 30.4, -257.0}},
  384. {3900, {33.7, -285.6, 1803, -84.2, 348, -75.0, 33.7, -285.6}},
  385. {4000, {36.8, -306.2, 1621, -85.1, 334, -75.7, 36.8, -306.2}}
  386. };
  387. /* V.56bis EIA LL-7, non-loaded loop */
  388. struct
  389. {
  390. int freq;
  391. float ad[8];
  392. } eia_ll7[] =
  393. {
  394. { 200, { 0.4, -81.3, 1848, -10.5, 1737, -15.6, 0.4, -81.3}},
  395. { 300, { 0.3, -68.9, 1785, -16.2, 1585, -21.6, 0.3, -68.9}},
  396. { 400, { 0.2, -68.1, 1646, -22.0, 1388, -25.8, 0.2, -68.1}},
  397. { 500, { 0.1, -57.0, 1528, -26.2, 1247, -27.7, 0.1, -57.0}},
  398. { 600, { 0.0, -59.8, 1349, -28.9, 1087, -27.3, 0.0, -59.8}},
  399. { 700, { 0.0, -45.0, 1205, -29.1, 975, -24.8, 0.0, -45.0}},
  400. { 800, {-0.1, -36.9, 1064, -26.8, 885, -19.7, -0.1, -36.9}},
  401. { 900, {-0.1, -37.1, 989, -22.6, 846, -13.5, -0.1, -37.1}},
  402. {1000, { 5.9, -29.2, 944, -16.6, 847, -6.1, 5.9, -29.2}},
  403. {1100, { 0.1, -30.8, 951, -10.5, 900, 0.3, 0.1, -30.8}},
  404. {1200, { 0.2, -40.7, 1008, -5.9, 999, 4.9, 0.2, -40.7}},
  405. {1300, { 0.4, -53.3, 1897, -4.0, 1122, 4.6, 0.4, -53.3}},
  406. {1400, { 0.5, -52.7, 1197, -4.8, 1253, 1.9, 0.5, -52.7}},
  407. {1500, { 0.6, -48.3, 1269, -8.4, 1339, -3.8, 0.6, -48.3}},
  408. {1600, { 0.6, -38.0, 1274, -13.2, 1337, -10.4, 0.6, -38.0}},
  409. {1700, { 0.5, -21.6, 1208, -16.9, 1250, -15.2, 0.5, -21.6}},
  410. {1800, { 0.4, 539.7, 1119, -17.8, 1143, -16.6, 0.4, 539.7}},
  411. {1900, { 0.3, 35.4, 1027, -14.7, 1036, -13.7, 0.3, 35.4}},
  412. {2000, { 0.3, 64.1, 989, -7.9, 998, -6.9, 0.3, 64.1}},
  413. {2100, { 0.4, 76.1, 1045, 0.1, 1040, 1.0, 0.4, 76.1}},
  414. {2200, { 0.6, 69.8, 1210, 5.3, 1197, 6.9, 0.6, 69.8}},
  415. {2300, { 1.0, 55.9, 1460, 4.6, 1430, 5.4, 1.0, 55.9}},
  416. {2400, { 1.2, 51.3, 1692, -2.8, 1640, -1.7, 1.2, 51.3}},
  417. {2500, { 1.3, 72.6, 1730, -13.4, 1666, -11.5, 1.3, 72.6}},
  418. {2600, { 1.3, 117.1, 1613, -49.6, 1556, -16.9, 1.3, 117.1}},
  419. {2700, { 1.1, 222.5, 1371, -19.5, 1334, -16.1, 1.1, 222.5}},
  420. {2800, { 1.1, 332.3, 1258, -8.9, 1243, -5.1, 1.1, 332.3}},
  421. {2900, { 1.7, 356.1, 1474, 4.8, 1480, 8.4, 1.7, 356.1}},
  422. {3000, { 2.8, 299.9, 2128, 6.6, 2143, 9.8, 2.8, 299.9}},
  423. {3100, { 3.9, 309.4, 2813, -10.5, 2882, -7.1, 3.9, 309.4}},
  424. {3200, { 4.4, 576.4, 2490, -27.7, 2487, -22.2, 4.4, 576.4}},
  425. {3300, { 5.6, 1030.6, 2237, -17.4, 2385, -9.0, 5.6, 1030.6}},
  426. {3400, {10.7, 570.2, 3882, -19.2, 4855, -14.9, 10.7, 570.2}},
  427. {3500, {17.3, 83.5, 4116, -57.4, 4649, -63.5, 17.3, 83.5}},
  428. {3600, {23.2, -130.6, 3057, -74.0, 3175, -78.6, 23.2, -130.6}},
  429. {3700, {28.3, -153.9, 2432, -80.0, 2471, -83.1, 28.3, -153.9}},
  430. {3800, {32.8, -292.4, 2055, -82.8, 2072, -85.1, 32.8, -292.4}},
  431. {3900, {36.9, -249.9, 1803, -84.2, 1811, -86.1, 36.9, -249.9}},
  432. {4000, {40.7, -356.2, 1621, -85.1, 1625, -86.7, 40.7, -356.2}}
  433. };
  434. /* V.56bis ETSI LL-1, non-loaded loop */
  435. struct
  436. {
  437. int freq;
  438. float ad[8];
  439. } etsi_ll1[] =
  440. {
  441. { 200, {-0.78, 14.0, 1248.5, -9.7, 1248.5, -9.7, -0.78, 14.0}},
  442. { 300, {-0.74, 10.0, 1220.9, -14.3, 1220.9, -14.3, -0.74, 10.0}},
  443. { 400, {-0.68, 8.0, 1185.2, -18.6, 1185.2, -18.6, -0.68, 8.0}},
  444. { 500, {-0.60, 7.0, 1143.9, -22.6, 1143.9, -22.6, -0.60, 7.0}},
  445. { 600, {-0.51, 6.0, 1099.0, -26.2, 1099.0, -26.2, -0.51, 6.0}},
  446. { 700, {-0.40, 5.6, 1052.5, -29.5, 1052.5, -29.5, -0.40, 5.6}},
  447. { 800, {-0.28, 5.3, 1005.9, -32.4, 1005.9, -32.4, -0.28, 5.3}},
  448. { 900, {-0.14, 5.0, 960.3, -35.0, 960.3, -35.0, -0.14, 5.0}},
  449. {1000, { 4.7, 4.6, 916.4, -37.3, 916.4, -37.3, 4.7, 4.6}},
  450. {1100, { 0.16, 4.3, 874.6, -39.3, 874.6, -39.3, 0.16, 4.3}},
  451. {1200, { 0.33, 3.6, 835.3, -41.1, 835.3, -41.1, 0.33, 3.6}},
  452. {1300, { 0.49, 2.6, 798.5, -42.6, 798.5, -42.6, 0.49, 2.6}},
  453. {1400, { 0.67, 2.0, 764.2, -43.9, 764.2, -43.9, 0.67, 2.0}},
  454. {1500, { 0.85, 1.0, 732.3, -45.1, 732.3, -45.1, 0.85, 1.0}},
  455. {1600, { 1.04, 0.6, 702.7, -46.1, 702.7, -46.1, 1.04, 0.6}},
  456. {1700, { 1.23, 0.3, 675.3, -47.0, 675.3, -47.0, 1.23, 0.3}},
  457. {1800, { 1.43, 40.0, 649.8, -47.7, 649.8, -47.7, 1.43, 40.0}},
  458. {1900, { 1.63, -1.0, 626.2, -48.4, 626.2, -48.4, 1.63, -1.0}},
  459. {2000, { 1.83, -2.0, 604.3, -48.9, 604.3, -48.9, 1.83, -2.0}},
  460. {2100, { 2.03, -3.3, 584.0, -49.4, 584.0, -49.4, 2.03, -3.3}},
  461. {2200, { 2.23, -3.6, 565.1, -49.8, 565.1, -49.8, 2.23, -3.6}},
  462. {2300, { 2.44, -4.3, 547.5, -50.1, 547.5, -50.1, 2.44, -4.3}},
  463. {2400, { 2.64, -5.0, 531.1, -50.4, 531.1, -50.4, 2.64, -5.0}},
  464. {2500, { 2.84, -6.1, 515.9, -50.6, 515.9, -50.6, 2.84, -6.1}},
  465. {2600, { 3.05, -6.6, 501.6, -50.8, 501.6, -50.8, 3.05, -6.6}},
  466. {2700, { 3.25, -7.3, 488.2, -51.0, 488.2, -51.0, 3.25, -7.3}},
  467. {2800, { 3.45, -7.6, 475.7, -51.1, 475.7, -51.1, 3.45, -7.6}},
  468. {2900, { 3.65, -8.3, 464.0, -51.1, 464.0, -51.1, 3.65, -8.3}},
  469. {3000, { 3.85, -8.6, 453.0, -51.2, 453.0, -51.2, 3.85, -8.6}},
  470. {3100, { 4.04, -9.3, 442.6, -51.2, 442.6, -51.2, 4.04, -9.3}},
  471. {3200, { 4.24, -10.3, 432.9, -51.2, 432.9, -51.2, 4.24, -10.3}},
  472. {3300, { 4.43, -10.6, 423.7, -51.2, 423.7, -51.2, 4.43, -10.6}},
  473. {3400, { 4.62, -11.3, 415.1, -51.2, 415.1, -51.2, 4.62, -11.3}},
  474. {3500, { 4.81, -11.6, 406.9, -51.1, 406.9, -51.1, 4.81, -11.6}},
  475. {3600, { 5.00, -12.3, 399.1, -51.1, 399.1, -51.1, 5.00, -12.3}},
  476. {3700, { 5.19, -13.0, 391.8, -51.0, 391.8, -51.0, 5.19, -13.0}},
  477. {3800, { 5.37, -13.4, 384.9, -51.0, 384.9, -51.0, 5.37, -13.4}},
  478. {3900, { 5.56, -13.8, 378.3, -50.9, 378.3, -50.9, 5.56, -13.8}},
  479. {4000, { 5.74, -14.4, 372.0, -50.8, 372.0, -50.8, 5.74, -14.4}}
  480. };
  481. /* V.56bis ETSI LL-2, non-loaded loop */
  482. struct
  483. {
  484. int freq;
  485. float ad[8];
  486. } etsi_ll2[] =
  487. {
  488. { 200, {-0.10, 15.0, 850.3, -3.4, 850.3, -3.4, -0.10, 15.0}},
  489. { 300, {-0.09, 8.0, 848.1, -5.1, 848.1, -5.1, -0.09, 8.0}},
  490. { 400, {-0.09, 7.0, 845.1, -6.7, 845.1, -6.7, -0.09, 7.0}},
  491. { 500, {-0.08, 5.0, 841.3, -8.4, 841.3, -8.4, -0.08, 5.0}},
  492. { 600, {-0.07, 4.6, 836.7, -10.0, 836.7, -10.0, -0.07, 4.6}},
  493. { 700, {-0.06, 4.3, 831.3, -11.6, 831.3, -11.6, -0.06, 4.3}},
  494. { 800, {-0.04, 3.8, 825.3, -13.2, 825.3, -13.2, -0.04, 3.8}},
  495. { 900, {-0.02, 3.4, 818.6, -14.8, 818.6, -14.8, -0.02, 3.4}},
  496. {1000, { 1.80, 3.0, 811.4, -16.3, 811.4, -16.3, 1.8, 3.0}},
  497. {1100, { 0.02, 2.6, 803.6, -17.8, 803.6, -17.8, 0.02, 2.6}},
  498. {1200, { 0.04, 2.3, 795.3, -19.3, 795.3, -19.3, 0.04, 2.3}},
  499. {1300, { 0.06, 1.3, 786.6, -20.7, 786.6, -20.7, 0.06, 1.3}},
  500. {1400, { 0.09, 0.9, 777.5, -22.1, 777.5, -22.1, 0.09, 0.9}},
  501. {1500, { 0.12, 0.6, 768.1, -23.5, 768.1, -23.5, 0.12, 0.6}},
  502. {1600, { 0.15, 0.3, 758.4, -24.8, 758.4, -24.8, 0.15, 0.3}},
  503. {1700, { 0.18, 0.0, 748.4, -26.1, 748.4, -26.1, 0.18, 0.0}},
  504. {1800, { 0.21, 15, 738.4, -27.3, 738.4, -27.3, 0.21, 15.0}},
  505. {1900, { 0.24, -1.0, 728.1, -28.5, 728.1, -28.5, 0.24, -1.0}},
  506. {2000, { 0.28, -2.3, 717.8, -29.7, 717.8, -29.7, 0.28, -2.3}},
  507. {2100, { 0.32, -2.6, 707.4, -30.8, 707.4, -30.8, 0.32, -2.6}},
  508. {2200, { 0.36, -3.0, 697.0, -31.9, 697.0, -31.9, 0.36, -3.0}},
  509. {2300, { 0.40, -3.3, 686.6, -33.0, 686.6, -33.0, 0.40, -3.3}},
  510. {2400, { 0.44, -3.6, 676.2, -34.0, 676.2, -34.0, 0.44, -3.6}},
  511. {2500, { 0.48, -4.5, 665.9, -35.0, 665.9, -35.0, 0.48, -4.5}},
  512. {2600, { 0.53, -5.4, 655.6, -35.9, 655.6, -35.9, 0.53, -5.4}},
  513. {2700, { 0.57, -6.3, 645.5, -36.8, 645.5, -36.8, 0.57, -6.3}},
  514. {2800, { 0.62, -6.6, 635.5, -37.7, 635.5, -37.7, 0.62, -6.6}},
  515. {2900, { 0.67, -6.9, 625.6, -38.6, 625.6, -38.6, 0.67, -6.9}},
  516. {3000, { 0.72, -7.5, 615.8, -39.4, 615.8, -39.4, 0.72, -7.5}},
  517. {3100, { 0.77, -8.3, 606.2, -40.2, 606.2, -40.2, 0.77, -8.3}},
  518. {3200, { 0.82, -8.6, 596.7, -40.9, 596.7, -40.9, 0.82, -8.6}},
  519. {3300, { 0.87, -9.3, 587.4, -41.6, 587.4, -41.6, 0.87, -9.3}},
  520. {3400, { 0.92, -9.6, 578.3, -42.3, 578.3, -42.3, 0.92, -9.6}},
  521. {3500, { 0.98, -10.3, 569.3, -43.0, 569.3, -43.0, 0.98, -10.3}},
  522. {3600, { 1.03, -10.6, 560.6, -43.7, 560.6, -43.7, 1.03, -10.6}},
  523. {3700, { 1.09, -11.3, 552.0, -44.3, 552.0, -44.3, 1.09, -11.3}},
  524. {3800, { 1.14, -11.6, 543.5, -44.9, 543.5, -44.9, 1.14, -11.6}},
  525. {3900, { 1.20, -12.3, 535.3, -45.4, 535.3, -45.4, 1.20, -12.3}},
  526. {4000, { 1.26, -13.3, 527.2, -46.0, 527.2, -46.0, 1.26, -13.3}}
  527. };
  528. /* V.56bis AD-1 AD-5 AD-6 AD-7 AD-8 AD-9 */
  529. struct
  530. {
  531. int freq;
  532. float ad[6];
  533. } ad[] =
  534. {
  535. { 0, {90.0, 90.0, 90.0, 90.0, 90.0, 90.0}},
  536. { 200, { 6.0, 3.2, 3.0, 2.9, 11.6, 23.3}},
  537. { 300, { 1.3, 1.4, 1.2, 1.1, 6.9, 13.9}},
  538. { 400, { 0.0, 0.4, 0.3, 0.3, 4.0, 7.9}},
  539. { 500, { 0.0, -0.1, 0.0, 0.1, 2.0, 4.1}},
  540. { 600, { 0.0, -0.1, 0.0, 0.1, 1.2, 2.4}},
  541. { 700, { 0.0, 0.1, 0.0, 0.0, 0.8, 1.7}},
  542. { 800, { 0.0, 0.0, 0.0, -0.1, 0.5, 1.1}},
  543. { 900, { 0.0, 0.0, 0.0, -0.1, 0.2, 0.4}},
  544. {1000, { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}},
  545. {1100, { 0.0, 0.0, 0.1, 0.0, -0.1, -0.2}},
  546. {1200, { 0.0, 0.0, 0.1, 0.1, -0.1, -0.2}},
  547. {1300, { 0.0, 0.1, 0.2, 0.3, -0.1, -0.2}},
  548. {1400, { 0.0, 0.2, 0.3, 0.4, -0.1, -0.3}},
  549. {1500, { 0.0, 0.2, 0.3, 0.4, -0.2, -0.4}},
  550. {1600, { 0.0, 0.3, 0.5, 0.5, -0.1, -0.3}},
  551. {1700, { 0.0, 0.3, 0.5, 0.6, -0.1, -0.1}},
  552. {1800, { 0.0, 0.3, 0.5, 0.6, 0.0, 0.0}},
  553. {1900, { 0.0, 0.4, 0.7, 0.7, 0.1, 0.2}},
  554. {2000, { 0.0, 0.5, 0.8, 0.9, 0.2, 0.5}},
  555. {2100, { 0.1, 0.6, 1.0, 1.0, 0.5, 0.9}},
  556. {2200, { 0.2, 0.7, 1.1, 1.1, 0.6, 1.1}},
  557. {2300, { 0.3, 0.9, 1.2, 1.4, 0.8, 1.5}},
  558. {2400, { 0.4, 1.1, 1.5, 1.6, 0.9, 1.8}},
  559. {2500, { 0.5, 1.3, 1.8, 2.0, 1.1, 2.3}},
  560. {2600, { 0.6, 1.6, 2.4, 2.7, 1.4, 2.8}},
  561. {2700, { 0.7, 2.0, 3.0, 3.5, 1.7, 3.4}},
  562. {2800, { 0.7, 2.3, 3.5, 4.3, 2.0, 4.0}},
  563. {2900, { 0.9, 2.8, 4.2, 5.0, 2.4, 4.9}},
  564. {3000, { 1.1, 3.2, 4.9, 5.8, 3.0, 5.9}},
  565. {3100, { 1.2, 3.5, 5.6, 6.7, 3.4, 6.8}},
  566. {3200, { 1.3, 4.1, 6.7, 8.0, 3.9, 7.7}},
  567. {3300, { 1.6, 4.8, 8.0, 9.6, 4.6, 9.2}},
  568. {3400, { 1.8, 5.3, 9.1, 11.0, 5.4, 10.7}},
  569. {3500, { 2.4, 5.7, 10.3, 12.2, 6.3, 12.6}},
  570. {3600, { 3.0, 6.6, 12.1, 13.9, 7.8, 15.5}},
  571. {3700, { 5.7, 8.9, 15.8, 17.3, 10.3, 20.5}},
  572. {3800, {13.5, 15.7, 24.4, 25.7, 16.2, 32.4}},
  573. {3900, {31.2, 31.1, 42.2, 43.3, 29.9, 59.9}},
  574. {4000, {31.2, 31.1, 42.2, 43.3, 29.9, 59.9}}
  575. };
  576. /* V.56bis EDD-1 EDD-2 EDD-3 */
  577. struct
  578. {
  579. int freq;
  580. float edd[3];
  581. } edd[] =
  582. {
  583. { 0, {3.98, 3.76, 8.00}},
  584. { 200, {3.98, 3.76, 8.00}},
  585. { 300, {2.70, 3.76, 8.00}},
  586. { 400, {1.69, 2.20, 6.90}},
  587. { 500, {1.15, 1.36, 5.50}},
  588. { 600, {0.80, 0.91, 4.40}},
  589. { 700, {0.60, 0.64, 3.40}},
  590. { 800, {0.50, 0.46, 2.80}},
  591. { 900, {0.40, 0.34, 2.00}},
  592. {1000, {0.30, 0.24, 1.50}},
  593. {1100, {0.20, 0.16, 1.00}},
  594. {1200, {0.20, 0.11, 0.70}},
  595. {1300, {0.10, 0.07, 0.40}},
  596. {1400, {0.05, 0.05, 0.30}},
  597. {1500, {0.00, 0.03, 0.20}},
  598. {1600, {0.00, 0.01, 0.10}},
  599. {1700, {0.00, 0.00, 0.10}},
  600. {1800, {0.00, 0.00, 0.00}},
  601. {1900, {0.00, 0.02, 0.10}},
  602. {2000, {0.00, 0.04, 0.10}},
  603. {2100, {0.02, 0.08, 0.10}},
  604. {2200, {0.02, 0.12, 0.20}},
  605. {2300, {0.02, 0.16, 0.20}},
  606. {2400, {0.02, 0.20, 0.30}},
  607. {2500, {0.10, 0.27, 0.40}},
  608. {2600, {0.12, 0.36, 0.50}},
  609. {2700, {0.15, 0.47, 0.80}},
  610. {2800, {0.20, 0.60, 1.10}},
  611. {2900, {0.27, 0.77, 1.50}},
  612. {3000, {0.40, 1.01, 2.00}},
  613. {3100, {0.56, 1.32, 2.60}},
  614. {3200, {0.83, 1.78, 3.20}},
  615. {3300, {1.07, 1.78, 4.00}},
  616. {3400, {1.39, 1.78, 4.00}},
  617. {3500, {1.39, 1.78, 4.00}},
  618. {3600, {1.39, 1.78, 4.00}},
  619. {3700, {1.39, 1.78, 4.00}},
  620. {3800, {1.39, 1.78, 4.00}},
  621. {3900, {1.39, 1.78, 4.00}},
  622. {4000, {1.39, 1.78, 4.00}}
  623. };
  624. /* V.56bis PCM AD-1, AD-2, AD-3 */
  625. struct
  626. {
  627. int freq;
  628. float ad[3];
  629. } pcm_ad[] =
  630. {
  631. { 50, {41.4, 77.8, 114.2}},
  632. { 100, {15.5, 27.7, 39.9}},
  633. { 150, { 3.7, 6.1, 8.6}},
  634. { 200, { 0.5, 0.8, 1.0}},
  635. { 250, {-0.2, -0.2, -0.3}},
  636. { 300, {-0.2, -0.3, -0.4}},
  637. { 400, { 0.0, -0.2, -0.3}},
  638. { 500, {-0.2, -0.4, -0.5}},
  639. { 600, {-0.2, -0.3, -0.5}},
  640. { 700, {-0.2, -0.3, -0.5}},
  641. { 800, {-0.2, -0.4, -0.5}},
  642. { 900, {-0.2, -0.3, -0.4}},
  643. {1000, {-0.1, -0.2, -0.3}},
  644. {1100, {-0.2, -0.3, -0.3}},
  645. {1200, {-0.2, -0.3, -0.4}},
  646. {1300, {-0.2, -0.3, -0.5}},
  647. {1400, {-0.1, -0.3, -0.4}},
  648. {1500, {-0.1, -0.3, -0.4}},
  649. {1600, {-0.1, -0.2, -0.3}},
  650. {1700, {-0.1, -0.3, -0.4}},
  651. {1800, {-0.2, -0.3, -0.4}},
  652. {1900, {-0.2, -0.3, -0.3}},
  653. {2000, {-0.1, -0.2, -0.3}},
  654. {2100, {-0.1, -0.2, -0.3}},
  655. {2200, {-0.1, -0.3, -0.4}},
  656. {2300, {-0.1, -0.1, -0.2}},
  657. {2400, {-0.1, -0.1, -0.2}},
  658. {2500, { 0.0, -0.1, -0.1}},
  659. {2600, { 0.0, -0.1, -0.1}},
  660. {2700, { 0.0, 0.0, 0.1}},
  661. {2800, { 0.0, 0.0, 0.1}},
  662. {2900, { 0.1, 0.2, 0.2}},
  663. {3000, { 0.0, 0.0, 0.1}},
  664. {3100, { 0.0, 0.0, 0.0}},
  665. {3200, { 0.0, 0.0, 0.1}},
  666. {3300, { 0.3, 0.7, 1.0}},
  667. {3400, { 1.2, 2.4, 3.6}},
  668. {3500, { 3.2, 6.3, 9.5}},
  669. {3550, { 5.0, 9.6, 14.3}},
  670. {3600, { 7.0, 13.5, 19.9}},
  671. {3650, {10.0, 18.7, 27.5}},
  672. {3700, {13.4, 24.6, 35.8}},
  673. {3750, {18.1, 32.1, 46.2}},
  674. {3800, {24.3, 41.2, 58.2}},
  675. {3850, {32.5, 52.6, 72.7}},
  676. {3900, {43.4, 66.6, 89.8}},
  677. {4000, {43.4, 66.6, 89.8}}
  678. };
  679. /* V.56bis PCM EDD-1, EDD-2, EDD-3 */
  680. struct
  681. {
  682. int freq;
  683. float edd[3];
  684. } pcm_edd[] =
  685. {
  686. { 150, { 2.76, 5.5, 8.3}},
  687. { 200, { 1.70, 3.4, 5.1}},
  688. { 250, { 0.92, 1.8, 2.8}},
  689. { 300, { 0.55, 1.1, 1.7}},
  690. { 400, { 0.25, 0.5, 0.7}},
  691. { 500, { 0.12, 0.2, 0.4}},
  692. { 600, { 0.06, 0.1, 0.2}},
  693. { 700, { 0.03, 0.1, 0.1}},
  694. { 800, { 0.01, 0.0, 0.0}},
  695. { 900, { 0.00, 0.0, 0.0}},
  696. {1000, {-0.01, 0.0, 0.0}},
  697. {1100, {-0.01, 0.0, 0.0}},
  698. {1200, {-0.02, 0.0, -0.1}},
  699. {1300, {-0.02, 0.0, -0.1}},
  700. {1400, {-0.01, 0.0, 0.0}},
  701. {1500, {-0.01, 0.0, 0.0}},
  702. {1600, { 0.00, 0.0, 0.0}},
  703. {1700, { 0.00, 0.0, 0.0}},
  704. {1800, { 0.01, 0.0, 0.0}},
  705. {1900, { 0.02, 0.0, 0.0}},
  706. {2000, { 0.02, 0.0, 0.1}},
  707. {2100, { 0.04, 0.1, 0.1}},
  708. {2200, { 0.05, 0.1, 0.2}},
  709. {2300, { 0.06, 0.1, 0.2}},
  710. {2400, { 0.07, 0.1, 0.2}},
  711. {2500, { 0.10, 0.2, 0.3}},
  712. {2600, { 0.11, 0.2, 0.3}},
  713. {2700, { 0.14, 0.3, 0.4}},
  714. {2800, { 0.18, 0.4, 0.5}},
  715. {2900, { 0.22, 0.4, 0.6}},
  716. {3000, { 0.27, 0.5, 0.8}},
  717. {3100, { 0.34, 0.7, 1.0}},
  718. {3200, { 0.45, 0.9, 1.4}},
  719. {3250, { 0.52, 1.0, 1.6}},
  720. {3300, { 0.60, 1.2, 1.8}},
  721. {3350, { 0.66, 1.3, 2.0}},
  722. {3400, { 0.74, 1.5, 2.2}},
  723. {3450, { 0.79, 1.6, 2.4}},
  724. {3500, { 0.83, 1.7, 2.5}},
  725. {3550, { 0.84, 1.7, 2.5}},
  726. {3600, { 0.81, 1.6, 2.4}},
  727. {3700, { 0.81, 1.6, 2.4}},
  728. {3800, { 0.81, 1.6, 2.4}},
  729. {3900, { 0.81, 1.6, 2.4}},
  730. {4000, { 0.81, 1.6, 2.4}}
  731. };
  732. FILE *outfile;
  733. float impulse_responses[100][LINE_FILTER_SIZE];
  734. int filter_sets = 0;
  735. static void generate_ad_edd(void)
  736. {
  737. float f;
  738. float offset;
  739. float amp;
  740. float phase;
  741. //float delay;
  742. float pw;
  743. #if defined(HAVE_FFTW3_H)
  744. double in[FFT_SIZE][2];
  745. double out[FFT_SIZE][2];
  746. #else
  747. fftw_complex in[FFT_SIZE];
  748. fftw_complex out[FFT_SIZE];
  749. #endif
  750. fftw_plan p;
  751. int i;
  752. int j;
  753. int k;
  754. int l;
  755. #if defined(HAVE_FFTW3_H)
  756. p = fftw_plan_dft_1d(FFT_SIZE, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
  757. #else
  758. p = fftw_create_plan(FFT_SIZE, FFTW_BACKWARD, FFTW_ESTIMATE);
  759. #endif
  760. for (j = 0; j < 6; j++)
  761. {
  762. for (k = 0; k < 3; k++)
  763. {
  764. for (i = 0; i < FFT_SIZE; i++)
  765. {
  766. #if defined(HAVE_FFTW3_H)
  767. in[i][0] =
  768. in[i][1] = 0.0f;
  769. #else
  770. in[i].re =
  771. in[i].im = 0.0f;
  772. #endif
  773. }
  774. for (i = 1; i < FFT_SIZE/2; i++)
  775. {
  776. f = (float) i*SAMPLE_RATE/FFT_SIZE;
  777. amp = 0.0f;
  778. for (l = 0; l < (int) (sizeof(ad)/sizeof(ad[0])); l++)
  779. {
  780. if (f < ad[l].freq)
  781. break;
  782. }
  783. if (l < (int) (sizeof(ad)/sizeof(ad[0])))
  784. {
  785. offset = (f - ad[l - 1].freq)/(ad[l].freq - ad[l - 1].freq);
  786. amp = (1.0 - offset)*ad[l - 1].ad[j] + offset*ad[l].ad[j];
  787. amp = pow(10.0, -amp/20.0);
  788. }
  789. //delay = 0.0f;
  790. for (l = 0; l < (int) (sizeof(edd)/sizeof(edd[0])); l++)
  791. {
  792. if (f < edd[l].freq)
  793. break;
  794. }
  795. if (l < (int) (sizeof(edd)/sizeof(edd[0])))
  796. {
  797. offset = (f - edd[l - 1].freq)/(edd[l].freq - edd[l - 1].freq);
  798. //delay = (1.0f - offset)*edd[l - 1].edd[k] + offset*edd[l].edd[k];
  799. }
  800. //phase = 2.0f*M_PI*f*delay*0.001f;
  801. phase = 0.0f;
  802. #if defined(HAVE_FFTW3_H)
  803. in[i][0] = amp*cosf(phase);
  804. in[i][1] = amp*sinf(phase);
  805. in[FFT_SIZE - i][0] = in[i][0];
  806. in[FFT_SIZE - i][1] = -in[i][1];
  807. #else
  808. in[i].re = amp*cosf(phase);
  809. in[i].im = amp*sinf(phase);
  810. in[FFT_SIZE - i].re = in[i].re;
  811. in[FFT_SIZE - i].im = -in[i].im;
  812. #endif
  813. }
  814. #if 0
  815. for (i = 0; i < FFT_SIZE; i++)
  816. fprintf(outfile, "%5d %15.5f,%15.5f\n", i, in[i].re, in[i].im);
  817. #endif
  818. #if defined(HAVE_FFTW3_H)
  819. fftw_execute(p);
  820. #else
  821. fftw_one(p, in, out);
  822. #endif
  823. fprintf(outfile, "/* V.56bis AD-%d, EDD%d */\n", (j == 0) ? 1 : j + 4, k + 1);
  824. fprintf(outfile, "const float ad_%d_edd_%d_model[] =\n", (j == 0) ? 1 : j + 4, k + 1);
  825. fprintf(outfile, "{\n");
  826. /* Normalise the filter's gain */
  827. pw = 0.0f;
  828. l = FFT_SIZE - (LINE_FILTER_SIZE - 1)/2;
  829. for (i = 0; i < LINE_FILTER_SIZE; i++)
  830. {
  831. #if defined(HAVE_FFTW3_H)
  832. pw += out[l][0]*out[l][0];
  833. #else
  834. pw += out[l].re*out[l].re;
  835. #endif
  836. if (++l == FFT_SIZE)
  837. l = 0;
  838. }
  839. pw = sqrt(pw);
  840. l = FFT_SIZE - (LINE_FILTER_SIZE - 1)/2;
  841. for (i = 0; i < LINE_FILTER_SIZE; i++)
  842. {
  843. #if defined(HAVE_FFTW3_H)
  844. impulse_responses[filter_sets][i] = out[l][0]/pw;
  845. #else
  846. impulse_responses[filter_sets][i] = out[l].re/pw;
  847. #endif
  848. fprintf(outfile, "%15.5f,\n", impulse_responses[filter_sets][i]);
  849. if (++l == FFT_SIZE)
  850. l = 0;
  851. }
  852. fprintf(outfile, "};\n\n");
  853. filter_sets++;
  854. }
  855. }
  856. }
  857. static void generate_proakis(void)
  858. {
  859. float f;
  860. float f1;
  861. float offset;
  862. float amp;
  863. float phase;
  864. //float delay;
  865. float pw;
  866. int index;
  867. int i;
  868. int l;
  869. #if defined(HAVE_FFTW3_H)
  870. double in[FFT_SIZE][2];
  871. double out[FFT_SIZE][2];
  872. #else
  873. fftw_complex in[FFT_SIZE];
  874. fftw_complex out[FFT_SIZE];
  875. #endif
  876. fftw_plan p;
  877. #if defined(HAVE_FFTW3_H)
  878. p = fftw_plan_dft_1d(FFT_SIZE, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
  879. #else
  880. p = fftw_create_plan(FFT_SIZE, FFTW_BACKWARD, FFTW_ESTIMATE);
  881. #endif
  882. for (i = 0; i < FFT_SIZE; i++)
  883. {
  884. #if defined(HAVE_FFTW3_H)
  885. in[i][0] =
  886. in[i][1] = 0.0f;
  887. #else
  888. in[i].re =
  889. in[i].im = 0.0f;
  890. #endif
  891. }
  892. for (i = 1; i < FFT_SIZE/2; i++)
  893. {
  894. f = (float) i*SAMPLE_RATE/FFT_SIZE;
  895. f1 = f/200.0f;
  896. offset = f1 - floor(f1);
  897. index = (int) floor(f1);
  898. /* Linear interpolation */
  899. amp = ((1.0f - offset)*proakis[index].amp + offset*proakis[index + 1].amp)/2.3f;
  900. //delay = (1.0f - offset)*proakis[index].delay + offset*proakis[index + 1].delay;
  901. //phase = 2.0f*M_PI*f*delay*0.001f;
  902. phase = 0.0f;
  903. #if defined(HAVE_FFTW3_H)
  904. in[i][0] = amp*cosf(phase);
  905. in[i][1] = amp*sinf(phase);
  906. in[FFT_SIZE - i][0] = in[i][0];
  907. in[FFT_SIZE - i][1] = -in[i][1];
  908. #else
  909. in[i].re = amp*cosf(phase);
  910. in[i].im = amp*sinf(phase);
  911. in[FFT_SIZE - i].re = in[i].re;
  912. in[FFT_SIZE - i].im = -in[i].im;
  913. #endif
  914. }
  915. #if defined(HAVE_FFTW3_H)
  916. fftw_execute(p);
  917. #else
  918. fftw_one(p, in, out);
  919. #endif
  920. fprintf(outfile, "/* Medium range telephone line response\n");
  921. fprintf(outfile, " (from p 537, Digital Communication, John G. Proakis */\n");
  922. fprintf(outfile, "const float proakis_line_model[] =\n");
  923. fprintf(outfile, "{\n");
  924. /* Normalise the filter's gain */
  925. pw = 0.0f;
  926. l = FFT_SIZE - (LINE_FILTER_SIZE - 1)/2;
  927. for (i = 0; i < LINE_FILTER_SIZE; i++)
  928. {
  929. #if defined(HAVE_FFTW3_H)
  930. pw += out[l][0]*out[l][0];
  931. #else
  932. pw += out[l].re*out[l].re;
  933. #endif
  934. if (++l == FFT_SIZE)
  935. l = 0;
  936. }
  937. pw = sqrt(pw);
  938. l = FFT_SIZE - (LINE_FILTER_SIZE - 1)/2;
  939. for (i = 0; i < LINE_FILTER_SIZE; i++)
  940. {
  941. #if defined(HAVE_FFTW3_H)
  942. impulse_responses[filter_sets][i] = out[l][0]/pw;
  943. #else
  944. impulse_responses[filter_sets][i] = out[l].re/pw;
  945. #endif
  946. fprintf(outfile, "%15.5f,\n", impulse_responses[filter_sets][i]);
  947. if (++l == FFT_SIZE)
  948. l = 0;
  949. }
  950. fprintf(outfile, "};\n\n");
  951. filter_sets++;
  952. }
  953. int main(int argc, char *argv[])
  954. {
  955. int i;
  956. int j;
  957. if ((outfile = fopen(LINE_MODEL_FILE_NAME, "w")) == NULL)
  958. {
  959. fprintf(stderr, "Failed to open %s\n", "line_model.txt");
  960. exit(2);
  961. }
  962. generate_proakis();
  963. generate_ad_edd();
  964. fclose(outfile);
  965. if (argc > 1)
  966. {
  967. for (i = 0; i < LINE_FILTER_SIZE; i++)
  968. {
  969. printf("%d, ", i);
  970. for (j = 0; j < filter_sets; j++)
  971. {
  972. printf("%15.5f, ", impulse_responses[j][i]);
  973. }
  974. printf("\n");
  975. }
  976. }
  977. return 0;
  978. }