Fourier Tutorial Series - 1
graphics (for space variable)

ECE 3340  & generic                         Han Q. Le (c)

1. Review previous

1.1 From HW

tarr=Range[-0.5,0.5,1/256.];
nchan=16;
fcosn=Table[Cos[2 π m tarr],{m,0,nchan}] ;
coef={0.18625,0.110645,-0.02088,0.04475,0.01658,0.00237,-0.01098,0.003489,0.00573,0.00473,-0.00203,0.00018,0.00027,0.00139,-0.00005,0.00154,0.00054} ;
sumall=coef . fcosn;
img1=ListLinePlot[sumall,DataRange-> {-0.5,0.5}, PlotRange->All
,PlotStyle->{Thickness[0.02], Hue[0.35,1,0.5]}
,Filling-> {1-> {0,Hue[0.32,1,0.7,0.75]}}
,Axes-> False
, ImageSize->350,AspectRatio->Automatic]

1.2 Different coefficients

tarr=Range[-0.5,0.5,1/256.];
nchan=16;
fcosn=Table[Cos[2 π m tarr],{m,0,nchan}] ;coef12={0.4769,-0.0836,-0.0345,0.0687,-0.0292,0,0.0008,-0.0006,0.0014,0.0042,-0.0066,0.0022,0.0003,0.0001,0.0005,0.,-0.0021} ;
sumall12=coef12 . fcosn;
ListLinePlot[sumall12,DataRange-> {-0.5,0.5}
, PlotRange->{0,All}
,PlotStyle->{Thickness[0.02], Hue[0.,1,0.5]}
,Filling-> {1-> {0,Hue[0.15,1,1,1]}}
,Axes-> False
, ImageSize->350,AspectRatio->Automatic]

1.3 Still different coefficients

tarr=Range[-0.5,0.5,1/256.];
nchan=16;
fcosn=Table[Cos[2 π m tarr],{m,0,nchan}] ;coef13={0.5118,-0.0237,-0.2368,0.1724,-0.0215,0.0301,-0.0352,-0.0098,0.006,0.0036,0.014,-0.0092,-0.0008,-0.0068,0.0025,0.0055,-0.0009} ;
sumall13=coef13. fcosn;
ListLinePlot[sumall13,DataRange-> {-0.5,0.5}
, PlotRange->{0,All}
,PlotStyle->{Thickness[0.02], Hue[0.8,1,0.5]}
,Filling-> {1-> {0,Black}}
,Axes-> False
, ImageSize->350,AspectRatio->Automatic]

1.4 Fourier morphing

2-set morph

tarr=Range[-0.5,0.5,1/256.];
nchan=16;
fcosn=Table[Cos[2 π m tarr],{m,0,nchan}] ;coefcc={{0.4769,-0.0836,-0.0345,0.0687,-0.0292,0,0.0008,-0.0006,0.0014,0.0042,-0.0066,0.0022,0.0003,0.0001,0.0005,0.,-0.0021}
,{0.5118,-0.0237,-0.2368,0.1724,-0.0215,0.0301,-0.0352,-0.0098,0.006,0.0036,0.014,-0.0092,-0.0008,-0.0068,0.0025,0.0055,-0.0009}
};
delcoef=coefcc[[2]]-coefcc[[1]];

Code

Manipulate[
If[TrueQ[MORPHMounCat== ]
,Manipulate[
coeflinearinterpol=coefcc[[1]]+delcoef*t;

hueline=0.5+(0.8-0.5)*t;
huefill=0.15-0.35*t;
brfill=1-t;
ccmorphpts=Transpose[{Drop[coeflinearinterpol,1]
,-Range[0,Length[coeflinearinterpol]-2]}];
coefmorphGr=Show[ccptGr0
,Graphics[{Hue[huefill,1,1],Line[ccmorphpts],PointSize[0.03],Point /@  ccmorphpts }]
,ImageSize->220, AspectRatio->1.8
,Background->Black];
morph=coeflinearinterpol . fcosn;
morphGr=ListLinePlot[morph,DataRange-> {-0.5,0.5}
, PlotRange->{0,All}
,PlotStyle->{Thickness[0.02], Hue[hueline,1,0.5]}
,Filling-> {1-> {0,Hue[huefill,1,brfill]}}
,Axes-> False
, ImageSize->300,AspectRatio->Automatic];
hshift=1.*Max[coefcc[[  ;; , 2;; ]]];
fouriercomp=#[[1]]*#[[2]]+#[[3]] & /@ Drop[Transpose[{coeflinearinterpol,fcosn
,hshift*(Range[Length[fcosn]-1,0,-1])}],1];
fouriercompGr=ListLinePlot[Reverse[Release @ fouriercomp],DataRange-> {-0.5,0.5}
, PlotRange->{0,All}
,PlotStyle->Table[{Thickness[0.0075], Hue[1-((i-1)/(Length[fouriercomp]+1)),0.85,1]}
,{i,Length[fouriercomp]}]
, ImageSize->250,AspectRatio->1.5
,Background->Black] ;

Grid[{{,,Item[Style["Fourier coefficient morphing"
,16,White,FontFamily->"Century Gothic"],Background->Black]}
,{morphGr, fouriercompGr ,coefmorphGr}}, Alignment->Top
(*,Background->Black*)]


,{t,0,1}]
,]
,Grid[{{Control[{{MORPHMounCat,,},{,},ControlType->Toggler}] 
,Item[Style["Fourier morphing demo",16,FontFamily->"Century Gothic"]
,Background->Hue[0.45,0.6,1]]
}}]
,Initialization:>{
tarr=Range[-0.5,0.5,1/256.];
nchan=16;
fcosn=Table[Cos[2 π m tarr],{m,0,nchan}] ;coefcc={{0.4769,-0.0836,-0.0345,0.0687,-0.0292,0,0.0008,-0.0006,0.0014,0.0042,-0.0066,0.0022,0.0003,0.0001,0.0005,0.,-0.0021}
,{0.5118,-0.0237,-0.2368,0.1724,-0.0215,0.0301,-0.0352,-0.0098,0.006,0.0036,0.014,-0.0092,-0.0008,-0.0068,0.0025,0.0055,-0.0009}
};
delcoef=coefcc[[2]]-coefcc[[1]];
ccmnmx=MinMax[coefcc[[;; ,2 ;; ]]];
ccpts=Table[{c[[i]],2-i},{c,coefcc},{i,2,Length[coefcc[[1]]]}];
(* ccptGr0=Graphics[{White,Thickness[0.001]
,Line[{{0,0},{Length[coefcc[[1]]]-2,0}}]
,Line /@ Table[{{i-2,ccmnmx[[1]]},{i-2,ccmnmx[[2]]}}
,{i,2,Length[coefcc[[1]]]}]
,Hue[0.15,1,1],Thickness[0.003]
,Line [ccpts[[1]] ],PointSize[0.015],Point /@  ccpts[[1]] 
,Hue[0.85,1,1]
,Line [ccpts[[2]] ],PointSize[0.015],Point /@  ccpts[[2]] 
},ImageSize->625, AspectRatio->0.25
,Background->Black] ; *)
ccptGr0=Graphics[{White,Thickness[0.001]
,Line[{{0,0},{0,-Length[coefcc[[1]]]+2}}]
,Line /@ Table[{{ccmnmx[[1]],2-i},{ccmnmx[[2]],2-i}}
,{i,2,Length[coefcc[[1]]]}]
,Hue[0.15,1,1],Thickness[0.003]
,Line [ccpts[[1]] ],PointSize[0.03],Point /@  ccpts[[1]] 
,Hue[0.85,1,1]
,Line [ccpts[[2]] ],PointSize[0.03],Point /@  ccpts[[2]] 
},ImageSize->625, AspectRatio->0.25
,Background->Black]
}]

