antenna toolbox /antenna designer /antenna array designer
MATLAB_HFSS_API、PCAAD (快速计算阵列方向图)
学个Antenna:Matlab天线工具箱知多少(一) - 知乎 (zhihu.com)
MATLAB-HFSS-API入门教程-第3讲 - 知乎 (zhihu.com)
从单元到阵列——利用MATLAB进行天线和天线阵原型设计 - MATLAB & Simulink (mathworks.cn)
MATLAB-HFSS-API工具包下载:点击code按钮 ,在下拉菜单里找到下载按钮。
yuip/hfss-api: A HFSS API to control HFSS from Matlab (github.com)
本人是MATLAB和HFSS小白,学了一段时间,今天跑通了MATLAB调用HFSS自动建模、分析、优化的程序,跟大家分享一下。
附的例子是上面连接中的examples的dipole_example ,大概思路可以概括如下:
1、创建vbs脚本文件,以文本的形式向vbs文件里写创建模型、设置边界条件、激励端口、辐射条件、仿真、结果等的代码,关闭vbs文件,
2、在MATLAB中通过system命令执行vbs脚本,运行hfss进行建模仿真,得到结果文件,
3、在MATLAB中,运行结果文件,与设置的设计要求进行比较,优化参数,重新执行1~2,直至满足要求
% Description:
% ------------
% A simple example to demonstrate the HFSS-MATLAB-API. This script
% optimizes a dipole antenna design to resonate at a specified frequency.
% The initial length of the dipole is taken to be half the wavelength and
% is optimized so that the simulated resonance frequency and the desired
% resonance frequency are close.
%
clc; clear variables; close all;
% Add paths to the required m-files.
% add manually the API root directory
% 软件路径不要有空格,因为有空格,重装了一次软件
addpath('https://www.gofarlic.com\MATLAB_excise\matlab_hfss_api\');
hfssIncludePaths('https://www.gofarlic.com\MATLAB_excise\matlab_hfss_api\');
% Antenna Parameters.
fC = 150e6; % Frequency of Interest.
Wv = 3e8/fC; % Wavelength.
L = Wv/2; % Antenna Length.
gapL = 5e-2; % Antenna Gap.
aRad = 2e-2; % Antenna Radius.
% Simulation Parameters.
fLow = 100e6;
fHigh = 200e6;
nPoints = 201;
% AirBox Parameters.
AirX = Wv/2 + L; % Include the antenna length.
AirY = Wv/2;
AirZ = Wv/2;
% Temporary Files. These files can be deleted after the optimization
% is complete. We have to specify the complete path for all of them.
% With pwd we save them in the current directory.
tmpPrjFile = [ 'https://www.gofarlic.com\MATLAB_excise\matlab_hfss_api\examples\Dipole1_\tmpDipole.aedt'];%
tmpDataFile = [ 'https://www.gofarlic.com\MATLAB_excise\matlab_hfss_api\examples\Dipole1_\tmpData.m'];%
tmpScriptFile = [ 'https://www.gofarlic.com\MATLAB_excise\matlab_hfss_api\examples\Dipole1_\dipole_example.vbs'];%vbs脚本名称
% HFSS Executable Path.
hfssExePath = 'https://www.gofarlic.com\AnsysEM\AnsysEM21.1\Win64\ansysedt.exe';
%https://www.gofarlic.com\Program Files\AnsysEM\AnsysEM21.1\Win64\reg_ansysedt.exe
% Plot Colors.
pltCols = ['b', 'r', 'k', 'g', 'm', 'c', 'y'];
nCols = length(pltCols);
% Optimization stop conditions.
maxIters = 15; % max # of iterations.
Accuracy = 0.01; % accuracy required (1%).
hasConverged = false;
fprintf('The Initial Dipole Length is %.2f meter...\n', L);
for iIters = 1:maxIters
fprintf('Running iteration #%d...\n', iIters);
disp('Creating the Script File...');
% Create a new temporary HFSS script file.
fid = fopen(tmpScriptFile, 'wt');
% Create a new HFSS Project and insert a new design.
hfssNewProject(fid);
hfssInsertDesign(fid, 'without_balun');
% Create the Dipole.依据参数创建名为‘Dipole’的偶极子天线
hfssDipole(fid, 'Dipole', 'X', [0, 0, 0], L, 2*aRad, gapL, 'meter');
% Assign PE boundary to the antenna elements.
%‘Dipole1’‘Dipole2’和上面定义的‘Dipole’相关联
%‘Antennas’是定义的‘PE’边界的名称
hfssAssignPE(fid, 'Antennas', {'Dipole1', 'Dipole2'});
% Create a Lumped Gap Source (a rectangle normal to the Y-axis)
% 创建激励端口,名为‘GapSource’
hfssRectangle(fid, 'GapSource', 'Y', [-gapL/2, 0, -aRad], 2*aRad, ...
gapL, 'meter');
hfssAssignLumpedPort(fid, 'LumpedPort', 'GapSource', ...
[-gapL/2, 0, 0], [gapL/2, 0, 0], 'meter');
% Add an AirBox.
%依据参数创建名为‘AirBox’的长方体
hfssBox(fid, 'AirBox', [-AirX, -AirY, -AirZ]/2, [AirX, AirY, AirZ], ...
'meter');
%辐射边界名为‘ABC’
hfssAssignRadiation(fid, 'ABC', 'AirBox');
% Add a Solution Setup.
hfssInsertSolution(fid, 'Setup150MHz', fC/1e9);
hfssInterpolatingSweep(fid, 'Sweep100to200MHz', 'Setup150MHz', ...
fLow/1e9, fHigh/1e9, nPoints);
% Save the project to a temporary file and solve it.
hfssSaveProject(fid, tmpPrjFile, true);
hfssSolveSetup(fid, 'Setup150MHz');
% Export the Network data as an m-file.
hfssExportNetworkData(fid, tmpDataFile, 'Setup150MHz', ...
'Sweep100to200MHz');
% Close the HFSS Script File.
fclose(fid);
% Execute the Script by starting HFSS.
disp('Solving using HFSS...');
%执行Vbs脚本,运行Ansys HFSS进行设计、仿真
%通过system函数实现的,可以跟进去仔细查看
hfssExecuteScript(hfssExePath, tmpScriptFile);
% Load the data by running the exported matlab file.
run(tmpDataFile);
%for循环,依次生成tmpData2、tmpData3、……
tmpDataFile = [pwd, '\tmpData', num2str(iIters), '.m'];
% The data items are in the f, S, Z variables now.
% Plot the data.
disp('Solution Completed. Plotting Results for this iteration...');
figure(1);
hold on; grid on;
plot(f/1e6, 20*log10(abs(S)), pltCols(mod(iIters, nCols) + 1));
hold on;
xlabel('Frequency (MHz)');
ylabel('S_{11} (dB)');
axis([fLow/1e6, fHigh/1e6, -20, 0]);
% Find the Resonance Frequency.
[Smin, iMin] = min(S);
fActual = f(iMin);
fprintf('Simulated Resonance Frequency: %.2f MHz\n', fActual/1e6);
% Check if the required accuracy is met.
if (abs((fC - fActual)/fC) < Accuracy)
disp('Required Accuracy is met!');
fprintf('Optimized Antenna Length is %.2f meter.\n', L);
hasConverged = true;
break;
end
% Adjust the antenna length in accordance with the discrepancy between
% the estimated and desired resonance frequency.
% 优化算法
L = L*fActual/fC;
% Loop all over again ...
disp('Required accuracy not yet met ...');
fprintf('The new estimate for the dipole length is %.2f meter\n', L);
end
if (~hasConverged)
disp('Max Iterations exceeded. Optimization did NOT converge ...');
end
disp('');
disp('');
% Remove all the added paths.
hfssRemovePaths('https://www.gofarlic.com\MATLAB_excise\matlab_hfss_api\');
rmpath('https://www.gofarlic.com\MATLAB_excise\matlab_hfss_api\');