信号导数近似
用 MovingMap 近似计算来自不规则采样连续时间序列的信号的导数.
In[1]:=
ts = TimeSeries[
Table[{t, EllipticTheta[1, t, 0.3]}, {t,
Join[{0.}, RandomReal[{0, 2 Pi}, 254], {2. Pi}]}]]
Out[1]=
In[2]:=
RegularlySampledQ[ts]
Out[2]=
In[3]:=
ListPlot[ts, PlotTheme -> "Detailed"]
Out[3]=
使用每个滑动窗口边界的值和时间来计算差商.
In[4]:=
quotient[values_, times_] :=
First[Differences[values]/Differences[times]]
In[5]:=
mm = MovingMap[quotient[#BoundaryValues, #BoundaryTimes] &,
ts, {.01, Right}]
Out[5]=
与导数的理论结果比较.
In[6]:=
prime = D[EllipticTheta[1, t, 0.3], t]
Out[6]=
In[7]:=
Show[Plot[prime, {t, 0, 2 \[Pi]}, PlotStyle -> Thick,
PlotTheme -> "Detailed", PlotLegends -> None],
ListPlot[mm, PlotStyle -> Red]]
Out[7]=
使用 MovingMap,同时用 Line 代替上面的商函数来产生一个近似于原时间序列的割线图.
In[8]:=
line[yvals_, xvals_] := Line[Transpose[{xvals, yvals}]];
In[9]:=
lines = MovingMap[ line[#BoundaryValues, #BoundaryTimes] &,
ts, {1.3, Right, {0, 2. \[Pi], .1}}];
In[10]:=
Graphics[{Black, lines["Values"]}]
Out[10]=