1 ## Copyright (C) 2006,2007,2008 Carlo de Falco
3 ## This file is part of:
4 ## OCS - A Circuit Simulator for Octave
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.
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.
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/>.
19 ## author: Carlo de Falco <cdf _AT_ users.sourceforge.net>
23 ## @deftypefn{Function File} @
24 ## {[@var{a},@var{b},@var{c}]=} Mvoltagesources(@var{string},@var{parameters},@
25 ## @var{parameternames},@var{extvar},@var{intvar},@var{t})
27 ## SBN file implementing models for voltage sources.
29 ## @var{string} is used to select among models. Parameters are listed
30 ## as inner items. Possible models are:
33 ## @item @var{string} = "DC" (Static indipendent voltage source)
35 ## @item V -> Current source value
37 ## @item @var{string} = "sinwave" (Sinusoidal indipendent voltage
40 ## @item shift -> mean value of sinusoidal input
41 ## @item Ampl -> amplitude of sinusoidal wave
42 ## @item f -> frequency of sinusoidal wave
43 ## @item delay -> delay of sinusoidal wave
45 ## @item @var{string} = "pwl" (Piecewise linear voltage source)
47 ## @item takes as parameter times and values. For example @code{0 1 4 6}
48 ## means at time instant 0 value 1, at time instant 4 value 6, etc.
50 ## @item @var{string} = "squarewave" (Square wave)
52 ## @item low -> low-state value
53 ## @item high -> high-state value
54 ## @item tlow -> duration of low-state
55 ## @item thigh -> duration of high-state
56 ## @item delay -> delay of square wave
57 ## @item start -> starting voltage value
59 ## @item @var{string} = "step" (Voltage step)
61 ## @item low -> low-state value
62 ## @item high -> high-state value
63 ## @item tstep -> time instant of step transition
65 ## @item @var{string} = "VCVS" (Voltage controlled voltage source)
67 ## @item K -> Control parameter
71 ## See the @cite{IFF file format specifications} for details about
72 ## the output structures.
74 ## @seealso{prs_iff,asm_initialize_system,asm_build_system}
77 function [a,b,c] = Mvoltagesources (string,parameters,parameternames,extvar,intvar,t)
86 for ii=1:length(parameternames)
87 eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])
93 b = [0 0 1;0 0 -1;1 -1 0];
98 for ii=1:length(parameternames)
99 eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])
102 DV = shift+Ampl * sin(2*pi*(t+delay)*f );
106 b = [0 0 1;0 0 -1;1 -1 0];
107 c = [0 0 -DV]' + b * [extvar;intvar];
112 times = parameters(1:2:end-1);
113 values= parameters(2:2:end);
115 DV = interp1(times,values,t,"linear","extrap");
119 b = [0 0 1;0 0 -1;1 -1 0];
120 c = [0 0 -DV]' + b * [extvar;intvar];
124 for ii=1:length(parameternames)
125 eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])
145 b = [0 0 1;0 0 -1;1 -1 0];
146 c = [0 0 -DV]' + b * [extvar;intvar];
150 for ii=1:length(parameternames)
151 eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])
163 b = [0 0 1;0 0 -1;1 -1 0];
164 c = [0 0 -DV]' + b * [extvar;intvar];
169 for ii=1:length(parameternames)
170 eval([parameternames{ii} "=" num2str(parameters(ii)) ";"])
176 b = [0 0 0 0 1;0 0 0 0 -1;0 0 0 0 0;0 0 0 0 0;1 -1 -K K 0];
180 error (["unknown section:" string])