Jump to content
  • 0

Graphing wave frequency as custom channel (?) in WavForms


Agouti

Question

Hi all,

I'm hoping someone can help me define a custom channel in WaveForms, or point me to a better way to do it. I am familiar with adding virtual Math channels in desktop scopes, so that is my approach here.

What I need to do is graph the frequency of a frequency-modulated square wave as a separate custom channel, so it can be displayed under a waveform capture. I assume this should be possible using the scripting under Measurements in WaveForms, but I'm having a little trouble wrapping my head around how it works and the best approach to take. I'd also like to be able to log the frequency under the Logging tab, too.

If I was doing it through say Python in post processing, I would find all the zero crossings, measure the period between them, then graph the inverse as frequency, but this doesn't seem like the approach for ECMAScript?

I'm doing this using the device Demo source in WaveForms, as I need to make sure what I want will work before I buy the hardware.

Many thanks in advance!

Edited by Agouti
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 1

Hi @Agouti

With Math channel the data can only be delayed. For compensation bidirectional shifting is available under Channel gear dropdown.
However with Logging you can process the data to show the exact length of each pulse.

image.png

if(!Scope.Ref1.enable) Scope.Ref1.Clone(Scope.Channel1);
var src = Scope.Channel1.data;
var c = src.length;
var dt = 1.0/Scope.Time.Rate.real;
var pwm = [];
var p = src[0]>0;
var t = dt, j = 0;
for(var i = 1; i < c; i++, t+=dt){
    if(p==(src[i]>0)) continue;
    p = !p;
    for(; j<i; j++) pwm.push(t);
    t = 0;
}
for(; j<c; j++) pwm.push(t);
Scope.Ref1.setData(pwm, Scope.Time.Rate.real);

 

Link to comment
Share on other sites

  • 0

Hi @attila

Sorry, looks like I didn't explain myself clearly - I want basically the reverse of that, the input is the variable frequency square wave in C1 and the output is the kHz as a channel. That's still a very interesting little function, and it was a good learning experience figuring it out (even though the shorthand JavaScript was pretty confusing at first).

 

Edit: Worked something out, code is as follows, not pretty but I'm not really sure how to improve it as things like initializing the frequency on the first zero crossing would need some way of looking forward, which I don't think is possible in the Math framework. Obviously C1 needs to be AC coupled since it's only looking for zero crossings.

Init:

var prev = NaN;
var lastCross=-1;
var ret=0;

Function:

if(isNaN(prev)){
  prev = C1;
}

if((prev<=0 && C1>0) || (prev>=0 && C1<0)) {
  ret = 0.5/(Time-lastCross)
  lastCross=Time;
  prev=C1;
}

return ret;

 

This works, but I'd appreciate a more sophisticated way. For longer periods I've found I can record (aka stream to PC) then post-sample, is there a way to just set up hardware triggering and just capture the interval between triggers? Or some sort of hardware based frequency estimation?

 

Also, can I apply smoothing to the Math channel output to have slope between the points instead of hard steps?

Edited by Agouti
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
×
×
  • Create New...