How can I implement these for loops efficiently using covolution?
Mostra commenti meno recenti
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 Commento
Torsten
il 1 Ago 2023
If you don't know how to spell the method, you'd better stick to your loop solution.
Risposta accettata
Più risposte (1)
Bruno Luong
il 23 Ago 2023
Modificato: Bruno Luong
il 25 Ago 2023
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 Commenti
MAWE
il 23 Ago 2023
MAWE
il 23 Ago 2023
Bruno Luong
il 23 Ago 2023
Modificato: Bruno Luong
il 25 Ago 2023
Have you tried to do some study of the code or you just ask without study conv?
Categorie
Scopri di più su Dynamic System Models in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