3-set morph

tarr=Range[-0.5,0.5,1/256.];
nchan=16;
fcosn=Table[Cos[2 π m tarr],{m,0,nchan}] ;coef3set={{0.18625,0.110645,-0.02088,0.04475,0.01658,0.00237,-0.01098,0.003489,0.00573,0.00473,-0.00203,0.00018,0.00027,0.00139,-0.00005,0.00154,0.00054}
,{0.4769,-0.0836,-0.0345,0.0687,-0.0292,0,0.0008,-0.0006,0.0014,0.0042,-0.0066,0.0022,0.0003,0.0001,0.0005,0.,-0.0021}
,{0.5118,-0.0237,-0.2368,0.1724,-0.0215,0.0301,-0.0352,-0.0098,0.006,0.0036,0.014,-0.0092,-0.0008,-0.0068,0.0025,0.0055,-0.0009}
,{0.18625,0.110645,-0.02088,0.04475,0.01658,0.00237,-0.01098,0.003489,0.00573,0.00473,-0.00203,0.00018,0.00027,0.00139,-0.00005,0.00154,0.00054}
};
delcoef3=Drop[coef3set,1]-Drop[coef3set,-1];

Code

Manipulate[
If[TrueQ[MORPH3way== ]
,Manipulate[
If[TrueQ[icontr=="manual"]
,kindx=Min[Max[2,Ceiling[kcomp]],nchan];
If[!TrueQ[kampold== kamp],
coeflinearinterpol[[kindx]]=Abs[kamp]*If[kamp≥ 0,ccmnmx3[[2]],ccmnmx3[[1]]];
kampold= kamp
,];
kopac=0.75
,fl=Floor[t];it=Min[3,fl+1];
coeflinearinterpol=coef3set[[it]]+delcoef3[[it]]*(t-fl);
hueline=If[t<1, 0.35+(0.5-0.35)*t
,If[t<2, 0.5+(0.8-0.5)*(t-fl),0.8+(0.35-0.8)*(t-fl)]];
huefill=If[t< 1,0.32+(0.15-0.32)t
,If[t<2, 0.15-0.35*(t-1),0.8+(0.35-0.8)(t-fl)]];
brfill=If[t<1,1,If[t<2,2-t,t-fl]];
kopac=0
] ;
ccmorphpts=Transpose[{Drop[coeflinearinterpol,1]
,-Range[0,Length[coeflinearinterpol]-2]}];
coefmorphGr3=Show[ccptGr0
,Graphics[{White,Opacity[0.4],Polygon[Join[ccmorphpts,Reverse @ ccpts[[it]]]]
,Hue[huefill,1,1,1],Line[ccmorphpts],PointSize[0.03],Point /@  ccmorphpts
,White,Opacity[kopac],PointSize[0.06]
 ,Point[{coeflinearinterpol[[kindx]],2-kindx}]}]
,ImageSize->220, AspectRatio->1.8
,Background->Black];
morph3w=coeflinearinterpol . fcosn;
morphGr3=ListLinePlot[morph3w,DataRange-> {-0.5,0.5}
, PlotRange->{0,All}
,PlotStyle->{Thickness[0.02], Hue[hueline,1,0.5]}
,Filling-> {1-> {0,Hue[huefill,1,brfill]}}
,Axes-> False
,ImageSize->350,AspectRatio->Automatic];
hshift=1.*Max[coef3set[[  ;; , 2;; ]]];
fouriercomp=#[[1]]*#[[2]]+#[[3]] & /@ Drop[Transpose[{coeflinearinterpol,fcosn
,hshift*(Range[Length[fcosn]-1,0,-1])}],1];
 fouriercompGr3=ListLinePlot[Reverse[Release @ fouriercomp],DataRange-> {-0.5,0.5}
, PlotRange->{0,All}
,PlotStyle->Table[{Thickness[0.0075], Hue[1-((i-1)/(Length[fouriercomp]+1)),0.85,1]}
,{i,Length[fouriercomp]}]
, ImageSize->250,AspectRatio->1.5
,Background->Black] ;

Grid[{{,,Item[Style["Fourier coefficient morphing"
,16,White,FontFamily->"Century Gothic"],Background->Black]}
,{morphGr3, fouriercompGr3 ,coefmorphGr3}}, Alignment->Top
(*,Background->Black*)]

,Grid[{{Control[{t,0,2.999,0.001}],Control[{{icontr,"auto",},{"auto","manual"},SetterBar}]
,Control[{{kcomp,2,"Fourier (k^th)"},2,nchan,1}],Control[{{kamp,0,""},-1,1}]
}}]]
,]
,Grid[{{Control[{{MORPH3way,,},{,},ControlType->Toggler}] 
,Item[Style["Fourier morphing demo - 3 way",16,FontFamily->"Century Gothic"]
,Background->Hue[0.32,0.6,1]]
}}]
,Initialization:>{
tarr=Range[-0.5,0.5,1/256.];
nchan=16;
fcosn=Table[Cos[2 π m tarr],{m,0,nchan}] ;coef3set={{0.18625,0.110645,-0.02088,0.04475,0.01658,0.00237,-0.01098,0.003489,0.00573,0.00473,-0.00203,0.00018,0.00027,0.00139,-0.00005,0.00154,0.00054}
,{0.4769,-0.0836,-0.0345,0.0687,-0.0292,0,0.0008,-0.0006,0.0014,0.0042,-0.0066,0.0022,0.0003,0.0001,0.0005,0.,-0.0021}
,{0.5118,-0.0237,-0.2368,0.1724,-0.0215,0.0301,-0.0352,-0.0098,0.006,0.0036,0.014,-0.0092,-0.0008,-0.0068,0.0025,0.0055,-0.0009}
,{0.18625,0.110645,-0.02088,0.04475,0.01658,0.00237,-0.01098,0.003489,0.00573,0.00473,-0.00203,0.00018,0.00027,0.00139,-0.00005,0.00154,0.00054}
};
delcoef3=Drop[coef3set,1]-Drop[coef3set,-1];
ccmnmx3=MinMax[coef3set[[;; ,2 ;; ]]];
ccpts=Transpose[{#,-Range[0,Length[coef3set[[1]]]-2]}]& /@ coef3set[[;; , 2 ;;]];ccptGr0=Graphics[{White,Thickness[0.001]
,Line[{{0,0},{0,-(Length[coef3set[[1]]]-2)}}]
,Line /@ Table[{{ccmnmx3[[1]],2-i},{ccmnmx3[[2]],2-i}}
,{i,2,Length[coef3set[[1]]]}]
,Hue[0.35,1,1],Thickness[0.003]
,Line [ccpts[[1]] ],PointSize[0.035],Point /@  ccpts[[1]] 
,Hue[0.15,1,1]
,Line [ccpts[[2]] ],PointSize[0.035],Point /@  ccpts[[2]] 
,Hue[0.85,1,1]
,Line [ccpts[[3]] ],PointSize[0.035],Point /@  ccpts[[3]] 
}
,Background->Black];
kindx=2;kopac=0.;
}]

