PDA

View Full Version : 90 deg phase shift - do I need a hiltert transform?


Dave
02-24-2005, 06:01 PM
I'm trying to design something in which data is collected from a dual
channel A/D. If the inputs are x and y, I need to get a 90 degree phase
shift of x, then multiply it by y.

x and y will both contain data points which should in principle be sine
waves (ignoring noise), since the A/D will be sampling sine waves. The
frequency is known to a high degree of accuracy.

One option (I think) is to work out how many samples collected in a
buffer constitute 90 degrees, ignore them, then do a multiply of the
rest. So if 1000 samples makes up a full wave, then 250 will make up a
quarter wave, so I should compute the output A as

A1=x[250]*y[1]
A2=x[251]*y[2]
A3=x[253]*y[3] etc

But if the frequency was not known (which I admit it is in my case),
that would be impossible.

My understanding is that the Hilbert transform of a sine wave gives a
cosine wave, and so doing a Hilbert transform will work. But when I use
Matlab to compute the Hilbert transform of a set of real numbers, the
result becomes complex.

Now I know imaginary numbers are used to represent phase angle. So I'm a
bit confused here. Two methods

* ignore data for a quarter wave, then do real multiples
* use all the data, performing a Hilbert transform on one

would seem to give very different answers.

Can anyone clarify where my logic is breaking down, since clearly
something is very wrong with my thinking?

Richard Webb
02-24-2005, 07:06 PM
"Dave" <[email protected]> wrote in message news:[email protected]...
> I'm trying to design something in which data is collected from a dual
> channel A/D. If the inputs are x and y, I need to get a 90 degree phase
> shift of x, then multiply it by y.
>
> x and y will both contain data points which should in principle be sine
> waves (ignoring noise), since the A/D will be sampling sine waves. The
> frequency is known to a high degree of accuracy.
>
> One option (I think) is to work out how many samples collected in a
> buffer constitute 90 degrees, ignore them, then do a multiply of the
> rest. So if 1000 samples makes up a full wave, then 250 will make up a
> quarter wave, so I should compute the output A as
>
> A1=x[250]*y[1]
> A2=x[251]*y[2]
> A3=x[253]*y[3] etc
>
> But if the frequency was not known (which I admit it is in my case),
> that would be impossible.
>
> My understanding is that the Hilbert transform of a sine wave gives a
> cosine wave, and so doing a Hilbert transform will work. But when I use
> Matlab to compute the Hilbert transform of a set of real numbers, the
> result becomes complex.
>
> Now I know imaginary numbers are used to represent phase angle. So I'm a
> bit confused here. Two methods
>
> * ignore data for a quarter wave, then do real multiples
> * use all the data, performing a Hilbert transform on one
>
> would seem to give very different answers.
>
> Can anyone clarify where my logic is breaking down, since clearly
> something is very wrong with my thinking?
>
>
>

You are correct, the Hilbert transform will give you a 90 degree phase shift
.... well almost! How close to 90 degrees you get depends on how you
implement your hilbert transform. The most common and simplest method is to
use a FIR filter, but of course the number of taps you use will have a
direct result on your filters performance, and this depends on how much
processing power you've got available. When you design your filter you can
design it such that you get better phase shift performance at the expense of
magnitude ripple, or you can flatten out the magnitude response with less
accuracy in your phase shift.

Using the 'hilbert' command in Matlab does indeed give you a complex output,
and correcty so. The output of the hilbert command is an in-phase (real) and
quadrature (imag) channel. The real part is your input and the imag part is
the 90 degree shifted version of your input.

Rich.

Allan Herriman
02-24-2005, 07:10 PM
On Thu, 24 Feb 2005 18:01:05 +0000, Dave <[email protected]> wrote:

>I'm trying to design something in which data is collected from a dual
>channel A/D. If the inputs are x and y, I need to get a 90 degree phase
>shift of x, then multiply it by y.
>
>x and y will both contain data points which should in principle be sine
>waves (ignoring noise), since the A/D will be sampling sine waves. The
>frequency is known to a high degree of accuracy.

If these are sine waves of known frequency, then a 90 degree phase
shift is simply a delay. Is there any reason why a delay isn't
suitable?

(Note that the delay may not be an integer number of samples.)

Regards,
Allan

Dave
02-24-2005, 08:42 PM
Allan Herriman wrote:
> On Thu, 24 Feb 2005 18:01:05 +0000, Dave <[email protected]> wrote:
>
>
>>I'm trying to design something in which data is collected from a dual
>>channel A/D. If the inputs are x and y, I need to get a 90 degree phase
>>shift of x, then multiply it by y.
>>
>>x and y will both contain data points which should in principle be sine
>>waves (ignoring noise), since the A/D will be sampling sine waves. The
>>frequency is known to a high degree of accuracy.
>
>
> If these are sine waves of known frequency, then a 90 degree phase
> shift is simply a delay. Is there any reason why a delay isn't
> suitable?
>
> (Note that the delay may not be an integer number of samples.)
>
> Regards,
> Allan
I wanted to do this as generic as possible, as in principle at least the
system could work at any frequency, so whilst around 70MHz was
anticipated as being what would be used, the optimal might have been a
big higher - perhaps to 100MHz. As such, doing this with a Hilbert
Transform seemed more logical. I'd rather let the frequency of operation
be set by the hardware, and leave the software to work at any frequency.

