Matlab convolution code in C : <p>I'm trying to make the MATLAB conv function in C. So far I have this:</p>

<pre><code>int n=Length(SignalArray);
int m=Length(FilterArray);
TempX=[SignalArray,Zeros(1,FilterArray)];
TempH=[FilterArray,Zeros(1,SignalArray)];
for(int i=0;i&lt;n+m-1;i++){
       ResultArray(i)=0;
        for(int j=0;j&lt;=m-1;j++){
            if(i-j+1&gt;0){
                int TempVal=ResultArray(i)+TempX(j)*TempH(i-j);
                ResultArray(i)=TempVal;
            }
        }
    }
</code></pre>

<p>The first elements of the convolution result come out to be fine but the last element either comes out to be right or is shown to be a really high number ( something like 10 to the power 9).</p>

<p>Please help.</p>
