This question already has an answer here:

I am able to take the expression $\cos 11t-\cos 12t$ and use the sum to product identity to write it in the form $$\left(2\sin\frac t2\right)\sin\frac{23}{2}t.$$ I can then plot the function and use the slower oscillating part as an "envelope" for the function.

Plot[{2 Sin[t/2] Sin[23 t/2], 2 Sin[t/2], -2 Sin[t/2]}, {t, 0, 4 Pi}]

enter image description here

Does someone have a way of changing the expression $$12\sin11t-11\sin 12t$$ into a similar form so that I can again use part of the new form for the envelope of this function?


marked as duplicate by Michael E2, Karsten 7., Dr. belisarius, Öskå, Simon Woods Mar 9 '15 at 19:39

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


You can use HilbertTransform for these things. M does not have HilbertTransform, but easy to make it. Using the Hilbert transform definition from this answer and using the definition of the envelope being the absolute part of $f(t)+I h(t)$ where $h(t)$ is the Hilbert transform gives

hilbertTransform[f_,u_,t_] := 1/Pi FullSimplify[Convolve[f, 1/u, u, t,PrincipalValue -> True]];

and now

f[t_] := 12 Sin[11 t] - 11 Sin[12 t];
h = hilbertTransform[f[t], t, u];
Plot[{f[t], Abs[f[t] + I (h /. u -> t)]}, {t, 0, 12}]

Mathematica graphics

To get both sides, just change the sign

z = Abs[f[t] + I (h /. u -> t)];
Plot[{f[t], z, -z}, {t, 0, 12}]

Mathematica graphics

  • $\begingroup$ There's something I don't understand. The hilbertTransform gives a different answer than the OP's and my approaches. It seems that one of them must be incorrect. (That is, each may be a correct answer to different questions.) Can you clarify? There must be different definitions of envelope, perhaps. See for example Envelope_(waves) (wikipedia). $\endgroup$ – Michael E2 Mar 9 '15 at 12:55
  • $\begingroup$ @MichaelE2 I am using the envelope as defined in DSP terminology. Please see the second method here (the Hilbert transform method) envelope-detection-1 and this is how how I do it in Matlab. (in Matlab, the discrete version of Hilbert transform is used, via fft/ifft method as the implementation). Here is full example of envelope detection using Hilbert envelope-extraction-using-the-analytic-signal $\endgroup$ – Nasser Mar 9 '15 at 13:07
  • $\begingroup$ Thanks. What little I know about signal processing I learned in an electronics laboratory course in 1983, but I probably learned about beats in physics in H.S. $\endgroup$ – Michael E2 Mar 9 '15 at 13:17
  • $\begingroup$ @MichaelE2 beating waves is not really envelope detection. It does look like it, sure, but I assumed the question is about envelope detection for signals. I remembered doing this for a HW sometime ago, that is all, but had to look up the details now again. $\endgroup$ – Nasser Mar 9 '15 at 13:20
  • $\begingroup$ The OP's example makes it seem to be about beats to me. I think it's a question of definitions - and there's yet another math. def. of envelope. :) In any case I learned something new - thanks, again! $\endgroup$ – Michael E2 Mar 9 '15 at 13:38

Here's a way via solving for the parameters in the trigonometric identity:

expr = 12 Sin[u t] - 11 Sin[v t];
form = a Sin[(v - u) t/2 - b] Sin[(v + u) t/2 - c];
sol = First@Solve[
          expr - form // TrigReduce // Simplify // TrigExpand,
          {Sin[t u], Cos[t u], Sin[t v], Cos[t v]}
          ], 0] == 0] /. C[_] -> 0;
form /. sol /. {u -> 11, v -> 12}
  -22 Cos[(23 t)/2] Sin[t/2]

(There are four nonzero coefficients and only three unknowns, hence Most.)

Plot[{-22 Cos[(23 t)/2] Sin[t/2], 22 Sin[t/2], -22 Sin[t/2] }, {t, 0, 4 Pi}]

Mathematica graphics

  • $\begingroup$ Mike, fascinating, wonderful answer, but this looks like a wrong answer. Try -22 Cos[(23 t)/2] Sin[t/2] == 12 Sin[11 t] - 11 Cos[12 t] /. {t -> 0}. You can also Plot[-22 Cos[(23 t)/2] Sin[t/2], {t, 0, 4 Pi}], then Plot[12 Sin[11 t] - 11 Cos[12 t], {t, 0, 4 Pi}] and you will see different graphs. $\endgroup$ – David Mar 9 '15 at 16:37
  • $\begingroup$ Ooops. My mistake! Sorry. I have a Cos where I should have a Sin. $\endgroup$ – David Mar 9 '15 at 16:45
  • $\begingroup$ @David No, I think you're right...Hmm. I'll investigate. $\endgroup$ – Michael E2 Mar 9 '15 at 16:51
  • $\begingroup$ @David I think it's wrong and I haven't figured out how to coax the right answer out of Mathematica. I'll undelete it, but please double check that it is correct. Thanks. $\endgroup$ – Michael E2 Mar 9 '15 at 20:47
  • $\begingroup$ It is so close to being correct, but yes, it is not the same as 12sin11t−11sin12t. Evidence is here. However, I still hope you work at this, because I find it very interesting and it helps me learn more about the possibilities using Mathematica. $\endgroup$ – David Mar 10 '15 at 3:52

Not to compete the excellent answer of Nasser, but to look at the problem differently I propose the following. Let

f[t_] := 12*Sin[11 t] - 11*Sin[12 t];

Then one can look for the extremum points of this function:

 eq1 = D[f[t], t] == 0

(*  132 Cos[11 t] - 132 Cos[12 t] == 0  *)

sl = Solve[eq1, t];

There is a lot of solutions here. Let us make a list of those only belonging to the first period:

    lst1 = Table[Drop[sl[[i, 1, 2, 1]] // N, -1], {i, 2, Length[sl]}]

(*  {-3.005, 3.005, -2.73182, 2.73182, -2.45864, 2.45864, -2.18546, 
2.18546, -1.91227, 1.91227, -1.63909, 1.63909, -1.36591, 1.36591, 
-1.09273, 1.09273, -0.819546, 0.819546, -0.546364, 0.546364,
-0.273182, 0.273182}  *)

They all yield the abscissas of the extremum points. Let us now form the list of both the abscissas and ordinates:

    lst2 = Map[{#, f[#]} &, lst1];

and visualize them:

enter image description here

That's it already, but it can be plotted better than that:

       lst3 = Sort[
   Select[lst2, #[[1]] < 0 && #[[2]] >= 0 || #[[1]] > 0 && #[[2]] < 
        0 &]];
lst4 = Sort[
   Select[lst2, #[[1]] < 0 && #[[2]] < 0 || #[[1]] > 0 && #[[2]] > 
        0 &]];

Show[{ListLinePlot[{lst3, lst4}, InterpolationOrder -> 2],
  ListPlot[{lst3, lst4}]

yielding the following:

enter image description here

Have fun!


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