Superposition of Two Sine Waves with Sum and Beats

Manipulate[
f1=freq1/440;
f2=freq2/440;
Plot[
{
If[showW,Sin[f1 x]],
If[showW,Sin[f2 x + p]a2],
If[showS,Sin[f2 x + p]a2+Sin[f1 x]],
If[showB,1-a2+Abs[Cos[(f2-f1)/2 x + p/2] 2 a2]],
If[showB,-1+a2-Abs[Cos[(f2-f1)/2 x + p/2] 2 a2]]
},
{x,0,2 π},
PlotLabel -> StringJoin["frequency of beats = ",ToString[Abs[f2-f1] 440]," Hz."],
PlotRange->{-2,2},
AspectRatio-> .6,
Ticks->{{0,π/2,π,3π/2,2Pi},{-2,-1,0,1, 2}},
Filling -> If[fill,{{1->{2}},{3 -> 0},{4->{5}}}],
PlotStyle -> {Blue, Purple, Black, Gray, Gray},
ImageSize->580
],
Row[{
Column[{
Control[{{freq1,440,"frequency 1"},440,30 440,Appearance->"Labeled"}],
Control[{{freq2,440,"frequency 2"},440,30 440,Appearance->"Labeled"}],
Control[{{a2,1,"amplitude 2"},0,1, 0.01,Appearance->"Labeled"}],
Row[{
Control[{{p,0,""},{0,π/2, π,3 π/2, 2 π}}],
Control[{{p,1," <-> phase 2"},0,2 π,Appearance->"Labeled", ImageSize -> Small}]
}]
}, Right],
Column[{
Control[{{showW,True,"show waves 1 and 2"},{True,False}}],
Control[{{fill,True,"show filling: waves 1 -> 2, sum and beats"},{True,False}}],
Control[{{showS,True,"show sum (wave 1 + wave 2)"},{True,False}}],
Control[{{showB,True,"show beats"},{True,False}}],
Row[{
Button["A", {freq1 =1 440,freq2 =1 440, a2 = 1,p =0,fill = True, showS = True, showW = True, showB = False},Appearance->"FramedPalette"],
Button["B", {freq1 =2 440,freq2 =2 440, a2 = 1,p =0,fill = True, showS = True, showW = True, showB = False},Appearance->"FramedPalette"],
Button["C", {freq1 =1 440,freq2 =2 440, a2 = 1,p =0,fill = True, showS = True, showW = True, showB = True},Appearance->"FramedPalette"],
Button["D", {freq1 =1 440,freq2 =2 440, a2 = .5,p =0,fill = True, showS = True, showW = True, showB =True},Appearance->"FramedPalette"],
Button["E", {freq1 =1 440,freq2 =1 440, a2 = 1,p =π,fill = True, showS = True, showW = True, showB = False},Appearance->"FramedPalette"],
Button["F", {freq1 =15 440,freq2 =13 440, a2 = 1,p =0,fill = False, showS = False, showW = True, showB = False},Appearance->"FramedPalette"],
Button["G", {freq1 =15 440,freq2 =13 440, a2 = 1,p =0,fill = True, showS = False, showW = True, showB = False},Appearance->"FramedPalette"],
Button["H", {freq1 =15 440,freq2 =13 440, a2 = 1,p =0,fill = True, showS = True, showW = True, showB = False},Appearance->"FramedPalette"],
Button["I", {freq1 =15 440,freq2 =13 440, a2 = 1,p =0,fill = True, showS = True, showW = True, showB = True},Appearance->"FramedPalette"],
Button["J", {freq1 =15 440,freq2 =13 440, a2 = 0.5,p =0,fill = True, showS = True, showW = True, showB = True},Appearance->"FramedPalette"],
Button["K", {freq1 =1 440,freq2 =30 440, a2 = 0.1,p =0,fill = False, showS = False, showW = True, showB = False},Appearance->"FramedPalette"],
Button["L", {freq1 =1 440,freq2 =30 440, a2 = 0.1,p =0,fill = False, showS = True, showW = True, showB = False},Appearance->"FramedPalette"],
Button["M", {freq1 =1 440,freq2 =30 440, a2 = 0.1,p =0,fill = False, showS = True, showW = False, showB = False},Appearance->"FramedPalette"],
Button["N", {freq1 =1 440,freq2 =30 440, a2 = 0.1,p =0,fill = True, showS = True, showW = False, showB = False},Appearance->"FramedPalette"],
Button["O", {freq1 =1 440,freq2 =30 440, a2 = 0.1,p =0,fill = True, showS = True, showW = True, showB = True},Appearance->"FramedPalette"]
}]
}, Right]
}],
AutorunSequencing->{1,2,3},TrackedSymbols->True
]

THIS NOTEBOOK IS THE SOURCE CODE FROM

"Superposition of Two Sine Waves with Sum and Beats" from The Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/SuperpositionOfTwoSineWavesWithSumAndBeats/

Contributed by: Arthur Stammet

A full-function Wolfram Mathematica system (Version 6 or higher) is required to edit this notebook.
GET WOLFRAM MATHEMATICA »

© The Wolfram Demonstrations Project & Contributors   |   Terms of Use   |   Make a new version of this Demonstration »