How to indicate input size to dsp.BlockLMSFilter when using MATLAB Coder?
조회 수: 2 (최근 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에서 Code Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!