DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Find point where two curves intersect after an initial start point

Hi,

 

I'm currently using the sample program (found here http://www.ni.com/white-paper/4193/en/). However, I need the program to to change the stop value it looks for. Instead of looking for when the channel drops below the input threshold, I want it to look for when it intersects with a vertical line. Basically my data should hit a threshold, then after the given time the set point should change. The data is oscillating and I need to find the intersection points at both the max and min peaks (as seen in "example picture 2.PNG"). In the picture I attached ("example picture.PNG) you see a red curve which is my feedback data, black line is the setpoint input, and the dots are associated with the sample program I linked before. I'm in no way an expert programmer and I have only been using Diadem 2014 for a couple of weeks now.

 

Any help would be appreciated. Thanks

Download All
0 Kudos
Message 1 of 11
(4,928 Views)

Sorry I should have been more clear on what my data is doing here. The data channel (red in the pictures) is the feedback channel and is a continuous curve. The input channel (black in the pictures) is a step value curve so it is either the max input or minimum input (either 70 or -40). So it was incorrect for me to state the intersection of the vertical line. Instead I should clarify I need to find when these discontinuities occur and plot them on my data channel (red curve).

 

Sorry for any confusion.

 

Thanks

0 Kudos
Message 2 of 11
(4,911 Views)

Hello OperatorJack,

 

I'm trying to understand the images you sent so I can help out some. I understand what the red and black channels represent and how the sample program is looking for input thresholds. Could you clarify a little more about what changes you want to make? It got a little unclear when you said "these discontinuities". If you could explain this a little more or create an image where you mark up one of your images with what you are looking to do, this might make it a little more clear.

 

Regards,

 

Rob S

Applications Engineering

National Instruments

www.ni.com/support

 

Rob S
Applications Engineer
National Instruments
0 Kudos
Message 3 of 11
(4,885 Views)

Sorry for causing some confusion for what I was looking for. I've attached three picturer that will hopefully clarify what I'm intending. The first picture (example picture 3.PNG) Shows the full spectrum with the CalcDurations.vbs ouput. The green dot is when the curve crosses the threshold initially and the red dot is when the curve crosses the threshold again. The second picture (example picture 4.PNG) shows a zoomed in version except this time I have removed the red dots and replaced them with hand drawn blue circles. These blue circles are where I want my new end points (red dots) to be. This point is when the setpoint (the black line in both pictures) switches from the high input to low input. Basically, I'm trying to find the point on the original red curve where this change in setpoint occurs and show it on the graph. I've attached a picture with part of the script that I think needs to change, you can find the full original script in the orginial post at linked page. What I have been trying to do is modify the two FIND statements or adding in an additional statement but have yet to find something that will correlate the point from the black curve to the red curve.

 

I hope that clarifies what I'm looking for. If it is still unclear I apologize and will do my best to fix it.

 

Thanks

Download All
0 Kudos
Message 4 of 11
(4,878 Views)

Hello OperatorJack,

 

The images helped to clarify. In this case, what I would do is search for the change in the values from the black line graph, and then once I had the time value (x) that the change occurred, use that value to see what the corresponding y value would be for the red graph. That way you'd have your x,y pair and be able to plot the point. I'm not sure how I would implement this with the existing script, but I just wanted to throw it out there. The DIAdem help often includes lots of examples of script pieces that can be reused for applications like this.

 

I'll see if I can find some useful functions that may be of some help and post them here.

 

Regards, 

Rob S
Applications Engineer
National Instruments
0 Kudos
Message 5 of 11
(4,846 Views)

HeroOfHyrule,

 

Thanks for your help and input. Yea I agree the best way to do this would be the same thing you suggested, unfortunately I lack the programming knowledge for Diadem to work that out on my own. So far the closest I've gotten is running the script again for the black line which gives me the the correct x-values I would need but I don't know how to find the corresponding y-value in the red graph. I'm sure there is a simple function to do it but getting it to integrate in with the current script is the part I'm having trouble with. Perhaps a whole new script to find the ending y-value would be the best solution. Thanks for looking around and seeing what you can find though.

 

Thanks

0 Kudos
Message 6 of 11
(4,843 Views)

Hey OperatorJack,

 

You might want to try giving the PNo function a try. I'm assuming that your channels are all the same lenght, so you should be able to use the PNo function with your value and the channel the value came from to get the index of where that value occurs. From there, you would just need to access the data in the same index location in the other channel. It would look something like this.

 

 

Index = PNo("Name of Black Channel", ValueYouFound)

' To get the index value into a variable

 

RedChannelYValue = Data.Root.ChannelGroup(1).Channels("NameOfRedChannel")(Index)

' To get the value of the data at the index location of the Red Channel

 

Once you have those, you should have your XY pair and be able to map. Let me know if you have any questions about what I posted, as this isn't the exact syntax, but just a general idea of how I might do something like this.

 

Regards,

 

Rob S
Applications Engineer
National Instruments
Message 7 of 11
(4,811 Views)

HeroOfHyrule,

 

Thanks for your input and solution. I actually ended up starting from scratch with my code and was able to come up with a different solution. I figured it would be easier then trying to modify an existing code. I used the ChnEventFind to find the times where my signals met the input condtions. Then used the CTNV function to get the values along the red line that corresponded the the times I just mentioned. Perhaps you can assist with another issue that I ran into though. When doing the calculations for the CTNV portion of the script I keep getting "type mismatch" errors. My code looks something like the following:

 

dim ChannelLength, FilterChannels, j, sFilterFormula, aFilterSymbols(3), aFilterValues(3)

j=0

For j=1 To 4

ChannelLength=ChnLength(CNo("[1]/[1]"))

FilterChannels = ChnAlloc("FilteredSens_0" & j,ChannelLength,1,DataTypeFloat64, "Numeric",2)

sFilterFomula= "R = A*(1+CTNV(B<1))"

aFilterSymbols(1) = "R"

aFilterSymbols(2) = "A"

aFilterSymbols(3) = "B"

 

'output channel

Set aFilterValues(1) = data.GetChannel("test/FilteredSens_0" & j)

'source channel

Set aFilterValues(2) = data.GetChannel("CombinedData/TempSens_0" & j)

'filter channel

Set aFilterValues(3) = data.GetChannel("test/EventStatus_0" & j)

Call Calculate(sFilterFormula, aFilterSymbols, aFilterValues)

 

 

Basically what I need to do is be able to iterate through the calculation and build channels for the results for each iteration. Any idea as to why I get the "type mismatch" and how I can fix it?

 

Thanks

0 Kudos
Message 8 of 11
(4,773 Views)

I should also note that when running the above script I only run into this issue when iterating. If I remove the loop and simply state j=1, j=2.. etc then the code will run fine and give me the expected result. So for some reasone the issues only exists when in the FOR loop.

 

Thanks

0 Kudos
Message 9 of 11
(4,771 Views)

Hey OperatorJack,

 

Any chance you could post any additional info on the type mismatch error? Maybe the debug log text of exactly what DIAdem claims the error is? My guess is that inside the FOR loop we are accidentally targeting a different channel than we expect for the CHNV function on the 2-4 iterations.

 

Regards,

Rob S
Applications Engineer
National Instruments
0 Kudos
Message 10 of 11
(4,741 Views)