LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate phase difference between two sine waves on FPGA

I have a problem to calculate phase difference between two sine waves on FPGA. Can anyone help please? Theoretically I could use the equation:

phase difference = arc cos (x1.x2/|x1||x2|), where x1 and x2 are the sine waves.

However I am looking for a practical solution that can be calculated on FPGA. Any bright idea please? Or how to implement the theoretical solution on FPGA? Thanks.

 

0 Kudos
Message 1 of 11
(6,349 Views)

Hi Noriker,

FPGA isn’t really designed to carry out analysis like this. You are likely to run into sizing constraints on the FPGA.

Is it possible for you to transfer the data from the FPGA onto the RT and then carry out the processing there? That is the best practice that we recommend.

http://forums.ni.com/t5/Example-Programs/How-to-Find-the-Max-Phase-Difference-of-Waveform-Signals/ta...
http://forums.ni.com/t5/Example-Program-Drafts/Calculate-Phase-Difference-of-Waveforms-Acquired-via-...

Above are two links to similar situations that are using these best practices.

If this is not going to work for you then the main thing to consider is why does the analysis need to be carried out on the FPGA?

Thanks,
Alastair

0 Kudos
Message 2 of 11
(6,291 Views)

Hi Alastaie, Thank you very much for your help. I have come across the links, but they cannot be used on FPGA. We need phase to be calculated on FPGA to get an instant and uninterrupted result for our control algorithm. Is this possible? We can use resample data from EPS rather than raw voltage data. Would that be a help?

0 Kudos
Message 3 of 11
(6,276 Views)

FPGAs aren't designed for processing like this as I said, however I have seen it be done with PWM. I have attached that example, hopefully you can adapt this to meet your needs, but it isn't the recommended way. 

0 Kudos
Message 4 of 11
(6,266 Views)

@Alastair: Why aren't FPGAs designed for processing like this, or then, what are FPGAs designed for?

 

I think there are many applications like these running on FPGAs, e.g. Lock-in amplifiers or phase-locked loops.

 

Talking about Lock-in amplifiers, this might be what you're looking for. Multiplying the 2 signals will give you the in-phase (X) and quadrature (Y) components. You'll have to filter these (low-pass filter), then convert X,Y to R,phi (e.g. using the high-throughput rectangular to polar function). The phi is your phase. Of course this only works if the 2 sine waves have the same frequency (or vary only slowly), but otherwise the term phase shift doesn't make much sense anyway.

You can find a Lock-in amplifier implementation for LV FPGA here: https://forums.ni.com/t5/Example-Programs/Lock-in-Amplifier-on-LabVIEW-FPGA/ta-p/3500412

I don't use this code, so I can't comment on it.

Message 5 of 11
(6,257 Views)

Hi, thanks very much for your idea. It reminds me I am using NI 3-phase PLL express vi to measure the frequency of three phase voltage. As this express VI also calculates phase, I could run two 3-phase PLL express vis and take the difference of their phase output. Does it present any problem? Thanks.

0 Kudos
Message 6 of 11
(6,252 Views)

I'm not sure about that, since you need the same reference.

If you have 2 independent PLLs they might not have the same reference and thus the 2 phases are not necessarily comparable.

0 Kudos
Message 7 of 11
(6,241 Views)

Hi, you are right. In fact, I do not even know what the phase output of 3-phase PLL express VI is. NI help says it is "The phase of 3-phase system" with no definition of it.

As to LIA, it calculate phase on RT target, not on FPGA. It collects data and transfers to RT for calculations.

I attached a simulation vi for FPGA, but it doesn't work. The error message reads as:

"An internal software error in the LabVIEW FPGA Module has occurred. Please contact National Instruments technical support at ni.com/support.

An internal error has occurred in the emulation manager."

 

Can anyone help? And any suggestions for the simulation vi itself? Am I on the right track?

Many thanks.

 

 

0 Kudos
Message 8 of 11
(6,206 Views)

I'm sorry I was not very precise before. You say you already use a PLL to detect the frequency of the sine waves.

One approach to get the phase of the 2 signals is to use a two-phase Lock-in amplifier:

  • Generate a sine and cosine of the detected frequency
  • Run the lock-in demodulator on each of your sine waves:
    • multiply your sine wave with both the generated sin/cos
    • low-pass filter both resulting components (X,Y)
    • Use rectangular to polar to detect the phase (with respect to the demodulation sine wave)
  • The difference between the 2 phases is the phase between the 2 sine waves

 

0 Kudos
Message 9 of 11
(6,185 Views)

Hi, thanks for your help, but the LIA link you suggested has lowpass filter and the third part of calculation on RT target, not FPGA. I'm trying to use Butterworth lowpass filter on FPGA and FPGA LUT to create a inverse cosine function, but I cannot get right answer. It's all because different data type restriction and conversion I am having trouble with. It will be so straight forward if it is done on RT or PC. Have you got any example code does lowpass filter and LUT of arccos on FPGA please?

0 Kudos
Message 10 of 11
(6,175 Views)