I am trying a simple example to do a discrete Fourier transform. My goal is to use DFT to find the frequencies that have built the time signal and then to a good approximation, use DFT data to find fourier series. Further, I have plan to use Fourier series to do extrapolation of the original time signal.
This is the code
timeData = Table[Sin[x], {x, 0, 10, 0.1}];
n = Length[timeData];
(*Compute the DFT*)
dftData = Fourier[timeData];
(*Only use the first half of the DFT coefficients*)
halfN = Floor[n/2] + 1;
(*Define the Fourier series function using the relevant frequencies*)
fourierSeries[t_] :=
dftData[[1]]/Sqrt[n] +
1/Sqrt[n] Sum[
2 (Re[dftData[[k + 1]]] Cos[2 Pi k t/n] -
Im[dftData[[k + 1]]] Sin[2 Pi k t/n]), {k, 1, halfN}]
(*Create the discrete data plot*)
discretePlot =
ListPlot[timeData, PlotStyle -> {Red, PointSize[Medium]},
AxesLabel -> {"Sample Index", "Amplitude"}];
(*Create the continuous Fourier series plot*)
continuousPlot =
Plot[fourierSeries[t], {t, 0, 150}, PlotRange -> All,
PlotStyle -> Blue, AxesLabel -> {"Sample Index", "Amplitude"}];
(*Combine the plots*)
Show[continuousPlot, discretePlot,
PlotLabel -> "Time-Domain Signal and Fourier Series",
GridLines -> Automatic]
and this is the plot I am getting
Comments needed.