How to Generate a 3D Radiation Pattern Similar to Sensor Array Analyzer in MATLAB using code?

61 次查看(过去 30 天)
Hello MATLAB Community,
I am currently working on visualizing the 3D radiation pattern of an antenna array in MATLAB. I would like to generate this pattern line-by-line in a manner similar to how it is visualized in the Sensor Array Analyzer app.
Here is what I've done so far:
  • I've created the array and calculated the directivity in dBi.
  • I've plotted the Azimuth ans Elevation Pattern, and it matches the curves from the toolbox.
What I need help with:
  1. Generating the 3D pattern line-by-line: How can I replicate the line-by-line plotting approach used in Sensor Array Analyzer? Is there a specific function or technique in MATLAB that can help achieve this?
Here is a snippet of the code I am currently using:
matlab
% Example MATLAB code (simplified)
theta = linspace(0, pi, 180); %zenith angle
phi = linspace(-pi, pi, 360); % azimuth angle
[THETA, PHI] = meshgrid(theta, phi);
% Assume AF_magnitude_dBi contains calculated directivity values
X = AF_magnitude_dBi .* sin(THETA) .* cos(PHI);
Y = AF_magnitude_dBi .* sin(THETA) .* sin(PHI);
Z = AF_magnitude_dBi .* cos(THETA);
figure;
surf(X, Y, Z, 'FaceAlpha', 0.8, 'EdgeColor', 'none');
colorbar;
title('3D Radiation Pattern');
xlabel('X');
ylabel('Y');
zlabel('Z');
What modifications or additional steps should I take to generate the pattern and obtain same as in the toolbox?
Any guidance or examples would be greatly appreciated!
Thank you in advance for your help!

回答(1 个)

Abhas
Abhas 2024-9-3
Hi Thibaut,
To generate a 3D radiation pattern line-by-line in MATLAB, similar to the Sensor Array Analyzer app, you can use a combination of plotting techniques. The idea is to iterate over the azimuth and elevation angles, plotting each line individually. You can follow the below steps to do so:
  1. Iterate Over Angles: Loop through the azimuth and elevation angles to plot each line separately.
  2. Use Plot3: Instead of "surf", use "plot3" to draw lines representing the radiation pattern at each angle.
  3. Adjust Transparency and Color: Use properties like "LineWidth" and "Color" to adjust the appearance of each line.
Here's the MATLAB code to reflect the above steps:
% Example MATLAB code with assumed AF_magnitude_dBi
theta = linspace(0, pi, 180); % zenith angle
phi = linspace(-pi, pi, 360); % azimuth angle
[THETA, PHI] = meshgrid(theta, phi);
% Assume AF_magnitude_dBi as a simple cosine pattern for demonstration
AF_magnitude_dBi = 10 * abs(cos(THETA));
X = AF_magnitude_dBi .* sin(THETA) .* cos(PHI);
Y = AF_magnitude_dBi .* sin(THETA) .* sin(PHI);
Z = AF_magnitude_dBi .* cos(THETA);
figure;
hold on;
for i = 1:length(phi)
% Extract line data for a constant azimuth angle
x_line = X(i, :);
y_line = Y(i, :);
z_line = Z(i, :);
% Plot the line
plot3(x_line, y_line, z_line, 'LineWidth', 1.5, 'Color', [0, 0, 1, 0.5]); % Semi-transparent blue lines
end
% Optionally, loop through elevation angles for cross-section lines
for j = 1:length(theta)
% Extract line data for a constant elevation angle
x_line = X(:, j);
y_line = Y(:, j);
z_line = Z(:, j);
% Plot the line
plot3(x_line, y_line, z_line, 'LineWidth', 1.5, 'Color', [1, 0, 0, 0.5]); % Semi-transparent red lines
end
colorbar;
title('3D Radiation Pattern (Line-by-Line)');
xlabel('X');
ylabel('Y');
zlabel('Z');
grid on;
view(3);
hold off;
You may refer to the following MathWorks documentation links to have a better understanding on plot3 and meshgrid:
  1. https://www.mathworks.com/help/matlab/ref/plot3.html
  2. https://www.mathworks.com/help/matlab/ref/meshgrid.html
  1 个评论
