## Uneven sampling

### 2022 May 31

A common trick when you're sampling and want to filter out noise of a particular frequency f is to space your samples regularly over a period of time of length 1/f. Then, by averaging your samples together, you'll get a good estimate of the DC component of the signal, and the component of frequency f is cancelled out completely, so it can't interfere in your measurement. This technique is common in electronics with the value of f set to 60Hz, the frequency of grid AC. This works because:

Where the noise function is defined as:

Here, A is a random variable, which is why this is considered noise, and it determines the amplitude and phase of the noise.

But sometimes this technique may not be an option. What if, rather than being able to choose nice evenly spaced samples at a particular frequency, you're forced to put your samples at particular predetermined points in time, which may not even be evenly spaced. What if you're only allowed to sample at:

In that case, it's still possible to get a pretty good result and to cancel out noise of frequency f. You'll just have to change how you're averaging, and in particular, to use a weighted average. Choose a set of weights w such that:

Then, for an input signal z(t), our weighted average will be:

What we then have is an optimization problem. We need to choose the weights to give a good result. Ideally, the weighted average will have the smallest possible variance, since that will mean that it's clustered as tightly around the true average as possible. We'll assume that each individual measurement has a standard deviation of σ and that the errors in each measurement are independent.

So this is the objective function we're trying to minimize:

Subject to the constraint:

This has the following result:

This is ignoring the fact that we want to cut out noise of frequency f. But this is simple to fix: we just add another constraint:

After adding this constraint, the weights may no longer all be exactly the same, but they will result in a weighted average that is insensitive to noise of frequency f. If we also want to filter out harmonics (eg. 120Hz, 180Hz), or just other frequencies, we add on another constraint for each frequency.

This technique has the advantage that it's mathematiclly straightforward to solve for the weights using least-squares.