# 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
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.25943079590797424, "perplexity": 1782.0060727013658}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 5, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-21/segments/1620243991759.1/warc/CC-MAIN-20210510174005-20210510204005-00445.warc.gz"}