# How can SquareWave be used as the input in OutputResponse?

I'd like to compute the response of a TransferFunctionModel when driven by a SquareWave. Here's a simple example,

or = OutputResponse[TransferFunctionModel[1/(s + 1), s], SquareWave[t], t];


which results in two copies of the error:

Reduce::nsmet: This system cannot be solved with the methods available to Reduce. >>

Oddly, or still gets set to

{(-1 + Piecewise[{{-E^t, Inequality[1/2, LessEqual, Mod[t, 1], Less, 1]}}, E^t])/E^t}


which looks like this:

and is the correct response of the system to UnitStep[t], but multiplied by SquareWave[t].

How can OutputResponse be used to find the response of a TransferFunctionModel driven by a SquareWave?

-

I think you are right about using finite sequence of pulses. But here is how you can get it still using SquareWave - you just need to introduce right cut-off. Then no sums over steps or pulses are needed and implementation is easy.

For example:

finiteSquareWave[t_] := UnitBox[.2 (t - 3)] SquareWave[t];
Plot[finiteSquareWave[t], {t, -2, 8}, Exclusions -> None,  Filling -> 0]


f[t_, z_] = OutputResponse[ TransferFunctionModel[1/(s + 1), s], finiteSquareWave[t], t]


Plot3D[f[t, z], {z, 0, 1.2}, {t, 0, 8},
AxesLabel -> {"Z", "T", "f(Z,T)"}, MeshFunctions -> {#1 &},
PlotRange -> All, PlotStyle -> Opacity[.5], MeshStyle -> Opacity[.3]]


This is similar to what you got with sums over UnitSteps.

-
I like this one. When I attempt to change the phase of the SquareWave using finiteSquareWave[t_] := UnitBox[.2 (t - 3)] SquareWave[t - 0.1];, the error returns. Any idea why? –  ArgentoSapiens Aug 20 '12 at 22:54
@ArgentoSapiens it is not an error, but just a message that solution is given not in an exact, but numerical form. Plotting function and other computations still work. –  Vitaliy Kaurov Aug 21 '12 at 0:58
3D plot looks pretty :-), but it's only a cylindrical function, so what's the third dimension for? –  stevenvh Aug 21 '12 at 8:37
@stevenvh f(z,t) - so 3 axis are z,t,f . It is a standard plot wolfram.com/xid/0g7kxbwzgfy-zycipu –  Vitaliy Kaurov Aug 21 '12 at 8:56

I hardly ever try to obtain an analytic expression from OutputResponse since I am really only interested in a plot of the response and an InterpolationFunction. So unless you have a need to see an analytical expression, use a numerical one. This happens when you provide a complete time specification as in {t,0,10} instead of just t.

Now you will obtain an InterpolationFunction which is for all practical purposes just as good. Not only is it faster, you know it will almost always work for any input.

In[3]:= or=OutputResponse[TransferFunctionModel[1/(s+1),s],SquareWave[t],{t,0,10}]
Out[3]= {InterpolatingFunction[{{0.,10.}},<>][t]}


But if you insist you want an analytical response, then may be there is a way. But see first if the above works for you.

Plot[or, {t, 0, 10}]


-

A fake, finite-time version of SquareWave can be made thus:

sw = With[
{period = 2},
Sum[
UnitStep[t - period/2 number] - UnitStep[t - period/2 (number + 1)],
{number, 0, 10, 2}
]
]


And this fake SquareWave works with OutputResponse:

or = OutputResponse[TransferFunctionModel[1/(s + 1), s], sw, t];
Plot[or, {t, 0, 10}]


-