0
\$\begingroup\$

This is about design of a JPEG compression/decompression scheme on an Altera FPGA. It is possible to have camera or SD card for image input and TV or SD card for image output. However, these interfaces introduce their own complexities.

To keep things simple in the early part of the project and to make it easier to thoroughly test the design, it is desired that it be possible to pass data of an image from MATLAB into the FPGA. MATLAB already has a lot of functions to manipulate data, so it is desired to send data to FPGA and read back the result after processing and compare the FPGA result with the result of identical processing done within MATLAB.

Basically data shall be read back from the FPGA from different stages of the JPEG compression and decompression processor to check how each part of the design is working.

So the question, how do I transmit data from MATLAB to the FPGA and read data back? Is there some tutorial on this somewhere?

\$\endgroup\$
  • 1
    \$\begingroup\$ Instrument control toolbox + UART would be the easiest if you don't need much bandwidth. Otherwise, you can write a native driver and call it from MATLAB using the shared library interface. \$\endgroup\$ – Peter Sep 26 '15 at 6:14
4
\$\begingroup\$

I have done something very similar in the past. My aim was to transfer an image (*.bmp) from PC to FPGA (internal BRAM), and send it back to PC after the watermarking process. As previously mentioned, UART is your best bet. Implement a UART in FPGA or use an existing design. For Xilinx, look at this design provided with the Picoblaze.

It is well documented and can be used as standalone in your design. You can also find older versions of this design for older Xilinx FPGAs. I think you can find similar designs for Altera (or vendor independent) easily.

On the MATLAB, you can read and write data to a serial object using these functions. I have had problems with baud rates above the standard 115200 so if you need real-time performance, UART might not be sufficient. Otherwise start with the lowest baud rate and test it for errors and try to achieve maximum.

Though MATLAB will be fast and easy for this application; since it is not free and not everyone might have access to it, another option is to use Python. In my case, I have written a Python script to communicate with the FPGA. It has a nice and simple serial library called pyserial for serial communication. You can use PIL (Python Imaging Library) for image processing and numpy for computation process.

However; if you are only interested in testing the design for functionality, you can just read pixel data from a file to process it in simulation. Output image data to a text file using MATLAB and then read it into a memory array defined in your testbench file. You can simulate your design as if its running on the hardware (assuming the design is synthesizable) and test it. You can output processed data to a file at any stage of the process and read it from MATLAB for comparison. After you make sure the design works perfectly, you can start implementing the communication interface on actual hardware.

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

The quick, dirty and cheap way is to incorporate a UART in the FPGA and use the built-in matlab serial object to transmit and receive pixel data. You can crank up the baud rate to near megaHertz speeds.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

This answer can be considered as a candidate for the Software Recommendations section of SE, but here goes: you could try one of the 3rd-party packages that offer a library of target-specific drag n' drop Simulink blocks to simplify the development. For instance: http://www.mathworks.com/products/connections/product_detail/product_35635.html?s_tid=srchtitle . By inserting your existing Matlab code into Simulink blocks you can then diagrammatically build your communication control scheme around your code, compile and download the code to the FPGA and run it.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.