在 Mathematica 中使用插值函数进行卷积
我正在使用 Mathematica 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 内部,并且没有时间去弄清楚。)您会发现它非常嘈杂。所以,我想把它弄平。我的第一个想法是使用 Convolve,并将其与高斯核集成,如下所示:
a = Convolve[PDF[NormalDistribution[0, 5], x], 3600*dpressures, x, y]
Returns
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}]
Returns
360 Sqrt[2/\[Pi]] Convolve[E^(-(x^2/50)), InterpolatingFunction[{{3.48961266 10^9, 3.49228746 10^9}},<>][x], x, 3489696000]]
这不是我想要的,我期待一个 -1 到 1 之间的数字。
I'm using Mathematica 7.
I have an interpolated function, here's an example:
pressures =
WeatherData["Chicago", "Pressure", {2010, 8}] //
DeleteCases[#, {_, _Missing}] & //
Map[{AbsoluteTime[#[[1]]], #[[2]]} &, #] & // Interpolation;
I'd like to compute it's derivative, which is straight forward:
dpressures = D[pressures[x], x]
Now, If you plot this funciton
Plot[3600*dpressures, {x, AbsoluteTime[{2010, 8, 2}], AbsoluteTime[{2010, 8, 30}]}]
(sorry, don't know how to post the image from within Mathematica, and don't have time to figure it out.) You'll find that it's very noisy. So, I'd like to smooth it out. My first thought was to use Convolve, and integrate it against a Gaussian kernel, something like the following:
a = Convolve[PDF[NormalDistribution[0, 5], x], 3600*dpressures, x, y]
Returns
360 Sqrt[2/\[Pi]] Convolve[E^(-(x^2/50)), InterpolatingFunction[{{3.48961266 10^9, 3.49228746 10^9}},<>], ][x], x, y]
Which looks reasonable to me. Unfortunately, I believe I have made a mistake somewhere, because the result I get back does not seem to be evaluatable. That is:
a /. y -> AbsoluteTime[{2010, 8, 2}]
Returns
360 Sqrt[2/\[Pi]] Convolve[E^(-(x^2/50)), InterpolatingFunction[{{3.48961266 10^9, 3.49228746 10^9}},<>][x], x, 3489696000]]
Which just ain't what I was looking for I'm expecting a number between -1 and 1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
卷积寻求卷积的闭合形式。您可以尝试数值卷积,从类似的内容开始
。但是,对于这个嘈杂的非平滑函数,数值积分将很困难。 (它无法使用默认设置,并且即使仔细选择设置也会很慢。)
我建议您直接对基础数据进行操作,而不是对噪声数据进行插值。
时间范围的界限:
使用插值每小时获取样本*:
现在
与 5 小时窗口内的平滑版本进行比较:
Convolve seeks a closed form for the convolution. You could try a numerical convolution, starting with something like
However, for this noisy non-smooth function the numerical integration will struggle. (It won't work with default settings, and would be slow even with carefully chosen settings.)
I suggest you operate directly on the underlying data instead of interpolating the noisy data.
The bounds of your time range:
Use your interpolation to get samples every hour*:
Now compare
with smoothed version over 5 hour window: