# Convert a piecewise definition of a single impulse into an impulse train

NOTE: See update at end of question

I have a function smoothstep (based on the derivative of a smoothstep function) that gives a single impulse as follows:

smoothstep = Piecewise[{{0, x <= -1},
{(1/32)*(35 - 105*x^2 + 105*x^4 - 35*x^6), -1 < x < 1},
{1, x >= 1}}]
Plot[{smoothstep}, {x, -1, 1}, GridLines -> Automatic,
PlotLegends -> "Expressions"]

**Piecewise[{{0, x <= -1},
{(1/32)*(35 - 105*x^2 + 105*x^4 - 35*x^6), -1 < x < 1},
{1, x >= 1}}, 0]**


I want to use this as the basis for a train of impulses, where single impulses like the one above appear at all instances of x+n a where n is the set of integers and a is a chosen positive integer. For example, for a=4, the function would return impulses in each of the ranges {...-9<=x<=-7,-5<=x<=-3,,-1<=x<=1,3<=x<=5,7<=x<=9...}, and return 0 in the ranges {...-7<x<-5,-3<x<-1,1<x<3,5<x<7...}.

I can't figure out the syntax to deliver this as a new piecewise function. How do I define n and a? Presumably it involves slots or double-slots...?

(I tried the following with no success:)

smoothstepimpulsetrain = Piecewise[
{{(1/32)*(35 - 105*(x - n*a)^2 + 105*(x - n*a)^4 -
35*(x - n*a)^6), Element[n, Integers]},
{0, NotElement[n, Integers]}}]
Plot[{smoothstepimpulsetrain /. a -> 4}, {x, 15, 15},
GridLines -> Automatic, PlotLegends -> "Expressions"]


UPDATE

@Michael E2 and @MikeY made the following suggestion, but it doesn't quite work, as you can see from the plot for a=1:

smoothstep[x_] := Piecewise[{{0, x <= -1},
{(1/32)*(35 - 105*x^2 + 105*x^4 - 35*x^6), -1 < x < 1},
{0, x >= 1}}];
train[x_, a_] := smoothstep[Mod[x, a, -1]];
Plot[{train[x, 1], train[x, 3], train[x, 5], train[x, 7]},
{x, 0, 10}]


Also note that summing these trains produces an incorrect plot - note the feeble little bump at x=5, and the anomalous behaviour in the range x=6->8:

Plot[{train[x, a] /. a -> 3 + train[x, a] /.
a -> 5 + train[x, a] /. a -> 7}, {x, 0, 10}]


Further suggestions?

• Something like f[Mod[x, 4, -1]]? – Michael E2 Dec 19 '18 at 17:03
• Hmmm... I see where you're going. But how would I incorporate that? – Richard Burke-Ward Dec 19 '18 at 17:33
• I don't have access to M right now, so I was kinda hoping that would be enough for you to figure the rest out. f here is supposed to be your piecewise function. So plug Mod[..] for x. Or write an function f[x_] := Piecewsie[..]. – Michael E2 Dec 19 '18 at 17:36
• Can't figure it out, sorry. I'm pretty new to M, and I last studied maths 5 years ago! – Richard Burke-Ward Dec 19 '18 at 18:37

## 1 Answer

UPDATED to allow overlapping pulses

Convert to function

smoothstep[x_] := Piecewise[{{0, x <= -1}, {(1/32)*(35 - 105*x^2 + 105*x^4 - 35*x^6), -1 < x <  1}, {0, x >= 1}}]


Modify to make the train, noting that the code assumes the pulse has a width of +/- $$d$$ and accepts that as input. for your code, $$d=1$$.

train[x_, a_, d_] := Module[{
kl = Floor[(x - d)/a] - 1,
kr = Ceiling[(x + d)/a] + 1,
k = 0,
summand = 0
},

For[k = kl, k <= kr, k++, summand += smoothstep[x - k a]];

summand

]


Plot letting a=4

Plot[train[x, 4, 1], {x, 0, 10}]


Plot again with an overlap of pulses ($$a=.3$$)

Plot[train[x, .3, 1], {x, 1, 3}]


• Appreciated, both of you – Richard Burke-Ward Dec 20 '18 at 9:50
• Sorry - update - it doesn't work for a=1... – Richard Burke-Ward Dec 20 '18 at 10:34
• Also, something goes wrong if you try to add two such impulse trains together: Plot[{train[x, a] /. a -> 2 + train[x, a] /. a -> 3}, {x, 0, 10}. I'll modify original question. – Richard Burke-Ward Dec 20 '18 at 10:53
• I fixed it to allow overlaps – MikeY Dec 20 '18 at 16:39