I have the following code in MATLAB
[Mx,Nx] = size(x);
[My,Ny] = size(y);
padded_x = zeros(Mx+2*(My-1),Nx+2*(Ny-1));
padded_x(My:Mx+My-1,Ny:Ny+Nx-1) = x;
y = rot90(y,2);
z = zeros(Mx+My-1,Nx+Ny-1);
for i=1:Mx+My-1
for j=1:Nx+Ny-1
z(i,j) = sum(sum(padded_x(i:i+My-1,j:j+Ny-1).*y));
end
end
that is part of a 2D convolution implementation. Is there any way that this can become faster? e.g. vectorizing these 2 for loops? I know that there are faster algorithms that compute 2D convolution, but I want to speed this one up. So, I am not looking for an algorithm with different complexity, just something with lower complexity constant. I would also like to keep this in MATLAB and not to use MEX - files etc. Finally, the supplied conv2 function is also not the solution I am looking for.