2
$\begingroup$

I need to generate a pulse with a given rise and fall time. Currently, I am using the command "UnitStep[t]-UnitStep[t-a]" to generate a pulse of width 'a'. But here I can't provide the rise and fall time. Is there any way to generate the required pulse?

$\endgroup$
3
  • $\begingroup$ A related question. $\endgroup$
    – J. M.'s torpor
    Jan 27 at 16:25
  • $\begingroup$ Would this do? f[x_, start_, a_, rise_, fall_] = Piecewise[{{0, x < start}, {(x - start)/rise, x < start + rise}, {1, x < start + a - fall}, {(start + a - x)/fall, x <= start + a}, {0, x > start + a}}] $\endgroup$ Jan 27 at 16:31
  • $\begingroup$ @DanielHuber, this is fine. Thank you for your help. $\endgroup$ Jan 27 at 17:11
10
$\begingroup$

Try this:

pulse[a_, t1_, t2_] := 0.5*((Tanh[x/t1] + 1) - (1 + Tanh[(x - a)/t2]));

Manipulate[
 Plot[pulse[a, t1, t2], {x, -5, 40}], {{a, 10}, 5, 20}, {{t1, 2}, 0.1,
   3}, {{t2, 2}, 0.1, 3}]

enter image description here

and play with the parameters a, t1 and t2 to choose ones of your liking.

Have fun!

$\endgroup$
1
  • $\begingroup$ Thank you for your response. This is I needed. $\endgroup$ Jan 27 at 18:15
3
$\begingroup$

For some applications, I prefer using something like "smoothstep" instead of $\tanh$. For this answer, however, I will instead use "rational smoothstep" to implement a "smoothpulse" function:

smoothstep[n_Integer, x_] := #^n/(#^n + (1 - #)^n) &[Clip[x, {0, 1}]]

smoothpulse[n_Integer, a_, t1_, t2_, x_] :=
      smoothstep[n, (x + t1)/t1] - smoothstep[n, (x - a)/t2]

Slightly modifying Alexei's Manipulate[], we have the following:

Manipulate[Plot[smoothpulse[n, a, t1, t2, x], {x, -5, 40}, PlotRange -> All],
           {{n, 2}, 1, 10, 1}, {{a, 10}, 5, 20}, {{t1, 2}, 0.1, 3}, {{t2, 2}, 0.1, 3}]

Manipulate for "smoothpulse"

$\endgroup$

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