# Large sample rate or large number of cycles when estimating frequency?

I wish to determine the frequency, amplitude and phase of a sine wave with some noise and I can only have a fixed number of samples. Should I go for many cycles and a small sample rate or a few cycles and a large sample rate?

I know that if I choose to use a DFT to determine the frequency then the spectral resolution will be the sample rate divided by the number of points. I must avoid aliasing so this suggests I should choose a small sample rate giving for example 3 or 4 points per cycle and capture many cycles of data. It may be a separate issue but the actual frequency will probably not correspond to a line in the spectrum so there will still be the, I think, unresolved issue of finding the frequency amplitude and phase from the small cluster of points around the maximum in the spectrum.

I could also choose an alternative method where I curve fit a sine wave to the data. This should give me best estimates in the least squares sense. However, for this method it is not clear which is best many cycles with a small sample rate or fewer with a large sample rate.

Is this a known problem with a known solution? Thanks for any input.

• To reduce the variance in your frequency estimate, you will want to increase the time duration of your observation window (not the sample rate). Provided that you're sampling at a high enough rate to avoid aliasing, there is no additional information conveyed by taking additional samples over the same time period. Sep 22, 2015 at 18:57
• @Jason R You may well be correct. Thanks. Do you have a reference for this? Or could you put your reasoning (and possibly maths) in an answer?
– Hugh
Sep 22, 2015 at 19:07

Jim Clay's answer is good, but there is a caveat: you want the sampling frequency low, but not too low.

If you have real-valued data (as opposed to complex-valued data), the you should try to avoid the DC (zero frequency) and $f_s/2$ (high frequency) bins. Because the FFT of real-value signals tend to "wrap" at these frequencies, so a bias is induced.

For example, this plot shows the FFT magnitudes of sinusoids with frequencies 0.5 bins and 2.5 bins. You can see that the peaks in the top plot (corresponding to negative and positive frequency peaks) overlap a little in the top one but not in the bottom one.

To see the effect of the bias, the scilab code below estimates the frequency from the FFT bin where the true frequency changes from 0 to 5 bins in steps of 0.01 bins. If there were no bias, you would expect a straight line (well, jagged because of the quantization that binning produces). Below about 1.5 bins the line is not straight.

Still working on the amplitude and phase estimates. They're a little tricky in the real-valued sinusoid case.

scilab Code Below

//25980
//omega = 2*%pi/N*1.5;
bin_true = [0:.01:5];
bin_hat = [];
for omega = 2*%pi/N*bin_true;
N = 50;
Ninterp = 10;
A = 1.382489;
phi = 2*%pi*0.89823749;
t = [0:N-1]
x = A*sin(omega*t+phi);

XX = abs(fft([x, zeros(1,(Ninterp-1)*N)]));

f = ([0:Ninterp*N-1] - Ninterp/2*N)/(Ninterp*N)

[mx,ix] = max(XX);

bin_hat = [bin_hat (ix-1)/Ninterp];
end

plot(bin_true,bin_hat)
xlabel('True bin');
ylabel('Estimated bin');
title('Bias for very low frequency real sinusoid estimation')

• Peter k. Thanks. The avoidance of DC is a good point and, as I stated in the question, the avoidance of the half sample rate is important for no aliasing. If I understand your plots correctly you are deliberately undersampling. The bias plot is revealing. Where is this bias coming from? Is this just because the frequency does not coincide with a bin? If you can see an easy method for getting the amplitude and phase from a DFT that would be good. I think this is difficult and perhaps a second question on its own.
– Hugh
Sep 22, 2015 at 20:03
• There are several interpolation method to remove the bias from non-DFT-bin-center frequencies. Those appear to have not been used the above plots. Sep 22, 2015 at 21:24
• @hotpaw2 Please could you elaborate on these interpolation methods? Perhaps this belongs to a new question or can you point me to a reference. Thanks
– Hugh
Sep 22, 2015 at 21:57
• Many interpolation methods. Separate/new question suggested. Sep 22, 2015 at 22:01

For frequency estimation of a pure sine wave, the difference between 2 slightly different frequency sine waves increases over time. So a longer time base (as long as the sample rate is well separated from the Nyquist rate, or any integer sub-multiple thereof) would provide a bigger difference in a fixed number of samples, thus making it more likely that two different frequency signals could be separated from the effects of noise on any one signal. This bigger separation difference is a close equivalent to better frequency estimation accuracy. Note that under-sampling is possible if the S/N ratio is good enough, and as long as you know, a-priori, the correct frequency range of your signal and stay away from integer multiples of Fs/2 being near to Festimated.

A longer time base also corresponds to a narrower frequency bin spacing of a DFT result, thus decreasing the percentage errors in any interpolation between bins that may be performed or required. But any frequency is a line in the spectrum after (high-quality/Sinc) interpolation.

Once you estimate the frequency, you can use two or more points (depending on the S/N ratio) to least squares fit a sine wave equation in two unknowns to estimate amplitude and phase. Or windowed-Sinc interpolation, followed by successive approximation is another method to estimate amplitude. Quadrature modulation of the signal against the estimated frequency can also be used to estimate phase (most accurately when referenced to the point or time at the center of the data window).

I would choose low sample rate, many cycles for a few reasons.

1. Assuming the sine wave doesn't have harmonics, there is no information about the sine wave at the higher frequencies.
2. If you do use a DFT to estimate the frequency, you will get the best frequency resolution from the low sample rate approach, because the Hz per "bin" is $\frac{f_s}{N}$, where $f_s$ is the sample frequency, and $N$ is the number of samples.
3. You could do a simple zero-crossing approach that would be very accurate if you have a large number of cycles. By zero-crossing I mean count how many times it crosses the zero point in $N$ samples, and use that to determine the frequency. This assumes that the noise power is low enough that erroneous zero-crossings are very rare.
• Thanks Jim good points. If I may I will be picky. Point 2 is the point I made in my original post and seems to be a good basis to start from. Point 3 is fast but will not achieve better resolution than Point 2 since there is the issue of the inevitable part of a cycle at the end that does not get counted leaving you with the same resolution. Also, it does not give amplitude and phase. This leaves your point 1 on "no information in higher frequencies". Is there a basis for this or is this point 2 again? If the spectrum is zero away from the peak it helps with identifying the peak.
– Hugh
Sep 22, 2015 at 18:00
• @hugh Phase relative to what? If you have only a single sine then the phase is somewhat moot. If you have two channels of a single sine of the same frequency then you can talk about the phase difference between the two channels and that can be determined using a zero-crossing approach. Sep 22, 2015 at 18:54
• @jaket You have a point. However I need a phase since I want to be able to give a formula for the data and I need to know what the starting phase is. Perhaps I should have stated that my sine wave may not be a sin that is zero at time zero and is more general.
– Hugh
Sep 22, 2015 at 19:03
• @Hugh Regarding point 1, what I meant is that the sine wave doesn't have any power beyond the low sample rate Nyquist frequency, so expanding the Nyquist frequency does nothing for you. In other words, you aren't capturing anything new about the sine wave by increasing the sample rate. Sep 22, 2015 at 20:17
• @JimClay I think you are correct. Again you are not invoking a fresh approach but expressing the DFT result in another way. What is interesting to me is that there seems to be a clear approach if you do the DFT and look at the frequency resolution, Somehow that deduction is extendable to all other approaches. Can we assert that if we work out the correct procedure using the DFT analysis then this is final and no other analysis will reveal a suitable alternative approach?
– Hugh
Sep 22, 2015 at 21:54