Forums

Full Version: Phase difference
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys

I have been using signalab to filter 2 signals from channels 1 & 2. Works well enough. However I can't figure out how to calculate the phase difference between the 2 signals? Even a time difference would help but again can't get this to work.

Any suggestions?

Thanks

Fanman
OK not much feedback so I'm hoping to stimulate discussion. I have tried to determine the time difference between ch1 and ch2 by using SLDetectLevels component to identify when the signals cross the time axis (i.e. when level is >0). I then tried to send this trigger to the TLStopWatch component to measure time difference. Unfortunately nothing worked. Maybe it is my understanding of how these components work. Would appreciate if anyone has experience with this.

Dave

Hi! If you would post some (partial) code we might get an idea what's (not) going on. Compiler and Lab-version as well.

Regards,
Dave
Hi Dave,

I have attached the project file. I'm using MS Visual Basic 2010 and have a registered version of SignalLab Ver 6.

Looking forward to finding a solution to this. Have been working on this for a long time now Smile

regards

Mark
Here is the basic code......

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

' OK really struggling to understand how components are mean't to operate
' Identify when levels > 0 i.e. cross time axis
' and measure time difference with stopwatch

If Val(DetectLevels1.OutputPins.GetPin(0).ToString) = 1 Then
StopWatch1.Start()
ElseIf Val(DetectLevels2.OutputPins.GetPin(0).ToString) = 1 Then
StopWatch1.Stop()
SegmentGauge1.Value = Val(StopWatch1.OutputPin.ToString)
End If

End Sub
Does anyone have any feedback? I find this forum to be a one way street. Questions get asked but never answered.
I've been fooling around with extracting raw data from the buffer and detecting when the values Cross time axis. Seems OK so far. When o try to trigger the stopwatch to start the application crashes. Can't figure out why?

Dave

There's only that much time in a day, sry for the delay.

If you want to detect if a value crosses an axis you should compare it to the previous value, not just for a value of >0 which may occur 100 times in a row. Maybe that's where the stopwatch gets confused as well.

Regards,
Dave
Well I think I have it sorted now. Its been tough understanding how the libraries work but this is how to do it.

Use 2 x GenricReal components to extract data from the sample buffers
Use an "if" statement to find when the samples cross the horizontal axis. You will get at which sample ID this happens for both Ch1 & Ch2. Exit the loop when the first cross over is detected.
Subtract the sample ID's to get the difference and divide by number of samples for one period of the signal.
Multiply by 360 and you'll get the phase difference.

There needs to be more info in the wiki online to help developers.
Reference URL's