How can I implement these for loops efficiently using covolution?
1 回表示 (過去 30 日間)
古いコメントを表示
I have this code
for xx=1:length(x)
for kk=1:length(x)
xSinc(xx) = xSinc(xx)+x(kk)*sinc(xx-kk-delta/T);
end
end
How can implement this efficiently using convultion in MATLAB?
1 件のコメント
Torsten
2023 年 8 月 1 日
If you don't know how to spell the method, you'd better stick to your loop solution.
採用された回答
Dyuman Joshi
2023 年 8 月 1 日
編集済み: Dyuman Joshi
2023 年 8 月 1 日
Simple multiplication would be good enough -
xx = 1:length(x);
kk = 1:length(x);
xSinc(xx) = xSinc(xx) + x(kk)*sinc(xx-kk'-delta/T);
5 件のコメント
Dyuman Joshi
2023 年 8 月 22 日
Please attach your code, so that I can reproduce the error and suggest solutions to tackle the issue.
その他の回答 (1 件)
Bruno Luong
2023 年 8 月 23 日
編集済み: Bruno Luong
2023 年 8 月 25 日
Use conv
x = (0:0.2:5).^2;
L = 3;
delta = rand; T = rand;
% Your method
xSinc = zeros(size(x));
for xx = 1:length(x)
for kk=max(xx-L,1):min(xx+L,length(x))
xSinc(xx) = xSinc(xx)+x(kk)*sinc(xx-kk-delta/T);
end
end
xSinc
% conv method
xSinc2 = conv(x, sinc((L:-1:-L)+delta/T), 'same')
norm(xSinc2-xSinc)
plot(xSinc, 'b')
hold on;
plot(xSinc2, 'r.')
3 件のコメント
Bruno Luong
2023 年 8 月 23 日
編集済み: Bruno Luong
2023 年 8 月 25 日
Have you tried to do some study of the code or you just ask without study conv?
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!