I'm trying to analyze the power spectrum of the reflected wave. Specifically, I want to compute the time series, take the Fourier transform, and average the absolute values to obtain the spectrum. The results are to be shown in a logarithmic scale (dB) versus frequency, with the frequency expressed in units of the incident wave frequency (i.e 1.6 in our case). Am I doing it correctly, if not what am I doing wrong? My plot is nowhere close to the original reflected wave and power spectrum that I am aiming for. So, I am just confused.
eqn = {x''[t] + 0.2 x'[t] + Exp[x[t]] - 1 == -4 Sin[1.6 t]};
ics = {x'[0] == 0, x[0] == 0};
sol = NDSolve[{eqn, ics}, x[t], {t, 0, 100}];
timeseries = Table[{t, x[t] /. sol[[1]]}, {t, 0, 100, 0.1}];
reflectedWave =
ListLinePlot[timeseries, GridLines -> Automatic,
PlotStyle -> {Black, Thick}]
fourierData = Fourier[timeseries[[All, 2]]];
n = Length[fourierData];
freq = Table[(i)/(n*0.1*1.6), {i, 0, n - 1}];
powerSpectrum = Abs[fourierData]^2;
powerSpectrumDB = 100 Log10[powerSpectrum];
ListLinePlot[Transpose[{freq, powerSpectrumDB}],
PlotRange -> {{0, 2}, All},
AxesLabel -> {"Frequency", "Power in DB"},
PlotLabel -> "Power Spectrum", PlotStyle -> {Red, Thick},
GridLines -> Automatic]