File:Convolution Animation (Boxcar).gif
| Description |
English: An animation of the convolution of two boxcar functions, f(t) (red) and g(t) (blue)
|
||
| Date | |||
| Source | Own work | ||
| Author | Inductiveload | ||
| Permission (Reusing this file) |
|
Mathematica Code
(*Function definitions*)
boxcar[x_, {a_, b_}] := UnitStep[x - a] - UnitStep[x - b]
f[t_] := boxcar[t, {-1/2, 1/2}];
g[t_] := boxcar[t, {-1/4, 1/4}]/2;
h[y_] := Module[
{t},
Convolve[f[t], g[t], t, y]
];
(*Parts of the drawing that only need to be computed once*)
constplots = Plot[
{f[t], g[t], h[t]},
{t, -2, 2},
PlotStyle -> {Red, {Blue, Dashed}, Black},
ClippingStyle -> False,
Axes -> False,
Exclusions -> False
];
anim =
Table[Show[
{
(*The plots we generated earlier*)
constplots,
(*Plot the time reversed g[t], g[\[Tau]-t]*)
Plot[g[\[Tau] - t],
{t, -5, 5},
PlotPoints -> 100,
ClippingStyle -> False,
PlotStyle -> Blue,
Exclusions -> False,
Axes -> False],
(*Plot the product of the f[t] and g[\[Tau]-t]*)
Plot[f[t]*g[\[Tau] - t],
{t, -5, 5},
PlotPoints -> 100,
ClippingStyle -> False,
Filling -> Axis,
FillingStyle -> Directive[Green, Opacity[0.2]],
PlotStyle -> Green,
Exclusions -> False,
Axes -> False],
(*Plot the embellishments*)
Graphics[
{{Blue, Line[{{\[Tau], -0.05}, {\[Tau], 1.1}}]},
{Red, Text[f, {.2, .96}, Background -> None]},
{Blue, Text[g, {.2, .55}, Background -> None]},
{Blue,
Text["g(\[Tau]-t)", {\[Tau] - 0.45, .4}, Background -> None]},
{Green,
Text["f(t)g(\[Tau]-t)", {\[Tau] - 0.35, -0.04},
Background -> None]},
{Black, Text[Star[f, g], {0, .22}, Background -> None]},
{Blue, Text["\[Tau]", {\[Tau], -0.1}, Background -> White]}
}]
},
PlotRange -> {{-1.9, 1.9}, {-.2, 1}}],
{\[Tau], -2, 2, .025}(*Table index is the time delay*)
];
ListAnimate[anim]
Export["anim2.gif", anim]
Category:Convolution
Category:Animated GIF files