Other Parts Discussed in Thread: C2000WARE
Hi
I'm implementing a first order low pass filter (fcut = ~0,1Hz / fsample = 30Khz):
-> G(z) = (1.046(...)e-05 z + 1.046(...)e-05) / (z-0.999(...))
-> The coefficients are declared as:
const float cfmed[4] = {1.04606151580810546875e-5,1.04606151580810546875e-5,1.0,-0.999979078769683837890625};
-> The 30 kHz loop is:
Out_k_1 = Out;
Out = In* cfmed[0] + In_k_1 * cfmed[1] - Out_k_1 * cfmed[3];
In_k_1 = In;
-> The input (In) and output (Out) are declared as float.
The problem is that i'm having unnaceptable static gain error.
For example, if I test the filter with constant input such as: 300.0; 300.5 and 299.2
I get: 299.760712, 299.760712 and 298.302002, respectively.
If i change all the variables and filter coeffs to "long double" I get better results.
But I also get problems with memory and timing (In fact, the complete application has a looot of filters and other things). So i need to work with float.
What intrigues me is that if I pause the execution and inspect cfmed[4], the coefficients "1.04606151580810546875e-5"are encoded as "00000000000000000000000000000000b" / (0x00000000) and the coefficient "0.999979078769683837890625" is encoded as "00100000000000000000000000000000b" (0x20000000).
I think that is is not in accordance with IEEE-754. Those numbers should be encoded as "00110111001011111000000000000000b" (0x372f8000) and "10111111011111111111111010100001b" (0xbf7ffea1).
I think that its the root of my static gain error.
So, I tried to replace the declaration: const float cfmed[4] = {1.04606151580810546875e-5,1.04606151580810546875e-5,1.0,-0.999979078769683837890625};
For: const float cfmed[4] = {0x372f8000,0x372f8000, 0x3f800000, 0xbf7ffea1};
Now, the filter is giving me only +/- INF output values!
What I'm doing wrong? Why it seems that the compiler is not enconding the floating point values as IEEE-754?
I'm using F28335, CCS V 8.3.1.00004 and Compiler V18.1.4.