Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20708 Discussions

Matlab code to verilog

Altera_Forum
Honored Contributor II
6,716 Views

Hi there, 

 

Is there a compiler which can convert Matlab code directly in to VHDL/verilog format so to implement the code directly in to FPGA? I am trying to write codes on MATLAB and would like to convert the code in to verilog format so to make my life easier.:)  

 

thnks
0 Kudos
22 Replies
Altera_Forum
Honored Contributor II
2,908 Views

Yes there is a simulink to FPGA automated converter from Altera, but I think it is expensive: 

http://www.altera.com/products/software/products/dsp/dsp-builder.html
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

Thanks @Amilcar, 

 

Actually I am looking for a compiler for Matlab not simulink that could convert the Matlab code to verilog/VHDL....any idea? ;)
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

Yes it is possible to convert, there is 2 process for this, 

1) the schematic can be drawn in Simulink and using the function makehdl() in MATLAB, the schematic can be converted to vhdl coding. u can refer the matlab help... 

 

2) consider the option of converting Matlab to C and C to VHDL as there are several (fairly reliable) converters on the market for this.
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

Thanks saurabraj 

 

That would help I guess.... I will posts as soon as I get this working but will I be able to find conversion software for verilog too because I am just a beginner and verilog is what I am learning now.....
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

You can check some below link for this 

1) c-to-verilog.com 

2) en.wikipedia.org/wiki/C_to_HDL
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

Thanks a lot saurabraj 

 

I give it a try.....:) I came across this site from Northwestern university: 

 

ece.northwestern.edu/cpdc/Match/Match.html 

 

and they have managed to make a compiler which converts the matlab code to verilog/VHDL but I can't seem to contact them..... 

 

I thought you guess would be interested in this.....
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

Hi Irtiq 

thanks for the info
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

HI again.....could you guys tell me how do I convert matlab code to C...I have been search for quite sometime and hasn't been able to find any way to convert matlab to C

0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

Matlab has a tool called mcc (matlab c compiler), available with some versions. It produces C or C++ or exe from m files. It excludes graphic functions(available at extra cost). type help mcc

0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

thanks everyone, but I have a problem, actually I am new to FPGA, verilog and have average knowledge of matlab, simulink but I am trying to implement Digital signal processing technique on to a FPGA, I have searched online but can't seemed to get a tutorial on how exactly do I implement DSP technique on to a FPGA. 

 

Could some one suggest me a good website or book which can teach me how to implement DSP technique on to an FPGA using simulink or matlab or even labview....  

 

Right now I am trying to implement a simple noise cancellation technique compose of Sinusoid wave+chirp and by using a low pass filter I am trying to minimized the output to get the desired output in simulink and later I would like to implement this on to my Altera FPGA board could someone provide me such simple example, I would be very grateful
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

I already posted a link to tools and docs on this thread. Did you read it ? 

What did you not understand ?
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

thanks for the instant reply Amilcar, 

 

I went through the Altera website you provided the link for and also downloaded the DSP builder add-on but is there any tutorial or examples that I could try replicating in simulink or matlab and implement it directly on to my Altera FPGA so to get better understanding of the code and mechanic. I basically learn better by following examples that can be implemented. :)
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

Okay here is some more information on the project that I am working on, I am student from BITS pilani university who is working on a project in which I want to apply Noise cancellation technique on to Altera FPGA using Digital Signal Processing in Matlab. I have the Algorithm for noise cancellation on Matlab but configuring FPGA with matlab is one major issue I am facing, but before I begin, I am trying to implement a low pass filter on to my FPGA using simulink, since I read online that this can be done easily on simulink, I have the ideas and plan on how to progress in my project but I lack technical knowledge in this field. I may have to learn Verilog and also need to know how to implement filter design on to a FPGA, I need any good tutorial or examples that could help me learn Verilog especially when it deals with filters and some examples that were already implemented on to an FPGA. 

 

Maybe now you could better understand my problem :)
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

No you do not need to learn VHDL nor Verilog. DSP builder does the job for you. Just use the library blocks that it provides and push the download buton.

0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

thanks amilcar, but could you give me any suggestion on what should I do first to make sure that my FPGA is properly interfacing with simulink,,,,Should I begin by making a LP filter?

0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

A counter is good. And then use ChipScope to test it.

0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

Hello 

I read your posts and i was wondering if you succeeded. I have been trying to do the same and am stuck at it. I have a code on MATLAB and want to translate it to Verilog(Not VHDL).Please let me know if you had success at it. 

 

Thanks
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

u can check the below link for converting Matlab to verilog 

 

Matlab to c or c++ 

1) http://www.mathworks.com/matlabcentral/newsreader/view_thread/270407 

2) http://www.mathworks.com/matlabcentral/newsreader/view_thread/235465 

 

C to verilog 

http://www.c-to-verilog.com/
0 Kudos
Altera_Forum
Honored Contributor II
2,908 Views

Thanks alot saurabhraj 

 

I want to explain a bit on what i have to do. I am using a MATLAB code for SPIHT image compression and i have individual files for each step, since SPIHT proceeds in several phases Dominant pass, Subordinate pass etc.. Now i was thinking if i could translate each file in to an individual module of Verilog.  

 

The links you sent me suggested converting to C and then to Verilog. It seems fairly undertandable to me, sadly I have zero experinece with C and do you think this will slow down the code? As in two steps will give significant delays? 

 

Thankyou
0 Kudos
Altera_Forum
Honored Contributor II
2,569 Views

Yes, you will gets tons of delays and bad performance from such a system (automated conversions). 

That is the reason that HDL engineers are well paid, but then again it takes a couple of years practice to be a good HDL coder. There is no such thing as "free meal" with automated converters. 

 

On the other hand if you use simulink model instead of matlab .m scripts as an entry language, then the translation to hardware is easy and straightforward. And even the automated tools can do a good job. 

That is why I told you guys to use "DSP builder" for simulink. But somehow you do not believe me. 

 

No problem, you are young, you will learn (the hard way) :) 

Good luck transforming .m into c and c into HDL.
0 Kudos
Reply