Jump to content
  • 0

Phase difference measurement in Logging on Analog Discovery 2


Grant Mathieson
 Share

Question

Any advice on how to get a phase measurement (between Ch1 and Ch2) included in Logging?

Digilent offer the following code, which works fine for me on Scope, but not (so far) Logging. I get the error, "Uncaught exception at <anonymous script, id=2091515652512>:6: ReferenceError: Can't find variable: Scope"

 

Thanks in advance.

Version from Digilent

// initialize local variables
var sum1 = 0
var sum2 = 0
var sum12 = 0
// for better performance get and use local copy of data array
var d1 = Scope.Channel1.data
var d2 = Scope.Channel2.data
var c = d1.length
for(var i = 0; i < c; i++){
sum1 += d1*d1
sum2 += d2*d2
sum12 += d1*d2
}
sum1 /= c
sum2 /= c
sum12 /= c
// last line of code is the measurement value
acos(sum12/sqrt(sum1*sum2))*180/PI

 

Version I use on Scope but does not work on Logging

 

var sum1 = 0

var sum2 = 0

var sum12 = 0

var d1 = Scope.Channel1.data

var d2 = Scope.Channel2.data

for(var i = 0; i < d1.length; i++){

sum1 += d1*d1

sum2 += d2*d2

sum12 += d1*d2

}

sum1 /= d1.length

sum2 /= d1.length

sum12 /= d1.length

acos(sum12/sqrt(sum1*sum2))*180/PI

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Thanks Attila, but I still have not got this working in Logging. The same error re-appeared. When I changed the Scope script to Scope1. etc., that stopped working. BTW I'm only using one scope at present. 

Thanks for the tip on addressing measurements in short form. In Scope, I used Scope.measure("Phase") and it gives identical numbers to the long form script.

Any other advice?

Link to comment
Share on other sites

  • 0
On 9/4/2018 at 5:44 PM, attila said:

Hi @Grant Mathieson

Sorry but I don't understand what problem you are facing.

Here the same phase measurement is calculated in Scope and in Script:

image.thumb.png.fda059b41c2065a607067b4769642b2d.png

 

Hi Attila,

Yes, I see that Scope and Scripting can do it, thank you. But I want to get it working in Logger. This is because I have signal changes that occur in the 10 ns to 100 ns timescale, but these occur in response to inputs that change over 0.1 s to 10 s. The Record mode in Scope seems limited by buffer size.  Is it any better in Logger? I also want to log the difference between Ch1 and Ch2, and preferably calculate the AC RMS, Peak2Peak, rise/fall time of that difference in Logger. Those calculations are trivial in Scope. Any advice would be appreciated. I'll keep trying in the meantime. Thank you.  Regards, Grant

Link to comment
Share on other sites

  • 0

Hi @Grant Mathieson

The Logger does not provide Scope measurements. This is intended for slow DC and AC signal monitoring.
If understand correctly you need sample rate of 100MHz and logging over several seconds or more.  The Record has limitation due on USB bandwidth of about 1MHz and 10M samples.

For precise periodically monitoring you could use a dummy Wavegen or Patterns, like for 100ms rate specify 99ms wait and 1ms run time. Otherwise you can also use the Scope/Time/Rate option. Select this in Scope as trigger source.
You can use Scope/View/Logging/Custom to store the needed measurements.

image.thumb.png.9ab818cf7873a988ca1e018a6d8b45a1.png

Link to comment
Share on other sites

  • 0
Posted (edited)

IMHO these calculations are redundant

sum1 /= c
sum2 /= c
sum12 /= c

@atilla

What is the source idea of this phase measuring method? I could not find it. 

Edited by Kabron
Link to comment
Share on other sites

  • 0

Hi @Kabron

For more precise measurement with newer software version you can use the FFT view, Spectrum or Network Analyzer.

See the default 'global' example.
I don't recall the name of this measurement but I will let you know tomorrow....

image.png.dbd6bcd720ef99eb02f925a618dc8ad4.png

Link to comment
Share on other sites

  • 0

Thanks for answer.

Not sure, that I understand how to measure phase numeric value with FFT, Spectrum or Network Analyzer.

The script you provided gives ultimate precision, but acos function is defined in 2 quadrants (0-180 degrees). It is not possible to define DUT nature (inductve/capacity). I'going to use custom script for such mesurements.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...