The design has changed a bit now, and a narrow band (< 0.3MHz ) crystal
filter added. As such, the simple delay is now possible, which is what my

A1=x[250]*y[1]
A2=x[251]*y[2]
A3=x[253]*y[3] etc

would do. So this is more of academic interest than practical, although
if it was possible to do it well using a Hilbert Transform, I would
still rather take that route, since its possible someone else might want
to implement this, and using fixed delays could be a pain.

Mike Yarwood
02-24-2005, 08:59 PM
"Allan Herriman" <[email protected]> wrote in
message news:[email protected]...
> On Thu, 24 Feb 2005 18:01:05 +0000, Dave <[email protected]> wrote:
>
>>I'm trying to design something in which data is collected from a dual
>>channel A/D. If the inputs are x and y, I need to get a 90 degree phase
>>shift of x, then multiply it by y.
>>
>>x and y will both contain data points which should in principle be sine
>>waves (ignoring noise), since the A/D will be sampling sine waves. The
>>frequency is known to a high degree of accuracy.
>
> If these are sine waves of known frequency, then a 90 degree phase
> shift is simply a delay. Is there any reason why a delay isn't
> suitable?
>
> (Note that the delay may not be an integer number of samples.)
>
> Regards,
> Allan
Hi Dave : you could also just use the scaled difference on the channel you
want to phase shift - it's close to differentiating your sinewave so you
ought to get something close to cosine (or -cosine - I can never remember).
Best of Luck - Mike

john
02-24-2005, 09:09 PM
Richard Webb wrote:
> "Dave" <[email protected]> wrote in message
news:[email protected]...
> > I'm trying to design something in which data is collected from a
dual
> > channel A/D. If the inputs are x and y, I need to get a 90 degree
phase
> > shift of x, then multiply it by y.
> >
> > x and y will both contain data points which should in principle be
sine
> > waves (ignoring noise), since the A/D will be sampling sine waves.
The
> > frequency is known to a high degree of accuracy.
> >
> > One option (I think) is to work out how many samples collected in a
> > buffer constitute 90 degrees, ignore them, then do a multiply of
the
> > rest. So if 1000 samples makes up a full wave, then 250 will make
up a
> > quarter wave, so I should compute the output A as
> >
> > A1=x[250]*y[1]
> > A2=x[251]*y[2]
> > A3=x[253]*y[3] etc
> >
> > But if the frequency was not known (which I admit it is in my
case),
> > that would be impossible.
> >
> > My understanding is that the Hilbert transform of a sine wave gives
a
> > cosine wave, and so doing a Hilbert transform will work. But when I
use
> > Matlab to compute the Hilbert transform of a set of real numbers,
the
> > result becomes complex.
> >
> > Now I know imaginary numbers are used to represent phase angle. So
I'm a
> > bit confused here. Two methods
> >
> > * ignore data for a quarter wave, then do real multiples
> > * use all the data, performing a Hilbert transform on one
> >
> > would seem to give very different answers.
> >
> > Can anyone clarify where my logic is breaking down, since clearly
> > something is very wrong with my thinking?
> >
> >
> >
>
> You are correct, the Hilbert transform will give you a 90 degree
phase shift
> ... well almost! How close to 90 degrees you get depends on how you
> implement your hilbert transform. The most common and simplest method
is to
> use a FIR filter, but of course the number of taps you use will have
a
> direct result on your filters performance, and this depends on how
much
> processing power you've got available. When you design your filter
you can
> design it such that you get better phase shift performance at the
expense of
> magnitude ripple, or you can flatten out the magnitude response with
less
> accuracy in your phase shift.
>
> Using the 'hilbert' command in Matlab does indeed give you a complex
output,
> and correcty so. The output of the hilbert command is an in-phase
(real) and
> quadrature (imag) channel. The real part is your input and the imag
part is
> the 90 degree shifted version of your input.
>
> Rich.

Note that in a real time implementation you will have to delay one
channel to match the filtered channel in time.

John

Jerry Avins
02-24-2005, 10:05 PM
Dave wrote:
> Allan Herriman wrote:
>
>> On Thu, 24 Feb 2005 18:01:05 +0000, Dave <[email protected]> wrote:
>>
>>
>>> I'm trying to design something in which data is collected from a dual
>>> channel A/D. If the inputs are x and y, I need to get a 90 degree
>>> phase shift of x, then multiply it by y.
>>>
>>> x and y will both contain data points which should in principle be
>>> sine waves (ignoring noise), since the A/D will be sampling sine
>>> waves. The frequency is known to a high degree of accuracy.
>>
>>
>>
>> If these are sine waves of known frequency, then a 90 degree phase
>> shift is simply a delay. Is there any reason why a delay isn't
>> suitable?
>>
>> (Note that the delay may not be an integer number of samples.)
>>
>> Regards,
>> Allan
>
> I wanted to do this as generic as possible, as in principle at least the
> system could work at any frequency, so whilst around 70MHz was
> anticipated as being what would be used, the optimal might have been a
> big higher - perhaps to 100MHz. As such, doing this with a Hilbert
> Transform seemed more logical. I'd rather let the frequency of operation
> be set by the hardware, and leave the software to work at any frequency.
>
> The design has changed a bit now, and a narrow band (< 0.3MHz ) crystal
> filter added. As such, the simple delay is now possible, which is what my
>
> A1=x[250]*y[1]
> A2=x[251]*y[2]
> A3=x[253]*y[3] etc
>
> would do. So this is more of academic interest than practical, although
> if it was possible to do it well using a Hilbert Transform, I would
> still rather take that route, since its possible someone else might want
> to implement this, and using fixed delays could be a pain.

