08-19-2010 08:42 AM
Hi all,
I am continuously acquiring two sinusoidal signals from the analog inputs of a daq card and saving the samples of the two signals into two different float type arrays. Can anyone tell me that how to calculate the phase shift between these two signals and as well as the peak voltage of the two signals? Please expain me with the help of an example code.
Thanks
08-19-2010 09:14 AM
Just look at the phasedif.cws sample program that ships with CVI. It does exactly what you're asking for.
08-20-2010 02:25 PM
Hi AI S
I have gone through the example of phase diff e.g and i have written the following code but when i run it , it gives the max value of 1st sine wave (outarray1) nearly equal (i-e 7.7 volt ) but it should be 8 V pk.
But for the 2nd sinewave (outarray2) it gives the max value from 0 volt to 1.5 volt pk but it should give 1.5 Volt pk only and the phase difference is displayed as 0.000 , even there is no update in decimals in it.
One more thing to tell that 1 complete sine wave consists of 1024 samples , therefore in outarray1 and outarray2 , there are 8 cycles each. In one iteration of the loop outarray1 is filled and in other iteration outarray2 is filled , then i calculate the phase shift. Please tell me what i am doing wrong.
Here is my code
double outarray1[8192],outarray2[8192] ;
double *peakLoc, *peakAmp, *peakDeriv;
int count;
static double wave1maxval = 0.0;
static int wave1maxind = 0;
static double wave2maxval = 0.0;
static int wave2maxind = 0;
static double phasediff;
PeakDetector (outarray1,8192,0.0, 3, 0, 1, 1, &count, &peakLoc, &peakAmp, &peakDeriv);
if (count>0)
{
wave1maxind = peakLoc[0];
wave1maxval = peakAmp[0];
SetCtrlVal(panelHandle,PANEL_wave1maxind, wave1maxind);
SetCtrlVal(panelHandle,PANEL_wave1maxval, wave1maxval);
}
if (peakLoc)
FreeAnalysisMem (peakLoc);
if (peakAmp)
FreeAnalysisMem (peakAmp);
if (peakDeriv)
FreeAnalysisMem (peakDeriv);
PeakDetector ( outarray2,8192,0.0, 3, 0, 1, 1, &count, &peakLoc, &peakAmp, &peakDeriv);
if (count>0)
{
wave2maxind = peakLoc[0];
wave2maxval = peakAmp[0];
SetCtrlVal(panelHandle,PANEL_wave2maxind, wave2maxind);
SetCtrlVal(panelHandle,PANEL_wave2maxval, wave2maxval);
}
if (peakLoc)
FreeAnalysisMem (peakLoc);
if (peakAmp)
FreeAnalysisMem (peakAmp);
if (peakDeriv)
FreeAnalysisMem (peakDeriv);
phasediff = (8/8192) * (wave1maxind - wave2maxind) * 360;
phasediff = fmod (phasediff, 360);
SetCtrlVal(panelHandle,PANEL_Phase_Diff,phasediff);
08-22-2010 06:36 AM
Please anyone else reply.
08-23-2010 03:21 AM
can you tell the frequency of you measuring signal and you sampling frequency?
08-26-2010 08:38 AM
Hi all,
I have done some work on calculating the phase shift and now my question is that
Suppose that i have an array of 8192 elements wnich consists of samples of sine wave, one complete cycle of sine wave has 1024 samples. It means there are total 8 cycles of sine wave.
If the value of this array is updated regularly after some time ( less than 1 sec) such that at the
zero location of array, there may be some other value each time or i mean to say that the samples of sine waves are shifting within the array.
How is it possible to calculate the accurate Peak value of sine wave every time with its correct index value?
I want to calculate the phase difference of the "sine wave in this updating and shifted array"
with another sine wave which is in another array and it is fixed at zero reference.
I have tried the Peak detector , MaxMin1D ( ) and FFT function to calculate the phase difference
but it is changing every time and incorrect.
Please tell me how to calculate exact phase shift in given conditions.
08-26-2010 10:55 AM - edited 08-26-2010 10:56 AM
What you want to do is use two arrays (sometimes called ping pong buffers) and perform calculations on one while the other is updated with new measurementd data. This avoids the conflict of trying to perform calculations on a buffer with updating data samples.
08-26-2010 11:42 AM
How noisy is your signal? You may need to use a threshhold other than 0.0 in your call to PeakDetector(). Or can you clean up or filter the signal before sampling it?
I don't understand the application of calculating the phase difference between two signals that were not captured at the same time. If you're comparing a previously captured signal with a signal captured at some variable time later, it doesn't seem to me that you're really measuring phase.