MATLAB Answers

Plotting a 3d plot using multiple for loops: using s parameter matrix (Z_PARAMS must not be NaN)

3 views (last 30 days)
Adam Bickerdike
Adam Bickerdike on 21 Feb 2021
Answered: Alan Moses on 24 Feb 2021
Hi all
I am wanting to plot a 3d graph , it will be S21 magnitude vs Frequency vs Distance. I have created a for loop that plots s21 against frequency, and I can plot that as a 2d plot at different distances. I write out a Z matrix and use the function z2s to convert to the s matrix. But when I implement the for loop for the distance variable (d) I recieve the error messages:
Error using CheckNetworkData (line 44)
Z_PARAMS must not be NaN
Error in z2s (line 17)
[m, z_params] = CheckNetworkData(z_params, 'N', 'Z_PARAMS');
Error in SinglSparam (line 58)
s_params = z2s(z_params);
This is the 2d graph I can plot:
Ideally I would like to plot a 3d graph that looks something similar to this (if you were to replace k23 with distance (d)):
clc
clear all
syms d
syms w
hold on
for d = 0:1.5e-06:0.015 %distance between 0 nd 0.0015 meters (same number of loops as)
RadiusA=0.006;
RadiusB=0.006;
NA=2;
NB=10;
doutA=0.013;
dinA=2*RadiusA;
doutB=0.016;
dinB=2*RadiusB;
DavgA=(doutA+dinA)/2;
DavgB=(doutB+dinB)/2;
pA=(doutA-dinA)/(doutA+dinA);
pB=(doutB-dinB)/(doutB+dinB);
LB=0.5*1.25663706E-06*NA^2*DavgA*(log(2.46/pA)+0.2*pA^2)
LA=0.5*1.25663706E-06*NB^2*DavgB*(log(2.46/pB)+0.2*pB^2)
m=(4*RadiusA*RadiusB)/((RadiusA+RadiusB)^2+d^2);
[K,E] = ellipke(m);
M = NA*NB*4*pi*0.0000001*(sqrt(RadiusA.*RadiusB)/sqrt(m))*((2-m)*K-2.*E)
KfactorCalc = M/sqrt(LA*LB);
RS = 5
RL = 5
R1 = 0.01
R2 = 0.001
C1 = 54.85e-12
C2 = 1.064e-09
t = 0
for i = 0:1e04:100e06 %frequency (0 and 100Mhz)
for w = i*2*pi %converting to w
t=t+1 %counter to count the number of times the for loop has repeated
Z11 = R1+1i*w*LA + (1/(1i*w*C1)) +RS;
Z12 = 1i*w*M;
Z21 =1i*w*M;
Z22 = R2+1i*w*LB + 1/(1/RL+1i*w*C2);
z_params = [Z11,Z12; Z21,Z22];
s_params = z2s(z_params);
y(t)= abs(s_params(2,1)); %creating an array
x = 1:t;
end
end
plot3(x,y,d);
ylim([0 1]);
xlim([1000 2000]);
title('S21 vs Frequency');
xlabel('Frequency (kHz))');
ylabel('S21 Magnitude');
end

Answers (1)

Alan Moses
Alan Moses on 24 Feb 2021
The error occurs because there is a multiplication of zero and infinity happening which causes a NaN to be input to the z2s function. You may need to handle some boundary conditions to ensure that NaN is not input to z2s function.
You may also refer here to add breakpoints to debug your code.

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!