# Two type of calculating R in steepest-descent modeling algorithm

I have wrote this algorithm for steepest descent:

function [e2,w_opt]=SteepestDescent_Alg2(x,d,itr,w)
N=length(w);
sample=length(x);

x1=zeros(sample,N);
for i=1:N
x1(:,i)=x(N-(i-1):end-(i-1));
end

R=x1'*x1/sample;
P=x1'*d/sample;
lambda=eig(R);
mu=1/(min(lambda)+max(lambda));

w_opt=zeros(size(w));
dd=(d.'*d)/(sample);
e2=zeros(1,itr);
for i=1:itr
e2(i)=dd+w_opt'*R*w_opt-2*P'*w_opt;

end
wc=R\P
end


These lines forming R:

x1=zeros(sample,N);
for i=1:N
x1(:,i)=x(N-(i-1):end-(i-1));
end
R=x1'*x1/sample;


But if we use other way to calculating R:

function R=corlnm2(h,N)
%This function obtains the correlation matrix of the output
%of an FIR filter which is derived by a white noise, and its
%coefficients are given in vector "h".
%"N" specifies the dimensions of "R".
%
%   R=corlnm2(h,N)
%j=sqrt(-1);
a=size(h);
if a(1)>a(2)
h=h';
end
m=length(h);

for k=1:N
if k<=m
R(k)=h(k:m)*h(1:m-k+1)';
else
R(k)=0;
end
end
R=toeplitz(R);
end


The code have written for this problem, also assume there is coloring filter with tap numerator coefficient of h:

Both two way of estimating R, getting value, really close together, but the second way gives weird learning curve. Also the input noise set to 0.1 variance, thus minimum kesi(Mean Square Error) must be 0.1, calculating R in first manner give correct learning cure(plot of MSE vs itteration) but the W's are extremely close to Wo even with more than 0.001 precision, why? And I think both way must give same answer why but this isn't ...?

• I just hate inlined URLs. I prefer to see images if they add to the text. If they don't add to the text, don't refer to them.
– Peter K.
Jun 30 '17 at 12:10
• You will find that you will get more answers with honey than with bile. Please don't be rude on this site, or any StackExchange site. Be nice
– Peter K.
Jun 30 '17 at 12:33
• @PeterK. Is this post not clear? that you've gaved it down vote. Jun 30 '17 at 13:11
• @PeterK. Still not cleared? :( Jul 7 '17 at 7:37

So let's have a look at your calculations:

x1(:,i)=x(N-(i-1):end-(i-1));


Let's say N = 10 and sample = 100 so that end = 110.

For i=1 that means we sum from 10 to 110.

For i=2 that means we sum from 9 to 109.

etc.

Comparing that with:

R(k)=h(k:m)*h(1:m-k+1)';


where m is the same as sample:

For k=1 that means we sum from 1 to 100.

For k=2 that means we sum from 2 to 99.

I think all that's happening is your first calculation is assuming x is zero-padded and the second one is assuming that it's not.

That there are differences between the two is hardly surprising, given that they are summing different (possibly random) values.

• h Isn't sample. that is number of tap of colorizer filter, wich is colorize x(n)!? It force x(n), to not being white. I apologize since it's not mentioned ... Jul 9 '17 at 17:10