1
$\begingroup$

I'm using this code which evaluates the FFT of my original signal (which is a time series). Using the Manipulate function of Mathematica it is possible to vary the parameters (m for the magnitude, p for the phase, l for the length of the wave). At this point, I was wondering if there is a way, or more precisely a methodology to optimize the parameters mentioned above, to choose the "best" parameter value to use to calculate the reconstructed signal.

Edit1:My intent here is to reconstruct the signal of the original time series (thus excluding a fit on the time series) and then "fix" the parameters of the FFT (amplitude, phase mainly given a certain number of reconstruction terms, or also including the number of terms as a parameter to optimize.). In this way, "discretionary" parameters would not be chosen to show how the reconstructed signal "varies" as the values ​​assigned to the parameters vary, but rather only "optimized" parameter values ​​would be chosen Thanks so much in advance to anyone who will try to help me. Here is the time series I'm using.

And here is the code I'm writing:

notebookDirectory = NotebookDirectory[];


dataprices =   Import[FileNameJoin[{notebookDirectory,"database daily.xlsx"}], {"Data", 1, All, 5}];
datacfcprices = Import[FileNameJoin[{notebookDirectory, "database daily.xlsx"}], {"Data", 1, All, 8}];
dateread =   Import[FileNameJoin[{notebookDirectory, "database daily.xlsx"}], {"Data", 1, All, 1}];
(*Extract prices & date*)prices = dataprices;
cfc = datacfcprices;
cfc = datacfcprices;
timeseriesprice = Transpose[Join[{date}, {prices}]];
timeseriescfc = Transpose[Join[{date}, {cfc}]];
Manipulate[Module[{}, sig = cfc - Mean[cfc]; (*DC Offset*)  lenSig = Length[sig] + l;(*l,parameter for lenght*)  fftY = Fourier[sig, FourierParameters -> {1, -1}];  mag = (Abs[fftY]/(lenSig + l))*m;(*m,parameter for magnitude*)  phase = Arg[fftY]*p;(*p,parameter for phase*)  ordMag = Ordering[mag, All, GreaterEqual];  rec = Total[
Table[mag[[ordMag[[k]]]] Cos[
   2 Pi (ordMag[[k]] - 1) (n - 1)/lenSig + 
    phase[[ordMag[[k]]]]], {k, 1, numTerms}, {n, 1, 
  lenSig + r}]];  GraphicsRow[{ListPlot[{Tooltip[mag, "not used"], 
  Tooltip[Thread[{ordMag[[1 ;; numTerms]], 
     mag[[ordMag[[1 ;; numTerms]]]]}], "used in reconstruction"]},
  Filling -> Axis, PlotRange -> All, 
 PlotLabel -> "Fourier Transform of Signal", 
 PlotStyle -> {Blue, {Black, PointSize[0.015]}}], 
ListLinePlot[{Tooltip[sig, "signal"], 
  Tooltip[rec, "reconstruction"]}, 
 PlotLabel -> 
  "Sp500 Signal (blue) and Reconstructed Signal (brown)", 
 PlotRange -> All, Filling -> {1 -> {2}}]},   ImageSize -> 1200]], {{numTerms, 10,"Number of terms in reconstruction"}, 1, 50, 1, Appearance -> "Labeled"}, {{m, 1.6, "Magnitude"}, 1, 3, 0.1,  Appearance -> "Labeled"}, {{p, 0.3, "Phase"}, 0, 10, 0.1, Appearance -> "Labeled"}, {{l, 12, "Lengthwave"}, 1, 100, 1,  Appearance -> "Labeled"}, {{r, 100, "Forecast(days)"}, 1, 1000, 1,  Appearance -> "Labeled"}]

Edit2: For a better specification of my problem, I provide what should be the notation of the algebraic form of a parametric DFT. enter image description here

This notation is based on the modeling provided by the following authors in this paper: PONOMAREV A., PONOMAREVA O., SMIRNOVA N. “Fast Parametric Fourier Transform”, IEEE,2022 . It can be consulted Here

$\endgroup$
6
  • 3
    $\begingroup$ This sounds like an ill-posed problem. If you keep the number of terms as a parameter to be optimized, it will obviously try to increase this number very much, because this will generally lead to more accurate predictions. So you either should fix the number of terms, and then optimize only the rest of the parameters (see for example NonlinearModelFit), or come up with some scoring function that gives you a nice balance between good prediction and parsimonious model. $\endgroup$
    – Domen
    Feb 12 at 12:46
  • 2
    $\begingroup$ Also, as I assume you want to get a forecast of your data, people usually use other methods for time series, such as autoregressive models (see this guide as an example). $\endgroup$
    – Domen
    Feb 12 at 12:49
  • $\begingroup$ I am well aware there are other models for making time series forecasts. My intent here is to reconstruct the signal of the original time series (thus excluding a fit on the latter) and then "fix" the parameters of the FFT (amplitude, phase mainly given a certain number of reconstruction terms, or also including the number of terms as a parameter to optimize.). In this way, "discretionary" parameters would not be chosen to show how the reconstructed signal "varies" as the values ​​assigned to the parameters vary, but rather "optimized" parameter values ​​would be chosen, $\endgroup$ Feb 12 at 14:50
  • 1
    $\begingroup$ If you have n real data points, you the series is determined by n parameters (amplitudes and phases) . These are optimized. As I see it, the only leeway have have, is to reduce the number of terms. $\endgroup$ Feb 12 at 15:39
  • 1
    $\begingroup$ I have put some notes on how Fourier works here. This may help. $\endgroup$
    – Hugh
    Feb 13 at 9:00

0

Your Answer

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