DSPRelated.com
Forums

Can I Extract Fundamental from Partial Sine Wave?

Started by Clive Wallis November 16, 2003
I have some experimental data for In-phase and quadrature signals. 
Sometimes the data covers only half or less, of a full cycle.  There are
usually about 100 - 140 equally spaced (in time) points, but a few
points are often missing.

What technique can I use to calculate the fundamental frequency of the
sine wave?   I would like to write a program, or use a spread sheet,
which ever is appropriate, or use an existing procedure.

Any help would be appreciated. 

-- 
Regards    

	 Clive    G3CWV

         Hitchin, North Hertfordshire, UK.
"Clive Wallis" <clivew@zetnet.co.uk> wrote in message
news:2003111610211170399@zetnet.co.uk...
> I have some experimental data for In-phase and quadrature signals. > Sometimes the data covers only half or less, of a full cycle. There are > usually about 100 - 140 equally spaced (in time) points, but a few > points are often missing. > > What technique can I use to calculate the fundamental frequency of the > sine wave? I would like to write a program, or use a spread sheet, > which ever is appropriate, or use an existing procedure. > > Any help would be appreciated.
Clive, I was going to answer but figured somebody would know better than I. So, now with no answers forthcoming: Some will say that all you need are two samples to define a sinusoid. But, then you need to know something like the frequency or the amplitude - one or the other I imagine. You didn't say that you know the amplitude. If you tried this: 1) append a lot of zeros to the samples - say from 100 samples out to 1024 or 2048. 2) compute the FFT of the result. 3) find a peak in the magnitude squared of the FFT samples somewhere below 1/T radians/sec where T is the length of the original temporal epoch of samples (before you appended the zeros). The latter is because you have said you have less than one period of data available. The problem with this is that your sampling method implies a resolution of 1/T which is broader bandwidth than the fundamental frequency. And, the fundamental sinusoid should appear at positive and negative frequencies around zero. This means that the two frequency spikes will be smooshed together around zero - even if you remove the average (dc) out of the samples first. So, that isn't likely to work - and it's a pretty fundamental technique. You might try this iterative process if the signal to noise ratio is good: (I'm just making this up... so there must be improvements) If you have something less than 1/2 cycle, then you either have a one peak or one zero-crossing in the worst case. Usually, you will have both. If you have something more than 1/2 cycle, then you will have two peaks and a zero crossing or two zero crossings and a peak. If the sinusoid isn't distorted, then you might do something like this: 1) Create a set of duplicated samples with reversed sign (You will eventually slide those new samples in time relative to the original samples). 2) If there is more than 1/2 cycle, as you slide one past the other there will be a point where the beginning and end segments coincide in value. This makes use of temporal symmetry/asymmetry in a sinusoid. If you find such a point, then you have one cycle by combining the two and can measure the distance between zero crossings to determine frequency. Interpolation will help. It may be that this coincidence is found by computing the sum of squares of the differences in the overlapped region. 3) If there is less than 1/2 cycle the same idea would apply. In this case, it may help to reverse the samples in time and find a similar match. At this point, you have at least 1/2 cycle and then can use the process from (2). On the one hand, if you have lots of cycles in the sample epoch, then spectral analysis and estimation methods are well developed for doing this. On the other hand, if you have just a few points of perfect data / knowledge, then a purely analytical solution is reasonable. This tries to do something in between assuming that there's a high SNR. I don't know of any methods that do this - which is simply a matter of ny ignorance. It's more or less equivalent to matching a segment of a sinusoid of known amplitude and frequency in a least squares sense - you could write an algorithm to do that with some effort. If you have a starting poiint for frequency and amplitude, you could search the space of frequency and amplitude and phase / delay for the best match over the epoch of the samples. If you have a zero-crossing then you could hold the phase fixed and vary the frequency and amplitude. You'd end up with a peak in frequency / amplitude space with uncertainty in both dimensions. If you have in-phase and quadrature channels, there must be ways to combine them first or to make good use of the two channels in getting frequency. For example, it implies that there are 2x the data points I mentioned above regarding zero crossings and peak values. In 1/4 cycle you will have one zero crossing each and can compare their times to estimate frequency. Note that this is a single measurement which uses differencing - so it will be a noisy measurement! The same applies to the steps above. Enought arm-waving.... It should be pretty obvious that these "manual" methods are fraught with sources of error. You didn't say how accurately you want to determine the frequency. Fred AC7VR
Clive,

What you are trying to find are the A, w and fi parameters for the
equation:
 A*exp(jwt + fi) 
which makes the best fit with your data. You can do it with
autoregression.

Vladimir Vassilevsky

DSP and Mixed Signal Design Consultant

http://www.abvolt.com

 



Clive Wallis wrote:
> > I have some experimental data for In-phase and quadrature signals. > Sometimes the data covers only half or less, of a full cycle. There are > usually about 100 - 140 equally spaced (in time) points, but a few > points are often missing. > > What technique can I use to calculate the fundamental frequency of the > sine wave? I would like to write a program, or use a spread sheet, > which ever is appropriate, or use an existing procedure. > > Any help would be appreciated. > > -- > Regards > > Clive G3CWV > > Hitchin, North Hertfordshire, UK.
Vladimir Vassilevsky wrote:

> Clive, > > What you are trying to find are the A, w and fi parameters for the > equation: > A*exp(jwt + fi) > which makes the best fit with your data. You can do it with > autoregression. > > Vladimir Vassilevsky > > DSP and Mixed Signal Design Consultant > > http://www.abvolt.com
It's not quite that simple. As given, the waveform can have harmonics. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Clive Wallis <clivew@zetnet.co.uk> writes:

> I have some experimental data for In-phase and quadrature signals. > Sometimes the data covers only half or less, of a full cycle. There are > usually about 100 - 140 equally spaced (in time) points, but a few > points are often missing. > > What technique can I use to calculate the fundamental frequency of the > sine wave? I would like to write a program, or use a spread sheet, > which ever is appropriate, or use an existing procedure. > > Any help would be appreciated.
Hi Clive, If you do have in-phase and quadrature components, then it's going to be better than just one of these. Try one of the phase-weighted averaging techniques from: http://www.itee.uq.edu.au/~kootsoop/freqalgs.htm The fundamental equation is (in matlabese) : omegahat = angle(sum([ signal(1:T-1,:).*conj(signal(3:T+1,:)) ].*WN)) / 2; where signal is your complex signal (of length T+1; INPHASE + j*QUADRATURE), WN is a window function (of length T-1) and omegahat is your frequency estimate. Ciao, Peter K. -- Peter J. Kootsookos "I will ignore all ideas for new works [..], the invention of which has reached its limits and for whose improvement I see no further hope." - Julius Frontinus, c. AD 84
Jerry Avins <jya@ieee.org> wrote in message news:<bpbnaa$i7c$1@bob.news.rcn.net>...
> Vladimir Vassilevsky wrote: > > > Clive, > > > > What you are trying to find are the A, w and fi parameters for the > > equation: > > A*exp(jwt + fi) > > which makes the best fit with your data. You can do it with > > autoregression. > > > > Vladimir Vassilevsky > > > > DSP and Mixed Signal Design Consultant > > > > http://www.abvolt.com > > It's not quite that simple. As given, the waveform can have harmonics. > > Jerry
If your signal is a pure sine wave (maybe noisy), then try to best-fit the equation as proposed by Vladimir. If your signal is periodic but has an unknown harmonic structure, then you need more than one period to determine the fundamental period of a signal. All of the conventional methods (correlation, spectrum, cepstrum-based etc.) used for detecting fundamental period of a signal require at least 2 complete periods to be included in the analysis window (Well, you can try to reduce your window size with cross-correlation, but this is not a way to go). The only method which can reliably get you the period (or its inverse &#4294967295; fundamental frequency) of a periodic signal using analysis window slightly longer than one complete period (at least for clean periodic signals) is the method based on signal embedding in multi-dimensional state space followed by a nearest-neighbor search. It was first presented at ICASSP last year. Go to http://www.soundmathtech.com/pitch Download the ICASSP 2002 paper and the Matlab demo. Although it may look complicated, in reality it is very simple and you can easily implement it for your purposes in about half an hour. Regards, Dmitry Terez SoundMath Technologies, LLC P.O. Box 846 Cherry Hill, NJ 08003 USA P.S. There are US and international patent applications filed on the new method. But as long as it is used for non-commercial purposes, there is no need to worry about obtaining a license.
Bretthorst treats this kind of problem, and since his main application
is NMR data, he discusses quadrature data directly.  It's in some
sense a least-squares approach, but a bit more sophisticated.  His
typical data sets have many periods, but if your S/N is very high
there is no reason why it can't work with just part of a period.
Check out his book and articles at http://bayes.wustl.edu/; you might
also consider emailing him via that site as he may have FORTRAN
code doing this that he'd be willing to share with you.  His approach
is optimal if a sum of a finite number of sinusoids and Gaussian
noise is a good model for your data.  If not, you'd have to tell us
more before a good answer could be offered.

-Tom

-- 

To respond by email, replace "somewhere" with "astro" in the
return address.
Many thanks for all the advice and suggestions, which I'll study and try
out in the future.  

I normally measure the period of the sinusoid by plotting, and measuring
the time between peaks or troughs.  Not very accurate, but adequate for
my purposes.  The limitation of this method is when the difference
between the peaks of in-phase and quadrature measurements exceeds the
total sample time, ie. whem I'm getting less than a quarter of a cycle. 
 

-- 
Regards     

	 Clive    G3CWV

         Hitchin, North Hertfordshire, UK.
Clive Wallis <clivew@zetnet.co.uk> wrote in message news:<2003111610211170399@zetnet.co.uk>...
> I have some experimental data for In-phase and quadrature signals. > Sometimes the data covers only half or less, of a full cycle. There are > usually about 100 - 140 equally spaced (in time) points, but a few > points are often missing. > > What technique can I use to calculate the fundamental frequency of the > sine wave? I would like to write a program, or use a spread sheet, > which ever is appropriate, or use an existing procedure. > > Any help would be appreciated.
Clive, You've left some parts of your problem, even in your response, unspecified. Do you know there is only a single sinusoid plus noise? Do you know which samples are missing? The easy way is to quadrature downconvert and then just do a delta theta/delta t computation, i.e., when you quaddownconvert you transform your real samples into complex samples, so just compute the angle of the complex values and take their difference. That result, along with the sample period, will give you radians/second. The only problem is that you will get jumps when a sample is "missing" (whatever that means) or when you cross the arctan boundary values. If you have some idea of the sine wave frequency, you can alleviate both these problems by checking against some maximum delta phase and correcting or throwing out. --Randy
The message <567ce618.0311201253.64b204fb@posting.google.com>
from yates@ieee.org (Randy Yates) contains these words:

> You've left some parts of your problem, even in your response, >unspecified. > Do you know there is only a single sinusoid plus noise? Do you know which > samples are missing?
There is only a single sinusoid. Signal to noise ratio is normally 10 dB or better. I know which samples are missing, the time interval between adjacent samples jumps by more than one unit.
> The easy way is to quadrature downconvert and then just do a delta > >theta/delta t > computation, i.e., when you quaddownconvert you transform your real >samples > into complex samples, so just compute the angle of the complex values and > take their difference. That result, along with the sample period, will > >give you radians/second.
Thanks Randy. I'll try that method. It looks quite easy to implement. -- Regards Clive G3CWV Hitchin, North Hertfordshire, UK.