# Estimating the wavelength of a sinusoid

I have a sinusoidal signal embedded in noise, and I would like to estimate it's amplitude and frequency, so I can subtract it out.

I realize that an FFT can do the job for me, and that's what I've been doing - I took an FFT of the input signal, and looked at the frequency bin with the highest amplitude, used that as an estimate for the frequency of the wave, and then subtract it out.

But the problem is that the frequency is accurate to only half a bin, and the bin size can be fairly large (since my sample size is typically ~ 100 points), and hence the error in wavelength is big. This leaves fairly large residuals once I subtract.

So as step two, I used the frequency from the FFT as an estimate, and I used the Levenberg-Marquardt algorithm to fit for the frequency, phase and amplitude. This solution worked wonderfully for toy data that I generated, but it fails quite frequently on real data, because of the noise. The amplitude of the noise can be as large (at most) as the amplitude of the signal.

I figured that I can estimate the wavelength using an autocorrelation, but I'm not sure how to interpret the results in the case of more than one frequency component.

Question: Are there any methods of estimating the wavelength of the wave that aren't FFT? I figure since fitting for the frequency is failing with noise, I could try fitting for the wavelength, but any other suggestions are welcome!

Note: I haven't really tried padding with zeros while performing the FFT because the noise seems to go up in the fourier plane if I do, but I'll try it and report the success here.

• Why don't you band-pass filter your data before application of the Levenberg-Marquardt algorithm? The BPF need not be spot-on, but will clean the data up enough for the LMA estimator to give you accurate results. – Tarin Ziyaee Aug 9 '13 at 16:06
• Also, how are you seeding LMA? – Tarin Ziyaee Aug 9 '13 at 16:12
• I'm guessing you mean throw away the highest frequency components etc? Would the statistics of my noise matter in that case? I can assume it's gaussian, but that may not be strictly true in all cases. – Kitchi Aug 9 '13 at 16:12
• @user4619 - Seeding it with the frequency, amplitude and phase I get from the FFT. In toy data that I generated, this worked 100% of the time, but it seems to fail with noise. – Kitchi Aug 9 '13 at 16:22
• Do you only have 100 samples total? Or are you using a window of 100 samples from a longer data set? How many wavelengths per 100 samples do you expect? – hotpaw2 Aug 9 '13 at 16:38

The first thing to note is that the LMA algorithm is an estimator, and tries to minimize error in the least squares sense, between your data, and a model function of variable parameters.

Typical of LSE based frequency estimators, you need to seed them at values close to the global minima of the cost function, otherwise they will find another local minimum to lock on to, and hence they need to be seeded properly, or 'in the ball park', ostensibly using some apriori information. How to attain this a-priori information? See below.

This solution worked wonderfully for toy data that I generated, but it fails quite frequently on real data, because of the noise. The amplitude of the noise can be as large (at most) as the amplitude of the signal.

LMA will provide you with an amplitude, phase, and frequency estimate in the LS sense. Of course, the more noise there is in your data, the worse off this estimate is. This is why you will need to pre-process your data to remove as much noise as possible, before the application of the LMA.

You mention zero-padding your data, and while this will not increase your frequency resolution, this will certainly increase your frequency granularity. (Interpolation in the frequency domain). With those facts, I would attempt the following solution:

• Pre-Process the data via an (FIR) Band-Pass Filter centered around my frequency of interest.
• Perfrom a zero-padded FFT so as to ascertain the peak frequency of interest within the BPF'd data's band.
• From this peak, ascertain the frequency, amplitude, and phase, with which to seed LMA with. (Note, make sure to remove the phase offset the BPF filter added for the seeding value).
• Run the LMA.

I'm guessing you mean throw away the highest frequency components etc? Would the statistics of my noise matter in that case? I can assume it's gaussian, but that may not be strictly true in all cases

The statistics of the noise does not matter in this case. All you are doing is removing frequency bands where noise exists, independent of their statistics. In this way, you are not utilizing DFT bands where your signal does not exist, and retaining the DFT bands where your signal exists.