# Frequency measurement -- how to choose sampling ?

1. Jul 18, 2014

### csopi

Hi,

let's say I want to measure the frequency f of a periodic signal. I may take N data points with an arbitrary timestep of T.

The question is how shall I choose T for a fixed N to have the best accuracy? In principle the frequency resolution is 1/(N*T) when taking the Fourier transform, this would suggest to me to choose T as large as possible, i.e. T= 1/ (2*f) (Nyquist limit).

However I am not sure of that for several reasons. E.g. one may use least square fitting instead of Fourier transform, and it may increase the resolution, especially if I measure only a few oscillations. One other possibility is to pad up the measured signal with a constant signal (e.g. zeros) -- with this, one artificially increase the total measurement time, and with this the resolution. By the way, what is the theoretical max. accuracy, that one can reach with this latter trick?

2. Jul 18, 2014

### Simon Bridge

You want to find the frequency of a periodic signal by taking amplitude samples at uniform timestep - there is no way, a-priori, to choose the ideal time-step. There isn't one.

You need to have some idea what the frequency is going to be before you start - you need the time-step to be much smaller than the period of the signal but you cannot know what that is without knowing what the frequency is and that is what you are trying to measure.

Considering you have a fixed N for some reason (usually the sampling time is fixed, and you get to pick N, which determines T) then you want the largest value for T that can still resolve the frequency.
If, by some chance, you sample at exactly the nyquist frequency of the signal, then you will get equal size samples, what happens when you take the fourier transform of that?

Since you have to measure the frequency, you will probably want a time-step smaller than 1/2f ... play around a bit with different values and see what you get.

3. Jul 18, 2014

### olivermsun

You'd certainly want a sampling interval T safely smaller than 1/2f (the Nyquist frequency) as Simon Bridge mentions. In order to get the most accurate frequency estimate, what you care about is the product you mentioned: N*T = (total sampling time). Your goal is to sample as many periods of the wave as possible.

There are other methods besides Fourier transforms that can work, but the basic problem is remains the same: two waves with very close frequency only "diverge" after many oscillations, so you need to measure for a long time to tell the difference.

4. Jul 18, 2014

### f95toli

If you are measuring frequency is is usually a good idea to low pass filter the signal before it reaches the AD converter; that way you know you are not having a problem with aliasing.

Also, none of the methods you suggest work if you by "improve accuracy" mean a more accurate measurement of the true frequency. There are a few tricks you can use but you will quickly find that in practice what will ultimately limit you accuracy at short times is usually the white noise of the electronics (and the only way to improve on that is to increase the time you measure , i.e. the integration time) and well as how good your reference signal is (this obviously always sets the ultimate limit for a single device). The good news is that frequency is something we can measure really accurately quite easily, even with a basic frequency counter you should be able to get to something like 1 part in 10^7 or so within a few seconds of integration time. A "proper" lab setup will get you to something like 1 part in 10^11 or thereabouts if you have a good reference and a specialized setup will be close to maybe 1 part in 10^14 or even less (but you'd need a hydrogen maser as a reference)