Fourier Transform and Applications

ECE generic        Han Q. Le (c)

1. Introduction: numerical discovery approach

1.1 Run the app demo

We have made music and see a sound note can be a “fairly” periodic function:

sound signal                                               Fourier transform
      
zoom in to see the periodic signal

What is most remarkable is that the Fourier spectrum shows many peaks that have periodic spacing. It means that the sound signal can be written as:
                                       x[t]    ~        (∑_(m=-p)^p)(Subscript[X, m]) (e^(i m 2 π f t))     (1.1.1)
where f is the fundamental frequency found below:

and p are the number of peaks that are above the “fuzzy” noise floor.

Are those peaks are really regularly spaced? We can check by plotting:

fharmonic={521.73`,1043.46`,1556.74`,2074.`,2594.`,3120.`,3640.`,4164.`,4684.`,5217.31`,5731.`,6240.`,6766.`};
ffit=LinearModelFit[Transpose[{Range[Length[fharmonic]],fharmonic}],x,x, IncludeConstantBasis->False];
Show[ListPlot[fharmonic,PlotStyle-> {PointSize[0.03],Red}, PlotRange->{{0,Length[fharmonic]},All}
,Frame->True, GridLines->Automatic
,FrameLabel-> (Style[#,24,Black,FontFamily->"Calibri"] & /@ {"harmonic order","frequency (Hz)"})
,LabelStyle->{16,Black,FontFamily->"Arial"}
,PlotLegends->Style["data",Red,18,Bold,FontFamily->"Arial"]]
,Plot[ffit[x],{x,0,Length[fharmonic]},PlotStyle->{Thickness[0.005],Blue}
,PlotLegends->Style["linear fit",Blue,18,Bold,FontFamily->"Arial"]]
,ImageSize-> 450]

1.2 Construction of the signal

Let’s use Eq. (1.1.1) to reconstruct the signal. Since the signal is over a long duration with some slight variation, we’ll choose a narrow interval as show below:

({{}, {}, {(RowDefault)}, {}})      ({{({{Linear"Linear", dB"dB"}})}, {}, {({{"save"}, {({{"f = ", fc, "      period = ", ((1.`)/fc)}})}, {}})}})

Over this range of signal:

