My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
attenuatorfunc.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Qucs Attenuator Synthesis
3 ** attenuatorfunc.cpp
4 **
5 ** since 2006/6/14
6 **
7 **
8 **
9 **
10 **
11 *****************************************************************************/
12 #ifdef HAVE_CONFIG_H
13 #include <config.h>
14 #endif
15 
16 #include "attenuatorfunc.h"
17 
18 #include <qstring.h>
19 
22 
24 {
25  double Lmin, L, A;
26  L = pow(10, ATT->Attenuation / 10);
27 
28  A = (L + 1) / (L - 1);
29 
30  if(ATT->Zin > ATT->Zout)
31  {
32  Lmin = (2 * ATT->Zin / ATT->Zout) - 1 + 2 *
33  sqrt(ATT->Zin / ATT->Zout * (ATT->Zin / ATT->Zout - 1));
34  }
35  else
36  {
37  Lmin = (2 * ATT->Zout / ATT->Zin) - 1 + 2 *
38  sqrt(ATT->Zout / ATT->Zin * (ATT->Zout / ATT->Zin - 1));
39  }
40  ATT->MinimumATT = 10 * log10(Lmin);
41 
42  if(ATT->MinimumATT > ATT->Attenuation)
43  {
44  return -1;
45  }
46  else
47  {
48  switch(ATT->Topology)
49  {
50  case PI_TYPE:
51  {
52  ATT->R2 = ((L - 1) / 2) * sqrt(ATT->Zin * ATT->Zout / L);
53  ATT->R1 = 1 / (((A / ATT->Zin)) - (1 / ATT->R2));
54  ATT->R3 = 1 / (((A / ATT->Zout)) - (1 / ATT->R2));
55  break;
56  }
57  case TEE_TYPE:
58  {
59  ATT->R2 = (2 * sqrt(L * ATT->Zin * ATT->Zout)) / (L - 1);
60  ATT->R1 = ATT->Zin * A - ATT->R2;
61  ATT->R3 = ATT->Zout * A - ATT->R2;
62  break;
63  }
64  case BRIDGE_TYPE:
65  {
66  L = pow(10, ATT->Attenuation / 20);
67  ATT->R1 = ATT->Zin * (L - 1);
68  ATT->R2 = ATT->Zin / (L - 1);
69  break;
70  }
71  }
72  return 0;
73  }
74 }
75 
76 
78 {
79  // create the Qucs schematic
80  QString *s = new QString("<Qucs Schematic ");
81  *s += PACKAGE_VERSION;
82  *s += ">\n";
83  *s += "<Components>\n";
84 
85  switch(ATT->Topology)
86  {
87  case PI_TYPE:
88  *s += QString("<R R1 1 180 160 -30 -14 0 1 \"%1 Ohm\" 1 \"26.85\" 0 \"0.0\" 0 \"0.0\" 0 \"26.85\" 0 \"US\" 0>\n").arg(ATT->R1);
89  *s += QString("<R R2 1 210 130 -19 -42 0 0 \"%1 Ohm\" 1 \"26.85\" 0 \"0.0\" 0 \"0.0\" 0 \"26.85\" 0 \"US\" 0>\n").arg(ATT->R2);
90  *s += QString("<R R3 1 240 160 11 -14 0 1 \"%1 Ohm\" 1 \"26.85\" 0 \"0.0\" 0 \"0.0\" 0 \"26.85\" 0 \"US\" 0>\n").arg(ATT->R3);
91  *s += "<GND * 1 180 190 0 0 0 0>\n";
92  *s += "<GND * 1 240 190 0 0 0 0>\n";
93  *s += "</Components>\n";
94  *s += "<Wires>\n";
95  *s += "<240 130 280 130 \"\" 0 0 0 \"\">\n";
96  *s += "<140 130 180 130 \"\" 0 0 0 \"\">\n";
97  *s += "</Wires>\n";
98  *s += "<Diagrams>\n";
99  *s += "</Diagrams>\n";
100  *s += "<Paintings>\n";
101  *s += QString("<Text 125 60 12 #000000 0 \"%1 dB Pi-Type Attenuator\">\n").arg(ATT->Attenuation);
102  *s += QString("<Text 290 122 10 #000000 0 \"Z2: %1 Ohm\">\n").arg(ATT->Zout);
103  *s += QString("<Text 50 122 10 #000000 0 \"Z1: %1 Ohm\">\n").arg(ATT->Zin);
104  *s += "</Paintings>\n";
105  break;
106 
107  case TEE_TYPE:
108  *s += QString("<R R1 1 180 130 -25 -42 0 2 \"%1 Ohm\" 1 \"26.85\" 0 \"0.0\" 0 \"0.0\" 0 \"26.85\" 0 \"US\" 0>\n").arg(ATT->R1);
109  *s += QString("<R R2 1 210 160 10 -4 0 3 \"%1 Ohm\" 1 \"26.85\" 0 \"0.0\" 0 \"0.0\" 0 \"26.85\" 0 \"US\" 0>\n").arg(ATT->R2);
110  *s += QString("<R R3 1 240 130 -25 -42 0 2 \"%1 Ohm\" 1 \"26.85\" 0 \"0.0\" 0 \"0.0\" 0 \"26.85\" 0 \"US\" 0>\n").arg(ATT->R3);
111  *s += "<GND * 1 210 190 0 0 0 0>\n";
112  *s +="</Components>\n";
113  *s += "<Wires>\n";
114  *s += "<140 130 150 130 \"\" 0 0 0 \"\">\n";
115  *s += "<270 130 280 130 \"\" 0 0 0 \"\">\n";
116  *s += "</Wires>\n";
117  *s += "<Diagrams>\n";
118  *s += "</Diagrams>\n";
119  *s += "<Paintings>\n";
120  *s += QString("<Text 115 60 12 #000000 0 \"%1 dB Tee-Type Attenuator\">\n").arg(ATT->Attenuation);
121  *s += QString("<Text 290 122 10 #000000 0 \"Z2: %1 Ohm\">\n").arg(ATT->Zout);
122  *s += QString("<Text 50 122 10 #000000 0 \"Z1: %1 Ohm\">\n").arg(ATT->Zin);
123  *s += "</Paintings>\n";
124  break;
125 
126  case BRIDGE_TYPE:
127  *s += QString("<R R1 1 210 130 -19 -42 0 0 \"%1 Ohm\" 1 \"26.85\" 0 \"0.0\" 0 \"0.0\" 0 \"26.85\" 0 \"US\" 0>\n").arg(ATT->R1);
128  *s += QString("<R R2 1 180 160 -30 -14 0 1 \"%1 Ohm\" 0 \"26.85\" 0 \"0.0\" 0 \"0.0\" 0 \"26.85\" 0 \"US\" 0>\n").arg(ATT->Zin);
129  *s += QString("<R R3 1 240 160 11 -14 0 1 \"%1 Ohm\" 0 \"26.85\" 0 \"0.0\" 0 \"0.0\" 0 \"26.85\" 0 \"US\" 0>\n").arg(ATT->Zout);
130  *s += QString("<R R4 1 210 220 11 -14 0 1 \"%1 Ohm\" 1 \"26.85\" 0 \"0.0\" 0 \"0.0\" 0 \"26.85\" 0 \"US\" 0>\n").arg(ATT->R2);
131  *s += "<GND * 1 210 250 0 0 0 0>\n";
132  *s += "</Components>\n";
133  *s += "<Wires>\n";
134  *s += "<240 130 280 130 \"\" 0 0 0 \"\">\n";
135  *s += "<140 130 180 130 \"\" 0 0 0 \"\">\n";
136  *s += "<180 190 240 190 \"\" 0 0 0 \"\">\n";
137  *s += "</Wires>\n";
138  *s += "<Diagrams>\n";
139  *s += "</Diagrams>\n";
140  *s += "<Paintings>\n";
141  *s += QString("<Text 100 60 12 #000000 0 \"%1 dB Bridged-Tee-Type Attenuator\">\n").arg(ATT->Attenuation);
142  *s += QString("<Text 290 122 10 #000000 0 \"Z2: %1 Ohm\">\n").arg(ATT->Zout);
143  *s += QString("<Text 50 122 10 #000000 0 \"Z1: %1 Ohm\">\n").arg(ATT->Zin);
144  *s += "</Paintings>\n";
145  break;
146  }
147 
148  return s;
149 }