2. Fourier series

See Lecture on Fourier

Some demo

Plot[1-(x^2),{x,-1,1}]

Plot[1-(u^2)   /. u-> Mod[x+1,2]-1,{x,-5,5}]

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

((-4 m π Cos[m π]+4 Sin[m π])/(2 (m^3) (π^3))) /. Sin[π m]-> 0 /. Cos[π m]-> (((-1))^m)

Limit[((-4 m π Cos[m π]+4 Sin[m π])/(2 (m^3) (π^3))),m-> 0]

(∑_(m=1)^∞)-((2(((-1))^m))/((π^2) (m^2))) Cos[π m x]

Plot[-(( (PolyLog[2,-(E^(-I π x))]+PolyLog[2,-(E^(I π x))]))/(π^2)),{x,-1,1}]

fourierSynth[x_,n_]:=(2/3)-(4/(π^2))Total[Table[((((-1))^m)/( (m^2)))Cos[π m x],{m,n}]]

Plot[fourierSynth[x,4],{x,-1,1}]

Manipulate[
Grid[{{Plot[{(1-(x^2)),fourierSynth[x,n]},{x,-1,1}
,PlotStyle->{Red,Blue}]
,Plot[Log[10,#]& @ Abs[(1-(x^2))-fourierSynth[x,n]],{x,-1,1}
,PlotRange-> All
,PlotStyle->{Red,Blue}]
}}]
,{n,2,64,1}]

3. Numerical demos

3.1 House

house[u_,σx_]:=Block[{x}
,x=u (* +0.125 σx  *);
0.3(UnitBox[(x/(4.σx))]+If[x<-2 σx,0.,If[x<0.,(((x+2.σx))/(2 σx)),If[x<2. σx,(((2. σx-x))/(2 σx)) ,0] ]]+If[-1.6σx<x<-1.1 σx,0.65-0.5(((x+1.7σx))/(σx)),0.]
+If[2 σx≤ x≤ 2.5 σx,1,0])];

imghouse=Plot[house[x,0.15],{x,-0.5,0.5}
,PlotStyle->{Thick,Brown}
,Filling->{1-> {0,Hue[0.45,0.4,1]}}
,AspectRatio->Automatic]

nchan=32; funcname=house;
coef0=Table[Quiet[NIntegrate[funcname[x,0.15]*(E^(-I 2 π n x)),{x,-0.5,0.5},AccuracyGoal->3 ]]
,{n,0,nchan}] ;
coef=Join[{1},ConstantArray[2,nchan]]*coef0;
xpltarr=Range[-0.5,0.5,1/256.];
fexpn=Table[(E^(I 2 π n xpltarr )),{n,0,nchan}];
out=Re[coef . fexpn ];
imghouseFourier=ListLinePlot[out,DataRange-> {-0.5,0.5},PlotRange-> All
,PlotStyle->{Thick,Brown}
,Filling->{1-> {0,Hue[0.45,0.4,1]}}
,AspectRatio->Automatic]

Grid[{{imghouse,imghouseFourier}}]

A function

fouriergraphics[{funcArtnm_,σ_,styleparm_}, nFouriercomp_,nintv_]:=Block[{coef0
,coef,xpltarr,fexpn,outFS}
,coef0=Table[Quiet[NIntegrate[funcArtnm[x,σ]*(E^(-I 2 π n x)),{x,-0.5,0.5},AccuracyGoal->3 ]]
,{n,0,nFouriercomp}] ;
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
]
];

nchan=64;nintv=256;funcname=house;  σ=0.15;
styleparm={{Thick,Brown},{1-> {0,Hue[0.45,0.4,1]}}};
imghouseFourier=fouriergraphics[{funcname,σ, styleparm},nchan,nintv]

Grid[{Show[#,ImageSize->250] & /@ { imghouse,imghouseFourier}}]

3.2 Castle

castle[x_,σ_]:=Module[{u}
,u=Abs[x];
If[Abs[u-0.3]≤ 0.08
,0.65(1-2.5Abs[u-0.3])
,If[u≤ 0.22,0.65*(0.5+0.05*Sign[Cos[24 π u]])
,0]]
];

imgoriginal=Plot[castle[x,0.15],{x,-0.5,0.5}
,PlotStyle->{Thick,Hue[0.13,1,0.4]}
,Filling->{1-> {0,Hue[0.13,1,1]}}
,AspectRatio->Automatic]

nchan=64;nintv=256;funcname=castle;  σ=0.15;
styleparm={{Thick,Hue[0.13,1,0.4]},{1-> {0,Hue[0.13,1,1]}}};
imgFourier=fouriergraphics[{funcname,σ, styleparm},nchan,nintv]

Grid[{Show[#,ImageSize->250] & /@ { imgoriginal,imgFourier}}]

3.2 Multivalue-function: Heart

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]

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];
xpltarr=Range[-0.5,0.5,1/256.];
fexpn=Table[(E^(I 2 π n xpltarr )),{n,0,nchan}];
out=Re[coef . fexpn ];

imgH=ListLinePlot[out,DataRange-> {-0.5,0.5},PlotRange-> All
,PlotStyle->{Red}
,Filling->heartfill
,AspectRatio->Automatic
]

Fourier synthesis function V2

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
]
];

test previous

nchan=64;nintv=256;funcname=house;  σ=0.15;
styleparm={{{Thick,Brown}},{1-> {0,Hue[0.45,0.4,1]}}};
imghouseFourier=fouriergraphics2[{funcname,σ, styleparm},nchan,nintv]

nchan=32;nintv=256;funcname=heart;  σ=0.15;
styleparm={{{Thick,Red},{Thick,Red}},heartfill};
imgFourier=fouriergraphics2[{funcname,σ, styleparm},nchan,nintv]

3.3 Multivalue-function: pine tree

tri[x_,{w_,h_,s_}]:=If[Abs[x]<0.5w,h+If[x<0.,s (x+0.5w),s (0.5 w-x)],h];

pinetree[x_,σx_]:=0.5*{tri[x,{0.15,0.,40}]
,tri[x,{1,1,3}],1 (* UnitBox[x] *)
,tri[x,{0.85,2.75-0.85,3}],-2*0.5*0.85+2.75
,tri[x,{0.65,3.5-0.65,3.}],3.5-2*0.5*0.65
} ;
pinefill= {1-> {Axis,Hue[0.12,1,0.4]},
2->{{3},{None,Hue[0.37,1,0.55]}}
,4-> {{5},{None,Hue[0.33,1,0.65]}}
,6-> {{7},{None,Hue[0.27,1,0.75]}}
} ;

nchan=8;nintv=256; funcname=pinetree;
funcfill=pinefill; plotstyle={ConstantArray[{Thickness[0.],Hue[0.33,1,1]},3]};
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}}]

