FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > DSP

DSP comp.dsp newsgroup, mailing list

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-04-2009, 05:09 PM
luben_i
Guest
 
Posts: n/a
Default How to measure phase difference between generated sine and the same one after delay

Hi all,

I am working with DSP of Texas Instruments on an evaluation bard
TMS320C6711. I have to generate a sine wave, send it to the output of the
board. Then this sine wave passes through a system where it is delayed and
distorted in some way, and then I have to measure the phase difference
between the original and the received signal. I have no problems with the
generation of the sine wave, but the problem is with the phase difference.
Tried with FFT transform, but nothing happened. The sine frequency can be
up to 4kHz.
If someone can help me I would appreciate it very much.

Thank you in advance.


Reply With Quote
  #2 (permalink)  
Old 02-04-2009, 09:57 PM
dbell
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

On Feb 4, 12:09*pm, "luben_i" <[email protected]> wrote:
> Hi all,
>
> I am working with DSP of Texas Instruments on an evaluation bard
> TMS320C6711. I have to generate a sine wave, send it to the output of the
> board. Then this sine wave passes through a system where it is delayed and
> distorted in some way, and then I have to measure the phase difference
> between the original and the received signal. I have no problems with the
> generation of the sine wave, but the problem is with the phase difference..
> Tried with FFT transform, but nothing happened. The sine frequency can be
> up to 4kHz.
> If someone can help me I would appreciate it very much.
>
> Thank you in advance.


What is the output sample rate?

Dirk
Reply With Quote
  #3 (permalink)  
Old 02-04-2009, 11:14 PM
robert bristow-johnson
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

On Feb 4, 2:41*pm, HardySpicer <[email protected]> wrote:
> On Feb 5, 7:12 am, robert bristow-johnson <[email protected]>
> wrote:
>
>
>

....
>
> > to do this analytically, in order to avoid quadrant ambiguity, you
> > need to either do a Hilbert Transform on the (delayed) sine you're
> > measuring, OR since you said you have no trouble generating sines, you
> > should generate two identical sinusoids, except one is 90 degrees
> > advanced over the other. *now only one of the sinusoids is being
> > outputted, but both sin() and cos() are available to you internally,
> > as well as the received (delayed) sinusoid.

....
>
> easier way is to use a PLL and integrate the output.
>


