My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
vvnoise.cpp
Go to the documentation of this file.
1 /*
2  * vvnoise.cpp - correlated noise voltage sources class implementation
3  *
4  * Copyright (C) 2005, 2008 Stefan Jahn <stefan@lkcc.org>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this package; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * $Id: vvnoise.cpp 1825 2011-03-11 20:42:14Z ela $
22  *
23  */
24 
25 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include "component.h"
30 #include "vvnoise.h"
31 
32 #define NODE_V1P 0
33 #define NODE_V1N 3
34 #define NODE_V2P 1
35 #define NODE_V2N 2
36 
37 vvnoise::vvnoise () : circuit (4) {
38  type = CIR_VVNOISE;
39  setVoltageSources (2);
40 }
41 
42 void vvnoise::initSP (void) {
43  allocMatrixS ();
44  setS (NODE_V1P, NODE_V1N, 1.0);
45  setS (NODE_V1N, NODE_V1P, 1.0);
46  setS (NODE_V2P, NODE_V2N, 1.0);
47  setS (NODE_V2N, NODE_V2P, 1.0);
48 }
49 
50 void vvnoise::calcNoiseSP (nr_double_t frequency) {
51  nr_double_t C = getPropertyDouble ("C");
52  nr_double_t e = getPropertyDouble ("e");
53  nr_double_t c = getPropertyDouble ("c");
54  nr_double_t a = getPropertyDouble ("a");
55  nr_double_t k = a + c * pow (frequency, e);
56  nr_double_t u1 = getPropertyDouble ("v1") / k / kB / T0 / 4 / z0;
57  nr_double_t u2 = getPropertyDouble ("v2") / k / kB / T0 / 4 / z0;
58  nr_double_t cu = C * sqrt (u1 * u2);
59 
60  // entries of source 1
61  setN (NODE_V1P, NODE_V1P, +u1); setN (NODE_V1N, NODE_V1N, +u1);
62  setN (NODE_V1P, NODE_V1N, -u1); setN (NODE_V1N, NODE_V1P, -u1);
63  // entries of source 2
64  setN (NODE_V2P, NODE_V2P, +u2); setN (NODE_V2N, NODE_V2N, +u2);
65  setN (NODE_V2P, NODE_V2N, -u2); setN (NODE_V2N, NODE_V2P, -u2);
66  // correlation entries
67  setN (NODE_V1P, NODE_V2P, +cu); setN (NODE_V1N, NODE_V2N, +cu);
68  setN (NODE_V1P, NODE_V2N, -cu); setN (NODE_V1N, NODE_V2P, -cu);
69  setN (NODE_V2P, NODE_V1P, +cu); setN (NODE_V2N, NODE_V1N, +cu);
70  setN (NODE_V2P, NODE_V1N, -cu); setN (NODE_V2N, NODE_V1P, -cu);
71 }
72 
73 void vvnoise::initDC (void) {
74  allocMatrixMNA ();
77 }
78 
79 void vvnoise::initTR (void) {
80  initDC ();
81 }
82 
83 void vvnoise::initAC (void) {
84  initDC ();
85 }
86 
87 void vvnoise::calcNoiseAC (nr_double_t frequency) {
88  nr_double_t C = getPropertyDouble ("C");
89  nr_double_t e = getPropertyDouble ("e");
90  nr_double_t c = getPropertyDouble ("c");
91  nr_double_t a = getPropertyDouble ("a");
92  nr_double_t k = a + c * pow (frequency, e);
93  nr_double_t u1 = getPropertyDouble ("v1") / k / kB / T0;
94  nr_double_t u2 = getPropertyDouble ("v2") / k / kB / T0;
95  nr_double_t cu = C * sqrt (u1 * u2);
96  setN (NODE_5, NODE_5, u1); setN (NODE_6, NODE_6, u2);
97  setN (NODE_5, NODE_6, cu); setN (NODE_6, NODE_5, cu);
98 }
99 
100 // properties
101 PROP_REQ [] = {
102  { "v1", PROP_REAL, { 1e-6, PROP_NO_STR }, PROP_POS_RANGE },
103  { "v2", PROP_REAL, { 1e-6, PROP_NO_STR }, PROP_POS_RANGE },
104  { "C", PROP_REAL, { 0.5, PROP_NO_STR }, PROP_RNGII (-1, 1) },
105  PROP_NO_PROP };
106 PROP_OPT [] = {
107  { "a", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
108  { "c", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGE },
109  { "e", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
110  PROP_NO_PROP };
111 struct define_t vvnoise::cirdef =