File: ApplyCurrent2Port.m

package info (click to toggle)
openems 0.0.35%2Bgit20190103.6a75e98%2Bdfsg.1-3.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,544 kB
  • sloc: cpp: 40,417; python: 2,028; yacc: 580; makefile: 459; lex: 350; sh: 176; ruby: 19
file content (69 lines) | stat: -rw-r--r-- 1,705 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function [I_port I_orig_port] = ApplyCurrent2Port(net, port, current, varargin)
% function I_port = ApplyCurrent2Port(net, port, current, varargin)
%
%   Apply a total current to a given port of your network
%
% arguments:
%   port:           number of ports to apply the power to
%   current:        applied total current
%
% output:
%   I_port:         Total currents going into the ports
%
% See also: InitNetwork, SetPortTermination, AddElement2Port,
% ApplyRFPower2Port
%
% ------
% Cuicuit Toolbox (https://github.com/thliebig/CTB)
% (c) Thorsten Liebig, 2013

if (numel(port)>1)
    I_port = zeros(net.numPorts,net.numFreq);
    I_orig_port = zeros(net.numPorts,net.numFreq);
    for n=1:numel(port)
        [I_p I_op] = ApplyCurrent2Port(net, port(n), current(n), varargin{:});
        I_port = I_port + I_p;
        I_orig_port = I_orig_port + I_op;
    end
    return
end

if ((port<1) || (port>net.numPorts))
    error 'invalid port number'
end

if (numel(current)==1)
    current = current*ones(size(net.f))
end

if (numel(net.Z0)==1)
    Z0 = net.Z0*ones(net.numPorts,1);
else
    Z0 = net.Z0;
end

z_term = net.z;
for n=1:net.numPorts
    z_term(n,n,:) = z_term(n,n,:) + Z0(n);
end

z_mat = z_term;
z_mat(port,:,:) = [];
z_mat(:,port,:) = [];

port_other = 1:net.numPorts;
port_other(port) = [];

I_port(port,:) = current;

for fn = 1:numel(net.f)
    z_port_vec = -1*squeeze(z_term(port_other,port,fn));
    I_port(port_other,fn) = squeeze(z_mat(:,:,fn))\z_port_vec * current(fn);
end

I_orig_port=I_port*0;
for n=1:net.numPorts
    C = reshape(net.ABCD{n}(2,1,:),1,numel(net.f));
    D = reshape(net.ABCD{n}(2,2,:),1,numel(net.f));
    I_orig_port(n,:) = (Z0(n)*C + D) .* I_port(n,:);
end