conv と convmtx の両方を使用して、2 つのランダムなベクトル a と b の畳み込みを計算します。信号のサンプルはそれぞれ 1000 個です。この 2 つの関数が費やした時間を比較します。計算を 30 回繰り返して平均化することで不規則な変動を排除します。
Nt = 30;
Na = 1000;
Nb = 1000;
tcnv = 0;
tmtx = 0;
for kj = 1:Nt
a = randn(Na,1);
b = randn(Nb,1);
tic
n = conv(a,b);
tcnv = tcnv+toc;
tic
c = convmtx(b,Na);
d = c*a;
tmtx = tmtx+toc;
end
t1col = [tcnv tmtx]/Nt
t1col = 1×2
0.0005 0.0225
t1rat = tcnv\tmtx
t1rat = 42.9167
conv の方がほぼ 2 桁効率的です。
a が 1000 チャネルのマルチチャネル信号である場合について、この実行を繰り返します。事前割り当てを行い、conv のパフォーマンスを最適化します。
Nchan = 1000;
tcnv = 0;
tmtx = 0;
n = zeros(Na+Nb-1,Nchan);
for kj = 1:Nt
a = randn(Na,Nchan);
b = randn(Nb,1);
tic
for k = 1:Nchan
n(:,k) = conv(a(:,k),b);
end
tcnv = tcnv+toc;
tic
c = convmtx(b,Na);
d = c*a;
tmtx = tmtx+toc;
end
tmcol = [tcnv tmtx]/Nt
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.