4. The nature of different-frequency contribution

Why need many frequencies? A look at how each frequency contributes to an image.

4.1 image to be studied

funcdemo1[x_,σx_]:=Module[{u},u=1.15x;
(* If[Abs[x]≥ 0.5,{0.,0.,0.,0.,0.},
*)1.4*{If[Abs[u]≥ 0.5,0.,(Sqrt[0.5-Abs[u]])]
,If[Abs[u]≥ 0.5,0.,2.5(0.5^2.5-Abs[u]^2.5)]
,If[Abs[u]≥ 0.5,0.,2.5(0.5^2.5-Abs[u]^2.5)]
-If[Abs[u]≤ 0.3,
1.8If[Mod[u,0.1]≤ 0.05,Mod[u,0.1],0.1-Mod[u,0.1]],0.]
,If[Abs[u]≥ 0.5,0.,0.65(0.5^2-u^2)]+If[Abs[u]≤ 0.4,
1.8If[Mod[u,0.1]≤0.05,Mod[u,0.1],0.1-Mod[u,0.1]],0.]
,If[Abs[u]≥ 0.5,0.,0.65(0.5^2-u^2)]
}(* ]*)] ;
demo1fill={1-> {{2},Hue[0.55,0.4,0.8]}
,2-> {{3},White}
,3-> {{4},Black}
,4-> {{5},White}
,5-> {Axis,Hue[0.55,0.4,0.8]}};

nchan=16; funcname=funcdemo1;funcfill=demo1fill;
coef0=Chop[Table[Quiet[NIntegrate[funcname[x,σ]*(E^(-I 2 π n x)),{x,-0.5,0.5},AccuracyGoal->3 ]]
,{n,0,nchan}],10^-4] ;
coef=Join[{1},ConstantArray[2,nchan]]*# & /@ Transpose[coef0];
xpltarr=Range[-0.5,0.5,1/256.];
fexpn=Table[(E^(I 2 π n xpltarr )),{n,0,nchan}];

Dimensions[fexpn]
Dimensions[coef]

