Electronic – MATLAB to VHDL conversion

fpgaMATLABvhdlxilinx system generator

How to convert any MATLAB code(.m file) to VHDL(.hdl code). As i have to use my image processing code in a FPGA kit. Any solution?

  • Possible method: Using hdl coder in simulink, converting the original code into
    an embedded matlab code.

  • Areas of concern: Image processing, converting .m to .hdl, EMBEDDED
    MATLAB, how to fetch an image file in EMBEDDED MATLAB code?

Please give any example and explain.

Best Answer

My experience of Matlab to HDL (using AccelDSP which Xilinx then bought) has not been that great. One of my problems has always been that Matlab didn't offer any pleasing way to instantiate a module (entity in VHDL terms, object in OO terms) more than once if it had state inside. You had to pass the old state in as a parameter and the new state would come out as a result. ugh. Now it may be that Matlab's newer OO syntax is supported by HDL coder, but I'm betting not, as all HDL tools seem to limit dramatically what parts of the language you can use.

Simulink is a slightly different matter - if you use the Xilinx System Generator environment, you can use all the power of Matlab in the verification side of things, and the FPGA end is limited to what XSG provides you with blocks for - most of which are very low-level and efficient. I found it was all a bit too low-level though and creating parameterisable IP blocks was a right pain, so I went back to VHDL. I do miss being able to just call imread on any old image file from my testbench though!

Your area of concern regarding "fetching an image file" should ring alarm bells. FPGAs are almost always used for on-line image processing (ie taking an image from a camera in real-time). To do this you will need to understand how the pins of the imager chip (or whatever your real-time data source is) operate, and write code to interface to them.

As someone else said, if you have a big, fast FPGA, are only making a few systems, and are up for the learning curve (there's a lot more to FPGAs than just pressing the compile button... unlike with software), then go for it. Otherwise, you can use your Matlab as a specification to someone skilled-in-the-art.

In fact, I've used Matlab as both spec and source of test-data in the past... develop an algorithm in Matlab (with FPGAs in mind, but not coding in an FPGA-like way). Use this to create test data with golden results (exported as VHDL files). Then create a VHDL model which behaves bit-accurately the same as the Matlab (as checked against the golden reference data). I've found this much more productive (even with only one of me) than using "magic" HDL generators :)