JUK1
CPPVectFitAdaptor.m
Go to the documentation of this file.
1 function [S, z_ref, numPorts] = CPPVectFitAdaptor( filePath, N, Niter )
2  if nargin < 3 || isempty(Niter)
3  Niter = 5;
4  if nargin < 2 || isempty(N)
5  N = 100;
6  end
7  end
8  s2p = sparameters( filePath );
9 
10  freqSamples = s2p.Frequencies / 1e9;
11  Ns = length( freqSamples );
12  z_ref = s2p.Impedance;
13  numPorts = s2p.NumPorts;
14 
15  freqSamplesLong = [ freqSamples; (freqSamples(end) + freqSamples(2:end-1))];
16  freqSamplesLong = [ freqSamplesLong; (freqSamplesLong(end) + freqSamplesLong(2:end-1))];
17  freqSamplesLong = [ freqSamplesLong; (freqSamplesLong(end) + freqSamplesLong(2:end-1))];
18  freqSamplesLong = [ freqSamplesLong; (freqSamplesLong(end) + freqSamplesLong(2:end-1))];
19  freqSamplesLong = [ freqSamplesLong; (freqSamplesLong(end) + freqSamplesLong(2:end-1)); 100000];
20 
21 
22  fitData = struct("poles", {}, "residues", {}, "remainder", {});
23  S = repmat( fitData, s2p.NumPorts, s2p.NumPorts );
24 
25 
26  %Complex starting poles :
27  bet=linspace(2*pi*freqSamples(1),2*pi*freqSamples(Ns),N/2);
28 
29 
30  opts.relax=0; %Use vector fitting with relaxed non-triviality constraint
31  opts.stable=1; %Enforce stable poles
32  opts.asymp=2; %Include D in fitting
33  opts.skip_pole=0; %Do NOT skip pole identification
34  opts.skip_res=0; %DO NOT skip identification of residues (C,D,E)
35  opts.cmplx_ss=1; %Create real-only state space model
36 
37  opts.spy1=0; %No plotting for first stage of vector fitting
38  opts.spy2=0; %Create magnitude plot for fitting of f(s)
39  opts.logx=0; %Use linear abscissa axis
40  opts.logy=0; %Use logarithmic ordinate axis
41  opts.errplot=1; %Include deviation in magnitude plot
42  opts.phaseplot=0; %Do NOT produce plot of phase angle
43  opts.legend=1; %Include legends in plots
44 
45 
46 
47  % Find a complex rational model for freq domain data
48  for a = 1 : 1 : s2p.NumPorts
49  for b = 1 : 1 : s2p.NumPorts
50  poles=[];
51  for n=1:length(bet)
52  alf=-bet(n)*1e-2;
53  poles = [poles (alf-1j*bet(n)) (alf+1j*bet(n)) ];
54  end
55 
56  posData = squeeze(s2p.Parameters( a, b, : ));
57  t3 = 2*pi*1j*freqSamples.';%[freqSamples; (freqSamples(end) + freqSamples(2:end-1) ) ];
58  t4 = posData.';%[posData; flip(conj(posData(2:end-1))) ];
59 
60 
61  for iter=1:Niter
62  [SER,poles,rmserr,fit,opts] = vectfit3( t4, t3, poles, ones(1,Ns), opts );
63  end
64  S(a, b).poles = complex(poles);
65  S(a, b).residues = complex(SER.C);
66  S(a, b).remainder = complex(SER.D);
67  disp(rmserr);
68 
69  Dk=zeros(length(freqSamplesLong),N);
70  for m=1:N
71  Dk(:,m)=1./(2*pi*1j*freqSamplesLong-S(a, b).poles(m));
72  end
73  fitlonger = (Dk*S(a, b).residues.').' + S(a, b).remainder;
74 
75 
76 
77  if ( max( abs(fitlonger) ) > 1 )
78  close all;
79  [S, z_ref, numPorts] = CPPVectFitAdaptor( filePath, N-2 );
80  return;
81  end
82  if ( max( abs( S(a, b).residues ) ) > 1000 )
83  disp( "Large residue warning" );
84  end
85 
86  figure();
87  plot(freqSamples, abs(t4)); hold on; plot(freqSamplesLong, abs(fitlonger) ); hold off;
88 
89  filepath = sprintf("S(%d,%d).txt",a,b);
90  dlmwrite(filepath, [freqSamplesLong(1:floor(length(freqSamplesLong)/2)), abs(fitlonger(1:floor(length(freqSamplesLong)/2)).')],'delimiter',' ','precision','%20.12f')
91  end
92  end
93  fprintf( "%d poles", N );
94  S = S.';
95 end
pi
Definition: Freq.m:24
dlmwrite("fftoutput.txt", [freqSequence(idxLower:idxUpper).', dbm1(idxLower:idxUpper), dbm2(idxLower:idxUpper), dbmi(idxLower:idxUpper)], 'delimiter',' ', 'precision','%20.12f')
PURPOSE j at all freq
Definition: QPpassive.m:44
PURPOSE j D
Definition: QPpassive.m:30
PURPOSE j m
Definition: QPpassive.m:21
plot(d.time, d.(nodeNum))
hold on
Definition: comp.m:11
hold off
Definition: comp.m:12
end figure()
Undo scaling of outgoing poles
Undo scaling of outgoing residues
Turn this into a with identical frequencies along the rows s
fitData
freqSamples
Find a complex rational model for freq domain data for a
posData(end)
b
Definition: getResidues.m:47
for j
Definition: interch.m:13
end if abs(real(dotprod))>rstoerst rstoerst
disp("done")