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

5 visualizaciones (últimos 30 días)
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 comentario
Walter Roberson
Walter Roberson el 15 de Sept. de 2017
wkeep is going to have overhead, so it would be more efficient to write the code more directly without using wkeep.

Iniciar sesión para comentar.

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by