Matlab函数的卷积

问题描述 投票:0回答:1

我想在 Matlab 中计算卷积,我在脚本文件中声明函数。 MWE 是

a = 0.9; b = 0.5;

X = @(t) exp(-(b*t).^2);
Y = @(t) exp(-a*b*t.^2);

Z = convnfft(X,Y,'same'); % this is how you usually do convolution when t=linspace(-20,20,1000)

my_integral = integral(Z,-Inf,Inf)

我正在使用来自 MathWorks 网站的 this 卷积例程。

有没有高效的Matlab卷积例程/程序可以对

X
Y
函数进行卷积?如果我使用符号数学显式计算卷积积分,那么这些 MWE
X
Y
需要很长时间,并且计算我的实际函数将需要更长的时间。

我的目标是将

-Inf
的卷积结果整合到
Inf

matlab convolution symbolic-integration
1个回答
1
投票

也许你可以尝试下面的代码

a = 0.9; b = 0.5;

X = @(t) exp(-(b*t).^2);
Y = @(t) exp(-a*b*t.^2);

% convolution is formulated as `integral(@(u) X(z-u).*Y(u),-Inf,Inf)` at any given value `z`, and we can vectorize the convolution by `arrayfun`
fconv = @(t) arrayfun(@(z) integral(@(u) X(z-u).*Y(u),-Inf,Inf), t);

你可以像下面这样调用函数

fconv

>> fconv(1:5)
ans =

   1.803967   1.113875   0.498712   0.161908   0.038115
© www.soinside.com 2019 - 2024. All rights reserved.