1 function [S, z_ref, numPorts] = CPPVectFitAdaptor( filePath, N, Niter )
2 if nargin < 3 || isempty(Niter)
4 if nargin < 2 || isempty(N)
8 s2p = sparameters( filePath );
12 z_ref = s2p.Impedance;
13 numPorts = s2p.NumPorts;
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];
22 fitData =
struct(
"poles", {},
"residues", {},
"remainder", {});
23 S = repmat(
fitData, s2p.NumPorts, s2p.NumPorts );
26 %Complex starting
poles :
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
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
47 % Find
a complex rational model
for freq domain data
48 for a = 1 : 1 : s2p.NumPorts
49 for b = 1 : 1 : s2p.NumPorts
53 poles = [poles (alf-1j*bet(n)) (alf+1j*bet(n)) ];
56 posData = squeeze(s2p.Parameters(
a,
b, : ));
57 t3 = 2*
pi*1
j*
freqSamples.
';%[freqSamples; (freqSamples(end) + freqSamples(2:end-1) ) ];
58 t4 = posData.';%[posData; flip(conj(posData(2:end-1))) ];
62 [SER,poles,rmserr,fit,opts] = vectfit3( t4, t3,
poles, ones(1,Ns), opts );
65 S(
a,
b).residues = complex(SER.C);
66 S(
a,
b).remainder = complex(SER.D);
69 Dk=zeros(length(freqSamplesLong),N);
77 if ( max(
abs(fitlonger) ) > 1 )
79 [S, z_ref, numPorts] = CPPVectFitAdaptor( filePath, N-2 );
83 disp(
"Large residue warning" );
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
')
93 fprintf( "%d poles", N );
dlmwrite("fftoutput.txt", [freqSequence(idxLower:idxUpper).', dbm1(idxLower:idxUpper), dbm2(idxLower:idxUpper), dbmi(idxLower:idxUpper)], 'delimiter',' ', 'precision','%20.12f')
plot(d.time, d.(nodeNum))
Undo scaling of outgoing poles
Undo scaling of outgoing residues
Turn this into a with identical frequencies along the rows s
Find a complex rational model for freq domain data for a
end if abs(real(dotprod))>rstoerst rstoerst