5

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.

Saurav
  • 51
  • 1
  • 3
  • 2
    This sounds like a question you should ask the Matlab folks. Surely their marketing department can show you how easy this is. – Joe Hass Sep 09 '13 at 11:13
  • 6
    The Simulink code generator can work for a one-off research project, assuming your FPGA is big enough and fast enough -- the generated code isn't very resource-efficient. For a production design, you'd be better off hiring a consultant who has experience with this sort of design. (*cough*, *cough* :-) – Dave Tweed Sep 09 '13 at 12:04

2 Answers2

8

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 :)

Martin Thompson
  • 8,439
  • 1
  • 23
  • 44
  • 1
    I totally agree -- developing a MATLAB reference design and a VHDL/Verilog implementation *in parallel* is the way most people I know approach this sort of problem. – Dave Tweed Sep 09 '13 at 14:00
  • The problem with simulinks HDL coder is it has snippits of code for each block so you end up with a VERY inefficient design *IF* that code was flashed to an FPGA. WHAT it does excel at though is auto-generation of testbenches to then check certain implementations –  Mar 20 '15 at 14:29
-2

matlab to vhdl code conversion requires that you create a matlab function code and a test file script that test the matlab function, or you can create a simulink model and convert that model to vhdl or verilog.

here is one tutorial- matlab to vhdl conversion

but there are situations where it is not easy to convert matlab code to vhdl, for example if your matlab code contains exponential or log functions, fortunately there are other way around but requires extra learning to do that