# Generate a pulse with given rise and a fall time [duplicate]

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?

• A related question. Commented Jan 27, 2021 at 16:25
• 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}}] Commented Jan 27, 2021 at 16:31
• @DanielHuber, this is fine. Thank you for your help. Commented Jan 27, 2021 at 17:11

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


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

Have fun!

• Thank you for your response. This is I needed. Commented Jan 27, 2021 at 18:15

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