My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
coax.cpp
Go to the documentation of this file.
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, 2009, 2011 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 
26 /*
27  * coax.c - Puts up window for microstrip and
28  * performs the associated calculations
29  */
30 
31 
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <string.h>
35 #include <math.h>
36 
37 #include "units.h"
38 #include "transline.h"
39 #include "coax.h"
40 
42 {
43 }
44 
46 {
47 }
48 
49 /*
50  * get_coax_sub() - get and assign coax substrate parameters into coax
51  * structure
52  */
53 void coax::get_coax_sub ()
54 {
55  er = getProperty ("Er");
56  mur = getProperty ("Mur");
57  tand = getProperty ("Tand");
58  sigma = getProperty ("Sigma");
59 }
60 
61 /*
62  * get_coax_comp() - get and assign coax component parameters into
63  * coax structure
64  */
65 void coax::get_coax_comp ()
66 {
67  f = getProperty ("Freq", UNIT_FREQ, FREQ_HZ);
68 }
69 
70 /*
71  * get_coax_elec() - get and assign coax electrical parameters into
72  * coax structure
73  */
74 void coax::get_coax_elec ()
75 {
76  Z0 = getProperty ("Z0", UNIT_RES, RES_OHM);
77  ang_l = getProperty ("Ang_l", UNIT_ANG, ANG_RAD);
78 }
79 
80 /*
81  * get_coax_phys() - get and assign coax physical parameters into coax
82  * structure
83  */
84 void coax::get_coax_phys ()
85 {
86  din = getProperty ("din", UNIT_LENGTH, LENGTH_M);
87  dout = getProperty ("dout", UNIT_LENGTH, LENGTH_M);
88  l = getProperty ("L", UNIT_LENGTH, LENGTH_M);
89 }
90 
91 double coax::alphad_coax ()
92 {
93  double ad;
94  ad = (M_PI/C0) * f * sqrt(er) * tand;
95  ad = ad * 20.0 / log(10.0);
96  return ad;
97 }
98 
99 double coax::alphac_coax ()
100 {
101  double ac, Rs;
102  Rs = sqrt((M_PI * f * mur* MU0)/sigma);
103  ac = sqrt(er) * (((1/din) + (1/dout))/log(dout/din)) * (Rs/ZF0);
104  ac = ac * 20.0 / log(10.0);
105  return ac;
106 }
107 
108 /*
109  * analyze() - analysis function
110  */
112 {
113  double lambda_g;
114 
115  /* Get and assign substrate parameters */
116  get_coax_sub();
117 
118  /* Get and assign component parameters */
119  get_coax_comp();
120 
121  /* Get and assign physical parameters */
122  get_coax_phys();
123 
124  if (din != 0.0){
125  Z0 = (ZF0/2/M_PI/sqrt(er))*log(dout/din);
126  }
127 
128  lambda_g = (C0/(f))/sqrt(er * mur);
129  /* calculate electrical angle */
130  ang_l = (2.0 * M_PI * l)/lambda_g; /* in radians */
131 
132  setProperty ("Z0", Z0, UNIT_RES, RES_OHM);
133  setProperty ("Ang_l", ang_l, UNIT_ANG, ANG_RAD);
134 
135  show_results();
136 }
137 
138 
139 /*
140  * synthesize() - synthesis function
141  */
143 {
144  double lambda_g;
145 
146  /* Get and assign substrate parameters */
147  get_coax_sub();
148 
149  /* Get and assign component parameters */
150  get_coax_comp();
151 
152  /* Get and assign electrical parameters */
153  get_coax_elec ();
154 
155  /* Get and assign physical parameters */
156  get_coax_phys();
157 
158  if (isSelected ("din")) {
159  /* solve for din */
160  din = dout / exp(Z0*sqrt(er)/ZF0*2*M_PI);
161  setProperty ("din", din, UNIT_LENGTH, LENGTH_M);
162  } else if (isSelected ("dout")) {
163  /* solve for dout */
164  dout = din * exp(Z0*sqrt(er)/ZF0*2*M_PI);
165  setProperty ("dout", dout, UNIT_LENGTH, LENGTH_M);
166  }
167 
168  lambda_g = (C0/(f))/sqrt(er * mur);
169  /* calculate physical length */
170  l = (lambda_g * ang_l)/(2.0 * M_PI); /* in m */
171  setProperty ("L", l, UNIT_LENGTH, LENGTH_M);
172 
173  show_results();
174 }
175 
176 /*
177  * show_results() - show results
178  */
179 void coax::show_results()
180 {
181  double fc;
182  short m, n;
183 
184  atten_dielectric = alphad_coax () * l;
185  atten_cond = alphac_coax () * l;
186 
187  setResult (0, atten_cond, "dB");
188  setResult (1, atten_dielectric, "dB");
189 
190  n = 1;
191  fc = C0 / sqrt (er * mur) / (M_PI_2 * (dout + din)/(double) n);
192  setResult (2, "none");
193  if (fc <= f) {
194  char text[256], txt[256];
195  strcpy (text, "TE(1,1) ");
196  m = 2;
197  fc = C0 / sqrt (er * mur) / (M_PI_2 * (dout + din)/(double) m);
198  while ((fc <= f) && (m<10)) {
199  sprintf(txt, "TE(n,%d) ",m);
200  strcat(text,txt);
201  m++;
202  fc = C0 / sqrt (er * mur) / (M_PI_2 * (dout + din)/(double) m);
203  }
204  setResult (2, text);
205  }
206 
207  setResult (3, "none");
208  m = 1;
209  fc = C0 / sqrt (er * mur) / ((dout - din)/(float) m);
210  if (fc <= f) {
211  char text[256], txt[256];
212  strcpy (text, "");
213  while ((fc <= f) && (m<10)) {
214  sprintf(txt, "TM(n,%d) ",m);
215  strcat(text,txt);
216  m++;
217  fc = C0 / sqrt (er * mur) / ((dout - din)/(double) m);
218  }
219  setResult (3, text);
220  }
221 }