Can we use dynamic variables to represent a numerator/denominator coefficients in transfer function block ?

Hi there,

I need to implement a moving Bandpass filter based on the measured frequency. Currently i am using c-script code to determine frequency of the system. However I couldnt use this frequency as the center frequency of BANDPASS filter. Could you Pl advice to solve this problem?

1 Like

Hi Dilan,

You cannot update a variable, for example “w01” in your case, within the simulation, however you can create a dynamic transfer function by expanding it as shown in the “Help” section (see the image below) and then feeding a value calculated from the simulation to this expanded transfer function.

I have created the attached model (both Standalone and Blockset versions) for the transfer function you described. (Note that this model contains model initialization commands that are accessible from:PLECSStandalone: The menu Simulation+SimulationParameters…+Initializations PLECS Blockset: The Simulink menu File + Model Properties + Callbacks + InitFcn*)

6

By comparing this equation with the equation from the “Help” section, we get the following numerator and denominator coefficients

n2 =0;n1=6282;n0=0;d2=1;d1=6282;d0=w01;

From these values, we can calculate the coefficients for the expanded transfer function (modeled in the “dynamic transfer fcn” subsystem) as follows:

b2=1/d2;b1=d1/d2;b0=d0/d2;a2=n2;a1=n1-n2b1;a0=n0-n2b0;

In your case, since your “d0” is a variable obtained from the simulation, we need to calculate the coefficients “a0” and “b0” from the simulation as well. We can achieve this by replacing the “Gain” blocks corresponding to “a0” and “b0” with “Product” blocks and then calculating their values from the simulation using a “function” component. In the attached model, the “variable” port corresponds to the measured frequency, “w01”.

This model can also be adapted to work with any other second order transfer function by changing the numerator and denominator coefficients under initialization parameters, as well as replacing the corresponding gain blocks in the “dynamic transfer fcn” subsystem with a product block combined with a “function” component, to accept the desired variable from the simulation, as shown above.

Regards,Manu

dynamic_transfer_function.plecs (21.1 KB)

dynamic_transfer_function.slx (24.4 KB)

Hi Manu,

Thank you! This solves my problem.

Best regards,

Isuru