Hello,
I am doing a recursive filter with IDL and i succed in, but i've now to translate my IDL code in C code, and i think i've got a problem with it. This is the code on the recursive filter i've to translate :
Y[0] = B[nb]*U[0] / A[na]
for K = 1 , number_of_dyn -1 do begin
Y(K) = ( TOTAL( B[nb-K>0:nb ]*U[K-nb>0:K ] ) $
- TOTAL( A[na-K>0:na-1]*Y[K-na>0:K-1] ) ) /A[na]
endfor
I done this in C :
y[0].real = b_coeff[filter_order]*tmp_o[thread][0].real / a_coeff[filter_order];
y[0].imag = b_coeff[filter_order]*tmp_o[thread][0].imag / a_coeff[filter_order];
for(int j = 1 ; j < WINDOW_WIDTH ; j++)
{
float *sig_part = total_sig(tmp_o[thread], j);
float *res_part = total_res( y, j);
y[j].real = (sig_part[0] - res_part[0]) / a_coeff[filter_order];
y[j].imag = (sig_part[1] - res_part[1]) / a_coeff[filter_order];
delete sig_part;
delete res_part;
}
with total_sig and total_res like this :
float *
total_sig ( complex *sig, int index)
{
float *coeff = new float[2];
for(int i = 0 ; i <= filter_order ; i++)
{
if( index - filter_order + i < 0)
break;
coeff[0] += b_coeff[i]*sig[index - filter_order + i].real;
coeff[1] += b_coeff[i]*sig[index - filter_order + i].imag;
}
return coeff;
}
float *
total_res ( complex *y, int index)
{
float *coeff = new float[2];
for(int i = 0 ; i < filter_order ; i++)
{
if(index - filter_order +i < 0)
break;
coeff[0] += a_coeff[i]*y[index - filter_order + i].real;
coeff[1] += a_coeff[i]*y[index - filter_order + i].imag;
}
return coeff;
}
this give me a good result, but not the same as result given by my IDL code...
if someone can help me...
Thanks
Greg
|