1
$\begingroup$

I'm converting the simulink diagram found in this paper to C code. I'm not familiar with matlab/simulink(too expensive) so need help interpreting the diagram. The problem I experience is that once a value like $\theta$, or $x_1$ becomes zero, zero is propagated everywhere due to the multiplication. The paper states that the integrators are initialized to zero, so I don't see how the system works.

Any ideas?

Below is the simulink diagram and my C code:

The block diagram is found in the paper above as Figure 1 and Figure 2 :

enter image description here

typedef struct  { float zeta,gamma;} PARAM_ANFfloat;
typedef struct  { float err,regressor,x1,theta;} STATE_ANFfloat;

typedef struct {PARAM_ANFfloat p;STATE_ANFfloat s;} ANFfloat;

void dspANFfloat_perform(ANFfloat *anf, float y)
{
    anf->s.err = y - anf->s.regressor;

    anf->s.theta = -anf->p.gamma * anf->s.x1 * anf->s.theta * anf->s.err;

    anf->s.x1 = anf->s.theta * anf->s.err * 2 * anf->p.zeta - anf->s.x1 * - anf->s.theta * anf->s.theta;

    anf->s.regressor = anf->s.x1;

}
$\endgroup$

1 Answer 1

2
$\begingroup$

In this line:

anf->s.theta = -anf->p.gamma * anf->s.x1 * anf->s.theta * anf->s.err;

you seem to be conflating $\theta$ and $\dot{\theta}$ (the derivative).

Equation 5 of the paper is:

$$ \dot{\theta} = -\gamma x_1 \theta \left[ y(t) - \sum_{l=1}^n \dot{x}_l \right] $$

Note that the left-hand term is the derivative of $\theta$, not $\theta$ itself.

$\endgroup$
5
  • $\begingroup$ Thank, Peter, for pointing out that error. My problem now is I don't understand how those integrator boxes work. The main integrator seems to be turning the derivative of theta into the new theta, as only theta appears in the diagram. Does just keeping a running sum of the derivatives form the derivative? Thus: anf->s.theta += -anf->p.gamma * anf->s.x1 * anf->s.theta * anf->s.err; $\endgroup$ Commented Feb 26, 2013 at 14:54
  • $\begingroup$ Could it be that the left side is not the derivative but a correction factor? $\endgroup$ Commented Feb 26, 2013 at 15:11
  • $\begingroup$ No, I believe they are really integrators, and simulink is pretending to be analog computer. What you probably want to do, to implement this in C, is to re-jig the algorithm for discrete-time implementation. $\endgroup$
    – Peter K.
    Commented Feb 26, 2013 at 16:08
  • $\begingroup$ I wonder if a running sum of the last N values would suffice for an integrator? $\endgroup$ Commented Feb 27, 2013 at 5:46
  • $\begingroup$ Yes, generally cumulative sums (or over the last N samples) will do as an integration and differencing can also do as differentiation. But things tend to need to be scaled relative to the sampling rate... and they are not exact analogies, so sometimes things do not work as expected from the continuous-time derivation. $\endgroup$
    – Peter K.
    Commented Feb 27, 2013 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.