3D plot of antenna factor
Show older comments
Can please someone halp me to draw a 3D plot. It should be something like: plot(THETA, PHI, AFlog); I know that I should have used a masgrid function, but I allways do it wrong. And I do not know why am I doing wrong.
clear all;
close all
dbstop if error
C=0; D=0; E=0;
Ep=0; AnI=0; JpI=0; R=0; Rn=0;
% number of elements N, wavenumber B
N = 3; %Number of elemnts in array
B = 0.14; %B =(2*pi/lambda), wavenumber
% Magnitude, Phase, X,Y,Z coordinate
An = [2 2 2]; %Magnitude of 1st, 2nd and 3rd element
Jp = [120 90 60]; %Phase of 1st, 2nd and 3rd element
Xn = [1 2 3]; % Position of 1st, 2nd and 3rd element on X-axis
Yn = [1 2 3]; % Position of 1st, 2nd and 3rd element on Y-axis
Zn = [1 2 3]; % Position of 1st, 2nd and 3rd element on Z-axis
THETA = (120*pi)/180; %120 degree of theta angle
PHI = (330*pi)/180; %330 degree of phi angle
% calculate the array factor
C = Xn.*sin(THETA).*cos(PHI);
D = Yn.*sin(THETA).*sin(PHI);
E = Zn.*cos(THETA);
Ep = B.*(C + D + E);
%convert degree into radian
JpI = (Jp.*pi)/180;
Rn = An.*exp(1i.*(Ep + JpI)); %Equation for array factor
R = sum(Rn);
AF = abs(R);
AFlog = 10 .* log (AF);
%azimut--> 0<Phi<360, elevation--> 0<Theta<180
Phi = (1:10:360)*pi/180; %azimuth
Theta = (1:10:180)*pi/180; %elevation
[THETA,PHI] = meshgrid(Theta,Phi);
%plot the array factor
figure();
mesh(THETA,PHI,AFlog); %display
surf((THETA,PHI,AFlog) %colored faces
title('Polar plot in 3D space')
xlabel('x-axis')
ylabel('y-axis')
zlabel('z-axis')
Best regards, Tadej
Answers (1)
Chandra Amma Palanisamy
2 minutes ago
The issue is that AFlog is calculated for a single pair of PHI and THETA values, resulting in a scalar, but it is later used in mesh(THETA,PHI,AFlog) where THETA and PHI are meshgrid matrices. To generate a valid 3D plot, the array factor must be computed for every point in the θ-φ grid so that AFlog has the same dimensions as THETA and PHI. Additionally, the command surf((THETA,PHI,AFlog) contains a syntax error and should be corrected to surf(THETA,PHI,AFlog). Finally, for dB, the values should typically be computed using 20*log10(abs(AF)) rather than 10*log(AF) to obtain the correct logarithmic magnitude representation.
clear all;
close all;
dbstop if error
% number of elements N, wavenumber B
N = 3; % Number of elements in array
B = 0.14; % B = 2*pi/lambda, wavenumber
% Magnitude, Phase, X,Y,Z coordinates
An = [2 2 2]; % Magnitudes of the 3 elements
Jp = [120 90 60]; % Phases of the 3 elements (degrees)
Xn = [1 2 3]; % X positions
Yn = [1 2 3]; % Y positions
Zn = [1 2 3]; % Z positions
% convert element phases to radians
JpI = deg2rad(Jp);
% ---- build the angular grid FIRST ----
% azimuth 0<Phi<360, elevation 0<Theta<180
Phi = deg2rad(1:10:360); % azimuth
Theta = deg2rad(1:10:180); % elevation
[THETA, PHI] = meshgrid(Theta, Phi); % both are numel(Phi) x numel(Theta)
% ---- accumulate the array factor OVER the grid ----
R = zeros(size(THETA)); % same size as the grid
for n = 1:N
Ep = B*( Xn(n).*sin(THETA).*cos(PHI) ...
+ Yn(n).*sin(THETA).*sin(PHI) ...
+ Zn(n).*cos(THETA) );
R = R + An(n).*exp(1i.*(Ep + JpI(n))); % sum contribution of element n
end
AF = abs(R);
AFlog = 20*log10(AF); % dB (use log10, not natural log)
% ---- plot ----
figure();
surf(THETA, PHI, AFlog); % colored faces
shading interp;
title('Array factor in 3D space');
xlabel('\theta (rad)');
ylabel('\phi (rad)');
zlabel('AF (dB)');
colorbar;

Categories
Find more on Full-Wave Analysis 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!