unexpected matlab expression during hdl code generation

4 views (last 30 days)
Dear sir/madam, whenever I am trying to generate a verilog code I am getting an 'Unexpected Matlab Expression' error.. I googled the solution, but I am unable to understand what's wrong... plz help.. Here's my code
function y = fir_project(x,h)
% x = [1/5,2/5,3/5,4/5];
% h = [1/3,1/3,1/3];
% initialize
x1 = 0;
x2 = 0;
y = zeros(1,length(x));
for k = 1:length(x)
if k-2 == -1 || k-2 == 0
x2 = 0;
else
x2 = x1;
end
if k-1 == 0
x1 = 0;
else
x1 = x(k-1);
end
y(k) = (h(1)*x(k))+(h(2)*x1)+(h(3)*x2);
end
end
The x and h values are given in comments. Thanks in advance. This is the error I am getting
emlhdlcoder.WorkFlow.Manager.instance.wfa_generateCode(' C:\Documents
\matlab\fir's project\firproj2.prj ');
|
Error: Unexpected MATLAB expression.

Answers (1)

Tim McBrayer
Tim McBrayer on 18 Mar 2014
I think that HDL Coder will have a hard time with your variable loop bound; this is hard to build hardware for. I have no issues when I use a constant 4 instead of the expression length(x) .

Categories

Find more on Code Generation in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!