# Using antenna magnitude data to plot max gain vs frequency

11 views (last 30 days)
Samantha Plesce on 20 Oct 2021
Edited: Abhimenyu on 23 Apr 2024
I have a set of antenna data which contains a frequency array, azimuth array, and a matrix of magnitude values; see attached photo for how data is arranged. (I have already read in these data sets from an excel file and placed them into their designated arrays/matrix).
I need to plot max gain vs. frequency from this data without using the antenna tool box. Does anyone know the matlab code to calculate antenna gain from frequency, azimuth, and magnitude?

Abhimenyu on 21 Apr 2024
Edited: Abhimenyu on 23 Apr 2024
Hi Samantha,
From the information shared, I could infer that you want to plot maximum gain versus frequency from the antenna magnitude data. As shown in the attached image, frequency is a 1-D array and magnitude is a 2-D matrix where each column corresponds to a frequency. To plot maximum gain versus frequency, the first step would be to convert the magnitude values to decibels, then use MATLAB's "max" function on every column to find maximum gain at each frequency and finally using the "plot" function to visualise the plot required.
Please follow the below-mentioned example MATLAB code to plot max gain versus frequency:
% Generating fake data for demonstration
frequency = linspace(1e9, 10e9, 100); % Frequency array (1 GHz to 10 GHz)
azimuth = linspace(0, 360, 36); % Azimuth array (0° to 360°)
magnitude = rand(size(azimuth, 2), size(frequency, 2)) * 20; % Random magnitude values (between 0 and 20)
% Convert magnitude to dB
gainInDB = 10 * log10(magnitude);
% Calculate max gain for each frequency
maxGain = max(gainInDB, [], 1);
% Plot max gain vs. frequency
figure;
plot(frequency, maxGain, 'b', 'LineWidth', 2);
xlabel('Frequency (Hz)');
ylabel('Max Gain (dB)');
title('Max Gain vs Frequency');
grid on;
I hope this helps!