Unable to perform assignment because the left and right sides have a different number of elements.
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to use this LMS algorithm to estimate the impulse response however i'm getting th following error.
"Unable to perform assignment because the left and right sides have a different number of elements.
Error in lms2 (line 10)
y(n) = sum(w.*xN); % Output signal "
The coefficents are as follows:
x is 38500x1 double
N is 200
THIS IS THE CODE BELOW.
function [y,e,J,c,w] = lms2(x,d,N,mu)
M = max(size(x));
y = zeros(1,M);
w = zeros(1,N); % initialise weight vector
for n = N:M
xN = x(n:-1:n-(N-1));
y(n) = {sum(w.*xN)}; % Output signal
e(n) = d(n) - y(n); % Error signal
w = w + mu*e(n)*xN; % filter coeffients update
c(n-N+1,:) = w(1,:); % matrix containing the coefficient vectors
end
J = e.^2; % learning curve
0 comentarios
Respuestas (1)
Deepak Meena
el 27 de Ag. de 2020
Hello Victor,
My understanding is that your problem is with the syntax and your understanding of least mean square algorithm is correct.
Now answering your question y(n) and {sum(w.*xN)} are of different data types
When you try this in command window:
>> y = zeros(1,1000);
>> y(12)
ans =
0
so here y(n) is a scalar integer. But on the other side
>> w = zeros(1,100);
>> xN = x(100:-1:1);
>> ans = w.*xN;
Here w : 1x100
xN: 100x1
Now when you check the dimension of "ans" in workspace you will find it will 100x100 double array .This is because " .*" stands for element wise multiplication .When we multiply a 1x100 array with 100x1 array element wise it produce 100x100 array. To read further about element wise multiplication consider this document.
Similarly, when you do
>> ans = sum(w.*xN);
here "ans" would be 100x1 matrix as it performs row wise operation. Addition to that when we add curly bracket with it create cell array. So on the LHS we have a scaler and on the RHS we have Cell array, that's why that error is coming up.
0 comentarios
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!