代码之家  ›  专栏  ›  技术社区  ›  John

数学中插值函数的卷积运算

  •  3
  • John  · 技术社区  · 16 年前

    我用的是数学7。

    pressures = 
      WeatherData["Chicago", "Pressure", {2010, 8}] // 
         DeleteCases[#, {_, _Missing}] & // 
        Map[{AbsoluteTime[#[[1]]], #[[2]]} &, #] & // Interpolation;
    

    我想计算它的导数,这是直接的:

    dpressures = D[pressures[x], x]
    

    现在,如果你画出这个函数

    Plot[3600*dpressures, {x, AbsoluteTime[{2010, 8, 2}], AbsoluteTime[{2010, 8, 30}]}]
    

    (抱歉,我不知道如何在Mathematica中发布图像,也没有时间去弄清楚。)你会发现 非常 吵闹。所以,我想把它摆平。我的第一个想法是使用卷积,并将其与高斯核进行积分,如下所示:

    a = Convolve[PDF[NormalDistribution[0, 5], x], 3600*dpressures, x, y]
    

    退换商品

    360 Sqrt[2/\[Pi]] Convolve[E^(-(x^2/50)), InterpolatingFunction[{{3.48961266 10^9, 3.49228746 10^9}},<>], ][x], x, y]
    

    a /. y -> AbsoluteTime[{2010, 8, 2}]
    

    退换商品

    360 Sqrt[2/\[Pi]] Convolve[E^(-(x^2/50)), InterpolatingFunction[{{3.48961266 10^9, 3.49228746 10^9}},<>][x], x, 3489696000]]
    

    这不是我想要的,我期待的是-1到1之间的数字。

    1 回复  |  直到 16 年前
        1
  •  5
  •   Andrew Moylan    16 年前

    卷积求卷积的封闭形式。你可以尝试一个数值卷积,从下面的开始

    NConvolve[f_, g_, x_, y_?NumericQ] := 
     NIntegrate[f (g /. x -> y - x), {x, -Infinity, Infinity}]
    

    然而,对于这种有噪声的非光滑函数,数值积分将很困难。(在默认设置下不起作用,即使在精心选择的设置下也会很慢。)

    时间范围的界限:

    In[89]:= {lower = Min[First[pressures]], upper = Max[First[pressures]]}    
    Out[89]= {3.48961*10^9, 3.49229*10^9}
    

    data = Table[pressures[x], {x, lower, upper, 3600}];
    

    ListLinePlot[Differences[data]]
    

    在5小时窗口内使用平滑版本:

    ListLinePlot[GaussianFilter[Differences[data], 5]]
    
    • 对于有噪声的数据,可能需要使用InterpolationOrder->1。