Conversion of MATLAB (.m) coding into Verilog HDL
138 views (last 30 days)
Show older comments
hamid
on 16 Sep 2011
Edited: MathWorks Support Team
on 8 Jan 2024
Dear All
I am doing a project in which i have to convert image encryption MATLAB code into Verilog HDL language code and then implemented it on DE2 Board. I have already searcehd a lot of questions regarding this matter but every one said that you have to write MATLAB code either into Embedded MATLAB code or on Simulink. My question is that is this possible that i write a code in simple MATLAB coding means in .m extension (not on Simulink or in Embedded MATLAB code) and convert it into Verilog HDL Langugae. Because i have only .m extension MATLAB code to convert.
Looking forward for a positive response and thanking all in advance.
Thanks Regards
0 Comments
Accepted Answer
Walter Roberson
on 16 Sep 2011
Edited: MathWorks Support Team
on 8 Jan 2024
***** Update by MathWorks Technical Support team*****
>> mlhdlc_demo_setup('aes')
You have to structure the code into design and testbench. See the above example for insights. Follow the workflow steps shown here...
This page covers several tutorials showing how to generate HDL from MATLAB code.
****************************************************************
You would probably have had to restrict the code to using the functions supported by Embedded MATLAB (even if not written with specific reference to Embedded MATLAB), and then you would probably have to run the code through MATLAB Coder (for Release R2011a or later). The result would be a C file, which you could then compile to HDL such as with one of these tools.
MATLAB Coder does not rely on any other toolboxes, but it seems likely to me that it is fairly expensive. I do not know, though, how the price would compare the alternatives.
1 Comment
Fangjun Jiang
on 16 Sep 2011
Embedded MATLAB belongs to Simulink. With MATLAB alone, no need and can't use the Embedded MATLAB Function block.
More Answers (3)
Fangjun Jiang
on 16 Sep 2011
What you heard is probably right. If you are looking for a Yes answer, you are probably going to be disappointed. Look at all the products at http://www.mathworks.com/products/?s_cid=global_nav, there are only two mentions of HDL. One is "Filter Design HDL Coder" toolbox under MATLAB. The other is "Simulink HDL Coder" toolbox under Simulink. That means you need to have at least one of the toolbox to be able to generate a HDL code. With only MATLAB, it can't be done at this point.
0 Comments
hamid
on 16 Sep 2011
1 Comment
Walter Roberson
on 16 Sep 2011
I do not have a price chart available, and I did not pay much attention to the MATLAB Coder price the last time I glanced at the chart. I think it was over $7000 for MATLAB Coder, but you would need to check with Sales to be sure (especially if you can get academic pricing.)
I did not investigate the C to HDL tools to see if any of them were free (and worth owning). It appears that many of them are specialized commercial products that I would expect would cost thousands of dollars.
Hemanth Kumar
on 23 Mar 2023
clearvars
close all
clc
nPUs = 1; % Number of primary users
nSUs = 2; % Number of secondary users
nSamps = 1e3; % Number of sensing samples per sensing period
snrdB = linspace(-12,-8,nSUs); snr = db2pow(snrdB); % Signal-to-noise ratio (SNR) of each SU
sPow = ones(1,nSUs); % Received PU signal power at each SU
nPow = sPow./snr; % Noise power at each SU
nMCEvents = 5e3; % Number of Monte Carlo events
nROCPts = 50; % Number of receiver operating characteristic (ROC) curve points
Ted = zeros(nMCEvents,1); % Preallocating for speed
TX = randi([0,1],nMCEvents,1); % Simulates hypotheses H0 and H1 for the received signal, 50% under H0 and 50% under H1
for i = 1:nMCEvents
H = sqrt(1/2)*complex(randn(nSUs,nPUs),randn(nSUs,nPUs)); % Rayleigh channel samples for each SU
X = sqrt(1/nPUs)*complex(randn(nPUs,nSamps),randn(nPUs,nSamps)); % Normally distributed primary user signal (weighted by sqrt(1/nPUs) for keeping desired SNR)
V = sqrt(diag(nPow)/2)*complex(randn(nSUs,nSamps),randn(nSUs,nSamps)); % AWGN
Y = TX(i)*sqrt(diag(sPow)/2)*(H*X) + V; % Received signal at each SU
Ted(i) = (1/nSUs)*sum((1/nSamps)*sum(abs(Y).^2,2)); % Energy detection test statistic
end
Thres = linspace(min(Ted),0.85*max(Ted),nROCPts); % Threshold decision for each ROC point
nH0 = sum(TX==0); % The number of times the PU transmitter(s) has been in the non-active state
nH1 = sum(TX==1); % The number of times the PU transmitter(s) has been in the active state
Pfa = sum(Ted>Thres&TX==0)/nH0; % Probability of false alarm for each decision threshold
Pd = sum(Ted>Thres&TX==1)/nH1; % Probability of detection for each decision threshold
figure
plot(Pfa,Pd)
title('ROC curve')
xlabel('Probability of false alrm')
ylabel('Probability of detection')
legend('ED','Location','SouthEast')
grid
3 Comments
Kiran Kintali
on 23 Mar 2023
Edited: Kiran Kintali
on 23 Mar 2023
>> mlhdlc_demo_setup('aes')
You have to structure the code into design and testbench. See the above example for insights. Follow the workflow steps shown here...
This page covers several tutorials showing how to generate HDL from MATLAB code.
https://www.mathworks.com/matlabcentral/fileexchange/50098-matlab-hdlcoder-examples
Rehannara Beegum Thajudeen
on 25 Aug 2023
I have a doubt in the line, Thres = linspace(min(Ted),0.85*max(Ted),nROCPts);.....here what is the significance of multiplying 0.85 with Ted? How we decide this constant value?
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!