Generate HDL code from SVM function in Matlab.
2 views (last 30 days)
Show older comments
Mohamed Egila on 18 Oct 2017
Commented: Mohamed Egila on 24 Oct 2017
I'm having Matlab 22.214.171.1241360 (R2016a), I need to generate HDL code from SVM function in Matlab. Please help. Thanks.
Tim McBrayer on 18 Oct 2017
Edited: Tim McBrayer on 18 Oct 2017
The R2016a list of built-in MATLAB functions supported for HDL code generation can be found at https://www.mathworks.com/help/releases/R2016a/hdlcoder/ug/functions-supported-for-hdl-code-generation-alphabetical-list.html .
Brian Ogilvie on 23 Oct 2017
The SVM function or ClassificationSVM object are not directly supported for HDL code generation but you can build your own version fairly easily. We had some internal projects that an intern worked on that involved an SVM for a size 36 feature vector that classified A-Z and 0-9. I can share the code that was created as a starting point for you. You will need to supply your trained Beta and Bias values plus decide on the data types that you need for your algorithm. This can generate a lot of logic and we were not able to fit much more than a detector and classifier for one digit in the smaller FPGA we were using at the time. Obviously, this is not production-ready code and just represents a starting point.
function y = fcn(u)
Beta = zeros(36,1);
Bias = zeros(36,1);
lin_u = zeros(36,1);
% Real Beta and Bias values from training set here
lin_u(ii) = Beta(ii).*u(ii) + Bias(ii);
f_neg = -lin_u;
f = 1-lin_u;
f(f<0) = 0;
f_neg = 1-f_neg;
f_neg(f_neg<0) = 0;
%%Function to perform easy sum
y = y_tmp(1); % the value of interest
Find more on Code Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!