% SIMIODE-TeacherStudent-Template.tex and simiode.cls for LaTeX2e
% Version 22 November 2016.
% 
% This template is to be used with the  class file "simiode.cls". 
%  
% The latest version of this class and template files 
% can be found at
% 
%       <http://www.SIMIODE.org> in the Author section.
%
% A "Quick Start Guide" appears below.
%
% This file must be processed with version LaTeX2e or higher.
% Appreciation to Mark Frantz, IUPUI; John Thoo, Yuba College; and Eric Sullivan, Carroll College.
%
\documentclass{simiode}
%
% With this version of the tex file and the associated SIMIODE.cls file you can produce BOTH a Student Version and a Teacher Version of your modeling scenario or technique narrative.
%
% Student Version contains the title STUDENT VERSION along with the NAME OF SCENARIO, with no abstract, no keywords, no tags, no author identifiers, and no COMMENTS section. The Student Version contains only the STATEMENT of the modeling scenario only with appropriate figures, data, instructions, and perhaps a bibliography appropriate for student resourcing, but nothing in the bibliography which would "give away" the nature of the modeling scenario, etc.
%
%The Teacher Version contains the material in the Student Version, namely the title NAME OF SCENARIO, now headed with   TEACHER VERSION, but also full author  identification, abstract, key words, tag words, and, following the STATEMENT, a section of COMMENTS which can be discussion of presentation  ideas, "solutions," techniques, etc.
%
% Authors can prepare a full Teacher Version using the notions immediately below  to create a pdf for review, but in review please eliminate all information about the author as we use a double-blind referee system. Such information will be restored when accepted and published in SIMIODE at www.simiode.org.
%
%***********   Toggle the following line to turn the teacher version on (1) or off (0). ***********
%
\def\TeacherEdition{0} % Toggle this line's value.
\newcommand{\teacher}[1]{\ifnum\TeacherEdition=1 #1 \fi}
%
% The \teacher{ } command wraps any text that will appear only in the teacher version of
% the document. See this file for examples. This has been done for you in the document below.   
% Rename the pdf after you compile each final version.
%
\usepackage{amsmath,amssymb}
\usepackage{color}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{url}
%
\renewcommand{\baselinestretch}{1.3}
%
% NOTE regarding macros %%
%
% Any macros defined for your paper should be contained in 
% the top matter. Likewise, any environment definitions such 
% as \newtheorem or \newenvironment should also go in the 
% top matter. 
% 
% Do not \input your macros as separate files within your 
% final version because more files make it harder for the 
% editors and users to keep track of and/or modify and 
% append your paper.
%
% Top matter is above and the beginning of the document below.
%
\begin{document}

\newpage
%
% You only need to change the NAME OF SCENARIO in the next line and delete the footnote. 
% See above for instructions on toggling from Teacher Version to Student Version.
%
\title{\ifnum\TeacherEdition=1 TEACHER VERSION  \else STUDENT VERSION \fi\\Trig Sum Representation}




\markboth{Trig Sum Representation}{Trig Sum Representation}

\author{Brian Winkel\\Director 
SIMIODE\\
Chardon OOH 44024 USA\\
BrianWinkel@simiode.org
}

\makeStitlePDFLaTex


\begin{abstract}
Students discover how to represent functions as sums of trigonometric functions and the value of such representations in many fields. This is an introduoction to the study of Fourier Series.
\end{abstract}



\section*{INTRODUCTION}

We are going to do something that might seem foolish, but in a moment we will ask you to consider the possibilities for such a goal. 

\vspace*{.3 true cm}
\begin{center}\parbox{14.4 true cm}{\Large GOAL: Represent the function $f(x) = x$ on the interval $[-\pi, \pi]$ as a sum of trigonometric functions of the form $\sin(n x), n = 1,2,3, \ldots $.}
\end{center}

\vspace*{.3 true cm}
\noindent We decided to shout it out so it is absolutely clear.  Why would anyone want to express a simple function like $f(x) = x$ as a sum of sine waves?  In so doing,  we can learn about representing other functions $f(x)$ as a sum of trigonometric functions -- an activity we show is worthy of our attention and study.

In chemistry, geology, astronomy, engineering, security, and  music,  among so many other fields,  often a signal or function is analyzed by breaking it into its ``harmonic'' or ``frequency'' components, i.e. finding a  sum of trigonometric functions which represents the function. The reason to represent a signal as a sum (or series -- ultimately an infinite sum over  many frequencies) of trigonometric functions is to analyze the different frequencies and their associated amplitudes which go into producing the signal. Often,  we render a picture of the frequencies with their amplitudes in a bar graph. This picture is called a {\it spectrum of the signal\/}. We show several spectrum plots below. 

Consider the following situations in which  a function (albeit a lot more complicated than our straight line $f(x) = x$) is represented as a sum of trigonometric functions.  

The spectrum of a signal can be used to identify the elements in a compound through chemical analysis, to  determine specific motion patterns of the earth in geology, to ascertain the gases in a distant body's atmosphere, to determine if something is going wrong in the case of the dynamic displacement of a moving part in engineering, to analyze the unique larynx sound produced by a human voice for security scanning, or to ascertain the signal produced by a specific instrument in shaping a more pleasant real or synthesized sound.  Some folks use this mathematics to analyze sales or inventory data and some folks use it to help their speculative desires(!) in the stock market. Thus, this spectrum or spectral analysis is in use all around us. We seek to find out what it's all about and how it ties into our study of differential equations that model reality. 

In Figure~\ref{fig:8-002-FidlerSpectroscopy} we see the results of stimulating chemical compounds and analyzing the emitted signal from the compound in an effort to identify the compound, while Figure~\ref{fig:8-002-SpectrumChemical} shows the spectra from absorbance of various chemicals.


Figure~\ref{fig:8-002-ScopePicoAnalyzer} shows the results of stimulating chemical compounds and analyzing the emitted signal from the compound in an effort to identify the compound while  
Figure~\ref{fig:8-002-SpectrumAnalyzer} shows the spectrum of two signals in comparison mode.  Finally, Figure~\ref{fig:8-002-SignalAnalyzer} shows a typical interface panel for a signal analyzer, offering up much information to the user.

\begin{figure}[h]
  \begin{center}
   \includegraphics[width=10 true cm]{8-002-FidlerSpectroscopy.eps}

\vspace*{-6.6 true cm}
\parbox{11 true cm}{\caption{
      fig:1-062-{fig:8-002-FidlerSpectroscopy}
      Spectral analysis at work in chemical analysis. The amplitudes of the respective signals emitting from a stimulate chemical sample identify  the chemical compound.}}
  \end{center}

\vspace*{-.7 true cm}
\end{figure}

    
\begin{figure}[!h]
  \begin{center}
   \includegraphics[width=10 true cm]{8-002-SpectrumChemical.eps}

\vspace*{-6.6 true cm}
\parbox{11 true cm}{\caption{
      \label{fig:8-002-SpectrumChemical}
      Spectral presentation at work in chemical analysis to determine the presence of chemical compounds in a material sample.}}
  \end{center}


\end{figure}


\begin{figure}[!h]
  \begin{center}
   \includegraphics[width=10 true cm]{8-002-ScopePicoAnalyzer.eps}

\vspace*{-6.6 true cm}
\parbox{11 true cm}{\caption{
      \label{fig:8-002-ScopePicoAnalyzer}
      Spectral analysis for headphone testing of signals depicts the amplitude (in decibels) for the many frequencies of a signal coming through a headphone. Such strategies are used to design and tune equipment.}}
  \end{center}
\vspace*{-.4 true cm}

\end{figure}


\begin{figure}[!t]
  \begin{center}
   \includegraphics[width=11 true cm]{8-002-SpectrumAnalyzer.eps}

\vspace*{-8.4 true cm}
\parbox{11 true cm}{\caption{
      \label{fig:8-002-SpectrumAnalyzer}
     Spectrum analyzer.}}
  \end{center}
\vspace*{-.4 true cm}

\end{figure}


\begin{figure}[!h]
  \begin{center}
   \includegraphics[width=11 true cm]{8-002-SignalAnalyzer.eps}

\vspace*{-6.8 true cm}
\parbox{11 true cm}{\caption{
      \label{fig:8-002-SignalAnalyzer}
     Signal analyzer with typical information for analyst offered by such equipment.}}
  \end{center}
\vspace*{-.6 true cm}

\end{figure}



\subsection*{Beginning the discovery}





There are a few details we need  to cover and we can be off to approximating our function and other functions, even  wild functions, using trigonometric functions. Odd and even functions will play a role in this  discovery path. However, initially  we shall confine our introductions to using sine functions  (all odd functions) to represent our sample function, which for now will be an odd function. An odd function, $g(x)$, is one for which $g(-x) = - g(x)$ for all $x$ in the domain of $g$, i.e. possesses symmetry through the origin.  Examples of odd functions include $f(x) = x$,  $f(x) = x^3$, $f(x) = x + x^5$, and our trigonometric functions $\sin(n x)$, $n = 1,2,3, \ldots $.  We will, of course, extend our results beyond this class of functions or signals, but now we confine our study to only odd functions. Indeed, we shall actually confine our efforts to odd functions over the interval $[-\pi,\pi]$.

\begin{quote}
Question:  How does one find the ``best" coefficients $b_1,b_2,b_3, \ldots,b_n$  to put into a linear combination $f_n(x) = b_1\sin(x) + b_2 \sin(2x) + b_3\sin(3x) + \ldots+b_n\sin(nx)$ so that $f_n(x)$ best approximates the straight line $f(x) = x$ over the interval $[-\pi, \pi]$? We are going to have to settle on what is ``best.'' You will do it rather naturally. 
\end{quote}

We set out a number of Activities for you to consider.

\begin{itemize}
\item [1)] 
Sketch several ``one term" approximations of $f(x) = x$ on the interval, $[-\pi, \pi]$, i.e.  find $f_1(x) = b_1 \sin(x)$, where you pick the $b_1$ value to get a feel for what values produce good approximations and what values produce bad ones. For example, $b_1 = 1$ is the obvious one to start, but $b_1 = -1$ is another. The latter is not as good as the former, for the latter goes ``opposite.'' Check this out by graphing both $f(x) = x$ and our estimation $f_1(x)$ with some values of $b_1$ on the same axes in your software package of choice.   With $b_1 = 1$ the estimate at least stays in the right direction. Now play with the amplitude of this one term approximation $f_1(x) = b_1\sin(x)$ and ascertain what value of $b_1$ appears to  be best, even though  we do not have a technical definition of best just yet. This is all just visual judgment.  See Figure~\ref{fig:8-002-OneTermApprox}. Which looks better?
\end{itemize}   



\begin{figure}[h]
\begin{minipage}[t]{7 true cm}
   \includegraphics[width=7 true cm]{8-002-OneTermApprox1.eps}
\vspace*{-5 true cm}
\begin{center}
\parbox{5.8 true cm}{(a) $f_1(x) = \sin(x)$ approximation of $f(x) = x$.}
\end{center}
\end{minipage} \ \hspace*{.1 true cm} \
\begin{minipage}[t]{7 true cm}
   \includegraphics[width=7 true cm]{8-002-OneTermApprox2.eps}
\vspace*{-5 true cm}
\begin{center}
\parbox{5.8 true cm}{(b) $f_1(x) = 1.5 \sin(x)$ approximation of $f(x) = x$.}
\end{center}
\end{minipage} 


\vspace*{-3.5 true cm}
\begin{center}
\parbox{10 true cm}{\caption{\label{fig:8-002-OneTermApprox} Two initial attempts at using just one sine function,  $\sin(x)$, to approximate $f(x) = x$ on the interval $[-\pi,\pi]$. (a) uses $f_1(x) = \sin(x)$ and (b) uses $f_1(x) = 1.5\sin(x)$.}}
\end{center}
\vspace*{-.8 true cm}
\end{figure}


After playing by hand with several values of $b_1$, we see just how weak using only one sine term is, so we move on to two terms. See  plots of two terms in Figure~\ref{fig:8-002-TwoTermApprox}.  Now sketch the addition of   multiples $b_1$ and $b_2$ of the two curves in $f_2(x) = b_1 \sin(x) + b_2 \sin(2x)$. Do a few and then  turn to technology to do plots.



\begin{figure}[t]

\vspace*{-.3 true cm}
\begin{minipage}[t]{7 true cm}
   \includegraphics[width=7 true cm]{8-002-TwoTermsApprox1.eps}
\vspace*{-5 true cm}
\begin{center}
\parbox{4.8 true cm}{(a) $f_2(x) = 1.5 \sin(x) + \sin(2x)$ approximation of $f(x) = x$.}
\end{center}
\end{minipage} \ \hspace*{.1 true cm} \ 
\begin{minipage}[t]{7 true cm}
   \includegraphics[width=7 true cm]{8-002-TwoTermsApprox2.eps}
\vspace*{-5 true cm}
\begin{center}
\parbox{4.8 true cm}{(b) $f_2(x) = 1.5 \sin(x)-\sin(2x)$ approximation of $f(x) = x$.}
\end{center}
\end{minipage} 


\vspace*{-3.5 true cm}
\begin{center}
\parbox{10 true cm}{
\caption{\label{fig:8-002-TwoTermApprox} Two initial attempts at using two sine generators $\sin(x)$ and $\sin(2x)$ to approximate $f(x) = x$ on the interval $[-\pi,\pi]$. (a) uses $f_2(x) = 1.5 \sin(x) + \sin(2x)$ and (b) uses $f_2(x) = 1.5 \sin(x)-\sin(2x)$ .}}
\end{center}
\vspace*{-.6 true cm}
\end{figure}


\subsection*{Systematic approach to finding coefficients}

Guessing will not do. We need to develop some criteria for best. 
Think about what would be a good criteria to measure the best fit. Just think about it and doodle on some scratch paper. A picture is worth a thousand words and may save a thousand moments in time.

Here are some criteria to consider for, say, a two term trigonometric sum, $b_1 \sin(x) + b_2 \sin(2x)$:

\begin{enumerate}
  \item The estimating sum of trigonometric functions stays closest to the function $f(x)$.
  \item Pick 20 points in the interval, $[-\pi,\pi]$, and select the parameters $b_1$ and $b_2$ which minimize the sum of the square errors between the function and the trigonometric sum at each of the corresponding $x$ values.
  \item Offer up, say 10 different candidates and have the class vote. 
  \item Minimize the total sum of the square errors between the function and the trigonometric sum at each point $x$ in the interval, $[-\pi,\pi]$. What corresponds to the sum when we add up an infinite number of errors?
  \item Look it up on the web.
  \item Select a few points on the plot of the function $y = f(x)$ and make sure the approximation goes through these points.
  \item Minimize the area between a proposed trigonometric sum and the function over the interval, $[-\pi,\pi]$.
 \end{enumerate} 

Some of these need clarification and some might be impractical, while some might seem within our reach but need attention to detail. Bring your own criterion and conduct  a discussion  in  groups to come to some consensus.  


\subsection*{Common consensus emerges}

The common consensus which always emerges is (4), i.e. minimize  the total sum of the square errors between the function and the trigonometric sum over each point $x$ in the interval, $[-\pi,\pi]$. This means minimize the following function, an integral, of the two parameters $b_1$ and $b_2$.

\begin{equation}\label{eq:MinTwo}
S(b_1,b_2) = \int_{x=-\pi}^{\pi} \left( f(x) - (b_1 \sin(x) + b_2 \sin(2x))\right)^2\, dx\, .
\end{equation}
So  the coefficients $b_1$ and $b_2$ that make the integral in (\ref{eq:MinTwo})  minimum are the best choices.  In consideration of  
(\ref{eq:MinTwo}) in our above criteria list the possibility that, since the integral will have positive and negative   parts, depending upon whether or not the function, $f(x)$, is  above or not of our approximation sum, respectively, the areas could cancel each other out giving an error of 0, but still not look good at all.   The suggestion to take the absolute value or square the difference are possibilities. Why would one be preferred over the other? Recall words like ``least squares'' from science labs past and present! Also think about how ``messy'' the absolute value function can be with a conditional statement as to whether or not the argument is positive or negative. 

Thus the criterion is to pick the coefficients $b_1$ and $b_2$ so that the integral of the difference squared between the function $f(x)$ and the approximation $f_2(x)=b_1 \sin(x) + b_2 \sin(2x)$ over the interval $[-\pi,\pi]$  is minimal, i.e. minimize (\ref{eq:MinTwo}).

Here for our function,  $f(x) = x$, we  compute  the objective function as offered in (\ref{eq:MinTwo}):

\vspace*{-.2 true cm}
\begin{eqnarray*}
S(b_1,b_2) &=& \int_{-\pi}^{\pi} (f(x) - (b_1 \sin(x) + b_2 \sin(2x))^2\, dx \,
\\ 
&=& \pi  b_1^2-4 \pi 
   b_1+\pi b_2^2  -2 b_2
   \pi +\frac{2 \pi
   ^3}{3} .
\end{eqnarray*}

This looks nice and clean as a function of the two variables, $b_1$ and $b_2$. 
\begin{itemize}\item [2)] Minimize $S(b_1,b_2)$ and thereby determine the best fitting combination of $\sin(x)$ and $\sin(2x)$ terms to be 
$$f_2(x) = 2 \sin(x) - 1 \sin(2x)\, $$
We immediately plot (see Figure~\ref{fig:BestTwoAndThreeTermsApprox}) and confirm visually  that this arrived at $f_2(x)$ is  better than those previously guessed. 
\end{itemize}

\begin{figure}

\begin{minipage}[t]{7 true cm}
   \includegraphics[width=7 true cm]{8-002-BestTwoTermsApprox.eps}
\vspace*{-5 true cm}
\begin{center}
\parbox{5.8 true cm}{(a) $f_2(x) = 2\sin(x) - 1\sin(2x)$, best two term approximation of $f(x) = x$.}
\end{center}
\end{minipage} \ \hspace*{.3 true cm} \
\begin{minipage}[t]{7 true cm}
   \includegraphics[width=7 true cm]{8-002-BestThreeTermsApprox.eps}
\vspace*{-5 true cm}
\begin{center}
\parbox{5.8 true cm}{ (b) $f_2(x) = 2 \sin(x)-1\sin(2x)+ \frac{2}{3}\sin(3x)$, best three term approximation of $f(x) = x$.}
\end{center}
\end{minipage} 


\vspace*{-3.0 true cm}
\begin{center}
\parbox{7.8 true cm}{\caption{\label{fig:BestTwoAndThreeTermsApprox} Best two (a) and three (b) term approximations of $f(x) = x$ on the interval $[-\pi,\pi]$.}}
\end{center}
\vspace*{-.8 true cm}
\end{figure}


\begin{itemize}
  \item [3)] Now determine three coefficients $b_1$, $b_2$, and $b_3$ which minimize the integral of the difference squared using three sine terms, i.e.
$$\int_{-\pi}^{\pi} (f(x) - (b_1 \sin(x) + b_2 \sin(2x)+ b_3 \sin(3x))^2\, dx \, ,$$
and confirm they are as offered in the caption of 
Figure~\ref{fig:BestTwoAndThreeTermsApprox}(b). In a similar manner as with two terms you should find these are $b_1=2$, $b_2=-1$, and $b_3 = \frac{2}{3}$. 
\item [4)] Develop the best coefficients for $n = 4$, 5, 6, and 7 term approximations, and see if you can generalize or see a pattern.
Use the resulting approximations and show that the estimates get better in comparing the resulting errors and graphs.
\item [5)] Make some comments and conclusions about the emerging coefficients $b_k$ and the resulting trigonometric sums. Then offer up a very general sum and take it to infinity, i.e. produce a trigonometric series.  Produce a general formula for $b_k$ based on your study here. Now, while we may not be able to get  a closed form for this series offer a conjecture as to what happens to our approximations as we take more and more terms of this resulting series.
\item [6)] Offer up a 20 term expression for an approximation using our trigonometric functions $\sin(n x)$ for $n = 1, 2, 3,  \ldots $ and render a plot of your sum and the function on the same axes. You should get something like Figure~\ref{fig:8-002-BestTwentyTermsApprox}.
\vspace*{-.4 true cm}
\end{itemize}


\begin{figure}[h]
\begin{center}
   \includegraphics[width=10 true cm]{8-002-BestTwentyTermsApprox.eps}

\vspace*{-7.6true cm}


\parbox{6.8 true cm}{\caption{\label{fig:8-002-BestTwentyTermsApprox}
Best twenty term approximations of $f(x) = x$ on the interval $[-\pi,\pi]$.}}
\end{center}
\end{figure}


\subsection*{General series}

We have confined our exploration to finding sums of a ``few" sine functions to approximate just one function $f(x) = x$ over the  specified interval $[-\pi, \pi]$. What would have to happen to find the best fitting sum of trigonometric functions $\sin(n x)$ for $n = 1, 2, 3, \ldots $ for a general function $f(x)$ over the domain $[-\pi, \pi]$? 

\begin{itemize}\item [7)] Defend (\ref{eq:nTerms}).\end{itemize} 

\vspace*{-.5 true cm}
\begin{eqnarray}\label{eq:nTerms}
f_n(b_1, b_2, \ldots, b_n) \!\!\!\!\!\!&=\!\!\!\!\!\!& \int_{-\pi}^{\pi} (f(x) - (b_1 \sin(x) + b_2 \sin(2x)+ b_3 \sin(3x) + \ldots + b_n \sin(nx))^2\, dx \,  \\ \nonumber
&=&\int_{-\pi}^{\pi} (f(x) - b_1 \sin(x) - b_2 \sin(2x)- b_3 \sin(3x) - \ldots - b_n \sin(nx))^2\, dx \, .
\end{eqnarray}

Minimizing the expression in (\ref{eq:nTerms})  poses a rather daunting task, for there are lots of cross terms from the squaring of such a large expression and then it is inside the integral and one would  still  have to integrate.  Mathematics offers the development and practice of a number of problem solving strategies. One of them is to break down a problem into simple pieces. So we proceed  in a reasoned and orderly fashion, to see just what this messy integral of the differences squared in (\ref{eq:nTerms}) will yield. 

First write out, as in ``long multiplication,''  the product inside the integral 
and plan a strategy to actually do the multiplication.

\vspace*{-.4 true cm}
\begin{eqnarray*}
&& f(x) - b_1 \sin(x) - b_2 \sin(2x)- b_3 \sin(3x) - \ldots - b_n \sin(nx)\\
\times && f(x) - b_1 \sin(x) - b_2 \sin(2x)- b_3 \sin(3x) - \ldots - b_n \sin(nx)
\end{eqnarray*}


Now, systematically looking into all the possible products we see we have 4 types of terms:
\begin{center}
\begin{tabular}{|c|c|c|c|}\hline
Type 1&Type 2&Type 3&Type 4\\ \hline
$f(x)f(x)$ & $b_kf(x) \sin(kx)$& $b_ib_j\sin(ix)\sin(jx)$& $b_ib_j\sin(ix)\sin(jx) = b_i^2 \sin^2(ix)$\\
&&$i\neq j$&$i = j$\\ \hline
\end{tabular}
\end{center}


\noindent Upon examination of these terms, in light of the fact that we wish to find the $b_k$'s which minimize the sum of squared differences integral (\ref{eq:nTerms}), we see that the Type 1 term (actually only one such term) has no bearing on the minimization and can be ignored. Type 2 terms are  clearly of interest as they contain our variables, $b_k$, and we see that the contribution these terms make to the sum, upon integration are 
$$\int_{-\pi}^{\pi} b_k f(x) \sin(kx)\, dx = b_k  \int_{-\pi}^{\pi} f(x) \sin(kx)\, dx $$
Type 3 and 4 are similar and we investigate two integrals:
$$ b_ib_j  \int_{-\pi}^{\pi}\sin(ix)\sin(jx) \, dx \,\,\, {\rm for} \,\,\, i\neq j \quad  {\rm and } \quad b_i^2 \int_{-\pi}^{\pi} \sin^2(ix) \, dx $$
The first cases of Type 3 (where $i \neq j$) yield $$b_ib_j\frac{2 j \cos (j \pi ) \sin
   (i \pi )-2 i \cos (i \pi )
   \sin (j \pi )}{i^2-j^2}\, .$$ Clearly as $i$ and $j$ are integers then the terms $\sin(i\pi)$ and $\sin(j\pi)$ are all 0. This means all the integrals of this form are 0 and contribute nothing to our minimization problem. 

Now, the second cases of Type 3 (where $i = j$) yield $b_i^2\pi -\frac{\sin (2 i \pi )}{2
   i}$. These terms are all just $b_i^2\pi$ as $\sin(2i\pi)$ is 0 for integers $i$. So  all this information says that the sum of square errors, the function of $n$ variables, $b_1, b_2, \ldots, b_n$, we seek to minimize, is simply (\ref{eq:FinSS}):

  \begin{equation}\label{eq:FinSS}
 f_n(b_1,b_2, \ldots, b_n) = \int_{-\pi}^{\pi} (f(x))^2\, dx + \sum_{j=1}^n 2 b_j \int_{-\pi}^{\pi} f(x) \sin(jx)\, dx +  \sum_{j=1}^n b_j^2 \pi\, . 
\end{equation}

Note that we get two of the terms when $i \neq j$.  From (\ref{eq:FinSS}) and our understanding of optimization of a function of more than one variable we see that if we are to minimize  $f_n(b_1,b_2, \ldots, b_n)$ then each of the partial derivatives with respect to $b_1$, $b_2$, \ldots, $b_n$, respectively,  are derivatives of a quadratic in that respective variable and must be set to 0 to obtain our minimum of  $f_n(b_1,b_2, \ldots, b_n)$. So, for example, taking the partial derivative with respect to $b_j$ and setting this derivative equal to 0 (necessary conditions for a minimum in this case) yields (\ref{eq:FINSSD}):

\begin{equation}\label{eq:FINSSD}
\frac{\partial f_n(b_1,b_2, \ldots, b_n)}{\partial b_j} = 2\int_{-\pi}^{\pi} f(x) \sin(jx)\, dx + 2 b_j \pi = 0\, ,$$ which tells us that $$b_j = \frac{1}{\pi}\int_{-\pi}^{\pi} f(x) \sin(jx)\, dx\, , \quad j = 1, 2, \ldots,\, .
\end{equation}

There it is!  For a given function $f(x)$ over the interval $[-\pi,\pi]$ pick the coefficients $b_j$  for the $\sin(jx)$ term according to (\ref{eq:FINSSD}) in order to minimize the integral of the squared difference between our sample function and the sine approximation candidate. We immediately try it for our original case, $f(x) = x$, for which we ``guessed"  $b_j = (-1)^{j+1} \frac{2}{j}$  based on a few terms.

\begin{equation}\label{eq:Try1}
b_j = \frac{1}{\pi}\int_{-\pi}^{\pi} f(x) \sin(jx)\, dx\, =  \frac{1}{\pi}\int_{-\pi}^{\pi} x \sin(jx)\, dx\, =  \frac{2 \sin (j \pi )-2 j \pi 
   \cos (j \pi )}{2 j^2 \pi } \, . 
\end{equation}
In (\ref{eq:Try1}) since $j$ is an integer the $\sin(j \pi)$ term is 0 and this leaves us with 
$$b_j = \frac{2 \sin (j \pi )-2 j \pi 
   \cos (j \pi )}{j^2 \pi } = \frac{-2 \cos(j \pi)}{j} $$
in which $\cos(j \pi)$   oscillates between $+1$ and $-1$ as $j$ is even or odd, respectively, i.e.  $b_j = (-1)^{j+1} \left(\frac{2}{j}\right)$.   

We summarize our accomplishments.

\begin{quote}
Given $f(x)$, an odd function defined on the interval $[-\pi,\pi]$, if we select  $b_j = \frac{1}{\pi}\int_{-\pi}^{\pi} f(x) \sin(jx)\, dx\,$ for $j = 1, 2, \ldots, n$ then the sum $\sum_{j=1}^n b_j\sin(jx)$ is a reasonable approximation for the function $f(x)$ on the interval $[-\pi,\pi]$ and as $n$ increases this approximation appears to get better. 
\end{quote} 

\begin{itemize}
\item[8)] Using our results thus far determine a sum of  trigonometric functions $\sin(nx)$, $n = 1, 2, 3, \ldots$ to render a best approximation of $f(x) = x^3$. Render plots to confirm your efforts. NB:  We are still working on odd functions to approximate  the odd trigonometric functions $\sin(nx)$, $n = 1, 2, 3, \ldots$, so we do not address $f(x) = x^2$ yet.
\item[9)] As an example of what we can accomplish consider the stepwise defined odd function, (\ref{eq:StepFunction}).

\begin{equation}\label{eq:StepFunction}
f(x) = \left\{ 
\begin{array}{l}
-1, \quad \mbox{if \quad $x<0$}\\
+1, \quad \mbox{if \quad $x\geq 0$}\, .
\end{array}
\right.
\end{equation}

\noindent Using (\ref{eq:FINSSD}) determine the first 20 terms of the sum of  trigonometric functions $\sin(nx)$, $n = 1, 2, 3, \ldots$  we developed. Plot the results over the original function itself. You should get a plot which looks like  Figure~\ref{fig:8-002-StepSeries}. 
\end{itemize}

 \begin{figure}[h] 
\vspace*{-.6 true cm}
\begin{center}
 \includegraphics[width=10 true cm]{8-002-StepSeries.eps}
\vspace*{-8.0 true cm}


\parbox{9. true cm}{\caption{\label{fig:8-002-StepSeries} Best twenty term approximations of $f(x)$ defined to be 1 on the interval $(0,\pi]$ and -1 on the interval $[-\pi,0]$.}}
\end{center}
\vspace*{-1 true cm}
\end{figure}

\subsection*{An aside}

A Fourier series  is not to be confused with a Furry A series which is shown in Figure~\ref{fig:8-002-FurryASeries}.

\begin{figure}[!h]
  \begin{center}

   \includegraphics[width=1.6 true cm]{8-002-FurryASeries.eps}
\vspace*{-.7 true cm}

\parbox{9 true cm}{\caption{
      \label{fig:8-002-FurryASeries}
   A Furry A series.}}
  \end{center}
\end{figure}

\vspace*{-1 true cm}
 \subsection*{Full series - odd and even functions and combinations}


The development of trigonometric series to represent functions was laid out by Joseph Fourier, who studied heat transfer issues,  in  his 1822 publication,  ``\ldots {\it La Th\'eorie analytique de la chaleur\/}, which by its new methods and great results made an epoch in the history of mathematical and physical science, with the introduction of the Fourier Series."\cite{MNDB2013}


We just developed an approach for representing odd functions with a trigonometric sum using sine functions over the interval $[-\pi,\pi]$. More general functions will need odd and even functions, hence there is a  full sine and cosine Fourier series. Here  assume a function $f(t)$ which is defined on the interval $[-L,L]$ and $f(t)$ is  periodic with period $2L$, i.e.  repeats itself over and over in consecutive intervals of length $2L$, $[L, 3L]$, $[3L, 5L]$, $[5L, 7L]$, etc. This general Fourier series is given in (\ref{eq:GenFourier})

\begin{equation}\label{eq:GenFourier}
f(t) = \frac{a_0}{2}+\sum_{n=1}^{\infty} \left(a_n \cos \left(\frac{2 \pi n t}{L}\right) + b_n  \left(\frac{2 \pi n t}{L}\right)\right)\,  , 
\end{equation}
where the coefficients $a_n$ and $b_n$ are given in (\ref{eq:Coeff}):

\begin{equation}\label{eq:Coeff}
a_n = \frac{1}{L} \int_{-L}^L f(t) \cos \left(\frac{2 \pi n t}{L}\right)\, dt\, , \quad {\rm and} \quad 
 b_n = \frac{1}{L} \int_{-L}^L f(t) \sin \left(\frac{2 \pi n t}{L}\right)\, dt\, \quad {\rm for} \, \, \, n = 0,1,2,3, \ldots \, .
\end{equation}
Actually we need only start the indexing at $n = 1$ for the $b$ coefficients as $b_1 = 0$.

Further, we can develop formulae for  Fourier series over  the interval $[0, L]$, the latter being most useful in defining functions of time, $t$, for $t \geq 0$. We do this by extending our function $f(t)$ as either an odd or even function over the interval $[-L,L]$ and computing the Fourier series. We do this by considering an  odd or even extension from the interval $[0,L]$ to the interval $[-L,L]$ and then only using the domain of the resulting series (\ref{eq:GenFourier}) for the respective extensions  over the interval $[0,L]$. The result is

\begin{equation}\label{eq:EvenExt}
f(t) = a_0 + \sum_{n=1}^{\infty} a_n \cos \left(\frac{ \pi n t}{L}\right)\, , \quad {\rm where} 
\end{equation}

\begin{equation}\label{eq:EvenExt}
a_0 = \frac{1}{L} \int_0^L f(t) \, dt \quad {\rm and} \quad a_n = \frac{2}{L} \int_0^L f(t)\cos\left(\frac{n \pi t}{L}\right) \, dt\quad {\rm for} \,\,\, n\geq1 
\end{equation}
for the even extension or 

\begin{equation}\label{eq:OddExt}
f(t) =  \sum_{n=1}^{\infty} b_n \sin \left(\frac{ \pi n t}{L}\right)\, , \quad {\rm where} 
\end{equation}
\begin{equation}\label{eq:OddExt}
b_n = \frac{2}{L} \int_0^L f(t)\sin\left(\frac{n \pi t}{L}\right) \, dt\quad {\rm for} \,\,\, n\geq 1 \, .
\end{equation}
for the odd extension.

These two formulations, (\ref{eq:EvenExt})  and  (\ref{eq:OddExt}) will prove to be most useful (see Figure~\ref{fig:8-002-FourierCartoon}) in differential equations work we shall encounter, primarily in the solution strategies for partial differential equations.

\begin{figure}[!h]
\begin{center}
   \includegraphics[width=9.5true cm]{8-002-FourierCartoon.eps}
\vspace*{-6.2 true cm}
 
\parbox{11 true cm}{\caption{
      \label{fig:8-002-FourierCartoon}
  Reprinted from {\tt www.cartoonbank.com} with permission and license. Originally appeared in {\it The New Yorker\/}, 4 October 2010. p.~71}}
  \end{center}
\vspace*{-.4 true cm}
\end{figure}



\begin{itemize}\item [10)]
Determine  the Fourier coefficients $a_n$ and $b_n$ as given in (\ref{eq:Coeff}) for the Fourier series representation of $f(t) = t  + 5 t^2 - t^3 + 14 \vert t-3 \vert$ in the interval $[0, 4]$. Plot the function on the same axes as the first $n = 5, 10, 20$, and $50$ pairs of sine cosine terms and comment on what you see.
\end{itemize}






\subsection*{Spectrum issues}



The spectrum of a function is  a list of the amplitudes of the contributions of the individual frequencies to the Fourier series representation of that function.  It is used to fingerprint functions and other signals, such as those used in spectrometers in  chemistry, sound synthesizers used in  music, signal analyzers to detect irregularities in motion of machines through motion detector signals, and voice recognition units for security. 

The Fourier series representation of a function over the interval $[-L,L]$ is given in  (\ref{eq:GenFourierSpect}).
\begin{equation}\label{eq:GenFourierSpect}
f(t) = \frac{a_0}{2}+\sum_{n=1}^{\infty} \left(a_n \cos \left(\frac{2 \pi n t}{L}\right) + b_n  \left(\frac{2 \pi n t}{L}\right)\right)\,  . 
\end{equation}

\noindent The {\it spectrum\/} consists of the following pairs of numbers
\begin{equation}\label{eq:Spectrum}
\{n, \sqrt{a_n^2 + b_n^2}\}\, , n = 0,1,2,3, \ldots\, .
\end{equation}
where the $\sqrt{a_n^2 + b_n^2}$ terms are the computed amplitudes of the combined sine and cosine terms at each frequency, these being phase shifted sine functions often. In Figure~\ref{fig:8-002-FourierSpectrumTwoSine} we show the spectrum for 100 frequencies of the Fourier series approximation of the function $$f(x) = 150\sin(220\cdot 2 \pi t) + 100 \sin(440 \cdot2 \pi t)$$ an audio signal consisting of just two sound signals, a 220 Hz signal with amplitude 150 and a 440 Hz signal with amplitude 100. Notice the spikes at the contributing frequencies and the 0 values for all other frequencies.


\begin{figure}[!h]
\begin{center}
   \includegraphics[width=10 true cm]{8-002-FourierSpectrumTwoSine.eps}



\parbox{10.8 true cm}{\caption{\label{fig:8-002-FourierSpectrumTwoSine} Spectrum of two sound signals, a 220 Hz signal with amplitude 3 and a 440 Hz signal with amplitude 2.}}
\end{center}

\end{figure}


\vspace*{-.3 true cm}\begin{itemize}\item [11)]
Determine  the Fourier coefficients $a_n$ and $b_n$ are given in (\ref{eq:Coeff}) for the Fourier series representation of $f(t) = t  + 5 t^2 - t^3 + 14 \vert t-3 \vert$ in the interval $[0, 4]$. (This is the same function as in Activity (10) above.) 

