50 if (inter)
delete inter;
55 bool _isreal,
int it,
int dt) {
59 inter =
new interpolator ();
61 inter->rvectors (
v, f);
65 inter->cvectors (
v, f);
73 return inter->rinterpolate (x);
75 return inter->cinterpolate (x);
79 spfile::spfile () : circuit () {
82 spara = FMIN = SOPT = RN = NULL;
83 interpolType = dataType = 0;
85 setVariableSized (
true);
122 s.set (
r, c,
spara[i].interpolate (frequency));
165 assert (s.getCols () == s.getRows ());
166 int r,
c, ports = s.getCols () + 1;
172 for (sa = 0, r = 0; r < ports - 1; r++)
173 for (c = 0; c < ports - 1; c++) sa += s.get (r, c);
174 ss = (2 - g - ports + sa) / (1 - ports * g - sa);
175 res.set (ports - 1, ports - 1, ss);
176 fr = (1.0 - g * ss) / (1.0 - g);
179 for (r = 0; r < ports - 1; r++) {
180 for (sc = 0, c = 0; c < ports - 1; c++) sc += s.get (r, c);
181 res.set (r, ports - 1, fr * (1.0 - sc));
185 for (c = 0; c < ports - 1; c++) {
186 for (sr = 0, r = 0; r < ports - 1; r++) sr += s.get (r, c);
187 res.set (ports - 1, c, fr * (1.0 - sr));
191 for (r = 0; r < ports - 1; r++) {
192 for (c = 0; c < ports - 1; c++) {
193 fr = g * res (r, ports - 1) * res (ports - 1, c) / (1.0 - g * ss);
194 res.set (r, c, s.get (r, c) - fr);
205 assert (s.getCols () == s.getRows () && s.getCols () > 0);
206 int r,
c, ports = s.getCols ();
208 matrix res (ports - 1);
211 for (r = 0; r < ports - 1; r++) {
212 for (c = 0; c < ports - 1; c++) {
213 res.set (r, c, s (r, c) + g * s (r, ports - 1) *
214 s (ports - 1, c) / (1.0 - g * s (ports - 1, ports - 1)));
226 assert (s.getCols () == s.getRows () && n.getCols () == n.getRows () &&
227 n.getCols () == s.getCols () - 1);
229 int r,
c, ports = n.getCols () + 1;
233 matrix k (ports, ports - 1);
234 for (r = 0; r < ports - 1; r++) {
235 for (c = 0; c < ports - 1; c++) {
237 k.set (r, c, 1.0 + g * (s.get (r, ports - 1) - 1.0));
239 k.set (r, c, g * s.get (r, ports - 1));
242 for (c = 0; c < ports - 1; c++)
243 k.set (ports - 1, c, g * s.get (ports - 1, ports - 1) - 1.0);
247 for (r = 0; r < ports - 1; r++) d.set (r, 0, s.get (r, ports - 1));
248 d.set (ports - 1, 0, s.get (ports - 1, ports - 1) - 1.0);
263 assert (s.getCols () == s.getRows () && n.getCols () == n.getRows () &&
264 n.getCols () == s.getCols () && n.getCols () > 0);
265 int r, ports = n.getCols ();
270 matrix k (ports - 1, ports);
271 for (r = 0; r < ports - 1; r++) k.set (r, r, 1);
272 for (r = 0; r < ports - 1; r++)
273 k.set (r, ports - 1, g * s.get (r, ports - 1) /
274 (1.0 - g * s.get (ports - 1, ports - 1)));
277 matrix
d (ports - 1, 1);
278 for (r = 0; r < ports - 1; r++) d.set (r, 0, s.get (r, ports - 1));
281 matrix res (ports - 1);
283 norm (1.0 - g * s.get (ports - 1, ports - 1)) * d *
adjoint (d);
291 if (!strcmp (type,
"rectangular")) {
295 else if (!strcmp (type,
"polar")) {
302 if (!strcmp (type,
"linear")) {
305 else if (!strcmp (type,
"cubic")) {
311 if (
data == NULL)
data = dataset::load_touchstone (file);
327 "requires a %d-port\n", file, ports,
getName (),
364 if ((n = v->
getName ()) != NULL) {
365 if (!strcmp (n,
"frequency"))
sfreq = v;
366 else if (!strcmp (n,
"nfreq"))
nfreq = v;
375 if ((n = matvec::isMatrixVector (v->
getName (),
r,
c)) != NULL) {
384 if ((n = v->
getName ()) != NULL) {
386 if (!strcmp (n,
"Rn")) {
390 else if (!strcmp (n,
"Fmin")) {
394 else if (!strcmp (n,
"Sopt")) {
406 nr_double_t Rn, matrix
s) {
407 assert (s.getCols () == s.getRows () && s.getCols () == 2);
410 c.set (0, 0, (Fmin - 1) * (
norm (s.get (0, 0)) - 1) +
411 Kx *
norm (1.0 - s.get (0, 0) * Sopt));
412 c.set (1, 1,
norm (s.get (1, 0)) * ((Fmin - 1) + Kx *
norm (Sopt)));
413 c.set (0, 1, s.get (0, 0) / s.get (1, 0) * c.get (1, 1) -
414 conj (s.get (1, 0)) *
conj (Sopt) * Kx);
415 c.set (1, 0,
conj (c.get (0, 1)));
423 assert (s.getCols () == s.getRows () && c.getCols () == c.getRows () &&
424 s.getCols () == 2 && c.getCols () == 2);
426 n1 = c.get (0, 0) *
norm (s.get (1, 0)) -
427 2 *
real (c.get (0, 1) * s.get (1, 0) *
conj (s.get (0, 0))) +
428 c.get (1, 1) *
norm (s.get (0, 0));
429 n2 = 2.0 * (c.get (1, 1) * s.get (0, 0) -
430 c.get (0, 1) * s.get (1, 0)) / (c.get (1, 1) +
n1);
433 Sopt = 1 -
norm (n2);
434 if (
real (Sopt) < 0.0)
440 Fmin =
real (1.0 + (c.get (1, 1) - n1 *
norm (Sopt)) /
441 norm (s.get (1, 0)) / (1.0 +
norm (Sopt)));
444 Rn =
real ((c (0, 0) - 2.0 *
445 real (c (0, 1) *
conj ((1.0 + s (0, 0)) / s (1, 0))) +
446 c (1, 1) *
norm ((1.0 + s (0, 0)) / s (1, 0))) / 4.0);
450 return real (1.0 + c.get (1, 1) /
norm (s.get (1, 0)));
458 if (!strcmp (dc,
"shortall")) {
469 if (!strcmp (dc,
"short")) {
480 else if (!strcmp (dc,
"open")) {
528 PROP_RNG_STR4 (
"open",
"short",
"shortall",
"unspecified") },
std::complex< nr_double_t > nr_complex_t
void prepare(qucs::vector *, qucs::vector *, bool, int, int)
void calcNoiseSP(nr_double_t)
matrix adjoint(matrix a)
adjoint matrix
matrix ytos(matrix y, qucs::vector z0)
Admittance matrix to scattering parameters.
qucs::matrix calcMatrixCs(nr_double_t)
matrix real(matrix a)
Real part matrix.
#define T0
standard temperature
qucs::vector * getVariables(void)
#define PROP_RNG_STR2(s1, s2)
nr_double_t getPropertyDouble(const char *)
qucs::matrix expandNoiseMatrix(qucs::matrix, qucs::matrix)
void setVoltageSources(int)
#define K
Absolute 0 in centigrade.
static const nr_double_t z0
int getSize(void)
Get the number of ports the circuit element has.
matrix htos(matrix h, nr_complex_t z1, nr_complex_t z2)
Converts hybrid matrix to scattering parameters.
void setDependencies(strlist *)
qucs::matrix expandSParaMatrix(qucs::matrix)
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
matrix stoy(matrix s, qucs::vector z0)
Scattering parameters to admittance matrix.
qucs::matrix correlationMatrix(nr_double_t, nr_complex_t, nr_double_t, qucs::matrix)
matrix ztos(matrix z, qucs::vector z0)
Convert impedance matrix scattering parameters.
void createVector(int, int)
#define PROP_RNG_STR4(s1, s2, s3, s4)
void addVariable(qucs::vector *)
matrix cstocy(matrix cs, matrix y)
Converts S-parameter noise correlation matrix to admittance noise correlation matrix.
qucs::matrix shrinkNoiseMatrix(qucs::matrix, qucs::matrix)
void allocMatrixMNA(void)
nr_double_t norm(const nr_complex_t z)
Compute euclidian norm of complex number.
nr_complex_t interpolate(nr_double_t)
matrix gtos(matrix g, nr_complex_t z1, nr_complex_t z2)
qucs::matrix getInterpolMatrixS(nr_double_t)
void voltageSource(int, int, int, nr_double_t value=0.0)
void calcNoiseAC(nr_double_t)
matrix conj(matrix a)
Conjugate complex matrix.
void initSP(void)
placehoder for S-Parameter initialisation function
nr_double_t noiseFigure(qucs::matrix, qucs::matrix, nr_double_t &, nr_complex_t &, nr_double_t &)
qucs::vector * getDependencies(void)
char * getPropertyString(const char *)
void logprint(int level, const char *format,...)
strlist * getDependencies(void)
#define PROP_NO_SUBSTRATE
void setFile(const char *)
qucs::matrix shrinkSParaMatrix(qucs::matrix)