fharm0={521.`,1047.963143`,1561.251212`,2095.926285`,2609.214355`,3128.5`,3657.177498`,4170.465567`,4705.14064`};
ffit0=LinearModelFit[Transpose[{Range[Length[fharm0]],fharm0}],x,x, IncludeConstantBasis->False];
Grid[{{"Best-fitted fundamental frequency (Hz)   ",f0=ffit0[[1,2,1]]}}
,Background->Hue[0.15,1,1],Frame-> True]
Show[ListPlot[fharm0,PlotStyle-> {PointSize[0.03],Red}, PlotRange->{{0,Length[fharm0]+1},All}
,Frame->True, GridLines->Automatic
,FrameLabel-> (Style[#,24,Black,FontFamily->"Calibri"] & /@ {"harmonic order","frequency (Hz)"})
,LabelStyle->{16,Black,FontFamily->"Arial"}
,PlotLegends->Style["data",Red,18,Bold,FontFamily->"Arial"]]
,Plot[ffit0[x],{x,0,Length[fharmonic]},PlotStyle->{Thickness[0.005],Blue}
,PlotLegends->Style["linear fit",Blue,18,Bold,FontFamily->"Arial"]]
,ImageSize-> 450]

Let’s look at the Fourier components:

Here are the Fourier component (Subscript[X, m]):

Xfourier={0.00105554` -0.0024075` I,-0.00050213`+0.00312062` I,0.00019292000000000002` -0.00033453` I,0.00038492` +0.00016834` I,-0.00167107`+0.00166658` I,-0.00036519`+0.00009031000000000001` I,-0.00007283`+0.000049330000000000004` I,-0.00008946`+9.14`*^-6 I,0.00001506` +0.00006433` I};
Length[Xfourier]

Now, we just apply the formula:
                                       x[t]    ~        (∑_(m=-p)^p)(Subscript[X, m]) (e^(i m 2 π f t))     (1.1.1)

One more thing: we don’t have to sum from -p to p like the equation says. Because the signal is real, we can just add the positive p components and take the Real part.

So, this is the synthesize signal:

p=9;
xsynth[t_]:= 2Re[Sum[Xfourier[[m]] (E^(I  m 2 π  f0 t)),{m,1,p}]] ;

Let’s plot our synthesized signal (yellow) to compare with the original (green):

Pretty close, given that we use a mere 13 components out of 515. This what they sound like:

2. Fourier’s theorem

Is it true that any periodic function can be expressed as a sum of harmonics with frequencies that are integral multiples of the fundamental frequency? Yes, that is exactly what Fourier’s theorem says,...

which means that we can represent a periodic function as
                                              x[t]=(∑_(m=-∞)^∞)(Subscript[X, m]) (e^(i m 2 π (Subscript[f, 0]) t)) = (∑_(m=-∞)^∞)(Subscript[X, m]) (e^(i m (Subscript[ω, 0]) t))  ; (Subscript[f, 0])=(1/T)
where T is the period, and the Fourier coefficient is obtained as
                                                (Subscript[X, m])=(1/T)(∫_0^T)x[t](e^(-i m (Subscript[ω, 0]) t)) dt

It is quite easy to construct a periodic function. All we have to do is to define it over one period, and repeat it. In programming language,we use modulo function so that the variable repeating itself after each period.

Consider an example

2.1 Plot the function

Consider this simple function:
         x[t]= UnitBox[(t/σ)](1-2Abs[(t/σ)])   for t ∈[-0.5,0.5]
which can also be written as:
         x[t]=If[t≤-(σ/2),0, If[t≤ 0, ((2t+σ)/σ),If[t<(σ/2),((σ-2t)/σ),0]]]

Manipulate[u=.;
Column[{
Plot[If[t≤-0.5σ,0, If[t≤ 0, ((2t+σ)/σ),If[t<0.5σ,((σ-2t)/σ),0]]],{t,-2.5,2.5}, PlotRange-> All
,PlotStyle->{Thickness[0.005],Hue[0.35,1,1]}
,Filling-> {1->{0,Hue[0.3,0.5,1]}}
,Ticks->{Automatic,None}
,LabelStyle->{14, White, FontFamily->"Calibri"}
,Background->Black, ImageSize->600, AspectRatio->0.125]
,Plot[UnitBox[(u/σ)](1-2Abs[(u/σ)]) /. u-> Mod[t+0.5,1]-0.5,{t,-2.5,2.5}, PlotRange-> All
,PlotStyle->{Thickness[0.005],Hue[0.35,1,1]}
,Filling-> {1->{0,Hue[0.3,0.5,1]}}
,Ticks->{Automatic,None}
,Background->Black, ImageSize->600, AspectRatio->0.125
,LabelStyle->{14, White, FontFamily->"Calibri"}]}]
,{σ,0.5,1}]

2.2 Obtain Fourier coefficients

Let’s apply Fourier’s theorem to it. The Fourier’s theorem says first, we should obtain the coefficient:
                       (Subscript[X, m])=(1/T)(∫_0^T)x[t](e^(-i m (Subscript[ω, 0]) t)) dt = (1/T)(∫_0^T)x[t](e^(-i m 2 π t/T)) dt

σ1=.; T1=1; m=.;
xtriangle[t_,σ_]:= If[t≤-(σ/2),0, If[t≤ 0, ((2t+σ)/σ),If[t<(σ/2),((σ-2t)/σ),0]]];
(∫_(- T1/2)^( T1/2))xtriangle[t](E^(-I m  2 π t/T1))\[DifferentialD]t

Hence, the Fourier coefficient is:  -(((e^(-i m π σ1)) (((-1+(e^(i m π σ1))))^2))/(2 (m^2) (π^2) σ1))

But we can simplify it a bit:

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

FullSimplify[-((-2+2 Cos[m π σ1])/(2 (m^2) (π^2) σ1))]

((Simplify[1-((Cos[((m π σ1)/2)])^2)]+((Sin[((m π σ1)/2)])^2) )/((m^2) (π^2) σ1))

Hence, the Fourier coefficient is:

Xfc[m_,σ1_]:=((2 ((Sin[((m π σ1)/2)])^2))/((m^2) (π^2) σ1))

2.3 Apply the Fourier’s theorem numerically

Code

Manipulate[
If[TrueQ[RUNfourierTRIANGLE== ]
,Grid[{{
Manipulate[
σ1=σ;
Plot[UnitBox[(u/σ)](1-2Abs[(u/σ)]) /. u-> Mod[t+0.5,1]-0.5,{t,-1.,1.}, PlotRange-> All
,PlotStyle->{Thickness[0.005],Hue[0.35,1,1]}
,Filling-> {1->{0,Hue[0.3,0.5,1]}}
,Ticks->{Automatic,None}
,Background->Black, ImageSize->300, AspectRatio->0.25
,LabelStyle->{14, White, FontFamily->"Calibri"}]
,{{σ,0.5,"triangle width"},0.2,1}]
,Manipulate[
k=Min[Max[k0,0],32];
Column[{ListLinePlot[Transpose[{tarr1,fouriersum[{k,σ1},tarr1]}]
, PlotRange-> All
,PlotStyle->{Thickness[0.005],Hue[0.35,1,1]}
,Filling-> {1->{0,Hue[0.3,0.5,1]}}
,Ticks->{Automatic,None},LabelStyle->{14, White, FontFamily->"Calibri"}
,Background->Black, ImageSize->300, AspectRatio->0.25
,Epilog->Inset[Style["# fourier comp =
"<>ToString[k],12,White,FontFamily->"Arial"],ImageScaled[{0.3,0.8}]]
]
,Show[Table[fcomp[{j,σ1},tarr1,0.006],{j,0,k}]
,PlotRange-> {All,{yminpl,ymaxpl}}
,Background->Black,ImageSize-> 300
,AspectRatio->1.5]

}]
,{{k0,0,"# Fourier components"},0,32,1}]
}},Alignment-> Top]

,Button[,RUNfourierTRIANGLE= ]]
,{{RUNfourierTRIANGLE,,},{,},ControlType->Toggler}
,Initialization:>{
tarr1=Range[-160,160]/160.;
Xfc[m_,σ1_]:=If[m==0,0.5 σ1,((2 ((Sin[((m π σ1)/2)])^2))/((((m π))^2)  σ1))] ;
Δys=0.05;
yminpl=-Sum[Abs[2 Xfc[j,σ1]],{j,32}]-31*Δys;
ymaxpl=2 Xfc[0,σ1]+Δys;
fcomp[{k_,σ1_},ts_,thckn_]:=Block[{ys}
,ys=Δys*k+If[k==0,0.
,Sum[Abs[2 Xfc[j,σ1]],{j,k-1}]+Abs[ Xfc[k,σ1]]-Abs[ Xfc[0,σ1]]];
Graphics[{Thickness[thckn],Hue[(k/33.),0.8,1,1]
,Line[Table[{t,2Re[Xfc[k,σ1] (E^(I k 2 π t/1))]-ys},{t,ts}]]}]
];
fouriersum[{k_,σ1_},ts_]:=(Total /@ Table[2Re[Xfc[j,σ1] (E^(I j 2 π t/1))],{t,ts},{j,k}])+Xfc[0,σ1];

}]

3. Fourier signal synthesis

Can we use Fourier’s theorem to synthesize a signal? Certainly!

3.1 Example 1: signal synthesis concept

3.2 Example 2

4. Basic concept of Fourier analysis for a LTI system

A periodic signal can be decomposed into a sum of its Fourier components

With known system response, we know the output of each component. Remember this?

All we have to do is to add them up! See illustration below

4.1 Illustration of passive RC with Bode plots

4.2 Illustration of passive RC with Fourier analysis

To be continued to Fourier integral transform