really Hardy? however luben is generating his driving sinusoid
(whether it's by LUT or with a critically-stable oscillator), it's
only a small software modification to generate the quadrature
sinusoid. the code to do a PLL is more. (a PLL has a servo-
controller inside and implementing one's own PLL in software, while
doable, sometimes is messy.) and i think the "integrate the output"
is not necessary. the cleanest phase-discriminator for this is a
single multiplier (there's a natural integrator put on the output of
this if it is input to a DCO or NCO) and then the PLL osc will settle
on being pi/2 outa phase with the sinusoid that it tracks.

but if you're already implementing the driving oscillator, it's little
extra effort to generate
a parallel quadrature sinusoidal output. the alg to multiply and LPF
the results isn't a
big deal and the arg{ p + j*q } isn't so hard either, if you have a
good approximation
to the arctan() function.

r b-j

Reply With Quote
  #4 (permalink)  
Old 02-05-2009, 12:06 AM
Vladimir Vassilevsky
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay



robert bristow-johnson wrote:


> since you said you have no trouble generating sines, you
> should generate two identical sinusoids, except one is 90 degrees
> advanced over the other.


It doesn't have to be 90 degrees. A reasonable phase shift or a delay
for a few samples would do; it is no brainer to convert it to whatever
form. The 90 degree requirement is just a mental block.

Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com


Reply With Quote
  #5 (permalink)  
Old 02-05-2009, 12:39 AM
robert bristow-johnson
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

On Feb 4, 7:06 pm, Vladimir Vassilevsky <[email protected]>
wrote:
> robert bristow-johnson wrote:
> > since you said you have no trouble generating sines, you
> > should generate two identical sinusoids, except one is 90 degrees
> > advanced over the other.

>
> It doesn't have to be 90 degrees. A reasonable phase shift or a delay
> for a few samples would do; it is no brainer to convert it to whatever
> form. The 90 degree requirement is just a mental block.


yeah, that's probably right. but it has to be a non-zero and non-180
phase offset. and it has to be known. then it's just an adjustment of
coefficients. i think 90 degree phase shift will result in the best S/
N regarding word quantization. if the two oscillators were 1 degree
outa phase, the p and q signals would be largely the same and the
difference would be small enough that the quantization on the p and q
words would effect that difference more than it would if they were 90
degrees outa phase.

but i hadn't considered before that the two reference oscillators
wouldn't have to be precisely quadrature.

r b-j
Reply With Quote
  #6 (permalink)  
Old 02-05-2009, 12:47 AM
Jerry Avins
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

Vladimir Vassilevsky wrote:
>
>
> robert bristow-johnson wrote:
>
>
>> since you said you have no trouble generating sines, you
>> should generate two identical sinusoids, except one is 90 degrees
>> advanced over the other.

>
> It doesn't have to be 90 degrees. A reasonable phase shift or a delay
> for a few samples would do; it is no brainer to convert it to whatever
> form. The 90 degree requirement is just a mental block.


Maybe so, but 90 degrees is easer to generate than most other angles.
When I want a single-phase oscillator, I generate the quadrature signal
and discard it. Its only use is amplitude control.

Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Reply With Quote
  #7 (permalink)  
Old 02-05-2009, 12:50 AM
Steve Pope
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

Jerry Avins <[email protected]> wrote:

>Vladimir Vassilevsky wrote:


>> robert bristow-johnson wrote:


>>> since you said you have no trouble generating sines, you
>>> should generate two identical sinusoids, except one is 90 degrees
>>> advanced over the other.


>> It doesn't have to be 90 degrees. A reasonable phase shift or a delay
>> for a few samples would do; it is no brainer to convert it to whatever
>> form. The 90 degree requirement is just a mental block.


>Maybe so, but 90 degrees is easer to generate than most other angles.
>When I want a single-phase oscillator, I generate the quadrature signal
>and discard it. Its only use is amplitude control.


I will offer the opinion that when an imperfect quadrature
signal is used in a mixer, you can take the mixer's output
and back out of it the desired result. However, your
result will be noisier.

Steve
Reply With Quote
  #8 (permalink)  
Old 02-05-2009, 01:07 AM
Jerry Avins
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

Steve Pope wrote:
> Jerry Avins <[email protected]> wrote:
>
>> Vladimir Vassilevsky wrote:

>
>>> robert bristow-johnson wrote:

>
>>>> since you said you have no trouble generating sines, you
>>>> should generate two identical sinusoids, except one is 90 degrees
>>>> advanced over the other.

>
>>> It doesn't have to be 90 degrees. A reasonable phase shift or a delay
>>> for a few samples would do; it is no brainer to convert it to whatever
>>> form. The 90 degree requirement is just a mental block.

>
>> Maybe so, but 90 degrees is easer to generate than most other angles.
>> When I want a single-phase oscillator, I generate the quadrature signal
>> and discard it. Its only use is amplitude control.

>
> I will offer the opinion that when an imperfect quadrature
> signal is used in a mixer, you can take the mixer's output
> and back out of it the desired result. However, your
> result will be noisier.


Sure. Just as a few degrees separation is enough but noisy, a few
degrees off quadrature degrades the result very little.

Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Reply With Quote
  #9 (permalink)  
Old 02-05-2009, 01:11 AM
HardySpicer
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

On Feb 5, 12:14 pm, robert bristow-johnson <[email protected]>
wrote:
> On Feb 4, 2:41 pm, HardySpicer <[email protected]> wrote:
>
>
>
> > On Feb 5, 7:12 am, robert bristow-johnson <[email protected]>
> > wrote:

>
> ...
>
> > > to do this analytically, in order to avoid quadrant ambiguity, you
> > > need to either do a Hilbert Transform on the (delayed) sine you're
> > > measuring, OR since you said you have no trouble generating sines, you
> > > should generate two identical sinusoids, except one is 90 degrees
> > > advanced over the other. now only one of the sinusoids is being
> > > outputted, but both sin() and cos() are available to you internally,
> > > as well as the received (delayed) sinusoid.

> ...
>
> > easier way is to use a PLL and integrate the output.

>
> really Hardy? however luben is generating his driving sinusoid
> (whether it's by LUT or with a critically-stable oscillator), it's
> only a small software modification to generate the quadrature
> sinusoid. the code to do a PLL is more. (a PLL has a servo-
> controller inside and implementing one's own PLL in software, while
> doable, sometimes is messy.) and i think the "integrate the output"
> is not necessary. the cleanest phase-discriminator for this is a
> single multiplier (there's a natural integrator put on the output of
> this if it is input to a DCO or NCO) and then the PLL osc will settle
> on being pi/2 outa phase with the sinusoid that it tracks.
>
> but if you're already implementing the driving oscillator, it's little
> extra effort to generate
> a parallel quadrature sinusoidal output. the alg to multiply and LPF
> the results isn't a
> big deal and the arg{ p + j*q } isn't so hard either, if you have a
> good approximation
> to the arctan() function.
>
> r b-j


I meant analogue!
Reply With Quote
  #10 (permalink)  
Old 02-05-2009, 01:16 AM
Vladimir Vassilevsky
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay



robert bristow-johnson wrote:
> On Feb 4, 7:06 pm, Vladimir Vassilevsky <[email protected]>
> wrote:
>
>>robert bristow-johnson wrote:
>>
>>>since you said you have no trouble generating sines, you
>>>should generate two identical sinusoids, except one is 90 degrees
>>>advanced over the other.

>>
>>It doesn't have to be 90 degrees. A reasonable phase shift or a delay
>>for a few samples would do; it is no brainer to convert it to whatever
>>form. The 90 degree requirement is just a mental block.

>
>
> yeah, that's probably right. but it has to be a non-zero and non-180
> phase offset. and it has to be known. then it's just an adjustment of
> coefficients. i think 90 degree phase shift will result in the best S/
> N regarding word quantization.


Generating one sinewave and then delaying it for few samples so the
phase shift is roughly 90 degrees (and then taking that into account) is
cheaper then generating sin() and cos() separately. If the delay has to
be long, then a two pole filter can be used instead.


Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com
Reply With Quote
  #11 (permalink)  
Old 02-05-2009, 01:58 AM
Jerry Avins
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

Vladimir Vassilevsky wrote:

...

> Generating one sinewave and then delaying it for few samples so the
> phase shift is roughly 90 degrees (and then taking that into account) is
> cheaper then generating sin() and cos() separately.


That depends on how the sinusoid is generated. Often the quadrature
signal is almost free.

...

Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Reply With Quote
  #12 (permalink)  
Old 02-05-2009, 02:05 AM
robert bristow-johnson
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

On Feb 4, 8:11*pm, HardySpicer <[email protected]> wrote:
>
> I meant analogue!


so wiring up parts to his TI eval board would be easier than writing
about 20 or 30 lines of code? i guess that's the difference between
hardware folk and guys like me that get our hands dirty less
enthusiastically. i thought that the OP basically has all the
hardware he needs.

whatever :-)

r b-j
Reply With Quote
  #13 (permalink)  
Old 02-05-2009, 02:20 AM
stevepierson
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

On Feb 4, 9:09 am, "luben_i" <[email protected]> wrote:
> Hi all,
>
> I am working with DSP of Texas Instruments on an evaluation bard
> TMS320C6711. I have to generate a sine wave, send it to the output of the
> board. Then this sine wave passes through a system where it is delayed and
> distorted in some way, and then I have to measure the phase difference
> between the original and the received signal. I have no problems with the
> generation of the sine wave, but the problem is with the phase difference.
> Tried with FFT transform, but nothing happened. The sine frequency can be
> up to 4kHz.
> If someone can help me I would appreciate it very much.
>
> Thank you in advance.


FFT will most definitely work if you can keep the generated sine wave
bin centered (i.e., the FFT will be taken with a integer number of
sine waves), which should be easy if you are generating it, then
sample both waveforms at the same time, then look at the complex bin
of both FFT's at the frequecy of the input sine wave, if the input is
(x1,y1) and the output is (x2,y2), the phase is

angle = atan2(x1*y2-x2*y1,x1*x2+y1*y2)

let me know if you need any more clarification

Reply With Quote
  #14 (permalink)  
Old 02-05-2009, 02:49 AM
glen herrmannsfeldt
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and the ?same one after delay

robert bristow-johnson <[email protected]> wrote:
> On Feb 4, 12:09?pm, "luben_i" <[email protected]> wrote:
>
>> I am working with DSP of Texas Instruments on an evaluation bard
>> TMS320C6711. I have to generate a sine wave, send it to the output of the
>> board. Then this sine wave passes through a system where it is delayed and
>> distorted in some way, and then I have to measure the phase difference

(snip)

> measuring, OR since you said you have no trouble generating sines, you
> should generate two identical sinusoids, except one is 90 degrees
> advanced over the other. now only one of the sinusoids is being
> outputted, but both sin() and cos() are available to you internally,
> as well as the received (delayed) sinusoid.


> let's say that you output the cos() signal to the delay element:


> x[n] = cos(w*n )


> the delay element returns:


> y[n] = A*cos(w*n + phi) + noise


> and it's phi that you want to determine.


> consider


> p[n] = y[n] * cos(w*n)
> and
> q[n] = y[n] * sin(w*n)


> then consider what you get when you identically lowpass filter both p
> [n] and q[n] to the point that only the DC components of each
> survives. then consider those two DC residuals as the real and
> imaginary parts of a complex number. then compute the angle of that
> complex number.


I was about to write something similar, but then decided to see
what the other replies were. There are analog multiplier ICs
which take two voltages in and generate an output proportional
to the product. I believe there are also analog ATAN generators
to give you the actual phase angle, but that could also be
done after digitizing.

-- glen
Reply With Quote
  #15 (permalink)  
Old 02-05-2009, 08:06 PM
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

On Feb 4, 8:58 pm, Jerry Avins <[email protected]> wrote:
> Vladimir Vassilevsky wrote:
>
> ...
>
> > Generating one sinewave and then delaying it for few samples so the
> > phase shift is roughly 90 degrees (and then taking that into account) is
> > cheaper then generating sin() and cos() separately.

>
> That depends on how the sinusoid is generated. Often the quadrature
> signal is almost free.
>
> ...
>
> Jerry
> --
> Engineering is the art of making what you want from things you can get.
> ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ


The sin and cos multiplication is okay if you have a fixed phase
offset. However, the whole approach naturally complicates itself into
a "simple" PLL solution to track any time varying phase offset within
the relevant MTIE envelop (G.812).
Reply With Quote
  #16 (permalink)  
Old 02-05-2009, 08:28 PM
robert bristow-johnson
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

On Feb 5, 3:06*pm, [email protected] wrote:
>
> The sin and cos multiplication *is okay if you have a fixed phase
> offset.


or "slowly varying" phase offset. if the phase offset is wild, this
is not a case of driving an LTI system with a sinusoid and measuring
properties of the output sinusoid. it's not TI. if the phase offset
is increasing linearly with time, the system is actually changing the
frequency. if this phase variation is sufficiently slow (it doesn't
have to be fixed to a constant), and the LPF filters are a little less
slow in their response, you can track it. and it's not a PLL (no
feedback servo mechanism).

