performance - Kolmogorov – 滤波器 Matlab

标签 performance matlab filter

你好

我需要在应用中使用这个 Kolmogorov 过滤器。您将一些测量数据放入其中,并使用过滤器对其进行一些平滑处理。 我试着用“nchoosek”来做,但是当我尝试为 50 或更多的 I 做这件事时,它花费的时间太长了。

enter image description here

有人知道如何更快地做到这一点吗?

function [ filterd ] = kolmo(data, inter)
temp  = 0;
temp1 = 0;
filterd(1:10, 1) = NaN;

for t=inter+1:(length(data)-inter)
   for o=-inter:inter
    temp = temp + (nchoosek(2*inter, (inter+o))*data(t+o));

    temp1 = temp1 + nchoosek(2*inter, (inter+o));
   end

 filterd(t, 1) = temp/temp1;
 temp  = 0;
 temp1 = 0;
end

end

谢谢 安迪

最佳答案

这是一个无循环的解决方案:

function y = MySoln(x, K)

%# Get the binomial coefficient terms
FacAll = factorial(0:1:2*K)';
BinCoefAll = FacAll(end) ./ (FacAll .* flipud(FacAll));

%# Get all numerator terms
NumerAll = conv(x, BinCoefAll, 'valid');

%# Rescale numerator terms into output
y = (1 / sum(BinCoefAll)) * NumerAll;

我避免使用 nchoosek 而是使用阶乘手动计算二项式系数。这确保每个阶乘计算只执行一次。相比之下,OP 的解决方案可能对每个阶乘计算执行数百次。

一旦计算出二项式系数,就会直接应用 conv 的解决方案,然后按分母项缩放。

我在 OP 解决方案和我的解决方案之间进行了快速速度测试。速度测试使用具有 50 个元素的随机向量 x,并将 K 设置为 5。然后我对我的解决方案与 OP 进行 100 迭代解决方案。以下是结果:

Elapsed time is 2.637597 seconds. %# OP Solution
Elapsed time is 0.010401 seconds. %# My Solution

我对此非常满意。我怀疑从这一点可以使该方法更加有效(但很高兴被证明是错误的)。 :-)

关于performance - Kolmogorov – 滤波器 Matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14495684/

相关文章:

python - "Branch Predictions"和高级语言中的马尔可夫链

c# - 没有访问服务器配置的 asp.net mvc 2 的 GZip 或 Deflate 压缩

asp.net-mvc - 使用授权过滤器区分 Controller 操作

php - 在 PHP 中验证 URL 的更好方法

ruby - 如何使用 Ruby 有效地匹配来自 2 个数组的数据

python - 使用 python 读取大型文本文件比使用 Matlab 读取相同文本的相同代码慢得多,知道为什么吗?

在 WAN 上具有许多绑定(bind)变量的 oracle 插入非常慢

matlab - 新的 MATLAB 版本用类方法覆盖了我的函数。我还能调用我的函数吗?

performance - 按字典顺序对名称列表进行排序

.net - 其中一个是否比另一个使用更多的资源?