# Enforce Passivity Constraint for Flexible Beam

This example shows how to enforce passivity constraint for vibration control in a flexible beam using the Passivity Enforcement block.

### Flexible Beam Model

The following figure depicts an active vibration control system for a flexible beam.

In this setup, the actuator delivering the force $\mathit{u}\left(\mathit{t}\right)$ and the velocity sensor are collocated. You can model the transfer function from control input $\mathit{u}$ to the velocity $\mathit{y}$ using finite-element analysis. Keeping only the first six modes, you obtain a plant model of the following form.

$\mathit{G}\left(\mathit{s}\right)={\sum }_{\mathit{i}=1}^{6}\frac{{\alpha }_{\mathit{i}}^{2}\mathit{s}}{{\mathit{s}}^{2}+2\xi {\mathit{w}}_{\mathit{i}}\mathit{s}+{\mathit{w}}_{\mathit{i}}^{2}}$.

Configure the model parameters.

```xi = 0.05; alpha = [0.09877, -0.309, -0.891, 0.5878, 0.7071, -0.8091]; w = [1, 4, 9, 16, 25, 36];```

Construct the resulting beam model $\mathit{G}\left(\mathit{s}\right)$.

```G = tf(alpha(1)^2*[1,0],[1, 2*xi*w(1), w(1)^2]) + ... tf(alpha(2)^2*[1,0],[1, 2*xi*w(2), w(2)^2]) + ... tf(alpha(3)^2*[1,0],[1, 2*xi*w(3), w(3)^2]) + ... tf(alpha(4)^2*[1,0],[1, 2*xi*w(4), w(4)^2]) + ... tf(alpha(5)^2*[1,0],[1, 2*xi*w(5), w(5)^2]) + ... tf(alpha(6)^2*[1,0],[1, 2*xi*w(6), w(6)^2]);```

Check whether the model is passive.

`isPassive(G)`
```ans = logical 1 ```

With this sensor and actuator configuration, the beam is a passive system.

Open the Simulink® model and disable passivity constraint enforcement.

```mdl = 'passivityBeam'; open_system(mdl) constrained = 0;```

### Design LQG Controller

Before you apply the constraints, design an LQG controller for the beam model. LQG control is a natural formulation for active vibration control. The LQG control setup is depicted in this figure.

The signals $\mathit{d}$ and $\mathit{n}$ are the process and measurement noise, respectively.

The LQG objective is to minimize

$\mathit{J}=\underset{\mathit{T}\to \infty }{\mathrm{lim}}\mathit{E}\left({\int }_{0}^{\mathit{T}}\left({\mathit{y}}^{2}\left(\mathit{t}\right)+0.001{\mathit{u}}^{2}\left(\mathit{t}\right)\right)\mathit{dt}\right)$,

with noise variance

$\mathit{E}\left({\mathit{d}}^{2}\left(\mathit{t}\right)\right)=1$, $\mathit{E}\left({\mathit{n}}^{2}\left(\mathit{t}\right)\right)=0.01$.

Design the LQG controller.

```[a,b,c,d] = ssdata(G); M = [c d;zeros(1,12) 1]; % [y;u] = M * [x;u] QWV = blkdiag(b*b',1e-2); QXU = M'*diag([1 1e-3])*M; CLQG = lqg(ss(G),QXU,QWV);```

Simulate the LQG controller and plot its performance.

```% Simulate the model. out = sim(mdl); % Extract trajectories. logsout = out.logsout; % Plot trajectories of y. y = logsout.getElement('y'); y_vector = y.Values.Data(:,:)'; plot(y.Values.time,y_vector) grid on title('y')```

### Passivity Constraint

The beam model is passive from control input $\mathit{u}$ to the velocity $\mathit{y}$.

The Passivity Enforcement block accepts passivity constraint in the form ${\mathit{u}}_{\mathit{p}}={\mathit{f}}_{\mathit{p}}\left(\mathit{x}\right)+{\mathit{g}}_{\mathit{p}}\left(\mathit{x}\right)\mathit{u}$ and ${\mathit{y}}_{\mathit{p}}={\mathit{h}}_{\mathit{p}}\left(\mathit{x}\right)$. In this application, ${\mathit{f}}_{\mathit{p}}\left(\mathit{x}\right)=0$, ${\mathit{g}}_{\mathit{p}}\left(\mathit{x}\right)=1$, and ${\mathit{h}}_{\mathit{p}}\left(\mathit{x}\right)=\mathit{y}$.

### Simulate Controller with Passivity Constraint

To view the constraint implementation, open the `Constraint` > `Constrained` subsystem.

Enable the passivity constraint enforcement.

`constrained = 1;`

Run the model and plot the simulation results.

```% Simulate the model. out = sim(mdl); % Extract trajectories. logsout = out.logsout; % Plot trajectories of y. y = logsout.getElement('y'); y_vector = y.Values.Data(:,:)'; plot(y.Values.time,y_vector) grid on title('y')```

When you enforce the passivity constraint, the vibration in flexible beam is greatly reduced.

Close the model.

`bdclose(mdl)`