user28582: I am using an Accelerometer (on the MPU6050) and connected it to the Arduino Due. In order to filter the signal I am using an IIR Filter with the following transfer function:
H(z) = Y(z)/X(z) = B/A
B = 0.00000376 + 0.00001127*z^(-1) + 0.00001127*z^(-2) + 0.00000376*z^(-3)
A = 1 - 2.9372*z^(-1) + 2.8763*z^(-2) - 0.9391*z^(-3)
which is an IIR 3th Order Butterworth, Cutoff Freq: 0.5Hz, Samling Freq: 100Hz. These numbers can be calculated by any IIR calculator.
Thus, then discrete equation is:
y[n] = 0.00000376*x[n] + 0.00001127*x[n-1] + 0.00001127*x[n-2] + 0.00000376*x[n-3] + 2.9372*y[n-1] - 2.8763*y[n-2] + 0.9391*y[n-3]
I first tried it on the Arduino UNO. Then I found out that decimal point precision (float & double) on the UNO is only 6-7 digits. But the therm "B" in the transfer function has for example (0.00000376) 9 digits. I thought this is the porblem, so I switched to Arduino Due and now I am using double (instead of float) which should have enough precision.
It is still unstable. It is not oscillating but getting bigger. I also tried an IIR 4th Order Butterworth, Cutoff Freq: 1Hz, Samling Freq: 100Hz. This one is oscillating.
However, the only IIR that seems to be stable is an IIR 3th Order Butterworth, Cutoff Freq: 1Hz, Samling Freq: 100Hz.
I have no idea so far what the problem is. Could anyone help please?

user7508: 
The precision of a float is about 7 significant digits. The
constant term of B in your transfer function (0.00000376) has only 3
significant digits.
Your transfer function has a pole at z = 1. It is thus not really
stable, but only marginally stable. Any parasite DC component in
the input will make the output drift without bounds.

It seems to me that your problem is not related to the implementation of
the filter on the Arduino, but rather to the filter design. Where did
you get that transfer function from?
Edit: I looked at the filter you are trying to make. It turns out it
is very sensitive to the precision of the coefficients of A(z). If you
try to add these coefficients, they almost cancel out: their sum is
about 3e-5. At zero frequency, both A and B are 3e-5, and the transfer
function, which is their ratio, is 1. By rounding the coefficients to
four decimal places, you made the cancellation exact, and the transfer
function infinite.
Just write the transfer function with more decimal places in the
coefficients and it should work:
H(z) = 3.75592×10−6 (1 + 3 z−1 + 3 z−2 + z−3)
         ÷ (1 − 2.9371759 z−1 + 2.8763097 z−2 − 0.9391038 z−3)

28582: <p>I am using an Accelerometer (on the MPU6050) and connected it to the <strong>Arduino Due</strong>. In order to filter the signal I am using an IIR Filter with the following transfer function:</p>

<p>H(z) = Y(z)/X(z) = B/A</p>

<p>B = 0.00000376 + 0.00001127*z^(-1) + 0.00001127*z^(-2) + 0.00000376*z^(-3)</p>

<p>A = 1 - 2.9372*z^(-1) + 2.8763*z^(-2) - 0.9391*z^(-3)</p>

<p>which is an IIR 3th Order Butterworth, Cutoff Freq: 0.5Hz, Samling Freq: 100Hz. These numbers can be calculated by any IIR calculator.</p>

<p>Thus, then discrete equation is:</p>

<p>y[n] = 0.00000376*x[n] + 0.00001127*x[n-1] + 0.00001127*x[n-2] + 0.00000376*x[n-3] + 2.9372*y[n-1] - 2.8763*y[n-2] + 0.9391*y[n-3]</p>

<p>I first tried it on the Arduino UNO. Then I found out that decimal point <strong>precision</strong> (float &amp; double) on the UNO is <strong>only 6-7 digits</strong>. But the therm "B" in the transfer function has for example (0.00000376) <strong>9 digits</strong>. I thought this is the porblem, so I switched to Arduino Due and now I am using double (instead of float) which should have <strong>enough precision</strong>.</p>

<p>It is still unstable. It is not oscillating but getting bigger. I also tried an IIR 4th Order Butterworth, Cutoff Freq: 1Hz, Samling Freq: 100Hz. This one is oscillating.</p>

<p>However, the only IIR that seems to be stable is an IIR 3th Order Butterworth, Cutoff Freq: 1Hz, Samling Freq: 100Hz.</p>

<p>I have no idea so far what the problem is. Could anyone help please?</p>
 7508: <ol>
<li>The precision of a float is about 7 <strong>significant</strong> digits. The
constant term of B in your transfer function (0.00000376) has only 3
significant digits.</li>
<li>Your transfer function has a pole at <em>z</em> = 1. It is thus not really
stable, but only <em>marginally</em> stable. Any parasite DC component in
the input will make the output drift without bounds.</li>
</ol>

<p>It seems to me that your problem is not related to the implementation of
the filter on the Arduino, but rather to the filter design. Where did
you get that transfer function from?</p>

<p><strong>Edit</strong>: I looked at the filter you are trying to make. It turns out it
is very sensitive to the precision of the coefficients of A(z). If you
try to add these coefficients, they <em>almost</em> cancel out: their sum is
about 3e-5. At zero frequency, both A and B are 3e-5, and the transfer
function, which is their ratio, is 1. By rounding the coefficients to
four decimal places, you made the cancellation exact, and the transfer
function infinite.</p>

<p>Just write the transfer function with more decimal places in the
coefficients and it should work:</p>

<p>H(z) = 3.75592×10<sup>−6</sup> (1 + 3 z<sup>−1</sup> + 3 z<sup>−2</sup> + z<sup>−3</sup>)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;÷ (1 − 2.9371759 z<sup>−1</sup> + 2.8763097 z<sup>−2</sup> − 0.9391038 z<sup>−3</sup>)</p>
