Displaying report 1-1 of 1.
Reports until 02:31, Saturday 12 August 2023
CDS General
nikhil - posted 02:31, Saturday 12 August 2023 (11284)
StateSpace Model implementation within CDS

We currently do not have state-space filtering implemented within CDS. However, we can run a custom C-code, and the procedure to add a user C-code is described in the RCG developer's guide (see T080135).

State-space models have certain advantages over ZPK models.

  1. MIMO vs SISO: they can handle multi-input multi-output unlike ZPK.
  2. Time domain filtering is straightforward. For ZPK, we normally discretize using bilinear transform, convert to second-order sections, and then do the filtering.
  3. Numerical stability: In ZPK, if specific poles and zeros are very close to each other, they can lead to cancellations and numerical inaccuracies.
  4. Physical interpretation: Since the state variables (say, for a pendulum model) have physical significance, it is more intuitive.
  5. Useful for studying the dynamics (& response to control feedback) of an equivalent Digital Twin model of the actual physical plant. Useful to detect changes in the actual plant.
  6. Adaptive filtering: It is way easier to tweak the filter coefficients of [A,B,C,D] matrices of the state-space controller. 

 

Christopher Wipf previously wrote a routine to convert discrete state-space Matlab models to a CDS-compatible C function where the [A,BC,D] matrices are stored in the corresponding header files. I modified the code to work for any ZPK or StateSpace models. Users have the option to initialize the filter coefficients. I set up a 2-input 2-output filter model consisting of two separate lowpass filters, each with corner frequencies (0.5 Hz & 10 Hz), and checked the results on two inputs (random Gaussian noise in this case) and compared it with the expected one. They both match well. 

 

Next steps:

  1. Currently the filter coefficients are specified within the header files. Any change would require model recompilation. But it would be convinient if the [A,B,C,D] matrix values were read from epics records and sent as inputs to the cds C function block. Auto-generation of medm [A,B,C,D] matrices would make life easier.
  2. Implement & run Regina's double pendulum state-space model within CDS.
  3. Use this same idea to create a CDS C-code AI library (ex: blocks for neural nets, classic ML classifiers, regressors).

 

Notes:

# While compiling with custom C-code using cdsFunctionCall block,

 

 

Images attached to this report
Displaying report 1-1 of 1.