> However, the whole approach naturally complicates itself into
> a "simple" PLL solution to track any time varying phase offset within
> the relevant MTIE envelop (G.812).


dunno what either MTIE or G.812 is. i s'pose i could google it.

r b-j
Reply With Quote
  #17 (permalink)  
Old 02-05-2009, 08:41 PM
Jerry Avins
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

[email protected] wrote:
> On Feb 4, 8:58 pm, Jerry Avins <[email protected]> wrote:
>> Vladimir Vassilevsky wrote:
>>
>> ...
>>
>>> Generating one sinewave and then delaying it for few samples so the
>>> phase shift is roughly 90 degrees (and then taking that into account) is
>>> cheaper then generating sin() and cos() separately.

>> That depends on how the sinusoid is generated. Often the quadrature
>> signal is almost free.


...

> The sin and cos multiplication is okay if you have a fixed phase
> offset. However, the whole approach naturally complicates itself into
> a "simple" PLL solution to track any time varying phase offset within
> the relevant MTIE envelop (G.812).


The OP wants to measure the signal's delay through an LTI network. Where
might time varying phase offset arise?

Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Reply With Quote
  #18 (permalink)  
Old 02-06-2009, 05:50 AM
steveu
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and the same one after delay

>On Feb 4, 8:58 pm, Jerry Avins <[email protected]> wrote:
>> Vladimir Vassilevsky wrote:
>>
>> ...
>>
>> > Generating one sinewave and then delaying it for few samples so the
>> > phase shift is roughly 90 degrees (and then taking that into account

i=
>s
>> > cheaper then generating sin() and cos() separately.

>>
>> That depends on how the sinusoid is generated. Often the quadrature
>> signal is almost free.
>>
>> ...
>>
>> Jerry
>> --
>> Engineering is the art of making what you want from things you ca

get.
>

=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=A F=AF=AF=AF=AF=AF=AF=AF=
>=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= AF=AF=AF=AF=AF=AF=AF=AF=AF=
>=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF=AF= AF=AF=AF=AF=AF=AF
>
>The sin and cos multiplication is okay if you have a fixed phase
>offset. However, the whole approach naturally complicates itself into
>a "simple" PLL solution to track any time varying phase offset within
>the relevant MTIE envelop (G.812).


G.812 relates to synchronisation to a remote source in a PCM network. Th
OP appears to be sending something out, and looking at the phase shif
(i.e. delay) in what comes back. He has no reason to use a PLL to recove
the source clock. He *has* the source clock.

Steve

Reply With Quote
  #19 (permalink)  
Old 02-06-2009, 09:34 AM
luben_i
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and the same one after delay

Thank you for your advices. I decided to make a cross-correlation betwee
the output and the input signal and calculate the delay in samples betwee
the two signals. And then having in mind the sampling frequency and th
number of samples the phase difference is easy to find.

Luben.
Reply With Quote
  #20 (permalink)  
Old 02-06-2009, 07:23 PM
robert bristow-johnson
Guest
 
Posts: n/a
Default Re: How to measure phase difference between generated sine and thesame one after delay

On Feb 6, 4:34*am, "luben_i" <[email protected]> wrote:
> Thank you for your advices. I decided to make a cross-correlation between
> the output and the input signal and calculate the delay in samples between
> the two signals. And then having in mind the sampling frequency and the
> number of samples the phase difference is easy to find.


if you don't know, a priori, what quadrants can be ruled out, you must
cross-correlate the output to the input *and* you must cross-correlate
the output to a known phase-shifted version of the input (likely 90
degrees offset). you must do both cross correlations otherwize you
will not know the difference between a phase difference of phi from -
phi (or 360-phi). if it's only the input to output correlation, both
phi and -phi result in the same cross correlation.

r b-j
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How to measure phase difference between generated sine and thesame one after delay robert bristow-johnson DSP 2 02-04-2009 07:41 PM
Re: How to measure phase difference between generated sine and thesame one after delay Jerry Avins DSP 0 02-04-2009 05:45 PM
Re: How to measure phase difference between generated sine and thesame one after delay Rune Allnor DSP 0 02-04-2009 05:14 PM
time difference between two acoustic sine waves rashdk DSP 24 12-03-2007 03:32 PM
Undersampling to measure phase. Dr. David Kirkby DSP 13 09-28-2004 09:13 PM


All times are GMT +1. The time now is 04:18 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved