Class blog 2/14

ECE 3340 - Han Q. Le (c)

Questions from the class and things for next week.

1. Questions

1.1  How did you figure out the numbers in the array coef that will ...create the heart-shape?

Start from drawing the heart shape with an analytic formula (see CW)

heart[x_,σx_]:=0.85*{If[Abs[x]≤0.4,(Sqrt[0.4])-If[x<0.,(Sqrt[Abs[x+0.4]]),(Sqrt[Abs[0.4-x]]) ],(Sqrt[0.4])]
,If[Abs[x]≤0.4,If[x<0.,(Sqrt[0.4])+1.4(Sqrt[0.25^2-(x+0.15)^2])
,(Sqrt[0.4])+1.4(Sqrt[0.25^2-(x-0.15)^2])],(Sqrt[0.4])]};
heartfill={2-> {{1},Hue[0.,0.5,1.]}};

Plot[Release @ heart[x,σ],{x,-0.5,0.5}
,Filling->heartfill,AspectRatio->Automatic]

Then, the coefficients are simply obtained by the Fourier theorem:         
    (Subscript[c, m])=(1/Λ) (∫_(-Λ/2)^(Λ/2))heart[x,σ] (e^(-i 2 m π x/Λ  ))dx
where Λ is the period.

The code was given explicitly:

nchan=32; funcname=heart;funcfill=heartfill;
coef0=Chop[Table[Quiet[NIntegrate[funcname[x,σ]*(E^(-I 2 π n x)),{x,-0.5,0.5}
,AccuracyGoal->3 ]]
,{n,0,nchan}],(10^(-5)) ];
coef=Join[{1},ConstantArray[2,nchan]]* # & /@ Transpose[coef0]

The above are the coefficients (trimmed to 4 digits) and given in the classwork assignment.

1. 2 How did you know that using Cos function will create the heart-shape, instead of using Sin function, or Tan function, or Sec function?

ONLY SIN or COS functions form the complete ORTHOGONAL basis for the Fourier theorem. TAN and SEC are NOT the basis functions (see more in Section 2). This is critical.

Why only using Cos and not Sine?

Fourier theorem states:
  f[x]= ...  (Subscript[c, -m]) (e^(- i m 2 π x/Λ ))+...+(Subscript[c, -1]) (e^(- i  2 π x/Λ )) + (Subscript[c, 0])
               ...   (Subscript[c, m]) (e^(i m 2 π x/Λ ))   + ...+(Subscript[c, 1]) (e^( i  2 π x/Λ ))

Then, take the complex conjugate:
(SuperStar[f])[x]= ...  (Subscript[c, -m]^( * )) (e^( i m 2 π x/Λ ))+...+(Subscript[c, -1]^( * )) (e^(i  2 π x/Λ )) + (SuperStar[(Subscript[c, 0])])
               ...   (Subscript[c, m]^( * )) (e^(-i m 2 π x/Λ ))  + ...+(Subscript[c, 1]^( * )) (e^( i  2 π x/Λ ))
Since f[x] is real:            f[x] = (SuperStar[f])[x]    
Hence:                                            (Subscript[c, -m]) =(Subscript[c, m]^( * ))

Thus we can add pair-wise:
                                (Subscript[c, -m]) (e^(- i m 2 π x/Λ ))+(Subscript[c, m]) (e^(i m 2 π x/Λ )) = 2 Re[(Subscript[c, m]) (e^(i m 2 π x/Λ ))]

This is the reason we write:
                                               Re[ coef . fExpn ]  in the code.

Special case: Even or symmetric function:        f[-x] = f[x] 
then:                                                         (Subscript[c, -m]) =(Subscript[c, m]) 
Hence:           (Subscript[c, -m]) (e^(- i m 2 π x/Λ ))+(Subscript[c, m]) (e^(i m 2 π x/Λ )) = 2  (Subscript[c, m])  Cos[m 2 π x/Λ ]
Thus, we can use only Cos and no need for Sine.

The other special case: Odd or anti-symmetric function:   f[-x] = -f[x] 
Then:                                                (Subscript[c, -m]) =-(Subscript[c, m]) 
It follows:
                 (Subscript[c, -m]) (e^(- i m 2 π x/Λ ))+(Subscript[c, m]) (e^(i m 2 π x/Λ )) = (Subscript[c, m])  ((e^(i m 2 π x/Λ ))-(e^(-i m 2 π x/Λ )))
                                                                  = (Subscript[c, m]) 2 i Sin[m 2 π x/Λ ]
 Since:                                             (Subscript[c, -m]) =(Subscript[c, m]^( * )) =-(Subscript[c, m]) 
 (Subscript[c, m]) must be purely imaginary:             (Subscript[c, m])=± i |(Subscript[c, m])| 
 and the product         (Subscript[c, m]) 2 i Sin[m 2 π x/Λ ]  is real as expected.

Example of this case of odd function was when we did in the class for an odd function:

(1/Λ)(∫_(-(Λ/2))^(Λ/2))(x^3) (E^(-((I 2 π m x)/Λ)))\[DifferentialD]x

Substitute

((I (Λ^3) (m π (-6+(m^2) (π^2)) Cos[m π]-3 (-2+(m^2) (π^2)) Sin[m π]))/(8 (m^4) (π^4)))/.Sin[m π]-> 0

Substitute again:

((I (-6+(m^2) (π^2)) (Λ^3) Cos[m π])/(8 (m^3) (π^3))) /. Cos[m π]-> (((-1))^m)

(Subscript[c, m])=i (Λ^3) (((-1))^m) (( ((π^2) (m^2)-6))/(8 (π^3) (m^3)))   is a purely imaginary quantity.

The answer: because heart-shape function is an even function, hence, we can use only Cos functions, and they are sufficient. But never ever think of Tan or Sec as the basis functions for the Fourier series - please see Section 2.

1.3 How did you know that taking the dot product of coef and fcosn will create 2 arrays that when you plot, you will get the heart-shape?

See answer in 1.1 above. The coefficients were taken by the formula for Fourier series coefficients, hence what we do is simply reconstruct the original, up to the frequency that we choose (32 in this case).

Here is something to look at again to understand:

To draw a penguin, we need 12 single-value functions (12 drawing lines) as shown below. Beside 12 functions, we also need two constant lines for coloring. Execute to understand:

ellipse[x_,{a0_,b_,w_,h_},ibranch_]:=
If[ibranch>0.,
If[Abs[x-w]<a0,h+((b (Sqrt[(a0^2)-(w^2)+2 w x-(x^2)]))/a0) ,h]
,If[Abs[x-w]<a0,h-((b (Sqrt[(a0^2)-(w^2)+2 w x-(x^2)]))/a0) ,h]]; 
ellipseS[x_,{a0_,b_,w_,h_},ibranch_]:=
If[ibranch>0.,
If[w-a0<Abs[x]<w+a0,h+((b (Sqrt[Abs[2 w x]+(a0^2)-(w^2)-(x^2)]))/a0) ,h]
,If[w-a0<Abs[x]<w+a0,h-((b (Sqrt[Abs[2 w x]+(a0^2)-(w^2)-(x^2)]))/a0) ,h]];  

penguin[x_,σx_]:=0.3*{
ellipse[x,{0.5,2.,0,1},1]
,ellipse[x,{0.5,1.,0,1},1]
,
ellipse[x,{0.4,2,0,2},1]
 ,ellipse[x,{0.4,2,0,2},-1]  

 ,ellipse[x,{0.3,1.5,0,0.725},1]
 ,ellipseS[x,{0.1,0.5,0.15,2.7},1] 
 ,ellipseS[x,{0.1,0.5,0.15,2.7},-1] 
 ,ellipseS[x,{0.05,0.2,0.14,2.7},1] 
 ,ellipseS[x,{0.05,0.2,0.14,2.7},-1] 

,ellipseS[x,{0.15,0.4,0.2,0.},1] 

,ellipse[x,{0.125,0.25,0,2},1]
,If[Abs[x]<0.125,0.74+((0.8 (Sqrt[(0.1^2)+(x^2)]))/0.1),2.]
,2.
,0.
 } ;
penguinfill= {1-> {{2},Black}
,3-> {{13},Black}
,4-> {{13},Black}
 ,5-> {{14},White}
,6-> {{7},White},8-> {{9},Black}
,10-> {{14}, Hue[0.12,1,1]}
,11-> {{12}, Hue[0.12,1,1]}
} ;

This is the plot of penguin function:

funcname=penguin; funcfill=penguinfill;
 plotstyle={{Thickness[0.],GrayLevel[0.5]}};
styleparm={plotstyle,funcfill};imgoriginal=Plot[Release @ funcname[x,0.15],{x,-0.5,0.5}
,PlotStyle->plotstyle
,Filling->funcfill
,AspectRatio->Automatic]

We can get the Fourier coefficients by simply apply:
      (Subscript[c, m])=(1/Λ)(∫_(-(Λ/2))^(Λ/2))penguin[x] (e^(-((i 2 π m x)/Λ)))dx

These lines of code do it:
 imgFourier=fouriergraphics2[{funcname,σ, styleparm},nchan,nintv];

Here is the explanation how it is done inside Block function  fouriergraphics2

Read through the code below to understand the steps involved.

fouriergraphics2[{funcArtnm_,σ_,styleparm_}, nFouriercomp_,nintv_]:=Block[{coef0
,coef,xpltarr,fexpn,outFS}
,
coef0=Chop[Table[Quiet[NIntegrate[funcArtnm[x,σ]*(E^(-I 2 π n x)),{x,-0.5,0.5}
,AccuracyGoal->3 ]]
,{n,0,nFouriercomp}],(10^(-4)) ];

If[Length[Dimensions[coef0]]≥ 2 && Depth[coef0]≥   3
,coef=Join[{1},ConstantArray[2,nFouriercomp]]* # & /@ Transpose[coef0]
,coef=Join[{1},ConstantArray[2,nFouriercomp]]*coef0;
];
xpltarr=Range[-0.5,0.5,1./nintv];
fexpn=Table[(E^(I 2 π n xpltarr )),{n,0,nFouriercomp}];
outFS=Re[coef . fexpn ] ;
ListLinePlot[outFS,DataRange-> {-0.5,0.5},PlotRange-> All
,PlotStyle->styleparm[[1]]
,Filling->styleparm[[2]]
,AspectRatio->Automatic
]
];

The output of the above function is to reconstruct - or to do a Fourier synthesis of the function that we input, which, in this case, is penguin function.

