Help on Improving performance for MATLAB function

Im trying to make my function run faster and I was wondering if anyone can help me. I'm trying to calculate the following equation :

ImageShack - Image Hosting :: 29384513.jpg

where N and M are inputs. Basically i need to caluclate that sum for all values of m.

This is my current code:

function [e] = new5(M,N)

tic;

k=3;

n=(1:1:N);

d=zeros(1,M-1);

b=zeros(1,M-1);

for m=1:1:M-1;

d=m./M;

b=cos((n.^k)*d);

e(m)=(sum(b)/sqrt(N));

end

hold on

%plot histogram of data

hist(e,100);figure(gcf);

hold off

toc;

Any ideas?