Plot the spectrum for the first $n = 5, 10, 20$, and $50$ pairs of sine cosine terms (each as a plot of points $\{(k, {\rm Amplitude\,\,\, of\,\,\, frequency}\,\, k) \vert\, k  = 0, 1, 2, \ldots  n\}$)  and comment on what you see.
\item [12)] Determine  the Fourier coefficients $a_n$ and $b_n$ are given in (\ref{eq:Coeff}) for the Fourier series representation of 
$f(t) = 3 + 7 t +3 t^2 + 2 t^3$  in the interval $[-\pi,\pi]$. Plot the function on the same axes as the first $n = 5, 10, 20$, and $50$ pairs of sine cosine terms and comment on what you see.

Plot the spectrum for the first $n = 5, 10, 20$, and $50$ pairs of sine cosine terms (each as a plot of points $\{(k, {\rm Amplitude\,\,\, of\,\,\, frequency}\,\, k) \vert\, k  = 0, 1, 2, \ldots  n\}$)  and comment on what you see.
\end{itemize}


\subsection*{Using Fourier approximation in differential equations}

We consider the  differential equation (\ref{eq:ODE}) and use a Fourier series approximation for the driver function $f(t)$. 

\begin{equation}\label{eq:ODE}
3 y''(t) + 5 y'(t) + 6 y(t) = f(t), \quad y(0) = 0, \quad y'(0) = 0\,
\end{equation}
where the driver function, $f(t)$, is depicted in Figure~\ref{fig:8-002-ODEDriver}.

