I have a sine wave sampled at 16 samples per cycle, and a total of (approximately) 8 cycles, although where the data starts and stops with respect to the phase of the sine waves is not determined. Amplitude is reasonably constant. Resolution is around 10 bits. I need to generate an equation from that data to enable me to calculate a zero crossing point to an accuracy of better than one sample period.
Sine wave samples to sine wave equation
Started by ●September 29, 2014
Reply by ●September 29, 20142014-09-29
On 9/29/14 9:22 AM, Dirk Bruere at NeoPax wrote:> I have a sine wave sampled at 16 samples per cycle, and a total of (approximately) 8 cycles, although where the data starts and stops with respect to the phase of the sine waves is not determined.so you're confident that the sampling of the sine wave is precisely synchronized to the frequency of the sine? exactly 16 samples per cycle? if that's the case and frequency is not an issue, there is a least-squares fit formula that's pretty good. i'll have to scrape it up. i might have to re-derive it.> Amplitude is reasonably constant. Resolution is around 10 bits. > > I need to generate an equation from that data to enable me to calculate a zero crossing point to an accuracy of better than one sample period.if the frequency is known, then get the amplitude and phase and zero-crossings will come out of that. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●September 29, 20142014-09-29
On Monday, September 29, 2014 2:38:07 PM UTC+1, robert bristow-johnson wrote:> On 9/29/14 9:22 AM, Dirk Bruere at NeoPax wrote: > > > I have a sine wave sampled at 16 samples per cycle, and a total of (approximately) 8 cycles, although where the data starts and stops with respect to the phase of the sine waves is not determined. > > > > so you're confident that the sampling of the sine wave is precisely > > synchronized to the frequency of the sine? exactly 16 samples per > > cycle?Unfortunately not. It is almost certainly 16 samples +/- 1 sample. The actual figures are a frequency, fixed at between 120kHz and 130kHz, and a sample rate of 2 MSPS
Reply by ●September 29, 20142014-09-29
On 9/29/14 9:38 AM, robert bristow-johnson wrote:> On 9/29/14 9:22 AM, Dirk Bruere at NeoPax wrote: >> I have a sine wave sampled at 16 samples per cycle, and a total of >> (approximately) 8 cycles, although where the data starts and stops >> with respect to the phase of the sine waves is not determined. > > so you're confident that the sampling of the sine wave is precisely > synchronized to the frequency of the sine? exactly 16 samples per cycle? > if that's the case and frequency is not an issue, there is a > least-squares fit formula that's pretty good. i'll have to scrape it up. > i might have to re-derive it. >well, it's obvious. it's the same as the discrete Fourier series. let N be the number of samples for one cycle. in your case it's N=16. so your N samples are x[0], x[1], x[2], ... x[N-1] N-1 let a_k = 2/N SUM{ x[n] cos(2 pi k n/N) } n=0 N-1 and b_k = 2/N SUM{ x[n] sin(2 pi k n/N) } n=0 in your case k=1 . then, the continuous-time x(t) (where t is defined in between integer values) is N/2 x(t) = SUM{ a_k cos(2 pi k t/N) + b_k sin(2 pi k t/N) } k=1 but in your case, all a_k and b_k are zero except for k=1, so x(t) = a_1 cos(2 pi t/N) + b_1 sin(2 pi t/N) = sqrt{a_1^2 + b_1^2} cos(2 pi t/N + phi_1) where phi_1 = arg{ a_1 - j*b_1 }>> Amplitude is reasonably constant. Resolution is around 10 bits. >> >> I need to generate an equation from that data to enable me to >> calculate a zero crossing point to an accuracy of better than one >> sample period. > > if the frequency is known, then get the amplitude and phase and > zero-crossings will come out of that.the zero crossings will occur when the argument of the cosine are pi/2 or 3pi/2 or when 2 pi t/N + phi_1 = pi/2 or 2 pi t/N + phi_1 = 3 pi/2 solve for t. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●September 29, 20142014-09-29
On 9/29/14 9:45 AM, Dirk Bruere at NeoPax wrote:> On Monday, September 29, 2014 2:38:07 PM UTC+1, robert bristow-johnson wrote: >> On 9/29/14 9:22 AM, Dirk Bruere at NeoPax wrote: >> >>> I have a sine wave sampled at 16 samples per cycle, and a total of (approximately) 8 cycles, although where the data starts and stops with respect to the phase of the sine waves is not determined. >> >> >> >> so you're confident that the sampling of the sine wave is precisely >> >> synchronized to the frequency of the sine? exactly 16 samples per >> >> cycle? > > Unfortunately not. It is almost certainly 16 samples +/- 1 sample. > The actual figures are a frequency, fixed at between 120kHz and 130kHz, and a sample rate of 2 MSPSoh, crap. i just spelled out an answer based on that assumption. okay, *first* you have to do some frequency estimation. if what you really want are the zero-crossings (are you using *that* to determine frequency or do you actually not care so much what the frequency is and you just want the zero-crossings?) maybe you should just interpolate between points with something better than linear interpolation (like Hermite polynomials, which lately i have heard are called "bicubic splines" by the image-processing folk). but getting a closed-form zero crossing from that might be icky. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Reply by ●September 29, 20142014-09-29
On Mon, 29 Sep 2014 06:45:47 -0700, Dirk Bruere at NeoPax wrote:> On Monday, September 29, 2014 2:38:07 PM UTC+1, robert bristow-johnson > wrote: >> On 9/29/14 9:22 AM, Dirk Bruere at NeoPax wrote: >> >> > I have a sine wave sampled at 16 samples per cycle, and a total of >> > (approximately) 8 cycles, although where the data starts and stops >> > with respect to the phase of the sine waves is not determined. >> >> >> >> so you're confident that the sampling of the sine wave is precisely >> >> synchronized to the frequency of the sine? exactly 16 samples per >> >> cycle? > > Unfortunately not. It is almost certainly 16 samples +/- 1 sample. > The actual figures are a frequency, fixed at between 120kHz and 130kHz, > and a sample rate of 2 MSPSAccuracy? Noise? Cost concerns? Time available for the estimate? I'd be tempted to do an iterative best fit for frequency, amplitude, offset and phase. Then find the zero crossings from that. But it's computationally intensive, and possibly subject to false maxima (maybe not given the duration of your sample vector and your frequency limits -- but I'm not awake yet!) You could also consider using RBJ's Fourier technique to get the phase of the first 8 samples and the last 8 samples assuming 125kHz (I think that works out to two cycles in 8 samples). Then use your two phases to determine phase and frequency, then use that to determine zero crossings. You'd want to do some simulation to make sure it's reliable and not too susceptible to noise, however. -- www.wescottdesign.com
Reply by ●September 29, 20142014-09-29
On Monday, September 29, 2014 3:47:46 PM UTC+1, tim wrote:> On Mon, 29 Sep 2014 06:45:47 -0700, Dirk Bruere at NeoPax wrote: > > > > > On Monday, September 29, 2014 2:38:07 PM UTC+1, robert bristow-johnson > > > wrote: > > >> On 9/29/14 9:22 AM, Dirk Bruere at NeoPax wrote: > > >> > > >> > I have a sine wave sampled at 16 samples per cycle, and a total of > > >> > (approximately) 8 cycles, although where the data starts and stops > > >> > with respect to the phase of the sine waves is not determined. > > >> > > >> > > >> > > >> so you're confident that the sampling of the sine wave is precisely > > >> > > >> synchronized to the frequency of the sine? exactly 16 samples per > > >> > > >> cycle? > > > > > > Unfortunately not. It is almost certainly 16 samples +/- 1 sample. > > > The actual figures are a frequency, fixed at between 120kHz and 130kHz, > > > and a sample rate of 2 MSPS > > > > Accuracy? Noise? Cost concerns? Time available for the estimate?The accuracy is to be the maximum I can squeeze out of approx 128 samples in less than 5mS using a STM32F303x with DSP extensions running at 72MHz The noise is unknown, but probably less than 5% of signal amplitude. No cost concerns because h/w already exists and this is a s/w problem> I'd be tempted to do an iterative best fit for frequency, amplitude, > > offset and phase. Then find the zero crossings from that. But it's > > computationally intensive, and possibly subject to false maxima (maybe > > not given the duration of your sample vector and your frequency limits -- > > but I'm not awake yet!) > > > > You could also consider using RBJ's Fourier technique to get the phase of > > the first 8 samples and the last 8 samples assuming 125kHz (I think that > > works out to two cycles in 8 samples). Then use your two phases to > > determine phase and frequency, then use that to determine zero crossings.The frequency, although fixed for the duration of the sampling and known approximately, may vary slightly depending on transducers.> > > You'd want to do some simulation to make sure it's reliable and not too > > susceptible to noise, however. > > > > -- > > www.wescottdesign.comDirk
Reply by ●September 29, 20142014-09-29
>I have a sine wave sampled at 16 samples per cycle, and a total of(approxi=>mately) 8 cycles, although where the data starts and stops with respect to=>the phase of the sine waves is not determined. Amplitude is reasonablycons=>tant. Resolution is around 10 bits. > >I need to generate an equation from that data to enable me to calculate az=>ero crossing point to an accuracy of better than one sample period. >How about calculating the phase of each sample, then unwrap the phases, then do a linear least squares fit. Then you can interpolate this line to get the time-point of the zero crossing. -Doug _____________________________ Posted through www.DSPRelated.com
Reply by ●September 29, 20142014-09-29
On Mon, 29 Sep 2014 09:47:46 -0500, tim wrote:> On Mon, 29 Sep 2014 06:45:47 -0700, Dirk Bruere at NeoPax wrote: > >> On Monday, September 29, 2014 2:38:07 PM UTC+1, robert bristow-johnson >> wrote: >>> On 9/29/14 9:22 AM, Dirk Bruere at NeoPax wrote: >>> >>> > I have a sine wave sampled at 16 samples per cycle, and a total of >>> > (approximately) 8 cycles, although where the data starts and stops >>> > with respect to the phase of the sine waves is not determined. >>> >>> >>> >>> so you're confident that the sampling of the sine wave is precisely >>> >>> synchronized to the frequency of the sine? exactly 16 samples per >>> >>> cycle? >> >> Unfortunately not. It is almost certainly 16 samples +/- 1 sample. >> The actual figures are a frequency, fixed at between 120kHz and 130kHz, >> and a sample rate of 2 MSPS > > Accuracy? Noise? Cost concerns? Time available for the estimate? > > I'd be tempted to do an iterative best fit for frequency, amplitude, > offset and phase. Then find the zero crossings from that. But it's > computationally intensive, and possibly subject to false maxima (maybe > not given the duration of your sample vector and your frequency limits > -- > but I'm not awake yet!) > > You could also consider using RBJ's Fourier technique to get the phase > of the first 8 samples and the last 8 samples assuming 125kHz (I think > that works out to two cycles in 8 samples). Then use your two phases to > determine phase and frequency, then use that to determine zero > crossings. > > You'd want to do some simulation to make sure it's reliable and not too > susceptible to noise, however.Whoops -- I was thinking that you were getting two full cycles of your nominal center frequency in your 16 samples, not one. Unless you want to deal with all sorts of oddball end effects, you really want to do your 1- bin DFT over an integer number of cycles. Does the sensor turn on and off? How stable is its frequency when it's on? If it stays on, and if its frequency does not vary much from cycle to cycle, and if you can stand some latency before the synchronization is good, you could use a PLL. If you need to acquire phase quickly, there's things you could do (too complex to describe if you're not going to do it, but I can go there if you want). -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Reply by ●September 29, 20142014-09-29
On Monday, September 29, 2014 9:22:24 AM UTC-4, Dirk Bruere at NeoPax wrote:> I have a sine wave sampled at 16 samples per cycle, and a total of (approximately) 8 cycles, although where the data starts and stops with respect to the phase of the sine waves is not determined. Amplitude is reasonably constant. Resolution is around 10 bits. I need to generate an equation from that data to enable me to calculate a zero crossing point to an accuracy of better than one sample period.Dude, You need to determine your signal's frequency (actually, period) with sub-sample resolution first... Then you can do (e.g. least-squares) best-fit to internally generated oversampled sine wave with same exact frequency and amplitude Then you get your zero-crossings etc. And the only thing you can assume to know more or less precisely is your sampling rate - the rest are variables to be determined






