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?

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:

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.