0
$\begingroup$

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]**

enter image description here

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}]

enter image description here

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}]

enter image description here

Further suggestions?

$\endgroup$
  • 2
    $\begingroup$ Something like f[Mod[x, 4, -1]]? $\endgroup$ – Michael E2 Dec 19 '18 at 17:03
  • $\begingroup$ Hmmm... I see where you're going. But how would I incorporate that? $\endgroup$ – Richard Burke-Ward Dec 19 '18 at 17:33
  • $\begingroup$ 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[..]. $\endgroup$ – Michael E2 Dec 19 '18 at 17:36
  • $\begingroup$ Can't figure it out, sorry. I'm pretty new to M, and I last studied maths 5 years ago! $\endgroup$ – Richard Burke-Ward Dec 19 '18 at 18:37
0
$\begingroup$

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}]

enter image description here

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

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

enter image description here

$\endgroup$
  • $\begingroup$ Appreciated, both of you $\endgroup$ – Richard Burke-Ward Dec 20 '18 at 9:50
  • $\begingroup$ Sorry - update - it doesn't work for a=1... $\endgroup$ – Richard Burke-Ward Dec 20 '18 at 10:34
  • $\begingroup$ 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. $\endgroup$ – Richard Burke-Ward Dec 20 '18 at 10:53
  • $\begingroup$ I fixed it to allow overlaps $\endgroup$ – MikeY Dec 20 '18 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.