thibaut
thibaut 2024-9-3
Sorry, my question was not clear!
I want to obtain exactly same plot as with Sensor Array Analyzer but using my formulas to be sure that they are correct. That's why I'm doing a toy exemple with 4 Tx antennas in YZ plane:
With same parameters (frequency, antennas position, space betwenn antennas) in Sensor Array Analyzer, I obtain almost same curves for the cuts but something complitly different for 3D pattern.
% Define your antenna array parameters and call the function
num_ant_X = 1;
num_ant_Y = 2;
num_ant_Z = 2;:
d = 0.5; % Spacing between antennas in wavelength units
c = 3.0e8;
f = 3.5e9;
lambda_0 = c / f;
steering_theta_deg = 90;
steering_phi_deg = 0;
Pattern_array_factor_3d_func(num_ant_X, num_ant_Y, num_ant_Z, lambda_0, d, deg2rad(steering_theta_deg), deg2rad(steering_phi_deg), "omni");
function Pattern_array_factor_3d_func(num_ant_X, num_ant_Y, num_ant_Z, lambda_0, distance_between_antennas_longueur_onde, steering_theta, steering_phi, pattern)
% Calculate the positions of the elements centered around the origin
x_positions = (0:num_ant_X-1) - (num_ant_X - 1) / 2;
y_positions = (0:num_ant_Y-1) - (num_ant_Y - 1) / 2;
z_positions = (0:num_ant_Z-1) - (num_ant_Z - 1) / 2;
x_positions = x_positions * distance_between_antennas_longueur_onde * lambda_0;
y_positions = y_positions * distance_between_antennas_longueur_onde * lambda_0;
z_positions = z_positions * distance_between_antennas_longueur_onde * lambda_0;
% Elevation and azimuth angles
theta = linspace(0, pi, 180);
phi = linspace(-pi, pi, 360);
[THETA, PHI] = meshgrid(theta, phi);
% Array Factor (AF) Initialization
AF = zeros(size(THETA));
% Steering vector components
Us = sin(steering_theta) * cos(steering_phi);
Vs = sin(steering_theta) * sin(steering_phi);
Ws = cos(steering_theta);
% Loop over each antenna element
for x = x_positions
for y = y_positions
for z = z_positions
W = exp(-1j * 2 * pi * (x * Us + y * Vs + z * Ws) / lambda_0);
AF = AF + W .* exp(1j * 2 * pi * (x * sin(THETA) .* cos(PHI) + y * sin(THETA) .* sin(PHI) + z * cos(THETA)) / lambda_0);
end
end
end
% Optional radiation pattern modification (3GPP pattern, etc.)
if strcmp(pattern, "38.901")
radiation_pattern = radiation_pattern_38901(THETA, PHI); % This would need to be defined
AF_global_magnitude_squared = abs(AF).^2 .* radiation_pattern;
else
AF_global_magnitude_squared = abs(AF).^2;
end
AF_global_magnitude_squared_norm = AF_global_magnitude_squared / (num_ant_X * num_ant_Y * num_ant_Z);
% Convert to dBi
AF_magnitude_dBi = 10 * log10(AF_global_magnitude_squared_norm + 0.001);
% Convert to Cartesian coordinates for 3D plot
X = (AF_magnitude_dBi) .* sin(THETA) .* cos(PHI);
Y = (AF_magnitude_dBi) .* sin(THETA) .* sin(PHI);
Z = (AF_magnitude_dBi) .* cos(THETA);
% Plot the 3D radiation pattern
figure;
surf(X, Y, Z, 'FaceAlpha', 0.6, 'EdgeColor', 'none');
colorbar;
title('3D Radiation Pattern');
xlabel('X');
ylabel('Y');
zlabel('Z');
axis equal;
% Extract 2D cut at theta = 90 degrees (elevation pattern)
target_theta = pi / 2;
[~, closest_index_theta] = min(abs(theta - target_theta));
elevation_cut_pattern = AF_magnitude_dBi(:, closest_index_theta);
figure;
polarplot(phi, elevation_cut_pattern);
rlim([min(elevation_cut_pattern) max(elevation_cut_pattern)])
title('Elevation Pattern (dBi)');
% Extract 2D cut at phi = 0 degrees (azimuth pattern)
target_phi = 0;
[~, closest_index_phi] = min(abs(phi - target_phi));
azimuth_cut_pattern = AF_magnitude_dBi(closest_index_phi, :);
figure;
polarplot(theta, azimuth_cut_pattern);
rlim([min(azimuth_cut_pattern) max(azimuth_cut_pattern)])
title('Azimuth Pattern (dBi)');
end
There is a little difference in the values, I don't know why. And for zenith cut, there is a 90° rotation because one is plotting elevation and the other zenith.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Antennas, Microphones, and Sonar Transducers 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by