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

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

wkeep is going to have overhead, so it would be more efficient to write the code more directly without using wkeep.

댓글을 달려면 로그인하십시오.

 채택된 답변

a = randi(100,1,12)
n = 5;
out1 = circshift(a,n)
m = numel(a);
out2 = a(mod((1:m) - n - 1,m) + 1)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2017년 9월 15일

댓글:

2017년 9월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by