How can I make a circshift function, without using circshift nor shift matlab functions?

5 vues (au cours des 30 derniers jours)
I'm trying to make a circshift so I can get an efficient convolution program, and I have already obtained this by using the code below, however 'my circshift' is not efficient enough given that I'm trying to get the convolution between a pair of (1x70000) matrices.
I'd like to know if you can give me an idea of how can I improve my circshift. Thanks.
%CODE
%Here we introduce the two discrete signals
a=[1,2,3,4,5,6];
b=[1,2,3];
%We flip the second signal
bc=fliplr(b);
%We are going to make a circular shifting and a dot product, so we
%need nxn matrices. Here we assure matrix A gets as many leading zeros as elements in
%B, and matrix B gets as many leading zeros as elements in A to get a pair
%of nxn matrices.
A = [a,zeros(1,length(b)-1)];
B = ([bc, zeros(1, length(a)-1)]);
convol = [1,zeros(1,length(A)-1)];
%HERE IS MY PROBLEM
%This is 'my circhsift'
for i=1:length(a)-1; i; fb=fliplr(B); f=fb(1);
nb=wkeep(fb,length(B)-1,'r');fnb=fliplr(nb); B=[f,fnb];
end
BB=B;
for i=1:length(A)
A;
i;
fb=fliplr(BB);
f=fb(1);
nb=wkeep(fb,length(B)-1,'r');
fnb=fliplr(nb);
BB=[f,fnb];
convol(i)=dot(A,BB);
end
convol;
  1 commentaire
Walter Roberson
Walter Roberson le 15 Sep 2017
wkeep is going to have overhead, so it would be more efficient to write the code more directly without using wkeep.

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 15 Sep 2017
a = randi(100,1,12)
n = 5;
out1 = circshift(a,n)
m = numel(a);
out2 = a(mod((1:m) - n - 1,m) + 1)

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by