ADS-matlab联合仿真-参数修改

最近使用TADSInterface进行matlab-ADS联合仿真时,涉及到需要将ADS中的参数改为复数,但原先程序的正则表达式搜索范围中不包括复数,需要进行修改

1. 参数形式查看

TADSInterface中提供三种参数输入,引原文如下:

'double': in this case ParamValue must be a numeric value. For this specific exapmle (to change the frequency) we can call the method as ADS.ChangeParameter('SimFreq', 3, 'double'), which would replace the parameter value by 3 keeping units unchanged.
'string': in this case ParamValue must be a string without double quotes, e.g. a file name 'C:\Path\File.ext'. This ParamValue is used only for a string parameter values which are surrounded by double quotes in the netlist file, e.g. a touchstone file name for an SNP component. Since frequecny is not a string, this parameter type is not relevant for this example.
'custom': general case. In this case ParamValue must be a string, which will be written "as is" to the netlist as the parameter value. Please look inside the netlist file to see exact format and units the parameter has.

在此选取custom类型的参数来作为输入。

2. 修改源码中的正则表达式

查看源码中的ChangeComponentParameter()函数部分,发现其在custom对应代码中使用函数GetParameterValueCustomType()来寻找touchstone文件中要修改参数的位置

将返回目标位置与长度的代码改为:

%  将[Tok,iTokExt] = regexp(Ln,[ParamName'\s?=\s?(.+?)\s+[\w\[\]]+\s?='], 'tokens','tokenExtents');
%改为
[Tok,iTokExt] = regexp(Ln,[ParamName '\s?=\s?((?:[-+]?\d*\.?\d+\*?[ij]?([ij]?[-+]?\d*\.?\d+\*?[ij])?)?)\s*\\?'], 'tokens','tokenExtents');

3. 在ADS中修改初始参数

TADSInterface只会在touchstone文件中修改对应参数的值来影响仿真结果,但是不会对原理图中的值进行修改,所以首先需要将原理图中的初始参数设置为代码可以检测到的格式(即修改后的正则表达式对应的格式),如纯实数,或者格式为 'a+b*j' 的复数,如下图所示

4. 修改参数类型与复数符号

由于custom类型的输入必须为字符串,且matlab中默认的虚数单位都是i,但是ADS中使用的是j,故需要对参数的类型进行转换,可以参考如下代码:

% 这是修改S4P参数的一段代码
ADS.ChangeComponentParameter('S_Port:S3P2', 'S[1,2]', strrep(num2str(-1i/sqrt(2)),'i','*j'), 'custom');
ADS.ChangeComponentParameter('S_Port:S3P2', 'S[2,1]', strrep(num2str(-1i/sqrt(2)),'i','*j'), 'custom');
ADS.ChangeComponentParameter('S_Port:S3P2', 'S[2,3]', strrep(num2str(1/sqrt(2)),'i','*j'), 'custom');
ADS.ChangeComponentParameter('S_Port:S3P2', 'S[3,2]', strrep(num2str(1/sqrt(2)),'i','*j'), 'custom');  
% 使用num2str将参数转换为字符串,而后使用strrep替换掉字符串中的i即可

经过以上步骤后应该可以运行代码并直接修改参数为复数了,如下:

 可以看到Z4P元件中的Z11被修改。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值