summaryrefslogtreecommitdiff
path: root/CTB/z2s.m
diff options
context:
space:
mode:
Diffstat (limited to 'CTB/z2s.m')
-rw-r--r--CTB/z2s.m44
1 files changed, 44 insertions, 0 deletions
diff --git a/CTB/z2s.m b/CTB/z2s.m
new file mode 100644
index 0000000..9f2e165
--- /dev/null
+++ b/CTB/z2s.m
@@ -0,0 +1,44 @@
+function s = z2s(z,ref)
+% s = z2s(z [,ref])
+%
+% Z-matrix to scattering transformation
+%
+% input:
+% z: Z-matrix matrix nxnxf (f: number of frequencies)
+% ref: (optional) reference impedance (default 50 Ohm)
+%
+% output:
+% s: S-matrix nxnxf
+%
+% Reference: http://qucs.sourceforge.net/tech/node98.html
+%
+% Thorsten Liebig <thorsten.liebig@gmx.de>
+% Feb. 2013
+
+if nargin < 2
+ Z0 = 50;
+else
+ Z0 = ref;
+end
+
+N = size(z,1);
+Nf = size(z,3);
+
+if (numel(Z0)==1)
+ Z0 = Z0*ones(N,1);
+end
+
+E = eye(N);
+Zref = zeros(N,N);
+G = Zref;
+
+for n=1:N
+ Zref(n,n) = Z0(n);
+ G(n,n) = 1/sqrt(real(Z0(n)));
+end
+
+s=zeros(N,N,Nf); %preallocate
+
+for f=1:Nf
+ s(:,:,f) = G*(z(:,:,f)-Zref)/(z(:,:,f)+Zref)/G;
+end