# plotting a trig functions along with its envelope

Note: This questions is quite different from the ones referred to in the comments. Those deal with numerical questions, while this one is algebraic.

I have plots of the following type:

Plot[Cos[50 t] + Cos[51 t], {t, 0, 10}]


I would like to plot a envelope over this plot, i.e. another plot that joins all of maxima and minima of this plot respectively. Here is my attempt, but it's not exactly what I'd like:

Plot[{Cos[50 t] + Cos[51 t], Cos[t] + 1.5, -Cos[t] - 1.5}, {t, 0, 10}]


How can I generate the actual envelope?

• I'm guessing that's something like Cos[42x]+Cos[43x]? Jun 3, 2014 at 18:29
• this is completely true but this is for the Fig.1, I want to access to sheath while I do not access to any formula for that. Jun 3, 2014 at 18:32
• Well, you've got to give us some kind of input to start with. Jun 3, 2014 at 18:34
• I plotted these ones with: Plot[{Cos[50 t] + Cos[51 t], Cos[t] + 1.5, -Cos[t] - 1.5}, {t, 0, 10}], I used of simulated functions 'Cos[t] + 1.5' and '-Cos[t] - 1.5' for the sheath. Jun 3, 2014 at 18:36
• Nearly a duplicate of Elegant way of obtaining the envelope of oscillating function, which is a duplicate of Mathematica envelope for the bottom of a plot, a generic function. But this one just straight trigonometry. Aug 28, 2014 at 0:20

Playing with the manipulate below might help. It's based on the the acoustics of beats.

Manipulate[Plot[
{Cos[a*t] + Cos[b*t], 2*Cos[(b - a) t/2], -2*Cos[(b - a) t/2]}, {t, 0, 10},
PlotStyle -> {
Directive[Opacity[0.7]],
Directive[Black, Thick],
Directive[Black, Thick]}],
{{a, 20}, 1, 50}, {{b, 21}, 1, 50}]


• Thank you so much. this is correct Jun 3, 2014 at 18:58

Don't mind me, I'm just having fun.

Grab the definition of HilbertTransform from this previous post, and then:

f[t_] := Cos[50 t] + Cos[51 t] + Sin[53 t] (* more sinusoids = more fun *)
g[t_] := Evaluate@HilbertTransform[f[τ], τ, t]
h[t_] := Abs[f[t] + I g[t]]
Plot[{f[t], h[t], -h[t]}, {t, 0, 10}, ImageSize -> Large, PlotPoints -> 100,
PlotStyle -> {Automatic, Black, Black}]


You can see that the envelope has a nice analytical form:

ComplexExpand[h[t]] // FullSimplify


$\sqrt{3 + 2\cos t + 2\sin 2t + 2\sin 3t}$

• This way though doesn't seem to catch when the envelope should go to zero. Shouldn't it e.g. vanish near 2? Jun 4, 2014 at 8:34
• Should it? It still looks like a sinusoid with small but nonzero amplitude there. (The envelope correctly goes to zero for the original function in the question, if that's what you're concerned about.)
– user484
Jun 4, 2014 at 8:55
• Ah, OK then, you're right. Jun 4, 2014 at 9:02
• @Rahul: wow! that's really cool! Would this also work on a set of discrete data? Something like ListLinePlot[Accumulate[RandomReal[{-1, 1}, 1000]]] ... If not, how could one modify it so that it does? I have a bunch of data that makes a seemingly random curve like that and I'd like be able to integrate over some area under the curve like the one that you generated. (Hmmm, i just copy pasted your code, but didn't get the black curve :( what could have gone wrong?) May 16, 2015 at 3:46
• @Solarmew: You first need to copy the definition of the Hilbert transform from the post I linked to. It also gives a discrete version of the transform, which you could use in much the same way on discrete data.
– user484
May 16, 2015 at 15:58