How to resolve unsupported functions in MATLAB HDL Coder?

9 views (last 30 days)
Hello,
We have some simulation code written in MATLAB that we are trying to simulate and deploy on an FPGA, and so we are trying to use the HDL Coder tool for this task. However, we are receiving code generation issues indicating that the following functions are not supported:
  • diff
  • fft
  • exp
  • angle
  • ifft
  • filter
Is there perhaps a toolkit or package that replicates these functions with support for HDL coding? I tried referencing the list of supported functions found here:
But the links for supported functions don't seem to be working (at least for me).
Otherwise, is there a recommended way of resolving this?
Thank you,
James
P.S. I have successfully used the MATLAB Coder to generate C code for this project, if this helps.
  2 Comments
Walter Roberson
Walter Roberson on 30 Jan 2025
fft is handled by dsphdl.FFT
angle is handled by cordicangle
ifft is handled by dsphdl.IFFT
filter() itself is not handled, but there are a variety of filters handled, such as dsphdl.BiquadFilter and dsp.HighpassFilter and dsp.FIRFilter
James
James on 31 Jan 2025
Hello Walter,
Thank you for the response! For the filter() function specifically, this dependence comes from a custom implementation of MATLAB's smooth() function, which we had to write as smooth() is not supported for C or HDL code generation. I'm not sure which of the supported filters would be most appropriate to replace this function, but I can try to dig into this a bit more.
Best,
James

Sign in to comment.

Answers (1)

Kiran Kintali
Kiran Kintali on 30 Jan 2025
Edited: Kiran Kintali on 31 Jan 2025
Happy to assist you with your MATLAB to HDL workflow. Attached is a sample zip file with the code for the attached functions (using R2025a pre-release)
Many customers use HDL Coder to create custom MATLAB algorithms to generate HDL IP. To tailor our assistance to your application needs, could you provide me some details on the following?
  1. Development Approach: Are you planning to develop your MATLAB code in floating-point and utilize HDL Coder's integrated float2fixed workflow for fixed-point conversion before generating HDL? If so, what are your typical wordlength and fractionlength requirements?
  2. Floating-Point Hardware: Do you need to generate floating-point hardware directly from your MATLAB code for any functions within the HDL Coder workflow?
  3. Target Platform: Are you working with FPGA/SoC or ASIC? If it's FPGA/SoC, what is your target platform? For ASIC development, note that HDL Coder supports an HLS (SystemC) workflow compatible with the StratusHLS tool integrated into the Cadence Genus environment.
  4. Performance Requirements: What are your frequency and area requirements? MATLAB to HDL supports VHDL, Verilog, and SystemVerilog, as well as SystemC and Synthesizable C++ for HLS workflows.
Thanks
  3 Comments
Kiran Kintali
Kiran Kintali on 31 Jan 2025
MathWorks provides a comprehensive suite of predefined IP modules for various functions:
Unsupported Functions
  • Filter: The filter() function is not yet supported. Consider alternatives like dsphdl.BiquadFilter and dsp.FIRFilter.
  • Differences and Approximate Derivatives: The diff() function is not supported; you may need to create a custom function.
Custom MATLAB Code
You can also implement all the above functions as custom MATLAB code. Refer to the mathfcns.m example in this folder, which defines these operators from first principles.
Project Configuration
The attached .prj file is configured for Verilog. If you set up Vivado in your path, you can perform synthesis and P&R steps directly within the viewer. A test bench is automatically generated based on the testbench. You can also write runme.m files and run the entire workflow (float2fixed + hdlcodegen + testbench + synthesis steps) from command line. See command line workflow
Mixed Code Support
You can mix floating-point and fixed-point code. By enabling the integrated fixed-point conversion step in HDL Coder, you can convert floating-point code to fixed-point. If the code is already in fixed-point, you can instruct the float2fixed step to skip certain functions. Additionally, the MATLAB to HDL product includes automatic function replacement and lookup table generation features.
Additional Steps
  • Try the code generation and synthesis steps.
  • For further assistance, do not hesitate to reach out to MathWorks support.
Useful Resources
Examples and Demos
Several FFT-based examples are located in the design patterns folder (<matlabroot>/toolbox\hdlcoder\hdldesignpatterns\matlabhdl).
Use the following command to see fft based examples:
>> mlhdlc_demo_setup('fft')
To see the complete list of available sample code, try:
>> mlhdlc_demo_setup('list')
James
James on 3 Feb 2025
Hello Kiran,
Thank you for this very detailed information! I will take a look at these resources and the provided example project and let you know if we need any further assistance.
Best,
James

Sign in to comment.

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!