# urgent

Started by April 9, 2006
```hi
the meaning of this code
its about computing the autocorrelation function IN MATLAB

r1=[zeros(1,101)];
for i=1:1:50
x=rand(1,5000);
r=zeros(1,101);
fori=1:1:50
z=[x zeros(1,i)];
y=[zeros(1,i) x];
r(51+i)=sum(z.*y)./(5000-i);
end
r(51)=sum(x.*x)./(5000);
z=[ zeros(1,i) x];
y=[x zeros(1,i)];
r(i)=sum(z.*y)./(5000-i);

```
```"dew" <ukap70@gmail.com> wrote in message
> hi
> the meaning of this code
> its about computing the autocorrelation function IN MATLAB
>
> r1=[zeros(1,101)];
set up a column vector r1 of  101 elements all of which are set to 0
> for i=1:1:50
starting at i=1  execute the instructions between here and end then
increment i by 1 : exit for-end loop when i>50 : note that this overwrites
matlab's default value for i=sqrt(-1).
> x=rand(1,5000);
fill a 5000 element column vector x with double precision values between 0
and 1 selected from a uniform distribution - note that this is _inside_ the
loop
> r=zeros(1,101);
see r1 but this is _inside_ the loop so wipes out the last value that you
stored in r
> fori=1:1:50
set up a 50 element row vector fori  so that element n holds value n.
> z=[x zeros(1,i)];
add i zeros on to the end of x and call it z
> y=[zeros(1,i) x];
add i zeros on to the beginning of x and call it y effectively shifting the
non-zero values of y w.r.t. those of z
> r(51+i)=sum(z.*y)./(5000-i);
multiply the shifted and original sequence together , for some reason
normalise by dividing by 5000-i and store the sum in element 51+i of the 101
element vector r
> end
loop back incrementing i by 1 as previously noted or continue to next line
of code if i>50 after the increment
> r(51)=sum(x.*x)./(5000);
put the mean squared value of x in element 51 of r

at this point i is not incrementing any more , the vector fori has not been
used at all, nor has r1  and everything runs very very slowly as x is filled
with a new set of random numbers and  y and z are redimensioned every time
the loop executes. As r is zeroed at the start of each loop it should hold
non-zero values for element 51 and 101.

I could be completely wrong but thats as close as I can get to a description
of what this segment of code should be doing.
Best of luck - Mike

```