1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/****************************************************************************
** From Qucs Attenuator Synthesis
** attenuator_classes.cpp
**
** since 2006/6/14
**
*****************************************************************************/
#include <math.h>
#include <attenuator_classes.h>
// Bitmaps:
#include <att_pi.xpm>
#include <att_tee.xpm>
#include <att_bridge.xpm>
#include <att_splitter.xpm>
#include <pi_formula.xpm>
#include <tee_formula.xpm>
#include <bridged_tee_formula.xpm>
#include <splitter_formula.xpm>
#ifndef NULL
#define NULL 0
#endif
ATTENUATOR::ATTENUATOR( ATTENUATORS_TYPE aTopology )
{
m_Name = wxT("att_base");
m_Error = false;
m_Topology = aTopology;
m_ResultCount = 3; // If 3 values must be calculated
m_Zin = 50; // Ohms
m_Zin_Enable = true;
m_Zout = 50; // Ohms
m_Attenuation = 6.0; // dB
m_Attenuation_Enable = true;
m_MinimumATT = 0.0; // dB
m_SchBitMap = NULL;
m_FormulaBitMap = NULL;
}
ATTENUATOR::~ATTENUATOR()
{
delete m_SchBitMap;
delete m_FormulaBitMap;
}
#define KEYWORD_ATTENUATOR_ATT wxT( "Attenuation" )
#define KEYWORD_ATTENUATOR_ZIN wxT( "Zin" )
#define KEYWORD_ATTENUATOR_ZOUT wxT( "Zout" )
#define KEYWORD_ATTENUATORS wxT( "Attenuators/" )
void ATTENUATOR::ReadConfig( wxConfig* aConfig )
{
aConfig->SetPath( KEYWORD_ATTENUATORS + m_Name );
if( m_Attenuation_Enable )
aConfig->Read( KEYWORD_ATTENUATOR_ATT, &m_Attenuation, 6.0 );
aConfig->Read( KEYWORD_ATTENUATOR_ZIN, &m_Zin, 50.0 );
aConfig->Read( KEYWORD_ATTENUATOR_ZOUT, &m_Zout, 50.0 );
aConfig->SetPath( wxT( "../.." ) );
}
void ATTENUATOR::WriteConfig( wxConfig* aConfig )
{
aConfig->SetPath( KEYWORD_ATTENUATORS + m_Name );
aConfig->Write( KEYWORD_ATTENUATOR_ATT, m_Attenuation );
aConfig->Write( KEYWORD_ATTENUATOR_ZIN, m_Zin );
aConfig->Write( KEYWORD_ATTENUATOR_ZOUT, m_Zout );
aConfig->SetPath( wxT( "../.." ) );
}
ATTENUATOR_PI::ATTENUATOR_PI() : ATTENUATOR( PI_TYPE )
{
m_Name = wxT("att_pi");
m_SchBitMap = new wxBitmap( att_pi_xpm );
m_FormulaBitMap = new wxBitmap( pi_formula_xpm );
}
bool ATTENUATOR_PI::Calculate()
{
if( !ATTENUATOR::Calculate() )
return false;
m_R2 = ( (L - 1) / 2 ) * sqrt( m_Zin * m_Zout / L );
m_R1 = 1 / ( ( (A / m_Zin) ) - (1 / m_R2) );
m_R3 = 1 / ( ( (A / m_Zout) ) - (1 / m_R2) );
return true;
}
ATTENUATOR_TEE::ATTENUATOR_TEE() : ATTENUATOR( TEE_TYPE )
{
m_Name = wxT("att_tee");
m_SchBitMap = new wxBitmap( att_tee_xpm );
m_FormulaBitMap = new wxBitmap( tee_formula_xpm );
}
bool ATTENUATOR_TEE::Calculate()
{
if( !ATTENUATOR::Calculate() )
return false;
m_R2 = ( 2 * sqrt( L * m_Zin * m_Zout ) ) / (L - 1);
m_R1 = m_Zin * A - m_R2;
m_R3 = m_Zout * A - m_R2;
return true;
}
ATTENUATOR_BRIDGE::ATTENUATOR_BRIDGE() : ATTENUATOR( BRIDGE_TYPE )
{
m_Name = wxT("att_bridge");
m_Zin_Enable = false;
m_ResultCount = 2;
m_SchBitMap = new wxBitmap( att_bridge_xpm );
m_FormulaBitMap = new wxBitmap( bridged_tee_formula_xpm );
}
bool ATTENUATOR_BRIDGE::Calculate()
{
m_Zin = m_Zout;
if( !ATTENUATOR::Calculate() )
return false;
L = pow( 10, m_Attenuation / 20 );
m_R1 = m_Zin * (L - 1);
m_R2 = m_Zin / (L - 1);
return true;
}
ATTENUATOR_SPLITTER::ATTENUATOR_SPLITTER() : ATTENUATOR( SPLITTER_TYPE )
{
m_Name = wxT("att_splitter");
m_Attenuation_Enable = false;
m_Attenuation = 6.0;
m_MinimumATT = 6.0;
m_Zin_Enable = false;
m_SchBitMap = new wxBitmap( att_splitter_xpm );
m_FormulaBitMap = new wxBitmap( splitter_formula_xpm );
}
bool ATTENUATOR_SPLITTER::Calculate()
{
m_Attenuation = 6.0;
m_Zin = m_Zout;
m_R1 = m_R2 = m_R3 = m_Zout / 3.0;
return true;
}
bool ATTENUATOR::Calculate()
{
L = pow( 10, m_Attenuation / 10 );
A = (L + 1) / (L - 1);
if( m_Zin > m_Zout )
{
Lmin = (2 * m_Zin / m_Zout) - 1 + 2 *
sqrt( m_Zin / m_Zout * (m_Zin / m_Zout - 1) );
}
else
{
Lmin = (2 * m_Zout / m_Zin) - 1 + 2 *
sqrt( m_Zout / m_Zin * (m_Zout / m_Zin - 1) );
}
m_MinimumATT = 10 * log10( Lmin );
if( m_MinimumATT > m_Attenuation )
{
m_Error = true;
return false;
}
m_Error = false;
return true;
}