From: Stephen on
I am working with an eZdsp board and programming the board
with Simulink. I would like to implement the following in
Simulink.

Currently, I am inputting three 60Hz sinusoidal waveforms
(possibly with harmonics, but ideally these will be 60-Hz)
to the ADC (these do not correspond to three-phase voltages
from a power system, they do not have a 120 degree phase
difference). I need to use Simulink to determine the
magnitude and phase of the waveforms relative to each other.

Any help or insight in this area will be greatly appreciated.
From: Andy Robb on
"Stephen " <masterofpupets(a)drexel.edu> wrote in message
<fvn9h3$pa4$1(a)fred.mathworks.com>...
> I am working with an eZdsp board and programming the board
> with Simulink. I would like to implement the following in
> Simulink.
>
> Currently, I am inputting three 60Hz sinusoidal waveforms
> (possibly with harmonics, but ideally these will be 60-Hz)
> to the ADC (these do not correspond to three-phase voltages
> from a power system, they do not have a 120 degree phase
> difference). I need to use Simulink to determine the
> magnitude and phase of the waveforms relative to each other.
>
> Any help or insight in this area will be greatly appreciated.

You can multiply each of the signals by itself (preferably
over a whole multiple of periods) and take the square root
of the mean (RMS) in order to compare magnitude.

You can multiply the two signals together. The mean of the
result will be smaller than the product of the RMS of the
two inputs. This ratio (power factor) should give you an
idea of phase difference (it is the cosine of the phase
difference). Being a cosine, you cannot tell if the phase
difference is positive or negative.

One method of determining if the phase difference is
positive or negative is to recalculate the power factor with
a fixed time delay (say a single sample) on one signal.
Depending if the power factor increases or decreases (or
rarely stays the same), you can determine if the original
phase is positive or negative.

Harmonics will affect the accuracy of the results.

Alternatively, you could use a Hilbert transform to
transform each real waveform into a complex analytic
waveform. At any sample you can then directly determine the
magnitude and phase relationships just by comparing the
magnitude and phase of each analytic vector at that time.

Again, harmonics will affect the results.

Finally, you can go down the FFT route. It is easiest if you
can sample at an exact multiple of the wave frequency.
Alternatively, sample many periods and apply Hanning windows
before calculating the FFT (but this will spread each
frequency peak over 3 spectral lines). Calculate the
auto-power spectra of each of the inputs (by multiply each
spectrum by its conjugate) and the cross-power spectra
between each pair of inputs (by multiplying one spectrum by
the conjugate of the 'reference'). The total energy in the 3
spectral lines around each peak (with a Hanning window) will
be proportional to the square of the amplitude. The phase of
the cross-power at the highest peak will be a good
approximation to the phase difference between the signals.