NotebookDirectory[]

SetDirectory[NotebookDirectory[]]

Interval [a,b)

aa=1;bb=4;ff[x_]=x;fft[x_]:=ff[x-(Floor[((x-aa)/(bb-aa))])(bb-aa)];

picCabPE1f=Plot[{ff[x]},{x,1,4},PlotStyle->{{Thickness[0.007],Blue}},
Epilog->{
{Blue,PointSize[0.02],Point[{1,ff[1]}],Point[{4,ff[4]}]},{White,PointSize[0.014],Point[{4,ff[4]}]}
},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-5.5,6.5},{-1,5}},ImageSize->700]

Export["picCabPE1f.png",picCabPE1f,"PNG",Background->None]

picCabPE1nf=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Red}},
Prolog->{{Blue,Thickness[0.0072],Line[{{1,1},{4,4}}]},{Blue,PointSize[0.022],Point[{1,ff[1]}],Point[{4,ff[4]}]},{White,PointSize[0.014],Point[{4,ff[4]}]}},
Epilog->{
{Red,PointSize[0.018],Point[{#,fft[#]}]&/@Range[-8,7,3]},{{Red,PointSize[0.018],Point[{#,fft[#]+3}]},{White,PointSize[0.012],Point[{#,fft[#]+3}]}}&/@Range[-8,7,3]},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-5.5,6.5},{-1,5}},ImageSize->700]

Export["picCabPE1nf.png",picCabPE1nf,"PNG",Background->None]

picCabPFE1nf=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],RGBColor[0,.6,0]}},
Epilog->{
{RGBColor[0,.6,0],PointSize[0.02],Point[{#,fft[#]}]&/@Range[-8,7,3],Point[{#,fft[#]+3}]&/@Range[-8,7,3],Point[{#,fft[#]+3/2}]&/@Range[-8,7,3]},{White,PointSize[0.014],Point[{#,fft[#]}]&/@Range[-8,7,3],Point[{#,fft[#]+3}]&/@Range[-8,7,3]}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-5.5,6.5},{-1,5}},ImageSize->700]

Export["picCabPFE1nf.png",picCabPFE1nf,"PNG",Background->None]

picCabPE1=Plot[{ff[x],fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.003],Blue},{Thickness[0.005],Red}},
Epilog->{
{Red,PointSize[0.02],Point[{#,fft[#]}]&/@Range[-8,7,3]},{{Red,PointSize[0.02],Point[{#,fft[#]+3}]},{White,PointSize[0.014],Point[{#,fft[#]+3}]}}&/@Range[-8,7,3]},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-5.5,6.5},{-1,5}},ImageSize->700]

(*  Export["picCabPE1.png",picCabPE1,"PNG",Background->None]   *)

aa=-2;bb=2;ff[x_]=(x^2)-2;fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];

Plot[{ff[x],fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.009],Blue},{Thickness[0.005],Red}},AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-5.5,6.5},{-3,4}},ImageSize->700]

aa=0;bb=Pi;ff[x_]=Cos[x];fft[x_]:=ff[x-(Floor[((x-aa)/(bb-aa))])(bb-aa)];

picCabPECos=Plot[{ff[x],fft[x]},{x,-4 Pi,4 Pi},PlotStyle->{{Thickness[0.003],Blue},{Thickness[0.005],Red}},
Epilog->{
{Red,PointSize[0.015],Point[{#,fft[#]}]&/@Range[-3 Pi,4 Pi,Pi]},{{Red,PointSize[0.015],Point[{#,fft[#]-2}]},{White,PointSize[0.01],Point[{#,fft[#]-2}]}}&/@Range[-3 Pi,4 Pi,Pi]},
AspectRatio->Automatic,Ticks->{Range[-5 Pi,5 Pi,Pi/2],Range[-10,10]},PlotRange->{{-2 Pi-.5,2 Pi+.5},{-2.5,2.5}},ImageSize->700]

(* Export["picCabPECos.png",picCabPECos,"PNG",Background->None] *)

aa=-Pi;bb=Pi;Clear[ff]; ff[x_]=If[x<0,0,Cos[x]];fft[x_]:=ff[x-(Floor[((x-aa)/(bb-aa))])(bb-aa)];

picCabfwe=Plot[{ff[x]},{x,-Pi,Pi},PlotStyle->{{Thickness[0.006],Blue}},Exclusions->{0},
Epilog->{
{Blue,PointSize[0.015],Point[{-Pi,0}],
Point[{0,0}],Point[{0,1}],Point[{Pi,-1}]},{White,PointSize[0.01],Point[{0,0}],Point[{Pi,-1}]}
},
AspectRatio->1/5,Ticks->{Range[-5 Pi,5 Pi,Pi/2],Range[-10,10]},PlotRange->{{-4 Pi-.5,4 Pi+.5},{-1.5,1.5}},ImageSize->700]

Export["picCabfwe.png",picCabfwe,"PNG",Background->None]

picCabPEwe=Plot[{fft[x]},{x,-5 Pi,5 Pi},PlotStyle->{{Thickness[0.005],Red}},Exclusions->Range[-7Pi,7Pi,Pi],
Epilog->{
{Red,PointSize[0.015],Point[{#,0}]&/@Range[-6 Pi,6 Pi,Pi],Point[{#,1}]&/@Range[-6 Pi,6 Pi,2Pi],Point[{#,-1}]&/@Range[-7 Pi,6 Pi,2Pi]},{White,PointSize[0.01],Point[{#,0}]&/@Range[-6 Pi,6 Pi,2Pi],Point[{#,-1}]&/@Range[-7 Pi,6 Pi,2Pi]}
},
AspectRatio->1/5,Ticks->{Range[-5 Pi,5 Pi,Pi/2],Range[-10,10]},PlotRange->{{-4 Pi-.5,4 Pi+.5},{-1.5,1.5}},ImageSize->700]

Export["picCabPEwe.png",picCabPEwe,"PNG",Background->None]

picCabPFEwe=Plot[{fft[x]},{x,-5 Pi,5 Pi},PlotStyle->{{Thickness[0.005],RGBColor[0,0.7,0]}},Exclusions->Range[-7Pi,7Pi,Pi],
Epilog->{
{RGBColor[0,0.7,0],PointSize[0.015],Point[{#,0}]&/@Range[-6 Pi,6 Pi,Pi],Point[{#,1}]&/@Range[-6 Pi,6 Pi,2Pi],Point[{#,-1}]&/@Range[-7 Pi,6 Pi,2Pi],Point[{#,1/2}]&/@Range[-6 Pi,6 Pi,2Pi],Point[{#,-1/2}]&/@Range[-7 Pi,6 Pi,2Pi]},{White,PointSize[0.01],Point[{#,0}]&/@Range[-6 Pi,6 Pi,Pi],Point[{#,-1}]&/@Range[-7 Pi,6 Pi,2Pi],Point[{#,1}]&/@Range[-6 Pi,6 Pi,2Pi]}
},
AspectRatio->(1/5),Ticks->{Range[-5 Pi,5 Pi,Pi/2],Range[-10,10]},PlotRange->{{-4 Pi-.5,4 Pi+.5},{-1.5,1.5}},ImageSize->700]

Export["picCabPFEwe.png",picCabPFEwe,"PNG",Background->None]

Start

aa=0;bb=Pi;ff[x_]=Cos[x];fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)]

Plot[{ff[x],fft[x]},{x,-5,7},PlotStyle->{{Thickness[0.01],Blue},{Thickness[0.004],Red}}]

aa=-2;bb=2;ff[x_]=(x^2)-2;fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];


Plot[{ff[x],fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.009],Blue},{Thickness[0.005],Red}},AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-5.5,6.5},{-3,4}},ImageSize->700]

aa=1;bb=3;ff[x_]=x;fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];

picPE1=Plot[{ff[x],fft[x]},{x,-5,7},PlotStyle->{{Thickness[0.009],Blue},{Thickness[0.005],Red}},AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-5.5,6.5},{-3,5}},ImageSize->700]

(* Export["picPE1.png",picPE1,"PNG",Background->None] *)

aa=1;bb=3;ff[x_]=x;fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];


picPE1r=Plot[{ff[x]},{x,1,3},PlotStyle->{{Thickness[0.009],Blue}},Epilog->{
{Blue,PointSize[0.02],Point[{#,ff[#]}]&/@Range[1,3,2]},{{White,PointSize[0.014],Point[{#,ff[#]}]}}&[1]},AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-5.5,6.5},{-1,4}},ImageSize->700]

(* Export["picPE1r.png",picPE1r,"PNG",Background->None] *)

aa=-2;bb=2;ff[x_]=(x^2)-2;fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];


picPE1I=Plot[{ff[x],fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.009],Blue},{Thickness[0.005],Red}},AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-5.5,6.5},{-3,4}},ImageSize->700]

(* Export["picPE1I.png",picPE1I,"PNG",Background->None] *)

The above graphs do not provide enough information about the values of the functions at the jumps.  To provide such information we need to add few points on the graph. For example:

aa=1;bb=3;ff[x_]=x;fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];

picPE1a=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Red}},
Epilog->{
{Red,PointSize[0.02],Point[{#,fft[#]}]&/@Range[-5,7,2]},{{Red,PointSize[0.02],Point[{#,fft[#]-2}]},{White,PointSize[0.014],Point[{#,fft[#]-2}]}}&/@Range[-5,7,2]},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-5.5,6.5},{-1,4}},ImageSize->700]

(* Export["picPE1a.png",picPE1a,"PNG",Background->None] *)

picPE1fe=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},
Epilog->{
{{Green,PointSize[0.02],Point[{#,fft[#]-1}]},{Green,PointSize[0.02],Point[{#,fft[#]}]},{White,PointSize[0.014],Point[{#,fft[#]}]}}&/@Range[-5,7,2],{{Green,PointSize[0.02],Point[{#,fft[#]-2}]},{White,PointSize[0.014],Point[{#,fft[#]-2}]}}&/@Range[-5,7,2]},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-5.5,6.5},{-1,4}},ImageSize->700]

(* Export["picPE1fe.png",picPE1fe,"PNG",Background->None]*)

Example 2

Clear[en,aa,bb,ff,fft,cbb,nn];
en=2;

aa=-1;bb=1;ff[x_]=Sign[x];fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];
cbb[n_]=(1/1)Integrate[ff[x]Sin[((n Pi)/1)x],{x,-1,1}];
nn=20;

picPE[en]=Plot[{ff[x]},{x,-1,1},PlotStyle->{{Thickness[0.009],Blue}},Epilog->{{Blue,PointSize[0.02],Point[{#,ff[#]}]&/@{-1,0,1},Point[{0,1}],Point[{0,-1}]},{{White,PointSize[0.014],Point[{#,fft[#]+1}],Point[{#,fft[#]-1}]}}&[0],{White,PointSize[0.014],Point[{-1,-1}]}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEpe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Red}},Exclusions->Range[-8,8,1],
Epilog->{{Red,PointSize[0.02],Point[{#,0}]&/@Range[-6,7,2]},{Red,PointSize[0.02],Point[{#,1}]&/@Range[-7,7,2]},{{Red,PointSize[0.02],Point[{#,1}],Point[{#,-1}]},{White,PointSize[0.014],Point[{#,1}],Point[{#,-1}]}}&/@Range[-6,7,2],
{{Red,PointSize[0.02],Point[{#,-1}]},{White,PointSize[0.014],Point[{#,-1}]}}&/@Range[-7,7,2]},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},Exclusions->Range[-8,8,1],
Epilog->{{Green,PointSize[0.02],Point[{#,0}]&/@Range[-6,7,1]},{{Green,PointSize[0.02],Point[{#,1}],Point[{#,-1}]},{White,PointSize[0.014],Point[{#,1}],Point[{#,-1}]}}&/@Range[-6,7,1]},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfs[en]=Module[{pic1,pic1a,pic2},pic1=Plot[Evaluate[{fft[x]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Green}},Exclusions->Range[-8,8,1],
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];pic1a=Graphics[{{Green,PointSize[0.015],Point[{#,0}]&/@Range[-6,7,1]},{{Green,PointSize[0.015],Point[{#,1}],Point[{#,-1}]},{White,PointSize[0.01],Point[{#,1}],Point[{#,-1}]}}&/@Range[-6,7,1]}];pic2=Plot[Evaluate[{Sum[cbb[n]Sin[((n Pi)/1)x],{n,1,nn}]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Black}},Exclusions->None,
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];Show[pic1,pic1a,pic2]]

FullSimplify[Table[cbb[n],{n,1,20}]]

(* Export[StringJoin["picPE",ToString[en],".png"],picPE[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"pe.png"],picPEpe[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"fe.png"],picPEfe[en],Background->None];
Export[StringJoin["picPE",ToString[en],"fs.png"],picPEfs[en],Background->None]; *)

Example 3

Clear[en,aa,bb,ff,fft,cbb,nn];

en=3;

aa=-1;bb=1;ff[x_]=x;fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];

cbb[n_]=(1/1)Integrate[ff[x]Sin[((n Pi)/1)x],{x,-1,1}];
nn=20;

picPE[en]=Plot[{ff[x]},{x,-1,1},PlotStyle->{{Thickness[0.009],Blue}},Epilog->{{Blue,PointSize[0.02],Point[{#,ff[#]}]&/@{-1,1}},{White,PointSize[0.014],Point[{-1,-1}]}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEpe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Red}},Exclusions->Range[-7,8,2],
Epilog->{{Red,PointSize[0.02],Point[{#,1}]&/@Range[-7,7,2]},{{Red,PointSize[0.02],Point[{#,-1}]&/@Range[-7,7,2]},{White,PointSize[0.014],Point[{#,-1}]&/@Range[-7,7,2]}}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},Exclusions->Range[-7,8,2],
Epilog->{{Green,PointSize[0.02],Point[{#,0}]&/@Range[-7,7,2]},{{Green,PointSize[0.02],Point[{#,1}],Point[{#,-1}]},{White,PointSize[0.014],Point[{#,1}],Point[{#,-1}]}}&/@Range[-7,7,2]},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfs[en]=Module[{pic1,pic1a,pic2},pic1=Plot[Evaluate[{fft[x]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Green}},Exclusions->Range[-8,8,1],
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];pic1a=Graphics[{{Green,PointSize[0.015],Point[{#,0}]&/@Range[-7,7,2]},{{Green,PointSize[0.015],Point[{#,1}],Point[{#,-1}]},{White,PointSize[0.01],Point[{#,1}],Point[{#,-1}]}}&/@Range[-7,7,2]}];pic2=Plot[Evaluate[{Sum[cbb[n]Sin[((n Pi)/1)x],{n,1,nn}]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Black}},Exclusions->None,
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];Show[pic1,pic1a,pic2]]

FullSimplify[Table[cbb[n],{n,1,20}]]

(* Export[StringJoin["picPE",ToString[en],".png"],picPE[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"pe.png"],picPEpe[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"fe.png"],picPEfe[en],Background->None];
Export[StringJoin["picPE",ToString[en],"fs.png"],picPEfs[en],Background->None]; *)

Example 4

Clear[en,aa,bb,ff,fft,cbb,nn];

en=4;

aa=-1;bb=1;ff[x_]=Sign[x]-x;fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];
cbb[n_]=(1/1)Integrate[ff[x]Sin[((n Pi)/1)x],{x,-1,1}];
nn=20;

picPE[en]=Plot[{ff[x]},{x,-1,1},PlotStyle->{{Thickness[0.009],Blue}},Epilog->{{Blue,PointSize[0.02],Point[{#,ff[#]}]&/@{-1,0,1},Point[{0,1}],Point[{0,-1}]},{{White,PointSize[0.014],Point[{#,fft[#]+1}],Point[{#,fft[#]-1}]}}&[0],{White,PointSize[0.014],Point[{-1,0}]}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEpe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Red}},Exclusions->Range[-8,8,2],
Epilog->{{Red,PointSize[0.02],Point[{#,0}]&/@Range[-6,7,2]},{{Red,PointSize[0.02],Point[{#,1}],Point[{#,-1}]},{White,PointSize[0.014],Point[{#,1}],Point[{#,-1}]}}&/@Range[-6,7,2]},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},Exclusions->Range[-8,8,2],
Epilog->{{Green,PointSize[0.02],Point[{#,0}]&/@Range[-6,7,2]},{{Green,PointSize[0.02],Point[{#,1}],Point[{#,-1}]},{White,PointSize[0.014],Point[{#,1}],Point[{#,-1}]}}&/@Range[-6,7,2]},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfs[en]=Module[{pic1,pic1a,pic2},pic1=Plot[Evaluate[{fft[x]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Green}},Exclusions->Range[-8,8,1],
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];pic1a=Graphics[{{Green,PointSize[0.015],Point[{#,0}]&/@Range[-8,7,2]},{{Green,PointSize[0.015],Point[{#,1}],Point[{#,-1}]},{White,PointSize[0.01],Point[{#,1}],Point[{#,-1}]}}&/@Range[-8,7,2]}];pic2=Plot[Evaluate[{Sum[cbb[n]Sin[((n Pi)/1)x],{n,1,nn}]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Black}},Exclusions->None,
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];Show[pic1,pic1a,pic2]]

(* Export[StringJoin["picPE",ToString[en],".png"],picPE[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"pe.png"],picPEpe[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"fe.png"],picPEfe[en],Background->None];

Export[StringJoin["picPE",ToString[en],"fs.png"],picPEfs[en],Background->None]; *)

Example 5

Clear[en,aa,bb,ff,fft,cbb,nn];


en=5;

aa=-1;bb=1;ff[x_]=UnitStep[x];fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];
cbb[n_]=(1/1)Integrate[ff[x]Sin[((n Pi)/1)x],{x,-1,1}];
nn=20;

picPE[en]=Plot[{ff[x]},{x,-1,1},PlotStyle->{{Thickness[0.009],Blue}},Epilog->{{Blue,PointSize[0.02],Point[{-1,0}],Point[{0,0}],Point[{0,1}],Point[{1,1}]},
{White,PointSize[0.014],Point[{-1,0}],Point[{0,0}]}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEpe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Red}},Exclusions->Range[-8,8,1],
Epilog->{{Red,PointSize[0.02],Point[{#,1}]}&/@Range[-6,7,1],{{Red,PointSize[0.02],Point[{#,0}]},{White,PointSize[0.014],Point[{#,0}]}}&/@Range[-6,7,1]},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},Exclusions->Range[-8,8,1],
Epilog->{{Green,PointSize[0.02],Point[{#,1/2}]&/@Range[-6,7,1]},{{Green,PointSize[0.02],Point[{#,1}],Point[{#,0}]},{White,PointSize[0.014],Point[{#,1}],Point[{#,0}]}}&/@Range[-6,7,1]},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfs[en]=Module[{pic1,pic1a,pic2},pic1=Plot[Evaluate[{fft[x]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Green}},Exclusions->Range[-8,8,1],
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];pic1a=Graphics[{{Green,PointSize[0.015],Point[{#,1/2}]&/@Range[-6,7,1]},{{Green,PointSize[0.015],Point[{#,1}],Point[{#,0}]},{White,PointSize[0.01],Point[{#,1}],Point[{#,0}]}}&/@Range[-6,7,1]}];pic2=Plot[Evaluate[{(1/2)+Sum[cbb[n]Sin[((n Pi)/1)x],{n,1,nn}]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Black}},Exclusions->None,
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];Show[pic1,pic1a,pic2]]

(* Export[StringJoin["picPE",ToString[en],".png"],picPE[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"pe.png"],picPEpe[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"fe.png"],picPEfe[en],Background->None];
Export[StringJoin["picPE",ToString[en],"fs.png"],picPEfs[en],Background->None]; *)

Example 6

Clear[en,aa,bb,ff,fft,cbb,nn];

en=6;

aa=-1;bb=1;ff[x_]=Abs[x];fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];
caa[n_]=(1/1)Integrate[ff[x]Cos[((n Pi)/1)x],{x,-1,1}];caa0=(1/2)Integrate[ff[x],{x,-1,1}];
nn=20;

picPE[en]=Plot[{ff[x]},{x,-1,1},PlotStyle->{{Thickness[0.009],Blue}},Epilog->{{Blue,PointSize[0.02],Point[{-1,1}],Point[{1,1}]},
{White,PointSize[0.014],Point[{-1,1}]}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEpe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Red}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfs[en]=Module[{pic1,pic1a,pic2},pic1=Plot[Evaluate[{fft[x]}],{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},Exclusions->Range[-8,8,1],
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];pic2=Plot[Evaluate[{caa0+Sum[caa[n]Cos[((n Pi)/1)x],{n,1,nn}]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Black}},Exclusions->None,
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];Show[pic1,pic2]]

(* Export[StringJoin["picPE",ToString[en],".png"],picPE[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"pe.png"],picPEpe[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"fe.png"],picPEfe[en],Background->None];

Export[StringJoin["picPE",ToString[en],"fs.png"],picPEfs[en],Background->None]; *)

Example 7

Clear[en,aa,bb,ff,fft,cbb,nn];

en=7;
aa=-2;bb=2;ff[x_]=1-Abs[x];fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];
caa[n_]=(1/2)Integrate[ff[x]Cos[((n Pi)/2)x],{x,-2,2}];caa0=(1/4)Integrate[ff[x],{x,-2,2}];

nn=20;

picPE[en]=Plot[{ff[x]},{x,aa,bb},PlotStyle->{{Thickness[0.009],Blue}},Epilog->{{Blue,PointSize[0.02],Point[{-2,-1}],Point[{2,-1}]},
{White,PointSize[0.014],Point[{-2,-1}]}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEpe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Red}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfs[en]=Module[{pic1,pic1a,pic2},pic1=Plot[Evaluate[{fft[x]}],{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},Exclusions->Range[-8,8,1],
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];pic2=Plot[Evaluate[{caa0+Sum[caa[n]Cos[((n Pi)/2)x],{n,1,nn}]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Black}},Exclusions->None,
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];Show[pic1,pic2]]

(* Export[StringJoin["picPE",ToString[en],".png"],picPE[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"pe.png"],picPEpe[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"fe.png"],picPEfe[en],Background->None];

Export[StringJoin["picPE",ToString[en],"fs.png"],picPEfs[en],Background->None]; *)

Example 8

(2/Pi)Integrate[ff[x]Sin[ x],{x,0,Pi}]

Clear[en,aa,bb,ff,fft,cbb,nn];

en=8;
aa=0;bb=Pi;ff[x_]=Cos[x];fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];
cbb[n_]=(2/Pi)Integrate[ff[x]Sin[n x],{x,0,Pi}];
nn=20;

picPE[en]=Plot[{ff[x]},{x,aa,bb},PlotStyle->{{Thickness[0.009],Blue}},Epilog->{{Blue,PointSize[0.02],Point[{0,1}],Point[{Pi,-1}]},
{White,PointSize[0.014],Point[{0,1}]}},
AspectRatio->Automatic,Ticks->{Range[-10 Pi,10 Pi, Pi/2],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2,2}},ImageSize->500]

picPEpe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Red}},Epilog->{{Red,PointSize[0.02],Point[{#,1}],Point[{#,-1}]}&/@Range[-3Pi,4Pi,Pi],
{White,PointSize[0.014],Point[{#,1}]}&/@Range[-3Pi,4Pi,Pi]},
AspectRatio->Automatic,Ticks->{Range[-10 Pi,10 Pi, Pi/2],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2,2}},ImageSize->500]

picPEfe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},
Epilog->{{Green,PointSize[0.02],Point[{#,1}],Point[{#,-1}],,Point[{#,0}]}&/@Range[-3Pi,4Pi,Pi],
{White,PointSize[0.014],Point[{#,1}],Point[{#,-1}]}&/@Range[-3Pi,4Pi,Pi]},
AspectRatio->Automatic,Ticks->{Range[-10 Pi,10 Pi, Pi/2],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2,2}},ImageSize->500]

picPEfs[en]=Module[{pic1,pic1a,pic2},pic1=Plot[Evaluate[{fft[x]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Green}},Exclusions->Range[-9Pi,8Pi,Pi],
AspectRatio->Automatic,Ticks->{Range[-10 Pi,10 Pi, Pi/2],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2,2}},ImageSize->700];pic1a=Graphics[{{Green,PointSize[0.015],Point[{#,1}],Point[{#,-1}],,Point[{#,0}]}&/@Range[-3Pi,4Pi,Pi],
{White,PointSize[0.01],Point[{#,1}],Point[{#,-1}]}&/@Range[-3Pi,4Pi,Pi]}];
pic2=Plot[Evaluate[{Sum[cbb[n]Sin[n x],{n,2,nn}]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Black}},PlotPoints->250,Exclusions->None,
AspectRatio->Automatic,Ticks->{Range[-10 Pi,10 Pi, Pi/2],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2,2}},ImageSize->700];Show[pic1,pic1a,pic2]]

(* Export[StringJoin["picPE",ToString[en],".png"],picPE[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"pe.png"],picPEpe[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"fe.png"],picPEfe[en],Background->None];
Export[StringJoin["picPE",ToString[en],"fs.png"],picPEfs[en],Background->None]; *)

Example 9

Clear[en,aa,bb,ff,fft,cbb,nn];
   
en=9;

aa=0;bb=Pi;ff[x_]=Sin[x];fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];
caa[n_]=(2/Pi)Integrate[ff[x]Cos[n x],{x,0,Pi}];caa0=(1/Pi)Integrate[ff[x],{x,0,Pi}];

nn=20;

picPE[en]=Plot[{ff[x]},{x,aa,bb},PlotStyle->{{Thickness[0.009],Blue}},Epilog->{{Blue,PointSize[0.02],Point[{0,0}],Point[{Pi,0}]},
{White,PointSize[0.014],Point[{0,0}]}},
AspectRatio->Automatic,Ticks->{Range[-10 Pi,10 Pi, Pi/2],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2,2}},ImageSize->700]

picPEpe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Red}},
AspectRatio->Automatic,Ticks->{Range[-10 Pi,10 Pi, Pi/2],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2,2}},ImageSize->700]

picPEfe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},
AspectRatio->Automatic,Ticks->{Range[-10 Pi,10 Pi, Pi/2],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2,2}},ImageSize->700]

picPEfs[en]=Module[{pic1,pic1a,pic2},pic1=Plot[Evaluate[{fft[x]}],{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},Exclusions->Range[-8,8,1],
AspectRatio->Automatic,Ticks->{Range[-10 Pi,10 Pi, Pi/2],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2,2}},ImageSize->700];pic2=Plot[Evaluate[{caa0+Sum[caa[n]Cos[n x],{n,2,nn}]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Black}},Exclusions->None,
AspectRatio->Automatic,Ticks->{Range[-10 Pi,10 Pi, Pi/2],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2,2}},ImageSize->700];Show[pic1,pic2]]

(* Export[StringJoin["picPE",ToString[en],".png"],picPE[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"pe.png"],picPEpe[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"fe.png"],picPEfe[en],Background->None];
Export[StringJoin["picPE",ToString[en],"fs.png"],picPEfs[en],Background->None]; *)

Example 10

Clear[en,aa,bb,ff,fft,cbb,nn];

en=10;
aa=-1;bb=1;ff[x_]=x^2;fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];
caa[n_]=(1/1)Integrate[ff[x]Cos[((n Pi)/1)x],{x,-1,1}];caa0=(1/2)Integrate[ff[x],{x,-1,1}];
nn=20;

picPE[en]=Plot[{ff[x]},{x,aa,bb},PlotStyle->{{Thickness[0.009],Blue}},Epilog->{{Blue,PointSize[0.02],Point[{-1,1}],Point[{1,1}]},
{White,PointSize[0.014],Point[{-1,1}]}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEpe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Red}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfe[en]=Plot[{fft[x]},{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700]

picPEfs[en]=Module[{pic1,pic1a,pic2},pic1=Plot[Evaluate[{fft[x]}],{x,-7,7},PlotStyle->{{Thickness[0.005],Green}},Exclusions->Range[-8,8,1],
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];pic2=Plot[Evaluate[{caa0+Sum[caa[n]Cos[((n Pi)/1)x],{n,1,nn}]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Black}},Exclusions->None,
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-3.5,4.5},{-2,2}},ImageSize->700];Show[pic1,pic2]]

(* Export[StringJoin["picPE",ToString[en],".png"],picPE[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"pe.png"],picPEpe[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"fe.png"],picPEfe[en],Background->None];

Export[StringJoin["picPE",ToString[en],"fs.png"],picPEfs[en],Background->None]; *)

caa0

FullSimplify[caa[n],n∈Integers]

Example 11

Clear[en,aa,bb,ff,fft,cbb,caa,caa0,nn];

en=11;
aa=-2;bb=2;ff[x_]=Floor[x];fft[x_]:=ff[x-(Ceiling[((x-aa)/(bb-aa))]-1)(bb-aa)];
cbb[n_]=(1/2)Integrate[ff[x]Sin[((n Pi)/2)x],{x,-2,2}];
caa[n_]=(1/2)Integrate[ff[x]Cos[((n Pi)/2)x],{x,-2,2}];caa0=(1/4)Integrate[ff[x],{x,-2,2}];

nn=20;

picPE[en]=Plot[{ff[x]},{x,aa,bb},PlotStyle->{{Thickness[0.009],Blue}},Epilog->{{Blue,PointSize[0.02],Point[{#,ff[#]}]&/@Range[-2,2,1],Point[{#,ff[#]-1}]&/@Range[-2,2,1]},
{White,PointSize[0.014],Point[{-2,-2}],Point[{#,ff[#]-1}]&/@Range[-2,2,1]}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2.5,2.5}},ImageSize->700]

picPEpe[en]=Plot[{fft[x]},{x,-17,17},PlotStyle->{{Thickness[0.005],Red}},Exclusions->Range[-10,10,1],
Epilog->{{Red,PointSize[0.02],Point[{#,fft[#]}]&/@Range[-7,7,1],Point[{#,fft[#]-1}]&/@Range[-7,7,1],Point[{#,-2}]&/@Range[-10,7,4]},
{White,PointSize[0.014],Point[{#,fft[#]-1}]&/@Range[-7,7,1],Point[{#,-2}]&/@Range[-10,7,4]}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2.5,2.5}},ImageSize->700]

picPEfe[en]=Plot[{fft[x]},{x,-11,17},PlotStyle->{{Thickness[0.005],Green}},Epilog->{{Green,PointSize[0.02],
Point[{#,fft[#]-5/2}]&/@Select[Range[-7,10,1],(Mod[#-2,4]==0)&],
Point[{#,fft[#]-1/2}]&/@Select[Range[-7,10,1],Not[Mod[#-2,4]==0]&],Point[{#,fft[#]}]&/@Select[Range[-7,10,1],Not[Mod[#-2,4]==0]&],Point[{#,fft[#]-1}]&/@Range[-7,7,1],Point[{#,-2}]&/@Range[-10,7,4]},
{White,PointSize[0.014],Point[{#,fft[#]}]&/@Select[Range[-7,10,1],Not[Mod[#-2,4]==0]&],Point[{#,fft[#]-1}]&/@Range[-7,7,1],Point[{#,-2}]&/@Range[-10,7,4]}},
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2.5,2.5}},ImageSize->700]

picPEfs[en]=Module[{pic1,pic1a,pic2},pic1=Plot[Evaluate[{fft[x]}],{x,-7,7},PlotStyle->{{Thickness[0.003],Green}},Exclusions->Range[-8,8,1],
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2.5,2.5}},ImageSize->700];pic1a=Graphics[{{Green,PointSize[0.015],
Point[{#,fft[#]-5/2}]&/@Select[Range[-7,10,1],(Mod[#-2,4]==0)&],
Point[{#,fft[#]-1/2}]&/@Select[Range[-7,10,1],Not[Mod[#-2,4]==0]&],Point[{#,fft[#]}]&/@Select[Range[-7,10,1],Not[Mod[#-2,4]==0]&],Point[{#,fft[#]-1}]&/@Range[-7,7,1],Point[{#,-2}]&/@Range[-10,7,4]},
{White,PointSize[0.01],Point[{#,fft[#]}]&/@Select[Range[-7,10,1],Not[Mod[#-2,4]==0]&],Point[{#,fft[#]-1}]&/@Range[-7,7,1],Point[{#,-2}]&/@Range[-10,7,4]}}];pic2=Plot[Evaluate[{caa0+Sum[caa[n]Cos[((n Pi)/2)x],{n,1,nn}]+Sum[cbb[n]Sin[((n Pi)/2)x],{n,1,nn}]}],{x,-7,10},PlotStyle->{{Thickness[0.003],Black}},PlotPoints->300,Exclusions->None,
AspectRatio->Automatic,Ticks->{Range[-10,10],Range[-10,10]},PlotRange->{{-4.5,7.5},{-2.5,2.5}},ImageSize->700];Show[pic1,pic1a,pic2]]

(* Export[StringJoin["picPE",ToString[en],".png"],picPE[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"pe.png"],picPEpe[en],"PNG",Background->None];
Export[StringJoin["picPE",ToString[en],"fe.png"],picPEfe[en],Background->None];

Export[StringJoin["picPE",ToString[en],"fs.png"],picPEfs[en],Background->None];
*)

caa0

FullSimplify[caa[n],n∈Integers]

FullSimplify[cbb[n],n∈Integers]

NotebookDirectory[]