# How to implement the RLS for matrices

I need to implement the RLS algorithm but it's for matrices instead for vectors, I have made the below code, but still something wrong is not working well,

EDIT:

The code should be done as below,

But how can we process the line of g(:,n)=P*colo*((lamda + colo'*P*colo).^-1); This notation is valid if H is a vector, and y(n) is scalar, but now we have H is matrix and y(n) is a vector.

    clear all; clc;
N = 1000;                    %% Number of samples
H = randn(64,31);           %% The input matrix
c1 = randn(31,1);           %% The outpu desired vector;
p = length(H);
g1 = zeros(p,1);            %% initial RLS weight;
lamda=1;
sigma=1;
P=(sigma^-1)*eye(p);

for n = 1 : N
y(:,n) = H'*g1;
alpha(:,n) = c1(:,n) - y(:,n);                     % Instantaneous error of RLS
g(:,n)=P*colo*((lamda + H'*P*H).^-1);   % Gain vector
P=(lamda^-1)*P - g(:,n)*H'*(lamda^-1)*P;    % RLS intermediate term
g1 = g1 + alpha(n)*g(:,n);              % Weight update rule of RLS
end


As you know the normal RLS algorithm is working when the input data, which is H in my above code, is vector. so it will update the loop for as below:

for n = 1 : N
y(n) = H'*g1;
alpha(n) = c1(n) - y(n);                     % Instantaneous error of RLS
g(:,n)=P*colo*((lamda + H'*P*H).^-1);   % Gain vector
P=(lamda^-1)*P - g(:,n)*H'*(lamda^-1)*P;    % RLS intermediate term
g1 = g1 + alpha(n)*g(:,n);              % Weight update rule of RLS
end


That will work normal since y(n) and alpha will be scalars in that cases. but for my case, that will be vectors. I think, maybe we can convert the matrix H into a vector and then when finish the loop we convert it back to matrix ? but I'm not sure and I don't know how to do it, it's just an opinion.

Your help is highly appreciated. I really need to understand that point.

Thank you

• It looks like something is wrong with matrix zz because v is 64x64 and z is 32x64 so inner dimensions dont match... what do you mean something unexpected is happening? – Samuel Nov 2 '18 at 6:30
• I tried putting this as a comment but I can't find the comment button for the user – Samuel Nov 2 '18 at 6:31
• Thank you so much for your comment, something abnormal sometimes it gives me error that dimension matrices multiplication in y is not possible?? However it should be ok !! Is there another method we can do the complex RLS for matrices ?? – Fatima_Ali Nov 2 '18 at 7:34
• Can you just apply the vector RLS algorithm column-wise on the matrix? If not, can you give some more details about where the matrix shows up? What's the background application? – Peter K. Nov 2 '18 at 15:53
• Hello, The normal algorithm is using the input data as vector, H , when performing the step: for n = 1 : N y(n) = H'*g1; , y(n) will be scalar instead of vector in my case. and so on. I will now add these details in the question itself – Fatima_Ali Nov 2 '18 at 16:03