You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
9.1 KiB

  1. /*
  2. * coax.cpp - coaxial class implementation
  3. *
  4. * Copyright (C) 2001 Gopal Narayanan <gopal@astro.umass.edu>
  5. * Copyright (C) 2002 Claudio Girardi <claudio.girardi@ieee.org>
  6. * Copyright (C) 2005, 2006 Stefan Jahn <stefan@lkcc.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or (at
  11. * your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this package; see the file COPYING. If not, write to
  20. * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  21. * Boston, MA 02110-1301, USA.
  22. *
  23. */
  24. /*
  25. * coax.c - Puts up window for microstrip and
  26. * performs the associated calculations
  27. */
  28. #include <cmath>
  29. #include <cstdio>
  30. #include <cstdlib>
  31. #include <cstring>
  32. #include "coax.h"
  33. #include "units.h"
  34. COAX::COAX() : TRANSLINE()
  35. {
  36. m_Name = "Coax";
  37. Init();
  38. }
  39. double COAX::alphad_coax()
  40. {
  41. double ad;
  42. ad = ( M_PI / C0 ) * m_parameters[FREQUENCY_PRM] * sqrt( m_parameters[EPSILONR_PRM] )
  43. * m_parameters[TAND_PRM];
  44. ad = ad * 20.0 / log( 10.0 );
  45. return ad;
  46. }
  47. double COAX::alphac_coax()
  48. {
  49. double ac, Rs;
  50. Rs = sqrt( M_PI * m_parameters[FREQUENCY_PRM] * m_parameters[MURC_PRM] * MU0
  51. / m_parameters[SIGMA_PRM] );
  52. ac = sqrt( m_parameters[EPSILONR_PRM] )
  53. * ( ( ( 1 / m_parameters[PHYS_DIAM_IN_PRM] ) + ( 1 / m_parameters[PHYS_DIAM_OUT_PRM] ) )
  54. / log( m_parameters[PHYS_DIAM_OUT_PRM] / m_parameters[PHYS_DIAM_IN_PRM] ) )
  55. * ( Rs / ZF0 );
  56. ac = ac * 20.0 / log( 10.0 );
  57. return ac;
  58. }
  59. /**
  60. * \f$ Z_0 = \frac{Z_{0_{\mathrm{vacuum}}}}{\sqrt{\epsilon_r}}\log_{10}\left( \frac{D_{\mathrm{out}}}{D_{\mathrm{in}}}\right) \f$
  61. *
  62. * \f$ \lambda_g = \frac{c}{f \cdot \sqrt{ \epsilon_r \cdot \mu_r}} \f$
  63. *
  64. * \f$ L_{[\mathrm{rad}]} = \frac{ 2\pi\cdot L_{[\mathrm{m}]}}{\lambda_g} \f$
  65. * */
  66. void COAX::calcAnalyze()
  67. {
  68. double lambda_g;
  69. m_parameters[Z0_PRM] =
  70. ( ZF0 / 2 / M_PI / sqrt( m_parameters[EPSILONR_PRM] ) )
  71. * log( m_parameters[PHYS_DIAM_OUT_PRM] / m_parameters[PHYS_DIAM_IN_PRM] );
  72. lambda_g = ( C0 / ( m_parameters[FREQUENCY_PRM] ) )
  73. / sqrt( m_parameters[EPSILONR_PRM] * m_parameters[MUR_PRM] );
  74. /* calculate electrical angle */
  75. m_parameters[ANG_L_PRM] =
  76. ( 2.0 * M_PI * m_parameters[PHYS_LEN_PRM] ) / lambda_g; /* in radians */
  77. }
  78. /**
  79. * \f$ D_{\mathrm{in}} = D_{\mathrm{out}} \cdot e^{-\frac{Z_0*\sqrt{\epsilon_r}}{2\pi \cdot Z_{0_{\mathrm{vacuum}}}}} \f$
  80. *
  81. * \f$ D_{\mathrm{out}} = D_{\mathrm{in}} \cdot e^{ \frac{Z_0*\sqrt{\epsilon_r}}{2\pi \cdot Z_{0_{\mathrm{vacuum}}}}} \f$
  82. *
  83. * \f$ \lambda_g = \frac{c}{f \cdot \sqrt{ \epsilon_r \cdot \mu_r}} \f$
  84. *
  85. * \f$ L_{[\mathrm{m}]} = \frac{ \lambda_g cdot L_{[\mathrm{m}]}}{2\pi} \f$
  86. * */
  87. void COAX::calcSynthesize()
  88. {
  89. double lambda_g;
  90. if( isSelected( PHYS_DIAM_IN_PRM ) )
  91. {
  92. /* solve for din */
  93. m_parameters[PHYS_DIAM_IN_PRM] =
  94. m_parameters[PHYS_DIAM_OUT_PRM]
  95. / exp( m_parameters[Z0_PRM] * sqrt( m_parameters[EPSILONR_PRM] ) / ZF0 * 2 * M_PI );
  96. }
  97. else if( isSelected( PHYS_DIAM_OUT_PRM ) )
  98. {
  99. /* solve for dout */
  100. m_parameters[PHYS_DIAM_OUT_PRM] =
  101. m_parameters[PHYS_DIAM_IN_PRM]
  102. * exp( m_parameters[Z0_PRM] * sqrt( m_parameters[EPSILONR_PRM] ) / ZF0 * 2 * M_PI );
  103. }
  104. lambda_g = ( C0 / ( m_parameters[FREQUENCY_PRM] ) )
  105. / sqrt( m_parameters[EPSILONR_PRM] * m_parameters[MUR_PRM] );
  106. /* calculate physical length */
  107. m_parameters[PHYS_LEN_PRM] = ( lambda_g * m_parameters[ANG_L_PRM] ) / ( 2.0 * M_PI ); /* in m */
  108. }
  109. void COAX::showAnalyze()
  110. {
  111. setProperty( Z0_PRM, m_parameters[Z0_PRM] );
  112. setProperty( ANG_L_PRM, m_parameters[ANG_L_PRM] );
  113. // Check for errors
  114. if( !std::isfinite( m_parameters[Z0_PRM] ) || m_parameters[Z0_PRM] < 0 )
  115. {
  116. setErrorLevel( Z0_PRM, TRANSLINE_ERROR );
  117. }
  118. if( !std::isfinite( m_parameters[ANG_L_PRM] ) || m_parameters[ANG_L_PRM] < 0 )
  119. {
  120. setErrorLevel( ANG_L_PRM, TRANSLINE_ERROR );
  121. }
  122. // Find warnings to display - physical parameters
  123. if( !std::isfinite( m_parameters[PHYS_DIAM_IN_PRM] ) || m_parameters[PHYS_DIAM_IN_PRM] <= 0.0 )
  124. {
  125. setErrorLevel( PHYS_DIAM_IN_PRM, TRANSLINE_WARNING );
  126. }
  127. if( !std::isfinite( m_parameters[PHYS_DIAM_OUT_PRM] )
  128. || m_parameters[PHYS_DIAM_OUT_PRM] <= 0.0 )
  129. {
  130. setErrorLevel( PHYS_DIAM_OUT_PRM, TRANSLINE_WARNING );
  131. }
  132. if( m_parameters[PHYS_DIAM_IN_PRM] > m_parameters[PHYS_DIAM_OUT_PRM] )
  133. {
  134. setErrorLevel( PHYS_DIAM_IN_PRM, TRANSLINE_WARNING );
  135. setErrorLevel( PHYS_DIAM_OUT_PRM, TRANSLINE_WARNING );
  136. }
  137. if( !std::isfinite( m_parameters[PHYS_LEN_PRM] ) || m_parameters[PHYS_LEN_PRM] < 0.0 )
  138. {
  139. setErrorLevel( PHYS_LEN_PRM, TRANSLINE_WARNING );
  140. }
  141. }
  142. void COAX::showSynthesize()
  143. {
  144. if( isSelected( PHYS_DIAM_IN_PRM ) )
  145. setProperty( PHYS_DIAM_IN_PRM, m_parameters[PHYS_DIAM_IN_PRM] );
  146. else if( isSelected( PHYS_DIAM_OUT_PRM ) )
  147. setProperty( PHYS_DIAM_OUT_PRM, m_parameters[PHYS_DIAM_OUT_PRM] );
  148. setProperty( PHYS_LEN_PRM, m_parameters[PHYS_LEN_PRM] );
  149. // Check for errors
  150. if( !std::isfinite( m_parameters[PHYS_DIAM_IN_PRM] ) || m_parameters[PHYS_DIAM_IN_PRM] <= 0.0 )
  151. {
  152. if( isSelected( PHYS_DIAM_IN_PRM ) )
  153. setErrorLevel( PHYS_DIAM_IN_PRM, TRANSLINE_ERROR );
  154. else
  155. setErrorLevel( PHYS_DIAM_IN_PRM, TRANSLINE_WARNING );
  156. }
  157. if( !std::isfinite( m_parameters[PHYS_DIAM_OUT_PRM] )
  158. || m_parameters[PHYS_DIAM_OUT_PRM] <= 0.0 )
  159. {
  160. if( isSelected( PHYS_DIAM_OUT_PRM ) )
  161. setErrorLevel( PHYS_DIAM_OUT_PRM, TRANSLINE_ERROR );
  162. else
  163. setErrorLevel( PHYS_DIAM_OUT_PRM, TRANSLINE_WARNING );
  164. }
  165. if( m_parameters[PHYS_DIAM_IN_PRM] > m_parameters[PHYS_DIAM_OUT_PRM] )
  166. {
  167. if( isSelected( PHYS_DIAM_IN_PRM ) )
  168. setErrorLevel( PHYS_DIAM_IN_PRM, TRANSLINE_ERROR );
  169. else if( isSelected( PHYS_DIAM_OUT_PRM ) )
  170. setErrorLevel( PHYS_DIAM_OUT_PRM, TRANSLINE_ERROR );
  171. }
  172. if( !std::isfinite( m_parameters[PHYS_LEN_PRM] ) || m_parameters[PHYS_LEN_PRM] < 0.0 )
  173. {
  174. setErrorLevel( PHYS_LEN_PRM, TRANSLINE_ERROR );
  175. }
  176. // Check for warnings
  177. if( !std::isfinite( m_parameters[Z0_PRM] ) || m_parameters[Z0_PRM] < 0 )
  178. {
  179. setErrorLevel( Z0_PRM, TRANSLINE_WARNING );
  180. }
  181. if( !std::isfinite( m_parameters[ANG_L_PRM] ) || m_parameters[ANG_L_PRM] < 0 )
  182. {
  183. setErrorLevel( ANG_L_PRM, TRANSLINE_WARNING );
  184. }
  185. }
  186. /*
  187. * show_results() - show results
  188. */
  189. void COAX::show_results()
  190. {
  191. int m, n;
  192. char text[256], txt[256];
  193. m_parameters[LOSS_DIELECTRIC_PRM] = alphad_coax() * m_parameters[PHYS_LEN_PRM];
  194. m_parameters[LOSS_CONDUCTOR_PRM] = alphac_coax() * m_parameters[PHYS_LEN_PRM];
  195. setResult( 0, m_parameters[EPSILONR_PRM], "" );
  196. setResult( 1, m_parameters[LOSS_CONDUCTOR_PRM], "dB" );
  197. setResult( 2, m_parameters[LOSS_DIELECTRIC_PRM], "dB" );
  198. n = 1;
  199. m_parameters[CUTOFF_FREQUENCY_PRM] =
  200. C0
  201. / ( M_PI * ( m_parameters[PHYS_DIAM_OUT_PRM] + m_parameters[MUR_PRM] ) / (double) n );
  202. if( m_parameters[CUTOFF_FREQUENCY_PRM] > m_parameters[FREQUENCY_PRM] )
  203. strcpy( text, "none" );
  204. else
  205. {
  206. strcpy( text, "H(1,1) " );
  207. m = 2;
  208. m_parameters[CUTOFF_FREQUENCY_PRM] =
  209. C0
  210. / ( 2 * ( m_parameters[PHYS_DIAM_OUT_PRM] - m_parameters[MUR_PRM] )
  211. / (double) ( m - 1 ) );
  212. while( ( m_parameters[CUTOFF_FREQUENCY_PRM] <= m_parameters[FREQUENCY_PRM] ) && ( m < 10 ) )
  213. {
  214. sprintf( txt, "H(n,%d) ", m );
  215. strcat( text, txt );
  216. m++;
  217. m_parameters[CUTOFF_FREQUENCY_PRM] =
  218. C0
  219. / ( 2 * ( m_parameters[PHYS_DIAM_OUT_PRM] - m_parameters[MUR_PRM] )
  220. / (double) ( m - 1 ) );
  221. }
  222. }
  223. setResult( 3, text );
  224. m = 1;
  225. m_parameters[CUTOFF_FREQUENCY_PRM] =
  226. C0 / ( 2 * ( m_parameters[PHYS_DIAM_OUT_PRM] - m_parameters[MUR_PRM] ) / (double) m );
  227. if( m_parameters[CUTOFF_FREQUENCY_PRM] > m_parameters[FREQUENCY_PRM] )
  228. strcpy( text, "none" );
  229. else
  230. {
  231. strcpy( text, "" );
  232. while( ( m_parameters[CUTOFF_FREQUENCY_PRM] <= m_parameters[FREQUENCY_PRM] ) && ( m < 10 ) )
  233. {
  234. sprintf( txt, "E(n,%d) ", m );
  235. strcat( text, txt );
  236. m++;
  237. m_parameters[CUTOFF_FREQUENCY_PRM] =
  238. C0
  239. / ( 2 * ( m_parameters[PHYS_DIAM_OUT_PRM] - m_parameters[MUR_PRM] )
  240. / (double) m );
  241. }
  242. }
  243. setResult( 4, text );
  244. }