A Hilbert transform is expensive to compute. A somewhat less expensive
alternative that is sometimes acceptable is a pair of filters whose
outputs are 90 degrees apart but bear no simple relation to their common
input.

Jerry
--
Engineering is the art of making what you want from things you can get.
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

Dave
02-24-2005, 10:37 PM
Richard Webb wrote:
> "Dave" <[email protected]> wrote in message news:[email protected]...
>
>>I'm trying to design something in which data is collected from a dual
>>channel A/D. If the inputs are x and y, I need to get a 90 degree phase
>>shift of x, then multiply it by y.
>>
>>x and y will both contain data points which should in principle be sine
>>waves (ignoring noise), since the A/D will be sampling sine waves. The
>>frequency is known to a high degree of accuracy.
>>
>>One option (I think) is to work out how many samples collected in a
>>buffer constitute 90 degrees, ignore them, then do a multiply of the
>>rest. So if 1000 samples makes up a full wave, then 250 will make up a
>>quarter wave, so I should compute the output A as
>>
>>A1=x[250]*y[1]
>>A2=x[251]*y[2]
>>A3=x[253]*y[3] etc
>>
>>But if the frequency was not known (which I admit it is in my case),
>>that would be impossible.
>>
>>My understanding is that the Hilbert transform of a sine wave gives a
>>cosine wave, and so doing a Hilbert transform will work. But when I use
>>Matlab to compute the Hilbert transform of a set of real numbers, the
>>result becomes complex.
>>
>>Now I know imaginary numbers are used to represent phase angle. So I'm a
>>bit confused here. Two methods
>>
>>* ignore data for a quarter wave, then do real multiples
>>* use all the data, performing a Hilbert transform on one
>>
>>would seem to give very different answers.
>>
>>Can anyone clarify where my logic is breaking down, since clearly
>>something is very wrong with my thinking?
>>
>>
>>
>
>
> You are correct, the Hilbert transform will give you a 90 degree phase shift
> ... well almost! How close to 90 degrees you get depends on how you
> implement your hilbert transform. The most common and simplest method is to
> use a FIR filter, but of course the number of taps you use will have a
> direct result on your filters performance, and this depends on how much
> processing power you've got available. When you design your filter you can
> design it such that you get better phase shift performance at the expense of
> magnitude ripple, or you can flatten out the magnitude response with less
> accuracy in your phase shift.
>
> Using the 'hilbert' command in Matlab does indeed give you a complex output,
> and correcty so. The output of the hilbert command is an in-phase (real) and
> quadrature (imag) channel. The real part is your input and the imag part is
> the 90 degree shifted version of your input.
>
> Rich.
>
>
Cheers, that makes more sense now. I had not realised that the Hilbert
Transform gave the real and complex outputs - I assumed it output real
data, the meaning of which was the phase-shifted version of the input.

Once I understood that, I played around in Matlab and soon see the
Hilbert Transform, whilst giving pretty close to a 90 deg shifted
version, is far from perfect, whereas if I do implement this with a
delay, I can do (in principle at least) obtain a perfect 90 deg shifted
version of the input.


Hence I think I'll use a simple delay, and assume I know the input
frequency, which will actually be true now, although it was not in stone
when I started the project.

Clay
02-25-2005, 02:19 PM
> >
> > Using the 'hilbert' command in Matlab does indeed give you a
complex output,
> > and correcty so. The output of the hilbert command is an in-phase
(real) and
> > quadrature (imag) channel. The real part is your input and the imag
part is
> > the 90 degree shifted version of your input.
> >
> > Rich.
> >
> >
> Cheers, that makes more sense now. I had not realised that the
Hilbert
> Transform gave the real and complex outputs - I assumed it output
real
> data, the meaning of which was the phase-shifted version of the
input.
>

Hello Guys,
What you are describing here is related to the Hilbert transform. A
Hilbert transform of a real sequence is real. It sounds like Matlab is
actually making an analytic signal. An analytic signal has as it
imaginary part the Hilbert transform of the real part. So to be
technically correct, the description of Matlab's "Hilbert" function
actually performs an analytic extension of a function.

Just my 2 cent worth.

Now for the original problem. What rang of frequencies do you need this
phase over? If it is not large and you are staying away from very low
frequencies, a simple Hilbert transformer may be quite effecient.

Clay