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.

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.

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.

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.

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.

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.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

>>> 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.

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.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

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

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.

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.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

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.

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

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:

> 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.

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).

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.

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.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

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.

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.

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.