MATLAB: How to integrate HDL code from a MATLAB function and an FDATool filter in HDL Coder 3.2 (R2013a)

arrayfieldgateHDL Coderprogrammable

I am trying to use Mathworks products to generate HDL code for my FPGA. I have successfully generated code from a MATLAB function, and also successfully generated code for a filter that I built using FDATool. I would like to combine these two components, such that a signal goes through my function and then goes through my filter (or vice versa). How do I combine these two components in HDL Coder 3.2 (R2013a)?

Best Answer

There are several approaches that can be used to combine HDL code from a MATLAB function and from FDATool, depending on exactly how you would like to proceed. For example, you can try to integrate the function and the filter in MATLAB/Simulink and generate the HDL code as a single unit (this is probably a little easier), or you could try to generate the HDL code from both items separately and then combine them afterward.
1. The most straightforward way would be to bring both systems into Simulink and then generate the HDL code as a single unit. To do this, you can export the filter from FDATool to Simulink via File->Export to Simulink Model, and then click the “Realize Model” button. Then, you can port the MATLAB code into a MATLAB Function block. If you cascade these two blocks in Simulink, attach the necessary inports and outports, and create a subsystem from this, you can generate the HDL code as a single unit (right-click on the subsystem and go to HDL Code->Generate HDL for Subsystem).
2. If you would like to combine the HDL code using Mathworks tools after the HDL has already been generated, there is a “black box” approach, also using Simulink, which is detailed at the following link:
3. One additional way would be to design your filter using a system object and integrate this along with the function in a single M-file, and then generate HDL code from this combined MATLAB code. However, the caveat here is that not all of the current System objects are supported for HDL code generation. The list of supported System objects is available here:
If you start using Simulink, the HDL Workflow Advisor may come in handy. You can open this advisor by using the HDLADVISOR command, or going to Code->HDL Code->HDL Workflow Advisor in your Simulink model.