VHDL Code Generation using Matlab HDL Coder

706 Views Asked by At

I am sorry If I say some thing silly.Please forgive me: I am trying to convert Matlab code(given below) to VHDL code,using HDL coder.It contains a function called sum.But when I try to convert the code it gives me error :

code generation only supports SumModes 'SpecifyPrecision' and 'KeepLSB' for 'SUM' when the size of the inputs can vary at run-time.

But the thing is I have never used functions before.Can any one please help me on it.How should change my code to convert it to VHDL.It would be really nice!

function y = fcn(n,y1,y2)
n=10;
x1c=zeros(2*n-1,1);
for i=1:2*n-1
    if(i>n)
        j1=1;
        k1=2*n-i;
        j2=i-n+1;
        k2=n;
    else
        j1=n-i+1;
        k1=n;
        j2=1;
        k2=i;
    end
    x1c(i)=sum((y1(j1:k1)).*y2(j2:k2));
end
x1c=flipud(x1c).';
y=x1c;

This is cross correlation of y1 and y2. y1 and y2 are two vectors of same length and n is length of y1. I am really stuck please help! Thanks in advance!

1

There are 1 best solutions below

2
dieli On BEST ANSWER

@Haider: Take a look at

    n=10;
    y1 = 1:n;
    y2 = n:-1:1;
    x1c=zeros(1,2*n-1);
    for i=1:2*n-1
        y1_temp = zeros(1,2*n-1);
        y2_temp = zeros(1,2*n-1);
        if(i>n)
            j1=1;
            k1=2*n-i;
            j2=i-n+1;
            k2=n;
        else
            j1=n-i+1;
            k1=n;
            j2=1;
            k2=i;
        end
        y1_temp(j1:k1) = y1(j1:k1);
        y2_temp(j1:k1) = y2(j2:k2);
        x1c(i)=sum(y1_temp.*y2_temp);
    end

I compared the result with the Matlab xcorr function, and it seems the vector is reversed. Does this solve the error?