My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rectwaveguide.cpp
Go to the documentation of this file.
1 /*
2  * rectwaveguide.cpp - rectangular waveguide class implementation
3  *
4  * Copyright (C) 2001 Gopal Narayanan <gopal@astro.umass.edu>
5  * Copyright (C) 2005, 2006 Stefan Jahn <stefan@lkcc.org>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this package; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #include <stdio.h>
25 #include <string.h>
26 #include <math.h>
27 
28 #include "units.h"
29 #include "transline.h"
30 #include "rectwaveguide.h"
31 
33 {
34 }
35 
37 {
38 }
39 
40 /*
41  * returns k
42  */
43 double rectwaveguide::kval ()
44 {
45  double kval;
46  kval = 2. * M_PI * f * sqrt(mur * er)/C0;
47  return kval;
48 }
49 
50 /*
51  * given mode numbers m and n
52  * returns cutoff kc value
53  */
54 double rectwaveguide::kc (int m, int n)
55 {
56  double kcval;
57  kcval = sqrt(pow((m*M_PI/a),2.0) + pow((n*M_PI/b),2.0));
58  return kcval;
59 }
60 
61 /*
62  * given mode numbers m and n
63  * returns cutoff fc value
64  */
65 double rectwaveguide::fc (int m, int n)
66 {
67  double fcval;
68  fcval = (kc(m, n) * C0)/ (2 * M_PI * sqrt(mur * er));
69  return fcval;
70 }
71 
72 /*
73  * alphac - returns attenuation due to conductor losses for all propagating
74  * modes in the waveguide
75  */
76 double rectwaveguide::alphac ()
77 {
78  double Rs, k, f_c;
79  double ac;
80  short m, n, mmax, nmax;
81 
82  Rs = sqrt((M_PI * f * mur* MU0)/sigma);
83  k = kval();
84  ac = 0.0;
85  mmax = (int) floor (f/fc(1,0));
86  nmax = mmax;
87 
88  /* below from Ramo, Whinnery & Van Duzer */
89 
90  /* TE(m,n) modes */
91  for (n = 0; n<= nmax; n++){
92  for (m = 1; m <= mmax; m++){
93  f_c = fc(m, n);
94  if (f > f_c) {
95  switch (n) {
96  case 0:
97  ac += (Rs/(b * ZF0 * sqrt(1.0 - pow((f_c/f),2.0)))) *
98  (1.0 + ((2 * b/a)*pow((f_c/f),2.0)));
99  break;
100  default:
101  ac += ((2. * Rs)/(b * ZF0 * sqrt(1.0 - pow((f_c/f),2.0)))) *
102  (((1. + (b/a))*pow((f_c/f),2.0)) +
103  ((1. - pow((f_c/f),2.0)) * (((b/a)*(((b/a)*pow(m,2.)) + pow(n,2.)))/
104  (pow((b*m/a),2.0) + pow(n,2.0)))));
105  break;
106  }
107  }
108  }
109  }
110 
111  /* TM(m,n) modes */
112  for (n = 1; n<= nmax; n++) {
113  for (m = 1; m<= mmax; m++) {
114  f_c = fc(m, n);
115  if (f > f_c) {
116  ac += ((2. * Rs)/(b * ZF0 * sqrt(1.0 - pow((f_c/f),2.0)))) *
117  (((pow(m,2.0)*pow((b/a),3.0)) + pow(n,2.))/
118  ((pow((m*b/a),2.)) + pow(n,2.0)));
119  }
120  }
121  }
122 
123  ac = ac * 20.0 * log10(exp(1.)); /* convert from Np/m to db/m */
124  return ac;
125 }
126 
127 /*
128  * alphac_cutoff - returns attenuation for a cutoff wg
129  */
130 double rectwaveguide::alphac_cutoff ()
131 {
132  double acc;
133  acc = sqrt(pow(kc(1,0),2.0) - pow(kval(),2.0));
134  acc = 20 * log10(exp(1.0)) * acc;
135  return acc;
136 }
137 
138 /*
139  * returns attenuation due to dielectric losses
140  */
141 double rectwaveguide::alphad()
142 {
143  double k, beta;
144  double ad;
145 
146  k = kval();
147  beta = sqrt(pow(k,2.) - pow(kc(1,0),2.0));
148 
149  ad = (pow(k,2.0) * tand)/(2.0 * beta);
150  ad = ad * 20.0 * log10(exp(1.)); /* convert from Np/m to db/m */
151  return ad;
152 }
153 
154 /*
155  * get_rectwaveguide_sub
156  * get and assign rectwaveguide substrate parameters
157  * into rectwaveguide structure
158  */
159 void rectwaveguide::get_rectwaveguide_sub ()
160 {
161  er = getProperty ("Er");
162  mur = getProperty ("Mur");
163  sigma = getProperty ("Cond");
164  tand = getProperty ("Tand");
165  tanm = getProperty ("TanM");
166 }
167 
168 /*
169  * get_rectwaveguide_comp
170  * get and assign rectwaveguide component parameters
171  * into rectwaveguide structure
172  */
173 void rectwaveguide::get_rectwaveguide_comp ()
174 {
175  f = getProperty ("Freq", UNIT_FREQ, FREQ_HZ);
176 }
177 
178 /*
179  * get_rectwaveguide_elec
180  * get and assign rectwaveguide electrical parameters
181  * into rectwaveguide structure
182  */
183 void rectwaveguide::get_rectwaveguide_elec ()
184 {
185  Z0 = getProperty ("Z0", UNIT_RES, RES_OHM);
186  ang_l = getProperty ("Ang_l", UNIT_ANG, ANG_RAD);
187 }
188 
189 
190 /*
191  * get_rectwaveguide_phys
192  * get and assign rectwaveguide physical parameters
193  * into rectwaveguide structure
194  */
195 void rectwaveguide::get_rectwaveguide_phys ()
196 {
197  a = getProperty ("a", UNIT_LENGTH, LENGTH_M);
198  b = getProperty ("b", UNIT_LENGTH, LENGTH_M);
199  l = getProperty ("L", UNIT_LENGTH, LENGTH_M);
200 }
201 
202 
203 /*
204  * analyze - analysis function
205  */
207 {
208  double lambda_g;
209  double k;
210  double beta;
211 
212  /* Get and assign substrate parameters */
213  get_rectwaveguide_sub();
214 
215  /* Get and assign component parameters */
216  get_rectwaveguide_comp();
217 
218  /* Get and assign physical parameters */
219  get_rectwaveguide_phys();
220 
221  k = kval();
222 
223  if (kc(1,0) <= k) {
224  /*propagating modes */
225  beta = sqrt(pow(k,2.) - pow(kc(1,0),2.0));
226  lambda_g = (2. * M_PI)/beta;
227  /* Z0 = (k * ZF0)/beta; */
228  Z0 = 2.0 * ZF0 * (b/a) * 1/
229  sqrt(1.0 - pow((fc(1,0)/f),2.0));
230 
231  /* calculate electrical angle */
232  lambda_g = (2. * M_PI)/beta;
233  ang_l = (2.0 * M_PI * l)/lambda_g; /* in radians */
234  atten_cond = alphac () * l;
235  atten_dielectric = alphad () * l;
236  er_eff = (1.0 - pow((fc(1,0)/f),2.0));
237  } else {
238  /*evanascent modes */
239  Z0 = 0;
240  ang_l = 0;
241  er_eff = 0;
242  atten_dielectric = 0.0;
243  atten_cond = alphac_cutoff () * l;
244  }
245 
246  setProperty ("Z0", Z0, UNIT_RES, RES_OHM);
247  setProperty ("Ang_l", ang_l, UNIT_ANG, ANG_RAD);
248 
249  show_results ();
250 }
251 
252 /*
253  * synthesize - synthesis function
254  */
256 {
257  double lambda_g, k, beta;
258 
259  /* Get and assign substrate parameters */
260  get_rectwaveguide_sub();
261 
262  /* Get and assign component parameters */
263  get_rectwaveguide_comp();
264 
265  /* Get and assign electrical parameters */
266  get_rectwaveguide_elec();
267 
268  /* Get and assign physical parameters */
269  get_rectwaveguide_phys();
270 
271 
272  if (isSelected ("b")) {
273  /* solve for b */
274  b = Z0 * a * sqrt(1.0 - pow((fc(1,0)/f),2.0))/
275  (2. * ZF0);
277  } else if (isSelected ("a")) {
278  /* solve for a */
279  a = sqrt(pow((2.0 * ZF0 * b/Z0), 2.0) +
280  pow((C0/(2.0 * f)),2.0));
281  setProperty ("a", a, UNIT_LENGTH, LENGTH_M);
282  }
283 
284  k = kval ();
285  beta = sqrt(pow(k,2.) - pow(kc(1,0),2.0));
286  lambda_g = (2. * M_PI)/beta;
287  l = (ang_l * lambda_g)/(2.0 * M_PI); /* in m */
288 
289  setProperty ("L", l, UNIT_LENGTH, LENGTH_M);
290 
291  if (kc(1,0) <= k) {
292  /*propagating modes */
293  beta = sqrt(pow(k,2.) - pow(kc(1,0),2.0));
294  lambda_g = (2. * M_PI)/beta;
295  atten_cond = alphac () * l;
296  atten_dielectric = alphad () * l;
297  er_eff = (1.0 - pow((fc(1,0)/f),2.0));
298  } else {
299  /*evanascent modes */
300  Z0 = 0;
301  ang_l = 0;
302  er_eff = 0;
303  atten_dielectric = 0.0;
304  atten_cond = alphac_cutoff () * l;
305  }
306 
307  show_results ();
308 }
309 
310 void rectwaveguide::show_results ()
311 {
312  short m, n, mmax, nmax;
313 
314  setResult (0, er_eff, "");
315  setResult (1, atten_cond, "dB");
316  setResult (2, atten_dielectric, "dB");
317 
318  setResult (3, "none");
319  if (f >= (2.*fc(1,0))) {
320  char text[256], txt[256];
321  strcpy (text, "");
322  /* multiple modes possible in waveguide */
323  /* mmax = floor(f/fc(1,0));*/
324  mmax = 5;
325  nmax = mmax;
326  for (m = 2; m<= mmax; m++) {
327  for (n=0; n<= nmax; n++) {
328  if (f >= (fc(m,n))){
329  sprintf(txt,"TE(%u,%u) ",m, n);
330  strcat(text,txt);
331  }
332  }
333  }
334  setResult (3, text);
335  }
336 
337  setResult (4, "none");
338  if (f >= fc(1,1)){ /*TM(1,1) mode possible*/
339  char text[256], txt[256];
340  strcpy (text, "");
341  /* mmax = floor(f/fc(1,1));*/
342  mmax = 5;
343  nmax = mmax;
344  for (m = 1; m<= mmax; m++) {
345  for (n=1; n<= nmax; n++) {
346  if (f >= (fc(m,n))){
347  sprintf(txt,"TM(%u,%u) ",m, n);
348  strcat(text,txt);
349  }
350  }
351  }
352  setResult (3, text);
353  }
354 }