Determine Sample Size for Sensor Data I'm trying to determine the bias on a gyro that is under constant motion. The way I've been doing this is sampling it over a long period (~1 minute at 100Hz) and taking the average. However, if there is lots of motion, I need to sample longer, and if there is no motion just a few seconds is enough.
How would I be able to determine the number of samples required for a certain CI based on the amount of motion being experienced?
 A: I assume you want to find $n$ such that the margin of error $M$ in a 95%
confidence interval (CI) is of a desired size.
First, you need to have large enough time intervals between observations, so that your measurements $X_1, X_2, ..., X_n$ are independent. Also, to find a CI you need to be reasonably sure that the gyro is stable in a probability sense so that the $X_i$ can be considered all to have come from the same distribution.
If you knew that the population has $Var(X_i) = \sigma^2,$ then a 95% CI for
the the population mean $E(X_i) = \mu$ would be of the form
$$\bar X_n \pm 1.96 \sigma/\sqrt{n},$$
where $\bar X_n$ is the sample mean of a sample of size $n$
and $\pm 1.96$ cut 2.5% of the probability from the lower and upper tails, respectively,
of a standard normal distribution. (We are assuming that $\bar X_n$ is nearly
normal, which is reasonable if $n$ is moderately large and the distribution of the $X_i$s is not serverly skewed.)
Thus the 'margin of error' for your CI is $1.96 \sigma/\sqrt{n}$ and the
total length of the CI is twice that.
But I suppose you do not know the value of $\sigma$ and propose to
estimate it by the sample standard deviation $S_n$ of your sample of size $n.$
Then a 95% CI for $\mu$ is of the form
$$\bar X_n \pm t^*S_n/\sqrt{n},$$
where $\pm t^*$ cut 2.5%of the probability from the lower and upper
tails, respectively, of Student's t distribution with degrees of
freedom $\nu = n-1.$ 
You could find the margin of error and the total length of this CI in
the obvious way. 
But there is a slight difficulty that the value $t^*$
changes depending on $n.$ However, if $n > 30,$ then $t^* \approx 2,$
regardless of the sample size $n$. 
So, roughly speaking, you can
take the margin of error to be $M = 2S/\sqrt{n},$ where $S$ is the
sample SD from previous experiments with similar amounts of 'motion'.
Choose the margin of error $M$ that you seek and solve for $n = (t^*S/M)^2 = (2S/M)^2.$
If the $n$ you get is much smaller than $n = 30,$ then look at a
printed table of Student's t distribution and use the appropriate $t^*.$
That will give a 'new' $n.$ Use the corresponding 'new' $t^*$ for the
'next' $n.$ Iterate a couple of times and $n$ will
stabilize.
There are more elegant ways to solve this using a programmed 'quantile function' of the t 
distribution. However, as you see, a certain degree of guesswork
is involved in estimating $\sigma$ by $S,$ so the method I propose
should get you to a workable value of $n.$
Note: A 'sequential' approach would be to find the CI after each few observations
are taken (easy enough to program on a calculator) and stop when the CIs settle to the desired length.