start=Date[];
nchan=48;nintv=256;
imgFourier=fouriergraphics2[{funcname,σ, styleparm},nchan,nintv];
Grid[{Show[#,ImageSize->250] & /@ { imgoriginal,imgFourier}}]
Grid[{{"time taken: ",Take[Date[]-start,-3] . {3600,60,1} ," sec."}}, BaseStyle->{18, Italic, FontFamily->"Calibri"}]

If we use only 3 Fourier components: m=1, 2, 3, this is how it looks:

start=Date[];
nchan=3;nintv=256;
imgFourier=fouriergraphics2[{funcname,σ, styleparm},nchan,nintv];
Grid[{Show[#,ImageSize->250] & /@ { imgoriginal,imgFourier}}]
Grid[{{"time taken: ",Take[Date[]-start,-3] . {3600,60,1} ," sec."}}, BaseStyle->{18, Italic, FontFamily->"Calibri"}]

If we use only 4 Fourier component: m=1, 2, 3, 4, this is how it looks:

start=Date[];
nchan=4;nintv=256;
imgFourier=fouriergraphics2[{funcname,σ, styleparm},nchan,nintv];
Grid[{Show[#,ImageSize->250] & /@ { imgoriginal,imgFourier}}]
Grid[{{"time taken: ",Take[Date[]-start,-3] . {3600,60,1} ," sec."}}, BaseStyle->{18, Italic, FontFamily->"Calibri"}]

1.4 For example, if I want to plot a chair-shape, where should I begin with? How can I figure out the method?

Write a multi-value function to describe the chair the same way as penguin function describes a penguin, then do this: change funcname to chair with appropriate filling color for the chair.

chair[x_,σ_]:=(* your function here  *)

nchan=48 (* any value you wish *);
nintv=256; funcname=chair; funcfill=chairfill;
 plotstyle={{Thickness[0.],GrayLevel[0.5]}};
styleparm={plotstyle,funcfill};
imgoriginal=Plot[Release @ funcname[x,0.15],{x,-0.5,0.5}
,PlotStyle->plotstyle
,Filling->funcfill
,AspectRatio->Automatic];
imgFourier=fouriergraphics2[{funcname,σ, styleparm},nchan,nintv];
Grid[{Show[#,ImageSize->250] & /@ { imgoriginal,imgFourier}}]

That’s it.

Here, this is a simple example of the half-moon bridge:

moonbridge[x_,σ_]:={( ((((1/2)))^2) -(x^2)),If[Abs[x]≤(1/5),(Sqrt[((((1/5)))^2)-x^2]),0]};

This is how it looks:

moonfill={1-> {{2},Hue[0.6,0.3,0.9]}} ;
Plot[Release @ moonbridge[x,σ]
,{x,-0.5,0.5}, AspectRatio->Automatic
,Filling->moonfill
,Axes->False]

Now, see this:

nchan=16 (* this is good enough for smooth functions *);
(* you only have to change the name of function and fill  *)
nintv=256; funcname=moonbridge; funcfill=moonfill;
 plotstyle={{Thickness[0.],GrayLevel[0.5]}};
styleparm={plotstyle,funcfill};
imgoriginal=Plot[Release @ funcname[x,0.15],{x,-0.5,0.5}
,PlotStyle->plotstyle
,Filling->funcfill
,AspectRatio->Automatic];
imgFourier=fouriergraphics2[{funcname,σ, styleparm},nchan,nintv];
Grid[{Show[#,ImageSize->350] & /@ { imgoriginal,imgFourier}}]

Have fun! I suggest drawing a recliner. But here are more interesting artworks that had been tried by other students in the past. They didn’t look exactly the same. I only recalled the ideas.

,    
Just a few as examples. It was given as HW, but too labor-intensive for most, only a fraction of the class could do it. Triangle function (for pine tree) and Ellipse function (for penguin) were given. Students just combined them such as the witch hat, or ice cream cone.

2. Dot product in Fourier series theorem

2.1 Formal review (if you forgot linear algebra)

In an N-dimensional space with basis vectors:
                           {(Subscript[u, 1]) , (Subscript[u, 2]),  ...  (Subscript[u, N])}

Any point (or element) in that space can be represented as a DOT product:
             x = (Subscript[x, 1  ])(Subscript[u, 1]) +(Subscript[x, 2  ])(Subscript[u, 2]) + ... +(Subscript[x, N  ])(Subscript[u, N])  
     = (({{(Subscript[x, 1  ]), (Subscript[x, 2  ]), ⋯, (Subscript[x, N  ])}})) ·  (({{(Subscript[u, 1])}, {(Subscript[u, 2])}, {⋮}, {(Subscript[u, N])}}))
One can use the transpose format of the above, which is fine.

In Fourier series theorem, the functions:
     (1/(Sqrt[Λ])){(e^(-i  ∞ 2 π (x/Λ))) , ⋯,(e^(-i  m 2 π (x/Λ))) ,1,⋯,(e^(i m 2 π (x/Λ))) ,⋯,(e^(i ∞ 2 π (x/Λ)))}
form a complete orthonormal basis system: (infinite-dimension space) like the u basis vectors above.

For those who care about formal mathematics, the vector space in this case is the space of piece-wise continuous, square-integrable functions, defined in a finite interval. For convenience, we can let that interval be [0, Λ).

Then. the inner product of two vectors (i. e. two functions) f[x] and g[x] is defined to be:
                               f · g ≡ ⟨f|g⟩≡ (1/Λ) (∫_0^Λ)(SuperStar[f])[x] g[x]dx
(Notation bra ⟨ |  and ket | ⟩ are very useful in physics).

Denoting the function      (1/(Sqrt[Λ]))(e^(i n 2 π (x/Λ)))≡ (Subscript[ϵ, n])
Then, the set    
          (Subscript[{(Subscript[ϵ, n])}, n∈ℤ])≡ {(Subscript[ϵ, -∞]), ⋯, (Subscript[ϵ, -m]) ⋯ ,1,⋯,(Subscript[ϵ, m]) ,⋯ ,(Subscript[ϵ, ∞])} for  m∈(ℤ^(>0))

forms a complete orthonormal basis system:                             
          (Subscript[ϵ, m]) · (Subscript[ϵ, n]) ≡⟨(1/(Sqrt[Λ]))(SuperStar[((e^(i m 2 π (x/Λ))))])|(1/(Sqrt[Λ]))(e^(i n 2 π (x/Λ))) ⟩
                 ≡(1/Λ) (∫_0^Λ)(e^(i 2 π (n -m) (x/Λ)))dx = (Subscript[δ, m,n])   
The above is equivalent with:     (Subscript[u, m]) · (Subscript[u, n])= (Subscript[δ, m.n]) that are often used for the linear space of  (ℝ^N)

Hence, any piece-wise continuous, square-integrable function f[x] in that interval can be represented as: 
 f[x]= (({{(Subscript[c, -∞ ]), ⋯, (Subscript[c, -m]), ⋯, (Subscript[c, m]), ⋯, (Subscript[c, ∞ ])}})) ·  (({{(Subscript[ϵ, -∞])}, {⋮}, {(Subscript[ϵ, -m])}, {⋮}, {(Subscript[ϵ, m])}, {⋮}, {(Subscript[ϵ, ∞])}})) 
Or:
  f[x]= (({{(Subscript[c, -∞ ]), ⋯, (Subscript[c, -m]), ⋯, (Subscript[c, m]), ⋯, (Subscript[c, ∞ ])}})) · (1/(Sqrt[Λ])) (({{(e^(-i  ∞ 2 π (x/Λ)))}, {⋮}, {(e^(-i  m 2 π (x/Λ)))}, {⋮}, {(e^(i m 2 π (x/Λ)))}, {⋮}, {(e^(i ∞ 2 π (x/Λ)))}}))

which is (in conjugate-pair-wise arrangement)
 
f[x]= ...  (Subscript[c, -m]) (e^(- i m 2 π x/Λ ))+...+(Subscript[c, -1]) (e^(- i  2 π x/Λ )) + (Subscript[c, 0])
               ...   (Subscript[c, m]) (e^(i m 2 π x/Λ ))   + ...+(Subscript[c, 1]) (e^( i  2 π x/Λ ))
For a real-value function, there is no need to add the negative index part, we only need the positive index part and take the real part of the whole expression.

2.2 Formalism vs. numerical implementation with coding

The first commandment (or professional imperative) of numerical methods:
Thou shall do correct calculations.

The proof-of-the-pudding of understanding and practical skill is NOT about reproducing formulas or proofs. It’s about the capability to code to generate correct numerical results.

In our computer coding, it is:

{(Subscript[c, 0]) , 2 (Subscript[c, 1]) , 2 (Subscript[c, 2]) , ⋯ , 2 (Subscript[c, n])} =coef 
 
{(e^(i 0× 2 π (x/Λ))) , (e^(i  2 π (x/Λ))) , (e^(i  2 (2 π) (x/Λ))) , ⋯ ,(e^(i  m 2 π (x/Λ)))} =fexpn
 
Hence: outFS=Re[coef . fexpn ] ;
and that is why we use dot product.

Remember: Fourier functions are not only the basis functions of the space of piece-wise continuous, square-integrable functions, of course. We can arbitrarily generate an infinite number of basis systems simply using a linear transformation:

          (({{(Subscript[g, 1])}, {(Subscript[g, 2])}, {⋮}, {(Subscript[g, m])}, {⋮}})) =(({{(Subscript[r, 11]), (Subscript[r, 12]), ⋯, (Subscript[r, 1m]), ⋯}, {(Subscript[r, 21]), (Subscript[r, 22]), ⋯, (Subscript[r, 2m]), □}, {⋮, ⋮, ⋱, ⋮, □}, {(Subscript[r, m 1]), (Subscript[r, m 2]), ⋯, ⋱, □}, {⋮, □, □, □, □}}))  .  (({{(Subscript[f, 1])}, {(Subscript[f, 2])}, {⋮}, {(Subscript[f, m])}, {⋮}}))  

where R transformation martrix must be invertible or has non-zero determinant.

Numerous systems of basis functions are important in physics and engineering. Legendre, Laguerre, Hermite, Chevbyshev... polynomials are all well known. Other functions such as Bessels with Fourier azimuthal (e^(i l ϕ)), and Associated Laguerre polynomilas with spherical harmonics are important for differential equations of 2nd order in cylindrical and spherical coordinate.

2.3 True/proof-in-the-pudding skills: correct coding.

2.3.1 Example 1:

If you don’t feel comfortable with formal mathematics above, it is OK, just learn how to express in code correctly for numerical calculation. Follow this recipe:

1- IF THE COEF ARE GIVEN, then:

fexpn=Table[(E^(I 2 π n xarr/Λ)),{n,0,nchan}] ; 
(* very easy mistake if set Λ=1, then later
use the expression for a case when Λ ≠ 1 
It is a better programming practice to use explicit Λ even if it is 1 *)

fouriersynthesizedoutput= Re[ coef . fexpn ] ;

2- IF YOU WANT TO FIND THE COEF, then:

coef0=Table[(1/Λ)(∫_(-(Λ/2))^(Λ/2))functioninput[x] (E^(-((I 2 π m x)/Λ)))\[DifferentialD]x ,{m,0,nchan}] ;
(* alternative for less risk of typo errors: *)
coef0=(1./Λ)Table[NIntegrate[functioninput[x] (E^(-((I 2 π m x)/Λ))),{x,-0.5 Λ, 0.5 Λ}]
                        ,{m,0,nchan}] ;
coef=Join[{1},ConstantArray[2,nchan]]*coef0 ;
fouriersynthesizedoutput= Re[ coef . fexpn ];

Example: half circle:

functioninput[x_]:=(Sqrt[(0.5^2)-(x^2)]) ;
Plot[functioninput[x],{x,-0.5,0.5}, AspectRatio->Automatic]

nchan=8; Λ=1.;
coef0=(1./Λ)Table[NIntegrate[functioninput[x] (E^(-((I 2 π m x)/Λ))),{x,-0.5 Λ, 0.5 Λ}]
                        ,{m,0,nchan}] ;
Grid[Partition[coef0,4,4,1,""],Frame-> All
,BaseStyle->{16,FontFamily->"Calibri"}]

See the meaningless residuals in (10^(-18))? To clean them up:

nchan=8; Λ=1.;
coef0=(1./Λ)Table[NIntegrate[functioninput[x] (E^(-((I 2 π m x)/Λ))),{x,-0.5 Λ, 0.5 Λ}]
                        ,{m,0,nchan}] ;
coef0=Chop[coef0,(10^(-6))];
Grid[Partition[coef0,4,4,1,""],Frame-> All
,BaseStyle->{16,FontFamily->"Calibri"}]

There is no need to integrate with so much accuracy and precision:

nchan=8; Λ=1.;
coef0=(1./Λ)Table[NIntegrate[functioninput[x] (E^(-((I 2 π m x)/Λ))),{x,-0.5 Λ, 0.5 Λ}
,AccuracyGoal->5 ]
 (* 5 digits are MORE than enough for graphics display  *)
                        ,{m,0,nchan}] ;
coef0=Chop[coef0,(10^(-6))];
Grid[Partition[coef0,4,4,1,""],Frame-> All
,BaseStyle->{16,FontFamily->"Calibri"}]

FYI, function like half-circle has exact analytic results:

Λ=. ;
(1/Λ)  (∫_(-(Λ/2))^(Λ/2))(Sqrt[((((Λ/2)))^2)-(x^2)]) (E^(-((I 2 π m x)/Λ)))\[DifferentialD]x

It involves Bessel function J:              (Subscript[c, m])=(( (BesselJ[1, m π]))/(4 m))Λ
Bessel functions are known as the Sine, Cos, and Exp of the cylindrical coordinate.

But here, we use pure numerical method to handle any function (not specific like half-circle). To reconstruct, use the recipe above:

nchan=Length[coef0]-1; Λ=1.;
xarr=Range[-0.5 Λ,0.5 Λ,(Λ/128)];
fexpn=Table[(E^(I 2 π n xarr/Λ)),{n,0,nchan}] ; 
coef=Join[{1},ConstantArray[2,nchan]]*coef0 ; (*  very important  *)
fouriersynthesizedoutput= Re[ coef . fexpn ];
ListLinePlot[fouriersynthesizedoutput, PlotRange->All
,DataRange->MinMax[xarr]
,AspectRatio->Automatic]

2.3.2 Example 2:

Remember that a function can be a mapping from ℝ to (ℝ^N), in other words, a scalar can be mapped to a vector in N-dimensional space. Below, is a 3-values function:

functioninput2[x_]:={(Sqrt[(0.5^2)-(x^2)])
,(Sqrt[(0.1^2)-(((x-0.2*Round[5*x]))^2)])
,-0.6+If[Abs[x-0.1]≤0.1,-(Sqrt[(0.1^2)-(((x-0.1))^2)]),0]};
plotstyle2={{Thickness[0.],Black},{Thickness[0.],Black}
,{Thickness[0.02],Black}};
filling2={1-> {{2},Hue[0.,1,1]}} ;

Try to apply the above and see what you get. You will learn the important skill of array handling when having to deal with multi-value function.

Use this for the output:

Show[Graphics[{Black,Thickness[0.02]
,Line[{{0,0.1},{0,-0.6}}]}]
,ListLinePlot[fouriersynthesizedoutput, PlotRange->All
,DataRange->MinMax[xarr]
,PlotStyle->plotstyle2
,Filling->filling2
,AspectRatio->Automatic
]]

Answer (only if you get stuck)

functioninput2[x_]:={(Sqrt[(0.5^2)-(x^2)])
,(Sqrt[(0.1^2)-(((x-0.2*Round[5*x]))^2)])
,-0.6+If[Abs[x-0.1]≤0.1,-(Sqrt[(0.1^2)-(((x-0.1))^2)]),0]};
plotstyle2={{Thickness[0.],Black},{Thickness[0.],Black}
,{Thickness[0.02],Black}};
filling2={1-> {{2},Hue[0.,1,1]}} ;
(* start calculating coef 0  *)
nchan=32; Λ=1.;
coef0=Transpose[(1./Λ)Chop[Table[
NIntegrate[functioninput2[x] (E^(-((I 2 π m x)/Λ))),{x,-0.5 Λ, 0.5 Λ},AccuracyGoal->5 ]
                        ,{m,0,nchan}],(10^(-6))]] ;
coef=Table[Join[{1},ConstantArray[2,nchan]]*c,{c,coef0}];
(* alternative code 
coef=Join[{1},ConstantArray[2,nchan]]* # & /@ coef0 ;
*)

(* now, do Fourier synthesis  *)
xarr=Range[-0.5 Λ,0.5 Λ,(Λ/128)];
fexpn=Table[(E^(I 2 π n xarr/Λ)),{n,0,nchan}] ; 
fouriersynthesizedoutput= Re[ coef . fexpn ];

Show[Graphics[{Black,Thickness[0.02]
,Line[{{0,0.1},{0,-0.6}}]}]
,ListLinePlot[fouriersynthesizedoutput, PlotRange->All
,DataRange->MinMax[xarr]
,PlotStyle->plotstyle2
,Filling->filling2
,AspectRatio->Automatic
]]

3. Things for next class(es): Fourier from space to time

The objective in the next two lectures is to get to the concept of Fourier transform, and then learn discrete Fourier transform for numerical Fourier analysis. We also make a major transition: we study Fourier theorem for applications with space, now we will study it for applications with time.

From space:

to time:

3.1 Review basic concepts of time periodic signals

Physical concepts of time periodic signals: see app below

Review the mathematica object we use to describe the above physical signal: Euler’s complex number notation and for circuit, we call it phasor.

({{}, {}})

Although the signal can be described with harmonic functions sine or cosine in the Real Number space ℝ, it is more fundamental as well as mathematically more efficient to describe periodic phenomena in the Complex space ℂ

3.2 Fourier synthesis: generate a time signal

We will continue to do Fourier synthesis, but not for drawing. The variable in Section 1 above is x, which is for physical space, used for visual rendering of images. This time we will apply Fourier synthesis to time, variable t.

(Subscript[c, 1]) (e^(i 2 π (1f) t )) + (Subscript[c, 2]) (e^(i 2 π (2f) t )) +... + (Subscript[c, m]) (e^(i 2 π  (m f) t ))+...

Instead of space period Λ, we deal with time period T, and the most important parameter in this case is:
                    frequency                 f=(1/T)   unit: (1/time),     if (1/sec) , it is Hz
or:                angular frequency    ω=2 π f     unit: (radian/time)  such as radian Hz.

Remember that in the complex plane, (e^(i 2 π f t)) is a rotating point (or vector). It is the mathematical model for virtually all wave phenomena in nature. In circuit, we use this math for phasor. Learn more by downloading apps or visit the part on phasor in other courses.

Note also that we drop (Subscript[c, 0]): it is a meaningless constant in time-varying signals that we are interested in. Hence, set it as 0.

3.3 Numerical approach: coding a function using Block or Module to generate a time signal

Suppose we wish to generate a time signal, what do we need to know:
1- the frequency: call it freq
2- the amplitude and phase: this is represented as the complex amplitude of a phasor:
                        A (e^(i 2 π f t)) = |A| (e^(i ϕ))  (e^(i 2 π f t))
3- the sampling rate: how often do we sample the signal as output? t is continuous, but there is no such a thing as a continuous numerical array, we have to sample time with a finite set of discrete sampling point. Let’s call it srate
4- duration: how long in time is the signal? The signal may be forever, but numerically, there is a finite size of an array of numbers to be generated.

So, below is an example of such a function, we call it signalgen for signal generator:

signalgen[{freq_,tdur_,srate_},coef_]:=Module[{nsampl,Δt,tarr
,fExpn,sigout}
,
nsampl=Round[tdur*srate];Δt=1./srate;
tarr=(Range[nsampl]-1.)*Δt;
fExpn=Table[Exp[I 2 π n freq tarr],{n,Length[coef]}];
sigout=Re[coef . fExpn];
{ListLinePlot[Take[sigout,Round[5*srate/freq]]],sigout}
];

Example how to use it: we will generate a random signal:

nharmonics=RandomInteger[{2,6}];
coefLogamp=RandomReal[{-1,0},nharmonics];
coefϕ=π  RandomReal[{-1,1},nharmonics];
coef=(E^(coefLogamp+ I coefϕ));
freq=440.;tdur=1.;srate=22050;
u=signalgen[{freq,tdur,srate},coef];
Show[u[[1]],DataRange->{0,5*1./freq}
,Frame-> True, GridLines->Automatic
,FrameLabel->{"time (whichever 1/(unit of frequency))"
,"amplitude (a. u.)"}
,LabelStyle-> {18,Black}]

End

You are strongly encouraged to go through all the tutorials up to now. Send in questions if need help.