4. Time-Domain Response

4.1 Symbolic Approach

<< ControlSystems`

TransferFunction[s, (1/(s + 1))]

OutputResponse[%, Sin[10 t], t]

Plot[%, {t, 0, 10}];

StateSpace[{{-1, -k}, {1, 0}}, {{k, 
          0}, {0, -1}}]

StateResponse[% /. k -> (3/16), {c, 1.1 x10}, t, 
        InitialConditions -> {x10, c}] // Simplify

Plot[
        Evaluate[% /. {x10 -> 1, c -> 6}], {t, 0, 
          50}, PlotStyle -> {Thickness[ .005], Dashing[{ .05,  .01}]}, 
        PlotRange -> All, 
        PlotLabel -> "State Response"];

TransferFunction[s, {{(1/s)}, {(1/((s^2) + 2 s + 10))}}]

resp = 
      OutputResponse[Subsystem[%, All, 2], UnitStep[t - 1], t]

ComplexExpand[resp]

% // Simplify

Plot[%, {t, 0, 7}, PlotRange -> All];

system = 
      StateSpace[{{(1/2), (1/4)}, {(1/4), (1/2)}}, 
        DiagonalMatrix[{1, 1}], {{1, 2}}, 
        Sampled -> Period[1]]

inputs = {k, (E^(-k))}

StateResponse[system, inputs, k, 
          InitialConditions -> {-1, 2}] // ComplexExpand // 
      Simplify

OutputResponse[{{1, 2}}, %] // Simplify

OutputResponse[system, inputs, k, 
          InitialConditions -> {-1, 2}] // ComplexExpand // 
      Simplify

4.2 Simulating System Behavior

bridge = 
      TransferFunction[
        s, (((r^2) (Subscript[c, 1]) (Subscript[c, 2]) (s^2) + 2 r (Subscript[c, 2]) s + 1)/((r^2) (Subscript[c, 1]) (Subscript[c, 2]) (s^2) + (r (Subscript[c, 1]) + 2 r (Subscript[c, 2])) s + 1))]

bridge1 = % /. {r -> 1, (Subscript[c, 1]) -> 10, 
          (Subscript[c, 2]) -> (1/10)}

square[t_, τ_] := 
      Sign[Sin[((2  π  t)/( τ))]]

outs = OutputResponse[bridge1, square[t, 1], {t, 3}]

plot = 
        Plot[Evaluate[Flatten[{square[t, 1], %}]], {t, 0, 3}, 
          PlotStyle -> {Thickness[ .0075], 
              Dashing[{ .05,  .01}]}];

τ =  .1;

OutputResponse[bridge1, Table[square[t, 1], {t, 0, 3, τ}], 
      Sampled -> Period[τ]]

SimulationPlot[%, Sampled -> Period[τ], 
        PlotStyle -> Hue[0]];

Show[plot, %];

SimulationPlot[
        bridge /. {r -> 1, (Subscript[c, 1]) -> 10, 
            (Subscript[c, 2]) -> 1}, square[t, 1], {t, 3}];

SimulationPlot[
        bridge /. {r -> 1, (Subscript[c, 1]) -> 10, 
            (Subscript[c, 2]) -> 1}, square[t, 1], {t, 3}, 
        Sampled -> Period[ .1]];

UnitStep[(t - 1/2) (1 - t)]

SimulationPlot[
        bridge /. {r -> 1, (Subscript[c, 1]) -> 1, 
            (Subscript[c, 2]) -> 1}, %, {t, 5}, 
        MaxRelativeStepSize ->  .1];

ToDiscreteTime[
      bridge /. {r -> 1, (Subscript[c, 1]) -> 10, 
          (Subscript[c, 2]) -> 1}, Sampled -> Period[ .2]]

SimulationPlot[%, Table[Random[] -  .5, {100}]];

StateSpace[{{0, 1, 
          0}, {- .0071, - .111,  .12}, {0,  .07, - .3}}, {{0}, {- .095}, { .072}}]

Insert[%, DiagonalMatrix[{ .01, 1, 1}], -1]

ToDiscreteTime[%, Sampled -> Period[2]]

SimulationPlot[%, N[ .3 °], {t, 150}, 
        PlotLabel -> "State Response of Submarine"];

4.3 Step, Impulse, and Other Responses

s2[ω_, ζ_] = 
      TransferFunction[
        s, ((ω^2)/((s^2) + 2 ζ ω s + (ω^2)))]

OutputResponse[s2[(Subscript[ω, n]), 1], UnitStep[t], t]

SimulationPlot[s2[1,  .1], UnitStep[t], {t, 50}, 
        PlotLabel -> "Underdamped Second-Order System", 
        PlotRange -> All];

Plot3D[
        Evaluate[OutputResponse[s2[1, ζ], 1, 
              t][[1]]], {t, 0, 
          20}, {ζ, 0, 1.5}, 
        PlotLabel -> "Second-Order System", 
        AxesLabel -> {t, "ζ×10", "y(t)"}, 
        ViewPoint -> {-0.920, 3.110, 1.750}, PlotRange -> All, 
        PlotPoints -> 50];

s3[ω_, ζ_, p_] = 
      TransferFunction[
        s, (((ω^2) p)/(((s^2) + 2 ζ ω s + (ω^2)) (s + p)))]

MapAt[Limit[#, p -> ∞] &, %, 2]

OutputResponse[% /. {ω -> 
                1, ζ -> (1/2)}, UnitStep[t], t] // ComplexExpand // 
      Simplify

OutputResponse[s3[1, (1/2), 1], UnitStep[t], t] // ComplexExpand // 
      Simplify

OutputResponse[s3[1, (1/2), (1/2)], UnitStep[t], t] // ComplexExpand // 
      Simplify

Plot[Evaluate[Join[%, %%, %%%]], {t, 0, 8}, 
        PlotStyle -> {Thickness[ .005], Dashing[{ .03}], 
            Dashing[{ .05,  .02,  .01,  .02}]}, 
        PlotLabel -> "Step Response"];

SimulationPlot[s3[1. ,  .5, 1. ], t, {t, 0, 20}, 
        Epilog -> {Dashing[{0.025}], Line[{{0, 0}, {20, 20}}]}, 
        PlotLabel -> "Ramp Response"];

system = 
      StateSpace[{{0, 2}, {-1, -1}}, {{1, 1}, {1, 
            0}}, {{1, -2}}]

OutputResponse[%, DiracDelta[t], t] // ComplexExpand // 
      Simplify

Plot[Evaluate[Join @@ %], {t, 0, 10}, PlotRange -> All, 
        PlotStyle -> {Thickness[ .005], Dashing[{ .05,  .02}]}, 
        PlotLabel -> "Impulse Response"];

SimulationPlot[system, DiracDelta[t], {t, 10}, 
        ControlInputs -> 1, Sampled -> Period[ .25], 
        PlotLabel -> "Discrete Simulation of Impulse \
Response"];

myDiracDelta[
        t_, τ_:  0, α_:  
          100. ] := ((α )/(E^(α (t - τ)))) UnitStep[t - τ]

SimulationPlot[system, myDiracDelta[t], {t, 10}, 
        ControlInputs -> 1, PlotPoints -> 50, 
        PlotLabel -> "Analog Simulation of Impulse Response"];