How to indicate input size to dsp.BlockLMSFilter when using MATLAB Coder?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
David Fink
2021-7-15
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:
采纳的回答
Pranav Venuprasad
2021-7-19
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 个评论
Pranav Venuprasad
2021-7-29
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 DSP Algorithm Acceleration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!