MATLAB: Can’t I generate code for resample in MATLAB Coder

matlab coderresampleupfirdn

I have a MATLAB function that uses the "resample" function that I would like to generate code for using MATLAB Coder, but when I try to generate code, I get the following error:
??? upfirdn requires the DSP System Toolbox.Make sure that it is installed and that a license is available.
Error in ==>resamp_func Line: 7 Column: 9
Code generation failed
Why can't I generate code for "resample" in MATLAB Coder?

Best Answer

The "resample" function from Signal Processing Toolbox uses "upfirdn" under the hood, which requires DSP System Toolbox for code generation, as mentioned in this link. Thus, DSP System Toolbox is required for code generation for the "resample" function.
When 'resample' is called inside a MATLAB script, a 'signal_toolbox' license is checked out (Signal Processing Toolbox). If code is generated from the resample function, MATLAB also checks out the 'signal_blocks' license (DSP Systems Toolbox).
It should also be noted that resample does not accept variable length inputs and that the up/down sample rates (2nd/3rd argument), must be constant values or marked as coder.const if they are variables (they must not change during runtime). For situations where variable-length inputs are required, a workaround is to pre-allocate a temporary vector greater than or equal to the max vector size used during runtime, and then replace the first n elements with the actual signal, then post-process the output to reclaim the variable-size output signal.
If your code requires different up/down sample rates, you can use separate calls to 'resample' inside a switch-case block.