- https://www.mathworks.com/help/simulink/slref/discretefirfilter.html
- https://www.mathworks.com/help/dsp/ref/upsample.html
- https://www.mathworks.com/help/dsp/ref/downsample.html
Simulink - Constant as an argument to a MATLAB function block
2 次查看(过去 30 天)
显示 更早的评论
I am attempting to use upfirdn in a MATLAB function block, as in the following example, where x is a signal and h is an input from a constant block:
function y = useupfirdn(x, h)
% ... Initialize output, etc.
% ... Do more stuff...
y = upfirdn(x, h);
When I run the model, I get an error that says "The filter H must be constant." The same happens when it is used as a parameter.
I do not get the error when I build the filter using firls within the function block. However, the point of having it as an argument or a parameter is that I compute the coefficients prior to running the simulation, which would save time since the block is called often.
Is there something that I am missing?
0 个评论
回答(1 个)
Sebastian Castro
2018-11-7
Unfortunately, this is a documented limitation:
https://www.mathworks.com/help/signal/ref/upfirdn.html#d120e192101 (expand the C/C++ Code Generation section)
It seems like most of the FIR filter functionality in DSP System Toolbox has this limitation, so it's not specific to the upfirdn function.
Since you're trying to do this from a MATLAB Function block, I would recommend using the Simulink blocks for upsampling, downsampling, and filtering instead? Specifically, the filters can accept coefficients from an input port:
More generally, there's a whole page showing how to implement these in Simulink:
- Sebastian
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!