LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Squarish wave calculations

Let me start be aplogizing by the crudeness of my drawing.  It is the best I have here at home.  I am trying to wrap my brain around how to effectivily process the attached signal.

 

Attached I have the profile of a signal I am trying to make some specific measurements from.  I am trying to measure the height of the flat area between the two red ticks and then compare it to the flat area between the two green ticks.  In the end I will be subtracting the amplitude of the green from the red.  I expect the real world signal to be pretty consistant and periodic. Ideally the method would allow for the subtraction regardless of  frequency or the overall amplitude.  I just need the difference between the two.  Does this make sense?

 

 So my overall methodology RIGHT now is something like this.

Find the max of the waveform.  Use some percent of this as a trigger level.  Calculate the "start of the flat" using a rising edge and the finish using a falling edge.  Measure the values in between.  Average them.  This is value 1.  

 

Using frequency repeat the above process 1 period away.  This is value 2.  

 

Subtract them and I get the difference.   Continue the whole thing with a For loop for the entire waveform.  Does this sound right to anyone?  

 

Right now I can get the frequency easily, but I am having a little trouble getting the start and stop of my flat parts.  I think I can do it using basic trigger but I am wondering if there are some easier functions I am unaware of.  Any help suggestion tips would be grealty appreciated.  I am more than happy to elaborate further if I have been unclear.  I can try and post some code tomorrow but right now I am looking at the basic methodology.

 

Thanks so much.

TK

0 Kudos
Message 1 of 3
(2,703 Views)

Well, you don't say much about the nature of your data -- is it really as "clean" as shown in your figure?  Is the "Max" value consistent for Red and Green segments?

 

If it is fairly clean, you should be able to get a good estimate of Max (and you might not really want "Max" as much as you want "Flat Peak").  One way to determine the extent of Flat Peak (you'll need to experiment with your "real signals" which have "real noise") is as follows:

  • Determine the Max (which should be in the X interval of a Flat Peak).
  • Search to the Left and to the Right of the X interval where Max occurred for the first point that deviates "delta" from Max (it will, of course, be below Max).  Delta will depend a bit on the noisiness of your signal.  Let's say XL and XR are the left and right places where this deviation occurs.
  • If XL and XR really represent the left and right edges, then if you keep going left a bit from XL (or right a bit from XR), you'll depart even farther from Max (otherwise you might just have found a "noise" point-out-of-range, so should increase "delta").
  • If Delta is large, then you'll definitely be on the slope leading up to the flat.  To get a better estimate of XL and XR, you can "climb back up" until you get "closer" to Max, say "Epsilon", a number you pick based, again, on the quality of your data.

Another way of looking at this problem is to look at the derivatives of your signal.  The "flat" parts are where the derivative is 0, being positive on the left edge and negative on the right.  However, sometimes dealing with the signal itself is easier (and more immune to "injected noise" (taking derivatives emphasizes the high frequency components present in your signal, including random noise).

 

Bob Schor

0 Kudos
Message 2 of 3
(2,658 Views)

I think I found something I can work with.  Check out Waveform Scalar Limit Comparison and its example.  Looks like I can pretty easily end up with an array of numbers representing the flat tops and NaN inbetween each group.  Should make it easy to sort the groups from there.

 

Check out the function.  Hopefully there are not any obvious flaws in that logic.

0 Kudos
Message 3 of 3
(2,630 Views)