Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

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

+1 vote
3,995 views

 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?

asked May 9, 2019 by Dilan (17 points)

1 Answer

+2 votes

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*)

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-n2*b1;
a0=n0-n2*b0;

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

 

answered May 10, 2019 by Manu Parimi (363 points)
edited May 16, 2019 by Manu Parimi
Hi Manu,

Thank you! This solves my problem.

Best regards,

Isuru
...