]> Creatis software - CreaPhase.git/blob - octave_packages/ocs-0.1.3/sbn/Mcurrentsources.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / ocs-0.1.3 / sbn / Mcurrentsources.m
1 ## Copyright (C) 2006,2007,2008  Carlo de Falco, Culpo Massimiliano
2 ##
3 ## This file is part of:
4 ## OCS - A Circuit Simulator for Octave
5 ##
6 ## OCS 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.
9 ##
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program (see the file LICENSE); if not,
17 ## see <http://www.gnu.org/licenses/>.
18 ##
19 ## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
20 ## author culpo@math.uni-wuppertal.de
21
22 ## -*- texinfo -*-
23 ##
24 ## @deftypefn{Function File} @
25 ## {[@var{a},@var{b},@var{c}]=}Mcurrentsources(@var{string},@var{parameters},@
26 ## @var{parameternames},@var{extvar},@var{intvar},@var{t})
27 ##
28 ## SBN file implementing models for current sources.
29 ##
30 ## @var{string} is used to select among models. Parameters are listed
31 ## as inner items. Possible models are:
32 ##
33 ## @enumerate
34 ## @item @var{string} = "DC" (Static indipendent current source)
35 ## @itemize @minus
36 ## @item I -> Current source value
37 ## @end itemize
38 ## @item @var{string} = "VCCS" (Voltage controlled current source)
39 ## @itemize @minus
40 ## @item K -> Control parameter
41 ## @end itemize
42 ## @item @var{string} = "sinwave" (Sinusoidal indipendent current
43 ## source)
44 ## @itemize @minus
45 ## @item shift -> mean value of sinusoidal input
46 ## @item Ampl  -> amplitude of sinusoidal wave
47 ## @item f     -> frequency of sinusoidal wave
48 ## @item delay -> delay of sinusoidal wave
49 ## @end itemize
50 ## @item @var{string} = "VCPS" (Voltage controlled power source)
51 ## @itemize @minus
52 ## @item K -> Control parameter
53 ## @end itemize
54 ## @end enumerate
55 ##
56 ## See the @cite{IFF file format specifications} for details about 
57 ## the output structures.
58 ##
59 ## @seealso{prs_iff,asm_initialize_system,asm_build_system}
60 ## @end deftypefn
61
62 function [a,b,c] = Mcurrentsources (string,parameters,parameternames,extvar,intvar,t)  
63
64   switch string 
65     ## LCR part
66     case "DC"
67       for ii=1:length(parameternames)
68         eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])      
69       endfor
70       
71       a = zeros(2);
72       b = a;
73       c = [I -I]';
74       break
75
76     case "VCCS"
77       ## Voltage controlled current source
78       K = 1;
79       for ii=1:length(parameternames)
80         eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])      
81       endfor
82       
83       a = zeros(4);
84       b = [0  0  K -K;\
85            0  0 -K  K;\
86            0  0  0  0;\
87            0  0  0  0];
88       c = zeros(4,1);
89     ## NLC part
90     case "sinwave"
91       for ii=1:length(parameternames)
92         eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])      
93       endfor
94       
95       I = shift+Ampl * sin(2*pi*(t+delay)*f );
96       a = zeros(2);
97       b = a;
98       c = [I -I]';
99       break
100       
101     case "VCPS"
102       ## Voltage controlled power source
103       K = 1;
104       for ii=1:length(parameternames)
105         eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])      
106       endfor
107
108       dv   = extvar(3) - extvar(4);
109       I    = K*(dv^2);
110       dIdv = 2*K*dv;
111       
112       a = zeros(4);
113       b = [0  0  dIdv -dIdv;\
114            0  0 -dIdv  dIdv;\
115            0  0     0     0;\
116            0  0     0     0];
117       c = [I -I 0 0];
118
119     otherwise
120       error (["unknown section:" string])
121   endswitch
122
123 endfunction