Hello Martin,
To efficiently store and interpolate a computed pattern, you can follow these steps:
- Store the computed pattern in a variable, let us say "patternData", which is an 181x181 matrix representing the directivity pattern.
- Create a grid of azimuth and elevation values using the "meshgrid" function. Since the "pattern" function returns the pattern in AZ/EL order, you need to transpose the grid to match the pattern dimensions.
- Create a "griddedInterpolant" object using the "griddedInterpolant" function. Specify the 'linear' interpolation method for smooth interpolation.
- Query the interpolated pattern at any desired azimuth and elevation values using the "griddedInterpolant" object.
Here is an example:
patternData = peaks(181);
az = linspace(-180, 180, 181);
el = linspace(0, 90, 181);
[azGrid, elGrid] = meshgrid(az, el);
patternInterp = griddedInterpolant(azGrid', elGrid', patternData', 'linear');
interpValue = patternInterp(queryAz, queryEl);
disp(['Interpolated gain value at AZ=45° and EL=30°: ', num2str(interpValue)]);
Interpolated gain value at AZ=45° and EL=30°: 2.4518
You can visualize "patternData", the interpolated value, and the actual value in the "patternData" as follows:
surf(az, el, patternData');
[~, azIndex] = min(abs(az - queryAz));
[~, elIndex] = min(abs(el - queryEl));
plot3(azPlot, elPlot, interpValue, 'ro', 'MarkerSize', 10, 'LineWidth', 2);
plot3(azPlot, elPlot, patternData(elIndex, azIndex), 'kx', 'MarkerSize', 10, 'LineWidth', 2);
title('Peaks Function with Query Point Marked');
xlabel('Azimuth (degrees)');
ylabel('Elevation (degrees)');
legend('Peaks Surface', 'Interpolated Value', 'Actual Value', 'Location', 'Best');
disp(['Interpolated gain value at AZ=-45° and EL=30°: ', num2str(interpValue)]);
Interpolated gain value at AZ=-45° and EL=30°: 2.4518
disp(['Actual gain value from patternData at AZ=-45° and EL=30°: ', num2str(patternData(elIndex, azIndex))]);
Actual gain value from patternData at AZ=-45° and EL=30°: 2.4344
For detailed information about the "meshgrid" function and "griddedInterpolant", please refer to the following documentations:
I hope this helps!