\begin{figure}[h]
\begin{center}
   \includegraphics[width=8 true cm]{8-002-ODEDriver.eps}



\parbox{10.8 true cm}{\caption{\label{fig:8-002-ODEDriver} Driver function $f(t)$ for the differential equation (\ref{eq:ODE}).}}
\end{center}
\vspace*{-.3 true cm}
\end{figure}

The driver function, $f(t)$, consists of several step functions, each of which is  denoted by a Heaviside function, $u_a(t) = u(t-a)$.

\begin{equation}\label{eq:Heaviside}
u_a(t) = u(t-a) = \left\{ 
\begin{array}{l}
0, \quad \mbox{if $x<a$\, ,}\\
1, \quad \mbox{if  $x\geq a$\, .}\\
\end{array}
\right.
\end{equation}

\begin{equation}
f(t) = 3 u(t - (-10)) + 5 u(t - 7) - 
  7 u(t - (-2)) + 3 u(t - 10) + 
  5 u(t - 7) - 9 u(t - 2) 
\end{equation}

Figure~\ref{fig:8-002-ODEDriverAnd20TermFourierApprox} shows solutions to (\ref{eq:ODE}) using the actual driver function $f(t)$ and also using its $n=20$ term Fourier approximation on the same axes.


We could solve (\ref{eq:ODE}) using either Laplace transform techniques or a numerical solver. However,  for demonstration of the effectiveness of the Fourier series representation let us first take the Fourier approximation, say $n = 20$ terms, of the driver function $f(t)$, and use that in the  solution of (\ref{eq:ODE}) instead of the actual driver, $f(t)$.

Figure~\ref{fig:8-002-ODESOLDriverAnd20TermFourierApprox} shows the actual solution of (\ref{eq:ODE}) with that obtained using the $n=20$ term Fourier approximation of $f(t)$.  We see that the solutions are almost identical, thus illustrating the power of Fourier approximations in representing functions.




\begin{figure}[!h]
\begin{center}
   \includegraphics[width=8 true cm]{8-002-ODEDriverAnd20TermFourierApprox.eps}



\parbox{10.8 true cm}{\caption{\label{fig:8-002-ODEDriverAnd20TermFourierApprox}  Plot of solutions to (\ref{eq:ODE}) using the actual driver function $f(t)$ and also using its $n=20$ term Fourier approximation on the same axes over the interval $[-10,10]$.}}
\end{center}

\end{figure}

\vspace*{-.3 true cm}
\begin{figure}[!h]
\begin{center}
   \includegraphics[width=8 true cm]{8-002-ODESOLDriverAnd20TermFourierApprox.eps}



\parbox{10.8 true cm}{\caption{\label{fig:8-002-ODESOLDriverAnd20TermFourierApprox} Driver function $f(t)$ for the differential equation (\ref{eq:ODE}) and $n=20$ term Fourier approximation for $f(t)$ on the interval $[-10,10]$.}}
\end{center}
\end{figure}


\subsection*{Cleaning up a signal using Fourier series}

In the file 8-002-T-Mma-Filter-TrigSumRepresentation.nb (and .pdf) we offer up a situation in which we have some data with noise in it. We suspect the data is from a parabolic signal going through the origin $(0,0)$ which has had noise added to it in the form $a_k\cos(k t)$ and $b_k\sin(k t)$ for $k = 5, 8, 13$. We show how the spectrum identifies the frequency of the noise (see Figure~\ref{fig:8-002-FilterSpectrum}) and then how to subtract out the noise to recover the underlying parabola with some data fitting to accomplish the last step.


\begin{figure}[!h]
\begin{center}
   \includegraphics[width=15 true cm]{8-002-FilterSpectrum.eps}

\parbox{8.8 true cm}{\caption{\label{fig:8-002-FilterSpectrum}  Spectrum of signal with  high amplitudes of the suspicious frequencies $n = 5, 8, 13$ clearly standing out.}}
\end{center}
\vspace*{-.7 true cm}

\end{figure}

So, while the receiver may not know the noisy frequencies it is possible by analyzing the spectrum to see just what frequencies are contributing substantial noise in order to subtract out such noise. Thus this exploration can give students ideas on how Fourier series can be used in ``sleuthing.''

We also offer up the signal data with time and amplitude in an Excel file (8-002-T-Excel-Filter-TrigsumRepresentation.xls) for extraction and use in whatever software the reader wishes to use.



\section*{Conclusion}

Now  we have  the idea of just how a series of trigonometric functions can  approximate a function over any finite interval and we have seen several applications of such methods.  While this formal study was  due to Fourier in the early 19$^{\rm th}$ century and is in the domain of classical mathematics, we see that we can discover the approach for ourselves!  

\teacher{
\section*{NOTES FOR TEACHERS}

We have made a number of  comments to the students throughout this text narrative which are very appropriate for the teacher as well. We now put our remaining comments and solution strategies into a {\it Mathematica\/} file, 8-002-T-Mma-TrigSumRepresentation.nb (and .pdf). Furthermore, we have published
   an article \cite{Winkel2008} on this approach.
   }
  
\begin{thebibliography}{99}


\bibitem{MNDB2013} MNDB. 2013. Jean Baptiste Joseph Fourier. \href{http://www.nndb.com/people/558/000087297/}{http://www.nndb.com/people/558/000087297/}.
\teacher{\bibitem{Winkel2008} Winkel, B. J. 2008. Fourier Series: Optimization Opportunity. {\it International Journal of Mathematical
Education in Science and Technology\/}. 39(2): 276-284.}


\end{thebibliography}









\end{document}
