Some of Analog Filter Design block's parameters seems invalid when fetched with get_param()

4 views (last 30 days)
I am trying to convert an analog filter belonging to a Simulink model, into the corresponding transfer function in a Matlab script. To do this I was planning to use ss2tf(A,B,C,D) function, as the Analog Filter Design block implements the filter in state-space form.
The problem is however, when I try to get A, B, C, D matrices in Matlab script via get_param(filter, 'A'), for instance, it returns 'a' for A, 'b' for B and so on. And these lower-case letter variables are not defined in the workspace. I can get other parameters correctly.
The problem does not occur when working with State-Space block (that is genuinely added from the library and not formed by Analog Filter Design block), I can get numerical values for the matrices.
Why can't I get the matrices? Is there another way to calculate transfer function of Simulink filter?
I have uploaded a Simulink model and a script creating the problem.

Accepted Answer

Paul
Paul on 26 Oct 2021
Two options.
Option 1:
ws = get_param(gcb,'MaskWSVariables');
ws will be 1-dimensional structure array with fields Name and Value. One element of ws, let's assume it's 6, will have ws(6).Name = 'a'. Then ws(6).Value is the A matrix. Similarly for B, C, and D. If you want to automate that, you'll have to do something like
ws(string({ws.Name})=="a").Value
Option 2:
Use the linearize() command to get the ss model of the block, then use tf if you really want the transfer function representation
sys = tf(linearlize('mdlname','blkpath'))
where mdlname is the name of the Simulink model and blkpath is the full path to the block. Or
sys = tf(linearize(gcs,gcb))
if you have the block in question selected in the Simulink model
  1 Comment
tkarg
tkarg on 26 Oct 2021
Edited: tkarg on 26 Oct 2021
Why do ss and afd blocks' behaviours differ? I can get numerical value of the matrices of ss block, unlike analog filter.
Edit: Ok, because of masking.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!