LCOV - code coverage report
Current view: top level - src/components - ivnoise.cpp (source / functions) Hit Total Coverage
Test: qucs-core-0.0.19 Code Coverage Lines: 0 54 0.0 %
Date: 2015-01-05 16:01:02 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 58 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * ivnoise.cpp - correlated noise 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$
      22                 :            :  *
      23                 :            :  */
      24                 :            : 
      25                 :            : #if HAVE_CONFIG_H
      26                 :            : # include <config.h>
      27                 :            : #endif
      28                 :            : 
      29                 :            : #include "component.h"
      30                 :            : #include "ivnoise.h"
      31                 :            : 
      32                 :            : #define NODE_I1P 0
      33                 :            : #define NODE_I1N 3
      34                 :            : #define NODE_V2P 1
      35                 :            : #define NODE_V2N 2
      36                 :            : 
      37                 :            : using namespace qucs;
      38                 :            : 
      39                 :          0 : ivnoise::ivnoise () : circuit (4) {
      40                 :          0 :   type = CIR_IVNOISE;
      41   [ #  #  #  # ]:          0 :   setVoltageSources (1);
      42                 :          0 : }
      43                 :            : 
      44                 :          0 : void ivnoise::initSP (void) {
      45                 :          0 :   allocMatrixS ();
      46         [ #  # ]:          0 :   setS (NODE_I1P, NODE_I1P, 1.0);
      47         [ #  # ]:          0 :   setS (NODE_I1N, NODE_I1N, 1.0);
      48         [ #  # ]:          0 :   setS (NODE_V2P, NODE_V2N, 1.0);
      49         [ #  # ]:          0 :   setS (NODE_V2N, NODE_V2P, 1.0);
      50                 :          0 : }
      51                 :            : 
      52                 :          0 : void ivnoise::calcNoiseSP (nr_double_t frequency) {
      53                 :          0 :   nr_double_t C = getPropertyDouble ("C");
      54                 :          0 :   nr_double_t e = getPropertyDouble ("e");
      55                 :          0 :   nr_double_t c = getPropertyDouble ("c");
      56                 :          0 :   nr_double_t a = getPropertyDouble ("a");
      57                 :          0 :   nr_double_t k = a + c * qucs::pow (frequency, e);
      58                 :          0 :   nr_double_t i1 = getPropertyDouble ("i1") / k / kB / T0;
      59                 :          0 :   nr_double_t u2 = getPropertyDouble ("v2") / k / kB / T0;
      60                 :          0 :   nr_double_t ci = C * std::sqrt (i1 * u2) / 2;
      61                 :            : 
      62                 :            :   // entries of source 1
      63 [ #  # ][ #  # ]:          0 :   setN (NODE_I1P, NODE_I1P, +i1 * z0); setN (NODE_I1N, NODE_I1N, +i1 * z0);
      64 [ #  # ][ #  # ]:          0 :   setN (NODE_I1P, NODE_I1N, -i1 * z0); setN (NODE_I1N, NODE_I1P, -i1 * z0);
      65                 :            :   // entries of source 2
      66 [ #  # ][ #  # ]:          0 :   setN (NODE_V2P, NODE_V2P, +u2 /4/z0); setN (NODE_V2N, NODE_V2N, +u2 /4/z0);
      67 [ #  # ][ #  # ]:          0 :   setN (NODE_V2P, NODE_V2N, -u2 /4/z0); setN (NODE_V2N, NODE_V2P, -u2 /4/z0);
      68                 :            :   // correlation entries
      69 [ #  # ][ #  # ]:          0 :   setN (NODE_I1P, NODE_V2P, +ci); setN (NODE_I1N, NODE_V2N, +ci);
      70 [ #  # ][ #  # ]:          0 :   setN (NODE_I1P, NODE_V2N, -ci); setN (NODE_I1N, NODE_V2P, -ci);
      71 [ #  # ][ #  # ]:          0 :   setN (NODE_V2P, NODE_I1P, +ci); setN (NODE_V2N, NODE_I1N, +ci);
      72 [ #  # ][ #  # ]:          0 :   setN (NODE_V2P, NODE_I1N, -ci); setN (NODE_V2N, NODE_I1P, -ci);
      73                 :          0 : }
      74                 :            : 
      75                 :          0 : void ivnoise::initDC (void) {
      76                 :          0 :   allocMatrixMNA ();
      77                 :          0 :   voltageSource (VSRC_1, NODE_V2P, NODE_V2N);
      78                 :          0 : }
      79                 :            : 
      80                 :          0 : void ivnoise::initAC (void) {
      81                 :          0 :   initDC ();
      82                 :          0 : }
      83                 :            : 
      84                 :          0 : void ivnoise::initTR (void) {
      85                 :          0 :   initDC ();
      86                 :          0 : }
      87                 :            : 
      88                 :          0 : void ivnoise::calcNoiseAC (nr_double_t frequency) {
      89                 :          0 :   nr_double_t C = getPropertyDouble ("C");
      90                 :          0 :   nr_double_t e = getPropertyDouble ("e");
      91                 :          0 :   nr_double_t c = getPropertyDouble ("c");
      92                 :          0 :   nr_double_t a = getPropertyDouble ("a");
      93                 :          0 :   nr_double_t k = a + c * qucs::pow (frequency, e);
      94                 :          0 :   nr_double_t i1 = getPropertyDouble ("i1") / k / kB / T0;
      95                 :          0 :   nr_double_t u2 = getPropertyDouble ("v2") / k / kB / T0;
      96                 :          0 :   nr_double_t ci = C * std::sqrt (i1 * u2);
      97 [ #  # ][ #  # ]:          0 :   setN (NODE_I1P, NODE_I1P, +i1); setN (NODE_I1N, NODE_I1N, +i1);
      98 [ #  # ][ #  # ]:          0 :   setN (NODE_I1P, NODE_I1N, -i1); setN (NODE_I1N, NODE_I1P, -i1);
      99         [ #  # ]:          0 :   setN (NODE_5, NODE_I1P, ci);
     100         [ #  # ]:          0 :   setN (NODE_I1P, NODE_5, ci);
     101         [ #  # ]:          0 :   setN (NODE_5, NODE_5, u2);
     102                 :          0 : }
     103                 :            : 
     104                 :            : // properties
     105                 :            : PROP_REQ [] = {
     106                 :            :   { "i1", PROP_REAL, { 1e-6, PROP_NO_STR }, PROP_POS_RANGE },
     107                 :            :   { "v2", PROP_REAL, { 1e-6, PROP_NO_STR }, PROP_POS_RANGE },
     108                 :            :   { "C", PROP_REAL, { 0.5, PROP_NO_STR }, PROP_RNGII (-1, 1) },
     109                 :            :   PROP_NO_PROP };
     110                 :            : PROP_OPT [] = {
     111                 :            :   { "a", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
     112                 :            :   { "c", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGE },
     113                 :            :   { "e", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
     114                 :            :   PROP_NO_PROP };
     115                 :            : struct define_t ivnoise::cirdef =
     116                 :            :   { "IVnoise", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };

Generated by: LCOV version 1.11