02-27-2017 12:20 PM
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.
02-28-2017 10:11 AM
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
03-01-2017 04:06 AM
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?
03-01-2017 06:50 AM
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.
03-01-2017 08:17 AM - edited 03-01-2017 08:17 AM
@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.
03-01-2017 01:09 PM
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.
03-02-2017 04:09 AM
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.
03-04-2017 02:10 PM
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.
03-06-2017 03:07 AM
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:
03-06-2017 03:26 AM
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?