2
$\begingroup$

Consider this data. I would like to plot it via it Fourier discrete sine transform. However, I am getting a slight offset, as seen here

pdat = ListPlot[data];
ur = FourierDST[data];
n = Length[ur];
pdatFour = Plot[Sqrt[2/(n + 1)] Sum[ur[[r]] Sin[Pi/(n + 1) r s], {r, 1, n}], {s, 0, n}];

Show[pdat, pdatFour]

enter image description here

Any idea why?

$\endgroup$
3
  • $\begingroup$ The reason is math, not Mathematica.: see Gibbs phenomenon for explanation. $\endgroup$
    – user64494
    Commented Mar 13, 2023 at 18:25
  • $\begingroup$ I think some multiplier is omitted, when editing. It is not a good practice to edit the question, but not to indicate changes. It is not a good pratice not to present your data. $\endgroup$
    – user64494
    Commented Mar 13, 2023 at 18:40
  • $\begingroup$ @user64494 The data is presented. The edits are trivial, and they do not change the question. In case you are wondering, you can track the editing by clicking "edited (...)". Hope this helps! $\endgroup$
    – sam wolfe
    Commented Mar 13, 2023 at 19:46

1 Answer 1

4
$\begingroup$

You are scaling the output of the DST incorrectly. You can fix the offset by using Plot[Sqrt[4/(n + 1)] Sum[ur[[r]] Sin[Pi/(n + 1) r s], {r, 1, n}], {s, 0, n}, PlotRange -> All]; ( i.e., replace Sqrt[2/(n+1)] with Sqrt[4/(n+1)] ). A more elegant solution is to pay attention to the four kinds of DST shown in the Details section of the help file. You seem to be using type 1. Hence use:

ur = FourierDST[data,1];

and your plots align.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.