0
votes

My initial problem is that I have a continuous transfer function which coefficients change with time.

Currently the TF's coefficients are expressed in function of the block mask parameters. These parameters are tunable, and if I change the value in the mask parameters dialog during a simulation the response seems to react appropriately.

However how can I do just that in the code/block flow? Basically, I have the block parameter 'maskParam' which is set using the mask parameters dialog, and in the mask initialization commands: 'param=maskParam'. 'param' is used in the transfer function and I would like to change it in real time (as param=maskParam*f(t)).

I have already looked around and found relevant solutions but either it's unbelievably complicated; or the only transfer function which we are allowed to modify at runtime is discrete and 1) I would like to avoid z-transforming my quite complex TF (I don't have the control toolbox) 2) The sampling time seems to be fixed.. None uses this "dirty" technique of updating parameters, maybe that's the way around?

To illustrate: enter image description here

2

2 Answers

2
votes

I am assuming that you want to change your sim parameters whilst the simulation is running?

A solution is that you run your simulation for inf period and use/change a workspace variable during the simulation period to make the changes take effect. enter image description here for Example:

If you look at the w block, you can set it's value in runtime, by doing this:

set_param('my_model_name/w', 'value', 100); % Will change to 100 immediately

You can do similar things with arrays (i.e. a list of coefficients in your case).

HINT FOR YOU

You are using discrete transfer function block. Try the following:

1) Give your block a name e.g. fcn_1

2) In your script, type set_param('your_model_name/fcn_1', 'numerator', '[1 2]'); This will set the numerator value to [1 2]. Do the same for denominator.

3) You should be able to understand, through this exercise, how to handle the property names etc. so that you can change/get them using set_param/get_param.

I leave you to investigate further.

0
votes

The short answer is that Simulink blocks are not really designed to do this. By definition, a transfer function is Liner-Time Invariant, meaning its characteristics (read coefficients) do not vary with time.

Having said that, there are some workarounds, such as the ones you mentioned in your question. These are the correct way to approach the problem I'm afraid, other than the set_param method suggested by @ha9u63ar. See also this blog on the subject on the MathWorks web site.