How to indicate input size to dsp.BlockLMSFilter when using MATLAB Coder?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Joe M
el 13 de Jul. de 2021
Comentada: Pranav Venuprasad
el 29 de Jul. de 2021
I would like to use dsp.BlockLMSFilter in code that will be converted to C code via MATLAB Coder. I understand that Length and BlockSize of dsp.BlockLMSFilter must be entered as literals in the constructor for the object. I have tried to feed the object signals whose lengths are equal to an integer multiple of BlockSize, but I get a warning about variable input size when I run codegen, even if I have "released" the object beforehand. I have the same problem if I feed the signal to the object in successive BlockSize-length blocks.
Is there some way to assure a dsp.BlockLMSFilter object (in code that will be converted to C and compiled) that the size of the incoming signal is acceptable?
Suppose that x and d (in the simplified example below) are guaranteed to have lengths that are multiples of the BlockSize. How do I let the code generator know this? Is there an assert that might help?
function wts = example(x,d,mu) %#codegen
obj = dsp.BlockLMSFilter('Length',10,'BlockSize',10,'StepSizeSource','Input port');
[y,errs,wts] = obj(x,d,mu);
end
2 comentarios
David Fink
el 15 de Jul. de 2021
What specific warning or error are you seeing, and what commands are you using to generate code?
Note - if using the MATLAB Coder App, you can convert this to a code generation script via:
Respuesta aceptada
Pranav Venuprasad
el 19 de Jul. de 2021
The dsp.BlockLMSFilter object does not support variable input sizes as mentioned in the error message. This begavior is not specific to codegen. For example consider the code snippet below:
blms = dsp.BlockLMSFilter(10,5);
filt = dsp.FIRFilter;
filt.Numerator = fir1(10,[.5, .75]);
x = randn(1000,1); % Noise
d = filt(x) + sin(0:.05:49.95)'; % Noise + Signal
[y, err] = blms(x, d);
[y2, err2] = blms([x;x], [d;d]); % double the size of the input
The above snippet produces the following error even though the size of the input in the second step is a multiple of the "BlockSize" property of the dsp.BlockLMSFilter object.
Error using dsp.BlockLMSFilter/parenReference
Changing the size on input 1 is not allowed without first calling the release() method.
In codegen to lock the input frame size, you can provide the size of the input as a constant when compiling. In the example mentioned above, if the desired value of N is say 10, you can generate the C code using the following snippet
N = int32(10);
codegen myexample -args {coder.Constant(N)};
2 comentarios
Pranav Venuprasad
el 29 de Jul. de 2021
The dsp.BlockLMSFilter object maintains the internal state according to the update equations provided in the following documentation page: https://www.mathworks.com/help/dsp/ref/blocklmsfilter.html#f3-1110408 . If you would like to create a custom functionality for Block LMS filtering with variable size inputs, you can use make use of the equations outlined on the above page for the same.
Más respuestas (0)
Ver también
Categorías
Más información sobre DSP Algorithm Acceleration 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!