Azzera filtri
Azzera filtri

Could not determine the size of this expression

4 visualizzazioni (ultimi 30 giorni)
wang
wang il 13 Apr 2023
Commentato: Walter Roberson il 10 Mag 2023
I want to convert the LMS filter algorithm to Verilog, but need to solve the problem of variable matrix. The point is, why does MATLAB think this piece of code is mutable? How can I solve this problem?
Verilog does not Support mutable matrices, so I uncheck Support variable_size arrays.
function [yn,W,en]=LMS(xn,dn,M,mu)
itr = length(xn);
en = zeros(itr,1);
W = zeros(20,100);
for k = M:itr
x = xn(k:-1:k-M+1);
y = W(:,k-1).' * x;
en(k) = dn(k) - y ;
W(:,k) = W(:,k-1) + 2*mu*en(k)*x;
end
yn = inf * ones(size(xn));
for k = M:length(xn)
x = xn(k:-1:k-M+1);
yn(k) = W(:,end).'* x;
end
could not determine the size of this expression. Function 'LMS/MATLAB Function' (#90.543.553), line 19, column 12: "k:-1:k-M+1" Launch diagnostic report.
  4 Commenti
Fangjun Jiang
Fangjun Jiang il 10 Mag 2023
Modificato: Fangjun Jiang il 10 Mag 2023
This is a MATLAB Function block in Simulink. M is an input to the MATLAB Function block. At each simulation step, M could change, thus the size of x could change.
Does M change value during the simulation?
Walter Roberson
Walter Roberson il 10 Mag 2023
Odd... I only count 17 lines of code, but the error is on line 19. (I was trying to determine if the error was on the first assignment to x or the second assignment.)
If the error was on the second assignment, then maybe it might go away if you use a different variable instead of x in the second loop, so that it does not see the second loop as a redefinition of x.
It looks to me as if the two loops could be merged. The first loop is M:itr but iter = length(xn), so when the second loop is M:length(xn) that is really the same upper bound -- it is confusing that itr was not used there as well.

Accedi per commentare.

Risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by