Reply
Avnet Employee (Star Contributor)
Posts: 106
Registered: ‎07-07-2009

How do I implement my MATLAB algorithm in an FPGA?

This question comes up often, so I thought I'd post the Q & A here:

 

Starting with an algorithm in MATLAB, you have a couple of options for implementation in a Xilinx FPGA.

 

1.  Simulink HDL Coder: The MathWorks offers a tool called Simulink HDL Coder which creates synthesizable HDL from Simulink models and Embedded M-code.  This is very useful for quickly evaluating new algorithms in hardware.  However, higher performance is achieved by using the Xilinx DSP tools (option 2 below).


2.  Xilinx System Generator for DSP:  Xilinx offers a highly optimized library of blocks that can be simulated within Simulink and then compiled for FPGA implementation.  This tool is called Xilinx System Generator for DSP.  It would require you to transfer your design into the Simulink enviroment and replace the Simulink simulation-only blocks with System Generator blocks.  This design flow offers higher performance than HDL Coder because each block is pre-optimized IP for Xilinx FPGAs.

 

3.  Manually HDL Coding:  The final option is the most manual.  Based on your MATLAB algorithm, you would start from the beginning and code up your design in VHDL or Verilog (possibly instantiating Xilinx IP), create an HDL testbench and compair the input/output vectors of MATLAB with your HDL simulator.  Engineers have done it this way for decades, but it is a slow and error-prone approach.  Like The MathWorks HDL Coder it does have the advantage of yielding an HDL design that is not dependent upon a specific software tool.

 

4.  Synphony HSL:  Synopsys has a High Level Synthesis tool (HSL) called Synphony HLS that is advertised to take MATLAB code, quantize it and synthesize HDL code.  I haven't yet used this tool so I can't comment on their design flow.  It sounds similar to a tool that Xilinx recently discontinued called AccelDSP, which provided a great way to quickly prototype MATLAB algorithms and target FPGA hardware.  However, it did not usually yield the highest performance design.

 

Options #2 and #3 will be your least expensive path in terms of software tool costs and the best way to achieve the highest possible performance.

 

Newbie
Posts: 1
Registered: ‎06-27-2010

Re: How do I implement my MATLAB algorithm in an FPGA?

Hi,

 

I am currently working on a project which I have to interface with the Xilinx embedded device camera. I am new to Matlab and Xilinx and still learning.

 

I have written my codes in Matlab in .m file (M-code). But I have no idea how to use blocks in Simulink to interface with the camera to make it a reference design. There are 4 pre-loaded reference designs in the board.

 

Other than the 4 methods you mentioned above, is there any way which I can use Matlab commands instead to directly interface Matlab with the board and the camera?

 

 

Device: Xilinx Spartan 3A DSP FPGA VSK

            Matlab R2009A

 

 

Avnet Employee (Star Contributor)
Posts: 106
Registered: ‎07-07-2009

Re: How do I implement my MATLAB algorithm in an FPGA?

At the moment, the 4 methods I outlined earlier are the only feasible tool flows for implementing m-code in an FPGA.

 

One possible alternative you could consider is the use of the "Embedded M-code" System Generator Block, which allows you to import embedded m-code and target an Xilinx FPGA.  You can find more information about that and other blocks in the Xilinx System Generator for DSP User's Guide.

Avnet Employee (Star Contributor)
Posts: 106
Registered: ‎07-07-2009
Newbie
Posts: 1
Registered: ‎01-29-2013

Re: How do I implement my MATLAB algorithm in an FPGA?

Hi,

 

sorry for resurecting this thread, but I had the exact same question and was just wondering if this methods are still the most current or maybe some new way is better?

 

I am currently starting to develop a project where I need to do some sound processing on matlab and need to implement on an FPGA, but I dont have a lot of money, so it must be an entry level one.

 

Thank you

Avnet Employee (Star Contributor)
Posts: 106
Registered: ‎07-07-2009

Re: How do I implement my MATLAB algorithm in an FPGA?

A few things have changes and the story is getting better and better.

 

AccelDSP from Xilinx has been discontinued.  However Xilinx has acquired a High Level Synthesis (HLS) company and has been enhancing the technology to suppor their new Zynq devices.  This tool flow allows you to synthesize HDL from C code, quickly making tradeoffs of clock cycles vs. resource utilization.  You can read more about it here - Vivado HLS

 

MathWorks HDL Coder is giving very good results for programmable logic and Embedded Coder can be used to create applications that run under embedded Linux on the Zynq ARM processor.

 

You may want to consider ZedBoard for your project.  It includes a Xilinx Zynq 7020 device along with an audio codec from Analog Devices.  More info is at ZedBoard.org.  The audio path enables:

  • 24-bit stereo audio CODEC
  • Stereo line in/out
  • Headphone
  • Microphone input

 

Newbie
Posts: 1
Registered: ‎09-22-2015

Re: How do I implement my MATLAB algorithm in an FPGA?

Would it be possible to get an update of the various methods to convert Matlab code to FPGA, DSP, ARM. I have heard the Xilinx System Generator with the Matlab-Simulink approach is good. How does it compare to HDL Coder approach ?

 

thanks

John

Avnet Employee
Avnet Employee
Posts: 4
Registered: ‎03-29-2011

Re: How do I implement my MATLAB algorithm in an FPGA?

I believe  the following video from Mathworks best addresses your questions.  

Using Xilinx System Generator with Simulink and HDL Coder:

http://www.mathworks.com/videos/using-xilinx-system-generator-for-dsp-with-simulink-and-hdl-coder-81...

Highlighted
Avnet Employee (Star Contributor)
Posts: 106
Registered: ‎07-07-2009

Re: How do I implement my MATLAB algorithm in an FPGA?

I would also recommend looking through this tutorial on HW/SW co-design for Zynq:

http://www.mathworks.com/help/hdlcoder/examples/getting-started-with-hardware-software-codesign-work...