# Using Manipulate to show how Fourier transform varies

I have done the piecewise Fourier transform and now I am stuck with trying to get the final plot (on final picture) to make a manipulable plot.

I am new to Mathematica, hence I am using the trial version. The question has been done and I am not sure if answer is correct. I just need to know how to manipulate a double plotted wave of the step wave and the Fourier one with respect to n.

Any help would be appreciated!

Regards, Ben.

• Welcome to Mathematica.SE! Please do not post screenshots of your code. Instead, post the code in proper Mathematica syntax, properly formatted in code blocks. Edit our post by clicking the grey edit button at the bottom of your post and click the grey question mark on the right side of the editing toolbar for formatting help. – march Mar 17 '17 at 20:24

I am going to use Piecewise rather than While. Not a big deal but Piecewise is specifically designed for this type of problem. I am also going to use less than or equal so that there are no gaps (again, probably no affect for this problem).

f[t_] := Piecewise[{{-2, -π < t < -π/2}, {0, -π/2 <= t < 0},
{ 3, 0 <= t < π}}]


Now plot it and save the plot

plot1 = Plot[f[t], {t, -π, π}, Exclusions -> None,
Ticks -> {{-π, -π/2, 0, π/2, π}, {-2, 3}},
PlotRange -> {Automatic, {-2.5, 3.5}}, PlotStyle -> Black]


For the second plot the input function will be

FourierTrigSeries[f[t], t, n]


where n is the integer selected in Manipulate. However one needs to wrap this expression in Evaluate before feeding it to plot.

Below is an example with n = 3.

Plot[Evaluate[FourierTrigSeries[f[t], t, 3]], {t, -π, π},
Ticks -> {{-π, -(π/2), 0, π/2, π}, {-2, 3}},
PlotStyle -> Red]


Put this in a Manipulate where we ask for the number n to be an odd integer from 1 to 21. Use Show to display the two plots together.

Manipulate[
Show[
plot1,
Plot[Evaluate[FourierTrigSeries[f[t], t, n]], {t, -\[Pi], \[Pi]},
Ticks -> {{-\[Pi], -(\[Pi]/2), 0, \[Pi]/2, \[Pi]}, {-2, 3}},
PlotStyle -> Red]
],
{{n, 3}, 1, 21, 2}
]


The above was for n=3. The figure below is for n=7.

• That's great thank you! This is good for visualizing the convergence, very helpful. – BC939422 Mar 18 '17 at 12:24