outFourierComponent=Table[
Table[Re[coef[[ k,m]]*fexpn[[m]]   ],{k,Length[coef[[;;  , m]]]}] 
,{m,Length[fexpn]}];
(* examples of alternative advanced code  *)
(* outFourierComponent=Table[Re[fexpn[[m]] * #] & /@ coef[[ ;;   ,  m]]  ,{m,Length[fexpn]}]; *)
ypltrng=0.1* (Floor[#] & /@ (10*MinMax[outFourierComponent]+0.5)) ;

Grid[Partition[
Table[ListLinePlot[outFourierComponent[[m]]
,DataRange-> {-0.5,0.5},PlotRange->ypltrng
,PlotStyle->{{Thickness[0.],White}}
,Filling->funcfill, Frame->True
,AspectRatio->Automatic
,ImageSize->150
],{m,Length[outFourierComponent]}]
,5,5,1,""]]

Dimensions[outFourierComponent]
Dimensions[outFourierComponent[[1]]]

ypltrng={-0.4,0.6};
nline=Dimensions[outFourierComponent][[2]];
Manipulate[
subsetcomp=Take[outFourierComponent,i];
fouriersynthesis=Table[ Total[subsetcomp[[ ;; ,  k , ;; ]]],{k,nline}];


fouriersynthesizedImg=ListLinePlot[fouriersynthesis
,DataRange-> {-0.5,0.5},PlotRange->All
,PlotStyle->{{Thickness[0.],White}}
,Filling->funcfill, Frame->True
,AspectRatio->Automatic
,ImageSize->200
];
fouriercomponentImg=ListLinePlot[outFourierComponent[[i]]
,DataRange-> {-0.5,0.5},PlotRange->ypltrng
,PlotStyle->{{Thickness[0.],White}}
,Filling->funcfill, Frame->True
,AspectRatio->Automatic
,ImageSize->200
];
Grid[{{fouriersynthesizedImg
,fouriercomponentImg}}]
,{i,1,Length[outFourierComponent],1}]

observe each additional step of each Fourier Component

Manipulate[
If[TrueQ[FREQUENCYspatialdetailsDEMO==  ]

,Manipulate[
If[!TrueQ[iold==i]
,
fourierold=fouriersynthesizedImg;
fouriersynthesis= Re[# . Take[fexpn ,i] ]& /@  coef[[ ;;  , 1 ;; i]];
fouriersynthesizedImg=ListLinePlot[fouriersynthesis
,DataRange-> {-0.5,0.5},PlotRange->All
,PlotStyle->{{Thickness[0.],White}}
,Filling->funcfill, Frame->True
,AspectRatio->Automatic
,ImageSize->200
];
fouriercomponentImg=ListLinePlot[outFourierComponent[[i]]
,DataRange-> {-0.5,0.5},PlotRange->ypltrng
,PlotStyle->{{Thickness[0.],White}}
,Filling->funcfill, Frame->True
,AspectRatio->Automatic
,ImageSize->200
];

iold=i
,
];
Grid[{{fouriersynthesizedImg
,Column[{fouriercomponentImg
,fourierold
}]}}]
,{i,1,Length[outFourierComponent],1}
]
,]

,Grid[{{Control[{{FREQUENCYspatialdetailsDEMO,,},{,},ControlType->Toggler}] 
,Item[Style["See how high spatial frequency Fourier components
contribute to spatial details",16,FontFamily->"Century Gothic"]
,Background->Hue[0.45,0.6,1]]
}}]
,Initialization:>{
funcdemo1[x_,σx_]:=Module[{u},u=1.15x;
(* If[Abs[x]≥ 0.5,{0.,0.,0.,0.,0.},
*)1.4*{If[Abs[u]≥ 0.5,0.,(Sqrt[0.5-Abs[u]])]
,If[Abs[u]≥ 0.5,0.,2.5(0.5^2.5-Abs[u]^2.5)]
,If[Abs[u]≥ 0.5,0.,2.5(0.5^2.5-Abs[u]^2.5)]
-If[Abs[u]≤ 0.3,
1.8If[Mod[u,0.1]≤ 0.05,Mod[u,0.1],0.1-Mod[u,0.1]],0.]
,If[Abs[u]≥ 0.5,0.,0.65(0.5^2-u^2)]+If[Abs[u]≤ 0.4,
1.8If[Mod[u,0.1]≤0.05,Mod[u,0.1],0.1-Mod[u,0.1]],0.]
,If[Abs[u]≥ 0.5,0.,0.65(0.5^2-u^2)]
}(* ]*)] ;
demo1fill={1-> {{2},Hue[0.55,0.4,0.8]}
,2-> {{3},White}
,3-> {{4},Black}
,4-> {{5},White}
,5-> {Axis,Hue[0.55,0.4,0.8]}};

nchan=16; funcname=funcdemo1;funcfill=demo1fill;
coef0=Chop[Table[Quiet[NIntegrate[funcname[x,σ]*(E^(-I 2 π n x)),{x,-0.5,0.5},AccuracyGoal->3 ]]
,{n,0,nchan}],10^-4] ;
coef=Join[{1},ConstantArray[2,nchan]]*# & /@ Transpose[coef0];xpltarr=Range[-0.5,0.5,1/256.];
fexpn=Table[(E^(I 2 π n xpltarr )),{n,0,nchan}];
ypltrng={-0.4,0.6};


fouriersynthesizedImg=ListLinePlot[fouriersynthesis
,DataRange-> {-0.5,0.5},PlotRange->All
,PlotStyle->{{Thickness[0.],White}}
,Filling->funcfill, Frame->True
,AspectRatio->Automatic
,ImageSize->200
];

outFourierComponent=Table[
Table[Re[coef[[ k,m]]*fexpn[[m]]   ],{k,Length[coef[[;;  , m]]]}] 
,{m,Length[fexpn]}];

fouriercomponentImg=ListLinePlot[outFourierComponent[[i]]
,DataRange-> {-0.5,0.5},PlotRange->ypltrng
,PlotStyle->{{Thickness[0.],White}}
,Filling->funcfill, Frame->True
,AspectRatio->Automatic
,ImageSize->200
];


}]

4.2 related app

See app page 2.

5. Waveform - pulse synthesis

Below are Fourier coefficients for a few common waveforms. You can adapt these things for your HW, however, you must understand the different codes (functions) and their intended applications. There are those written for graphics output, and those for numerical output.

5.1 Square wave

Manipulate[
Plot[(UnitStep[t]-UnitStep[t-η T]) /. t-> Mod[u,T]
,{u,0,2.5}, PlotStyle->{Thickness[0.005],Hue[0.,0.85,1]}
,Filling->{1-> {0,Hue[0.05,0.85,1,0.4]}}
,AspectRatio->0.35, Background->Black,ImageSize->400]
,{{η,0.25},0.1,0.9},{{T,1},0.5,2}]

5.1.1 Integral

To obtain a Fourier coefficient:

(1/T)(∫_0^T)(UnitStep[t]-UnitStep[t-η T])(E^(-I m 2 π t/T))\[DifferentialD]t

% /. {(E^(2 I m π))-> 1 ,(E^(-2 I m π))-> 1 ,(E^(-2 I m π (1+η)))-> (E^(-2 I m π η)), UnitStep[T]->1,UnitStep[-T]-> 0,  UnitStep[-T η]-> 0, UnitStep[T-T η]-> 1}

((-I Expand[(E^(-2 I m π η)) (-1+(E^(2 I m π η)))])/(2 m π))

(E^( -I m π η))ExpToTrig[((-I ((E^( I m π η))-(E^( -I m π η))))/(2 m π))]

For coding, use this:

(E^(-I m π η))  η Sinc[m π η]

5.1.2 For computation

Demo only. You SHOULD extract, modify, adapt, do whichever needed for your own work.

Code

Manipulate[
Grid[{
{Item[Style["waveform",18,Black,FontFamily->"Century Gothic"],Background->Hue[0.35,0.4,1]]
,Item[Style["Fourier decomposition",18,Black,FontFamily->"Century Gothic"],Background->Hue[0.15,0.4,1]]}
,
{Plot[(UnitStep[t]-UnitStep[t-η T]) /. t-> Mod[u,T]
,{u,0,2.5},PlotRange-> {All,{-0.1,1.1}}
,  PlotStyle->{Thickness[0.0065],Hue[0.,0.85,1]}
,Filling->{1-> {0,Hue[0.05,0.85,1,0.4]}}
,AspectRatio->0.35, Background->Black,ImageSize->300]
,Column[{Show[fourierSumplot[k,{"square",η,T},tarr]
,PlotRange-> {All,{-0.1,1.1}}
,AspectRatio->0.35, Background->Black,ImageSize->300]
,Show[fourierCompplot1[k,{"square",η,T},tarr]
,AspectRatio->1.5, Background->Black,ImageSize->300]
}]
}},Alignment-> Top,Frame-> True,FrameStyle->White]
,{{η,0.25},0.1,0.9},{{T,1},0.5,2},{{k,16},0,32,1}
,Initialization:>{
tarr=Range[0,500]/200.;
bogusgraphics=Graphics[{Point[{-1,0}]}];
xFcoeff[m_,wfparm_]:=Block[{wf,η}
,{wf,η}=Take[wfparm,2]; 
If[wf=="square"
,(E^(-I m π η))  η Sinc[m π η]
,If[wf=="sawtooth"
,(E^(-2 I m π η))If[m==0,0.5 η,(( I (1-(E^(I m π η)) Sinc[m π η]))/(2 m π))]
,If[wf=="triangle"
,(η/2.) (E^(- I m π η))((Sinc[((m π η)/2)])^2)
,(η/2) (1-(E^(-(2/η)))) (1/(1+ I m π η))
]]]
];

fourierCompplot1[k_,wfparm_,vararr_]:=Block[{wf,η,tper,xLoc}
,wf=wfparm[[1]]; 
If[TrueQ[wf=="square"],{η,tper}=Take[wfparm,{2,3}] ; 
xLoc=vararr/tper;
If[k==0
,Graphics[{Thickness[0.0065],White,Line[{{xLoc[[1]],η},{Last[xLoc],η}}]}]
,Graphics[{Thickness[0.0065]
,Table[{Hue[(((m-1))/(k+1)),0.8,1]
,Line[Transpose[{xLoc
,2η Sinc[m π η]Re[(E^(I π m (2 xLoc- η))) ] +1.5 Log[1.k/m]}]]},{m,k}]
}]]
,bogusgraphics]
];

fourierSumplot[k_,wfparm_,vararr_]:=Block[{wf,η,tper,coefF,xLoc}
,{wf,η,tper}=Take[wfparm,3]; 
xLoc=vararr/tper;
coefF=Table[xFcoeff[m,wfparm],{m,k}];
Graphics[{Thickness[0.0065], White
,Line[Transpose[{xLoc
,2Re[coefF . Table[(E^(I 2 π m xLoc )),{m,k}]]
+ConstantArray[xFcoeff[0,wfparm],Length[xLoc]]
}]]
}]
];

}]

5.2 Sawtooth

Manipulate[
Plot[If[t≤ η T,(t/(η T)),0.]/. t-> Mod[u,T]
,{u,0,2.5},PlotRange-> {All,{-0.1,1.1}}
, PlotStyle->{Thickness[0.005],Hue[0.15,1,1]}
,Filling->{1-> {0,Hue[0.14,1,1,0.4]}}
,AspectRatio->0.35, Background->Black,ImageSize->400]
,{{η,0.75},0.1,0.9},{{T,1},0.5,2}]

5.2.1 Integral

η=.;
(1/T)(∫_0^(η T))(t/(η T))(E^(-I m 2 π t/T))\[DifferentialD]t

((-Expand[(E^(-2 I m π η)) (-1+(E^(2 I m π η))-2 I m π η)])/(4 (m^2) (π^2) η))

-(((E^( -I m π η))ExpToTrig[(E^( I m π η))-(E^(- I m π η))]-2 I (E^(-2 I m π η)) m π η)/(4 (m^2) (π^2) η))

Simplify[-((-2 I (E^(-2 I m π η)) m π η)/(4 (m^2) (π^2) η))]+Simplify[-((2 I (E^(-I m π η)) )/(4 (m^2) (π^2) η))]Sin[m π η]

Simplify[((I (E^(-2 I m π η)))/(2 m π))-((I (E^(-I m π η)))/(2 m π)) Sinc[m π η]]

Limit[(( (-1+(E^(I m π η)) Sinc[m π η]))/(2 m π)),m-> 0]

For coding, use this:

(E^(-2 I m π η))If[m==0,0.5 η,(( I (1-(E^(I m π η)) Sinc[m π η]))/(2 m π))]

5.2.2 For computation

Demo only. You SHOULD extract, modify, adapt, do whichever needed for your own work.

Manipulate[
Grid[{
{Item[Style["waveform",18,Black,FontFamily->"Century Gothic"],Background->Hue[0.35,0.4,1]]
,Item[Style["Fourier decomposition",18,Black,FontFamily->"Century Gothic"],Background->Hue[0.15,0.4,1]]}
,
{Plot[If[t≤ η T,(t/(η T)),0.]/. t-> Mod[u,T]
,{u,0,2.5},PlotRange-> {All,{-0.1,1.1}}
, PlotStyle->{Thickness[0.005],Hue[0.15,1,1]}
,Filling->{1-> {0,Hue[0.14,1,1,0.4]}}
,AspectRatio->0.35, Background->Black,ImageSize->300]
,Column[{Show[fourierSumplot[k,{"sawtooth",η,T},tarr]
,PlotRange-> {All,{-0.1,1.1}}
,AspectRatio->0.35, Background->Black,ImageSize->300]
,Show[fourierCompplot2[k,{"sawtooth",η,T},tarr]
,AspectRatio->1.5, Background->Black,ImageSize->300]
}]
}},Alignment-> Top,Frame-> True,FrameStyle->White]
,{{η,0.75},0.1,0.9},{{T,1},0.5,2},{{k,16},0,32,1}
,Initialization:>{
tarr=Range[0,500]/200.;
bogusgraphics=Graphics[{Point[{-1,0}]}];
xFcoeff[m_,wfparm_]:=Block[{wf,η}
,{wf,η}=Take[wfparm,2]; 
If[wf=="square"
,(E^(-I m π η))  η Sinc[m π η]
,If[wf=="sawtooth"
,(E^(-2 I m π η))If[m==0,0.5 η,(( I (1-(E^(I m π η)) Sinc[m π η]))/(2 m π))]
,If[wf=="triangle"
,(η/2.) (E^(- I m π η))((Sinc[((m π η)/2)])^2)
,(η/2) (1-(E^(-(2/η)))) (1/(1+ I m π η))
]]]
];

fourierCompplot2[k_,wfparm_,vararr_]:=Block[{wf,η,tper,xLoc}
,wf=wfparm[[1]]; 
If[TrueQ[wf=="sawtooth"],{η,tper}=Take[wfparm,{2,3}] ; 
xLoc=vararr/tper;
If[k==0
,Graphics[{Thickness[0.0065],White,Line[{{xLoc[[1]],0.5η},{Last[xLoc],0.5 η}}]}]
,Graphics[{Thickness[0.0065]
,Table[{Hue[(((m-1))/(k+1)),0.8,1]
,Line[Transpose[{xLoc
,2Re[(( I (1-(E^(I m π η)) Sinc[m π η]))/(2 m π))(E^(I 2π m (xLoc- η))) ] +1. Log[k/m]}]]},{m,k}]
}]]
,bogusgraphics]
];

fourierSumplot[k_,wfparm_,vararr_]:=Block[{wf,η,tper,coefF,xLoc}
,{wf,η,tper}=Take[wfparm,3]; 
xLoc=vararr/tper;
coefF=Table[xFcoeff[m,wfparm],{m,k}];
Graphics[{Thickness[0.0065], White
,Line[Transpose[{xLoc
,2Re[coefF . Table[(E^(I 2 π m xLoc )),{m,k}]]
+ConstantArray[xFcoeff[0,wfparm],Length[xLoc]]
}]]
}]
];

}]

5.3 Triangle

Manipulate[
Plot[If[t≤0.5 η T,((2t)/(η T)),If[t≤ η T,((2(η T-t))/(η T)),0]]/. t-> Mod[u,T]
,{u,0,2.5},PlotRange-> {All,{-0.1,1.1}}
, PlotStyle->{Thickness[0.005],Hue[0.35,1,1]}
,Filling->{1-> {0,Hue[0.32,1,1,0.4]}}
,AspectRatio->0.35, Background->Black,ImageSize->400]
,{{η,0.75},0.1,0.9},{{T,1},0.5,2}]

5.3.1 Integral

η=.;
(1/T)(∫_0^(η T/2))((2t)/(η T))(E^(-I m 2 π t/T))\[DifferentialD]t +(1/T)(∫_(η T/2)^(η T))((2(η T-t))/(η T))(E^(-I m 2 π t/T))\[DifferentialD]t

FullSimplify[-(((E^(-I m π η)) (-1+(E^(I m π η))-I m π η))/(2 (m^2) (π^2) η))+(((E^(-2 I m π η)) (-1+(E^(I m π η)) (1-I m π η)))/(2 (m^2) (π^2) η))]

-(((E^(-I m π η)) (Simplify[(-1+((Cos[((m π η)/2)])^2))]-((Sin[((m π η)/2)])^2)))/((m^2) (π^2) η))

For coding, use this:

(η/2) (E^(- I m π η))((Sinc[((m π η)/2)])^2)

5.3.2 For computation

Demo only. You SHOULD extract, modify, adapt, do whichever needed for your own work.

Manipulate[
Grid[{
{Item[Style["waveform",18,Black,FontFamily->"Century Gothic"],Background->Hue[0.35,0.4,1]]
,Item[Style["Fourier decomposition",18,Black,FontFamily->"Century Gothic"],Background->Hue[0.15,0.4,1]]}
,
{Plot[If[t≤0.5 η T,((2t)/(η T)),If[t≤ η T,((2(η T-t))/(η T)),0]]/. t-> Mod[u,T]
,{u,0,2.5},PlotRange-> {All,{-0.1,1.1}}
, PlotStyle->{Thickness[0.005],Hue[0.35,1,1]}
,Filling->{1-> {0,Hue[0.32,1,1,0.4]}}
,AspectRatio->0.35, Background->Black,ImageSize->300]
,Column[{Show[fourierSumplot[k,{"triangle",η,T},tarr]
,PlotRange-> {All,{-0.1,1.1}}
,AspectRatio->0.35, Background->Black,ImageSize->300]
,Show[fourierCompplot3[k,{"triangle",η,T},tarr]
,AspectRatio->1.5, Background->Black,ImageSize->300]
}]
}},Alignment-> Top,Frame-> True,FrameStyle->White]
,{{η,0.5},0.1,0.9},{{T,1},0.5,2},{{k,16},0,32,1}
,Initialization:>{
tarr=Range[0,500]/200.;
bogusgraphics=Graphics[{Point[{-1,0}]}];
xFcoeff[m_,wfparm_]:=Block[{wf,η}
,{wf,η}=Take[wfparm,2]; 
If[wf=="square"
,(E^(-I m π η))  η Sinc[m π η]
,If[wf=="sawtooth"
,(E^(-2 I m π η))If[m==0,0.5 η,(( I (1-(E^(I m π η)) Sinc[m π η]))/(2 m π))]
,If[wf=="triangle"
,(η/2.) (E^(- I m π η))((Sinc[((m π η)/2)])^2)
,(η/2) (1-(E^(-(2/η)))) (1/(1+ I m π η))
]]]
];
fourierCompplot3[k_,wfparm_,vararr_]:=Block[{wf,η,tper,xLoc}
,wf=wfparm[[1]]; 
If[TrueQ[wf=="triangle"],{η,tper}=Take[wfparm,{2,3}] ; 
xLoc=vararr/tper;
If[k==0
,Graphics[{Thickness[0.0065],White,Line[{{xLoc[[1]],0.5η},{Last[xLoc],0.5 η}}]}]
,Graphics[{Thickness[0.0065]
,Table[{Hue[(((m-1))/(k+1)),0.8,1]
,Line[Transpose[{xLoc
,η ((Sinc[((m π η)/2)])^2) Re[(E^(I π m (2xLoc- η))) ] +1. Log[k/m]}]]},{m,k}]
}]]
,bogusgraphics]
];

fourierSumplot[k_,wfparm_,vararr_]:=Block[{wf,η,tper,coefF,xLoc}
,{wf,η,tper}=Take[wfparm,3]; 
xLoc=vararr/tper;
coefF=Table[xFcoeff[m,wfparm],{m,k}];
Graphics[{Thickness[0.0065], White
,Line[Transpose[{xLoc
,2Re[coefF .Table[(E^(I 2 π m xLoc )),{m,k}]]
+ConstantArray[xFcoeff[0,wfparm],Length[xLoc]]
}]]
}]
];

}]

5.4 Exponential

Manipulate[
Plot[(E^(-2 t/(η T)))/. t-> Mod[u,T]
,{u,0,2.5},PlotRange-> {All,{-0.1,1.1}}
, PlotStyle->{Thickness[0.005],Hue[0.55,1,1]}
,Filling->{1-> {0,Hue[0.5,1,1,0.4]}}
,AspectRatio->0.35, Background->Black,ImageSize->400]
,{{η,0.5},0.1,0.9},{{T,1},0.5,2}]

5.4.1 Integral

η=.;
(1/T)(∫_0^T)(E^(-2 t/(η T)))(E^(-I m 2 π t/T))\[DifferentialD]t

For coding, use this:

(η/2) (1-(E^(-(2/η)))) (1/(1+ I m π η))

5.4.2 For computation

Demo only. You SHOULD extract, modify, adapt, do whichever needed for your own work.

Manipulate[
Grid[{
{Item[Style["waveform",18,Black,FontFamily->"Century Gothic"],Background->Hue[0.35,0.4,1]]
,Item[Style["Fourier decomposition",18,Black,FontFamily->"Century Gothic"],Background->Hue[0.15,0.4,1]]}
,
{Plot[(E^(-2 t/(η T)))/. t-> Mod[u,T]
,{u,0,2.5},PlotRange-> {All,{-0.1,1.1}}
, PlotStyle->{Thickness[0.005],Hue[0.55,1,1]}
,Filling->{1-> {0,Hue[0.5,1,1,0.4]}}
,AspectRatio->0.35, Background->Black,ImageSize->300]
,Column[{Show[fourierSumplot[k,{"exponential",η,T},tarr]
,PlotRange-> {All,{-0.1,1.1}}
,AspectRatio->0.35, Background->Black,ImageSize->300]
,Show[fourierCompplot4[k,{"exponential",η,T},tarr]
,AspectRatio->1.5, Background->Black,ImageSize->300]
}]
}},Alignment-> Top,Frame-> True,FrameStyle->White]
,{{η,0.25},0.1,0.9},{{T,1},0.5,2},{{k,16},0,32,1}
,Initialization:>{
tarr=Range[0,500]/200.;
bogusgraphics=Graphics[{Point[{-1,0}]}];
xFcoeff[m_,wfparm_]:=Block[{wf,η}
,{wf,η}=Take[wfparm,2]; 
If[wf=="square"
,(E^(-I m π η))  η Sinc[m π η]
,If[wf=="sawtooth"
,(E^(-2 I m π η))If[m==0,0.5 η,(( I (1-(E^(I m π η)) Sinc[m π η]))/(2 m π))]
,If[wf=="triangle"
,(η/2.) (E^(- I m π η))((Sinc[((m π η)/2)])^2)
,(η/2) (1-(E^(-(2/η)))) (1/(1+ I m π η))
]]]
];

fourierCompplot4[k_,wfparm_,vararr_]:=Block[{wf,η,tper,xLoc}
,wf=wfparm[[1]]; 
If[TrueQ[wf=="exponential"],{η,tper}=Take[wfparm,{2,3}] ; 
xLoc=vararr/tper;
If[k==0
,Graphics[{Thickness[0.0065],White,Line[{{xLoc[[1]],0.5η},{Last[xLoc],0.5 η}}]}]
,Graphics[{Thickness[0.0065]
,Table[{Hue[(((m-1))/(k+1)),0.8,1]
,Line[Transpose[{xLoc
,η (1-(E^(-(2/η))))Re[((E^(I 2π m xLoc))/(1+ I m π η)) ] + Log[1.k/m]}]]},{m,k}]
}]]
,bogusgraphics]
];

fourierSumplot[k_,wfparm_,vararr_]:=Block[{wf,η,tper,coefF,xLoc}
,{wf,η,tper}=Take[wfparm,3]; 
xLoc=vararr/tper;
coefF=Table[xFcoeff[m,wfparm],{m,k}];
Graphics[{Thickness[0.0065], White
,Line[Transpose[{xLoc
,2Re[coefF . Table[(E^(I 2 π m xLoc )),{m,k}]]
+ConstantArray[xFcoeff[0,wfparm],Length[xLoc]]
}]]
}]
];

}]

5.5 Common utilities for the 4 waveforms

xFcoeff[m_,wfparm_]:=Block[{wf,η}
,{wf,η}=Take[wfparm,2]; 
If[wf=="square"
,(E^(-I m π η))  η Sinc[m π η]
,If[wf=="sawtooth"
,(E^(-2 I m π η))If[m==0,0.5 η,(( I (1-(E^(I m π η)) Sinc[m π η]))/(2 m π))]
,If[wf=="triangle"
,(η/2.) (E^(- I m π η))((Sinc[((m π η)/2)])^2)
,(η/2) (1-(E^(-(2/η)))) (1/(1+ I m π η))
]]]
];

fourierSumFunc[t_,k_,wfparm_]:=Block[{wf,η,tper,coefF}
,{wf,η,tper}=Take[wfparm,3];
coefF=Table[xFcoeff[m,wfparm],{m,k}];
2Re[coefF . (E^(I 2 π Table[m t/tper ,{m,k}])) ]+xFcoeff[0,wfparm]
];

Example:

Plot[fourierSumFunc[t,50,{"sawtooth",0.75,1}],{t,0,2}]

6. Concept of bandwidth and pulse duration

6.1 Exponential pulse

Manipulate[
Plot[UnitStep[t](E^(-t/ τ)),{t,-0.5,0.5}, PlotRange-> All]
,{τ,0.01,0.5}]

FourierCoefficient[UnitStep[t](E^(-t/(2π τ))),t,n]

(1/τ)(∫_(-1/2)^(1/2)) UnitStep[t]*(E^(-t/τ))(E^(-I 2 π n t))\[DifferentialD]t

Manipulate[
Grid[{{ListPlot[Table[Abs[((-1+(E^(-(1/(2 τ))-I π n)))/(-1-2 I π n τ))],{n,0,40}]
,PlotRange->All,PlotStyle->{PointSize[0.02],Red}
,Filling->{1-> {Bottom,Blue}}, ImageSize->350]
,ListLogPlot[Table[Abs[(((-1+(E^(-(1/(2 τ))-I π n))))/(-1-2 I π n τ))],{n,0,40}]
,PlotRange->All,PlotStyle->{PointSize[0.02],Red}
,Filling->{1-> {Bottom,Blue}}, ImageSize->350]
}
,{ListPlot[Table[Arg[((-1+(E^(-(1/(2 τ))-I π n)))/(-1-2 I π n τ))]/π,{n,0,40}]
,PlotRange->{-1,1},PlotStyle->{PointSize[0.02],Hue[0.35,1,0.5]}
,Filling->{1-> {Bottom,Orange}}, ImageSize->350]
,}}]
,{τ,0.01,0.5}]

6.2 Gaussian pulse

(1/τ)(∫_(-1/2)^(1/2)) (E^(-(((t/τ))^2)))(E^(-I 2 π n t))\[DifferentialD]t

fouriercomponent[n_,τ_]:=Quiet[(1/2) (E^(-(n^2) (π^2) (τ^2))) (Sqrt[π]) (Erf[(1/(2 τ))-I n π τ]+Erf[(1/(2 τ))+I n π τ])];
Manipulate[
Grid[{{ListPlot[Table[Abs[fouriercomponent[n,τ]],{n,0,40}]
,PlotRange->All,PlotStyle->{PointSize[0.02],Red}
,Filling->{1-> {Bottom,Blue}}, ImageSize->350]
,ListLogPlot[Table[Abs[fouriercomponent[n,τ]],{n,0,40}]
,PlotRange->All,PlotStyle->{PointSize[0.02],Red}
,Filling->{1-> {Bottom,Blue}}, ImageSize->350]
}
,{ListPlot[Table[Arg[Chop[fouriercomponent[n,τ]]]/π,{n,0,40}]
,PlotRange->{-1,1},PlotStyle->{PointSize[0.02],Hue[0.35,1,0.5]}
,Filling->{1-> {Bottom,Orange}}, ImageSize->350]
,}}]
,{τ,0.01,0.5}]

6.3 Square pulse

(1/τ)(∫_(-1/2)^(1/2)) UnitBox[(t/τ)] (E^(-I 2 π n t))\[DifferentialD]t

fouriercomponent[n_,τ_]:=If[n==0,1,((Sin[n π τ])/(τ n π))];
Manipulate[
Grid[{{ListPlot[Table[Abs[fouriercomponent[n,τ]],{n,0,40}]
,PlotRange->All,PlotStyle->{PointSize[0.02],Red}
,Filling->{1-> {Bottom,Blue}}, ImageSize->350]
,ListLogPlot[Table[Abs[fouriercomponent[n,τ]],{n,0,40}]
,PlotRange->All,PlotStyle->{PointSize[0.02],Red}
,Filling->{1-> {Bottom,Blue}}, ImageSize->350]
}
,{ListPlot[Table[Arg[Chop[fouriercomponent[n,τ]]]/π,{n,0,40}]
,PlotRange->{-1,1},PlotStyle->{PointSize[0.02],Hue[0.35,1,0.5]}
,Filling->{1-> {Bottom,Orange}}, ImageSize->350]
,}}]
,{τ,0.01,0.5}]

6.4 Triangle (symmetric ramp) pulse

(1/τ)(∫_(-1/2)^(1/2)) (1-Abs[(t/τ)]) (E^(-I 2 π n t))\[DifferentialD]t

((1-Cos[n π]-n π Sin[n π]+2 n π Abs[τ] Sin[n π])/(2 (n^2) (π^2) τ Abs[τ]))/. Abs[τ]-> τ

FullSimplify[((1-Cos[n π]-n π Sin[n π]+2 n π τ Sin[n π])/(2 (n^2) (π^2) (τ^2)))]

((1-Cos[n π]+n π (-1+2 τ) Sin[n π])/(2 (n^2) (π^2) (τ^2))) /. Cos[n π]->(((-1))^n) /. Sin[n π]-> 0

Limit[((1-Cos[n π]+n π (-1+2 τ) Sin[n π])/(2 (n^2) (π^2) (τ^2))),n-> 0]

fouriercomponent[n_,τ_]:=If[n==0,((-1+4 τ)/(4 (τ^2))),((1+(((-1))^(1+n)))/(2 (n^2) (π^2) (τ^2)))];
Manipulate[
Grid[{{ListPlot[Table[Abs[fouriercomponent[n,τ]],{n,0,40}]
,PlotRange->All,PlotStyle->{PointSize[0.02],Red}
,Filling->{1-> {Bottom,Blue}}, ImageSize->350]
,ListLogPlot[Table[Abs[fouriercomponent[n,τ]],{n,0,40}]
,PlotRange->All,PlotStyle->{PointSize[0.02],Red}
,Filling->{1-> {Bottom,Blue}}, ImageSize->350]
}
,{ListPlot[Table[Arg[Chop[fouriercomponent[n,τ]]]/π,{n,0,40}]
,PlotRange->{-1,1},PlotStyle->{PointSize[0.02],Hue[0.35,1,0.5]}
,Filling->{1-> {Bottom,Orange}}, ImageSize->350]
,}}]
,{τ,0.01,0.5}]

HW on pulse shape

pulse: raised cosine, sech, trapeze.

Pre-classwork and HW project

Each generates a line art graphics that can be done with Fourier synthesis. Two options:
A- multi-line artwork (minimum 2 non-constant lines)
B- 2 or more single-line artworks and morph them

You have some data in a csv file. Analyze it.