how can I do a 3D plot for S-parameter based on S21, Frequency and Distance?
4 views (last 30 days)
Show older comments
Hello all,
I have 30 S21 measurments between two seperate anttennas. the disrance between two antenna is D. Now I wannt do a 3D plot for this expriment. Z axis equal to s21, x axis equals to distance and y axis equals to frequency. here is my code but it returns errors aboud dimension.
numfiles = 42;
filename = "D_"+(12:numfiles)+".s2p";
S = sparameters(filename(1));
D = [12:1:42];
freq = S.Frequencies;
numfreq = numel(freq);
s21_data = zeros(numfreq,numfiles);
% Read Touchstone files
for n = 1: (numfiles - 12);
S = sparameters(filename(n));
s21 = rfparam(S,2,1);
s21_data(:,n) = s21;
txt{n}= sprintf('D %i',n+12);
end
s21_db = 20*log10(abs(s21_data));
[D,freq]=meshgrid (D,freq);
mesh(D,freq,s21_db);
axis on;
grid on
0 Comments
Answers (1)
Abhinaya Kennedy
on 5 Jun 2024
Hi Peyman,
"meshgrid" creates two-dimensional grids from one-dimensional inputs. However, your "s21_db" data has three dimensions (frequency, distance, and amplitude). Here's how you can fix your code for a 3D plot:
% Read Touchstone files
for n = 1: (numfiles - 12);
S = sparameters(filename(n));
s21 = rfparam(S,2,1);
s21_data(:,n) = s21;
txt{n}= sprintf('D %i',n+12);
end
s21_db = 20*log10(abs(s21_data));
% No need for meshgrid, use surf for 3D surface plot
surf(D, freq, s21_db);
axis on;
grid on;
xlabel('Distance (D)');
ylabel('Frequency (Hz)');
zlabel('S21 (dB)');
title('S21 vs. Distance and Frequency');
We don't need "meshgrid" as "surf" can handle 3D data directly. This code will create a 3D surface plot with distance (D) on the x-axis, frequency on the y-axis, and S21 in dB on the z-axis.
You can look into this link for more information on "surf": https://www.mathworks.com/help/matlab/ref/surf.html
0 Comments
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!