Fourier Synthesis for Selected Waveforms

Manipulate[
Switch[waveshape,(* select the waveshape based on the PopupMenu value *)
"sine",a1=1;a2=0;a3=0;a4=0;a5=0;a6=0;a7=0;a8=0;a9=0,
"square",a1=1;a2=0;a3=(1/3);a4=0;a5=(1/5);a6=0;a7=(1/7);a8=0;a9=(1/9),
"sawtooth",a1=1;a2=(1/2);a3=(1/3);a4=(1/4);a5=(1/5);a6=(1/6);a7=(1/7);a8=(1/8);a9=(1/9),
"triangle",a1=1;a2=(1/(2^2));a3=(1/(3^2));a4=(1/(4^2));a5=(1/(5^2));a6=(1/(6^2));a7=(1/(7^2));a8=(1/(8^2));a9=(1/(9^2)),
"user",Null (* allow user-control --- no preset values *)];
(* with the amplitudes set, plot the resulting waveform *)
Plot[a1 Sin[x]+a2 Sin[2x]+a3 Sin[3x]+a4 Sin[4x]+a5 Sin[5x]+a6 Sin[6x]+a7 Sin[7x]+a8 Sin[8x]+a9 Sin[9x],{x,0,4π},PlotRange->All,PlotStyle->Thick,Ticks->None,ImageSize->{400,300}],
(* setup the controls *)
{{waveshape,"sine","waveform"},{"sine","square","sawtooth","triangle","user-defined"},ControlType->PopupMenu},
Delimiter,
Style["harmonics",Bold],
"enabled when waveform\nis \"user-defined\":\n",
{{a1,1,"fundamental"},0,1,Appearance->"Labeled",ImageSize->Tiny,Enabled->waveshape==="user-defined"},
{{a2,0,"2nd"},0,1,Appearance->"Labeled",ImageSize->Tiny,Enabled->waveshape==="user-defined"},
{{a3,0,"3rd"},0,1,Appearance->"Labeled",ImageSize->Tiny,Enabled->waveshape==="user-defined"},
{{a4,0,"4th"},0,1,Appearance->"Labeled",ImageSize->Tiny,Enabled->waveshape==="user-defined"},
{{a5,0,"5th"},0,1,Appearance->"Labeled",ImageSize->Tiny,Enabled->waveshape==="user-defined"},
{{a6,0,"6th"},0,1,Appearance->"Labeled",ImageSize->Tiny,Enabled->waveshape==="user-defined"},
{{a7,0,"7th"},0,1,Appearance->"Labeled",ImageSize->Tiny,Enabled->waveshape==="user-defined"},
{{a8,0,"8th"},0,1,Appearance->"Labeled",ImageSize->Tiny,Enabled->waveshape==="user-defined"},
{{a9,0,"9th"},0,1,Appearance->"Labeled",ImageSize->Tiny,Enabled->waveshape==="user-defined"},
AutorunSequencing->{1}
]

THIS NOTEBOOK IS THE SOURCE CODE FROM

"Fourier Synthesis for Selected Waveforms" from The Wolfram Demonstrations Project
 http://demonstrations.wolfram.com/FourierSynthesisForSelectedWaveforms/

Contributed by: Kenny F. Stephens II

A full-function Wolfram Mathematica 6 system is required to edit this notebook.
GET WOLFRAM MATHEMATICA 6 »

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