Hi, I'm writing program that calculates coefficients of a FIR filter. Anyway I have a problem regarding precision of numbers.

I need to use so called Blackman window:

;Code:w[i]=0.42-0.5*cos(2*pi*i/(Len-1))+0.08*cos(4*pi*i/(Len-1));

As you can notice coefficients are symetrical and for Len=11;

there is symetry around element w[5] which is equal 1.00

I wrote function that performs calculations:

When I execute this code I get following results:Code:#define pi 3.14159265 ... double* blackman(int Len) { double* array=malloc(sizeof(double)*Len); int i; for(i=0;i<Len;i++) array[i]=0.42-0.5*cos(2*pi*i/(Len-1))+0.08*cos(4*pi*i/(Len-1)); return array; }

-1.387779e-017

4.021286e-002

2.007701e-001

5.097871e-001

8.492299e-001

1.000000e+000

8.492299e-001

5.097871e-001

2.007701e-001

4.021286e-002

-2.775558e-017

As you can see the first and the second element should be 0.00

I have idea to use if(){} to check if argumet to cos function is 2*pi*k (k=0,1,2,3...) and to set appropriate element to 0.

Is there any other way to increase precision? I assume problem is coming from cos function because cosine function is usually calculated through Taylor's series.

All your ideas are welcome.

Thanks