Author |
Topic |
|
betab3
USA
8 Posts |
Posted - 09/16/2011 : 09:11:34 AM
|
Anybody knows which function/add-on should I use, to get the length of a the contour of an XY trace? I work on epilepsy and the "coastline" length is an extremely useful information, much more than the "area under curve", due to the high frequency component of the epileptic discharges. Beside WINLTP software and Axograph, no other software has an easy and quick operator\button\whatever to get this data. Being a PCLAMP user, this function could be easyly added to the preexisting Pclamp related add-on. WINLTP requires the import of ASCII files, and during the export from Pclamp, misses several digits (with a pathetic resulting trace once read in WINLTP). Axograph coastline function is rude and poor to manage. SO now I'm forced to do a tedious export\import on a spreadsheet where I have the function to calculate the coastline, but if it would be already embedded (as add-on) on Origin would be a extremely great improvement.
Thanks in advance for attention.
Origin Ver. and Service Release (Select Help-->About Origin): Operating System: |
|
betab3
USA
8 Posts |
Posted - 09/16/2011 : 09:14:05 AM
|
I forgot: OS: WinXP Origin version: 8.0 SR5 |
|
|
Hideo Fujii
USA
1582 Posts |
Posted - 09/16/2011 : 10:26:23 AM
|
Hi betab3,
How about the following steps?
1) Left-click on a contour line to select it, right-click it, then choose "Extract Contour Line". This produces an XY worksheet, A(X) B(Y). (Note: you may have several disjunctive segments together. Then, separate each other to create separate pairs of columns.) 2) Add a column C. 3) On C, run Set Column Values, and enter the following formula:i==1?0:col(C)[i-1]+sqrt((col(A)[i]-col(A)[i-1])^2+(col(B)[i]-col(B)[i-1])^2) The column C shows the cumulative length.
Does it work for your purpose?
--Hideo Fujii OriginLab |
Edited by - Hideo Fujii on 09/16/2011 10:29:53 AM |
|
|
betab3
USA
8 Posts |
Posted - 09/16/2011 : 11:26:43 AM
|
Thanks overall for prompt replay .
1) Left-click on a contour line to select it, right-click it, then choose "Extract Contour Line". This produces an XY worksheet, A(X) B(Y).
I have a single and continuous xy pair trace. So once I import the recording into Origin using the Pclamp filter, I've already a worksheet with two colums XY. I think that in this way this first step I can jump.
2) Add a column C.
done
3) On C, run Set Column Values, and enter the following formula:i==1?0:col(C)[i-1]+sqrt((col(A)[i]-col(A)[i-1])^2+(col(B)[i]-col(B)[i-1])^2) The column C shows the cumulative length.
I copied and pasted into the proper "set values" window, having previously selected the column C. Row in the header is "from 1 to 1". Row 1 returned a 0 while I have 3276401 lines with each values going from 0.002 to 0.01. The script window reports: "Last Executed by Unknown on -- Duration of the Last Execution is unknown Inputs: [Book1]Sheet1!Col(A) [Book1]Sheet1!Col("IN 0") Outputs: [Book1]Sheet1!Col(C)[1:1] "
Seems something went wrong, possibly my values are not appropriate? I'll think about during this weekend. Thanks for now.
Does it work for your purpose?
--Hideo Fujii OriginLab [/quote] |
|
|
Hideo Fujii
USA
1582 Posts |
Posted - 09/16/2011 : 1:25:17 PM
|
Hi,
Does your second column have the short name "B"?
Maybe you can change the formula to use the column number (col(2)) instead of the column name (col(B)) like below?i==1||col(1)[i-1]==(1/0)?0:col(3)[i-1]+sqrt((col(1)[i]-col(1)[i-1])^2+(col(2)[i]-col(2)[i-1])^2) This one can also deal with disjunctive segments.
--Hideo Fujii OriginLab
|
|
|
Hideo Fujii
USA
1582 Posts |
Posted - 09/16/2011 : 5:46:32 PM
|
My colleague has suggested that the following is a little better...
i==1||col(1)[i-1]==(1/0)?0:col(3)[i-1]+distance(col(1)[i],col(2)[i],col(1)[i-1],col(2)[i-1])
--Hideo Fujii OriginLab |
Edited by - Hideo Fujii on 09/16/2011 5:47:13 PM |
|
|
betab3
USA
8 Posts |
Posted - 09/19/2011 : 11:21:14 AM
|
Hi, tried both but result was poor. Not because of something wrong in the formula, but because being the coastline depending on the x axis, if the values on the y are much smaller, in the "sum" of x_y, the weight of the y is always negligible. To help understand this, I will send a couple of files I have to analyze, in pclamp abf format. One is with an epileptic wave, ther other (2) is just baseline of the same experiment, having so similar noise. These are named example 1 and example 2.abf Here comes the first problem, because for some unknown reason, the x axixs is not imported. So adding an arbitrary x from 1 with 1 step, y values are 1000 smaller.. So once you apply the formula and plot the resulting column, what I get is a linear segment. BTW, what's matter is just the final value, that at the end of the column.. So I just added an arbitrary x and than added another column where I subtracted the data resulting from the formula application, at the x corresponding value. This is something similar to the subtraction of the "basaeline". But I don't know if this is correct. I discovered that the formula used in Axograph function is written in C. Knowing it works fine (but axograph has his own boring problems..) I can freely copy it and paste here down:
localLanguage C
// Global variables are saved between runs. boolean firstCoastlineMeasure = true; double coastlineMin; double coastlineMax;
program "Measure Coastline" { // Local program variables are not saved between runs. long window, trace, group, episode; long episodeCount; double Coastline; double anArray[1]; double CoastlineArray[1]; string yTitle, yUnits; // Only display this message the first time the program is run. if ( firstCoastlineMeasure ) { firstCoastlineMeasure = false; Alert( "Measure 'coastline' parameter and generate a graph of coastline vs event number. " "\n\nThe coastlines are calculated over a specified range of each episode." ); } if ( frontWindowIsNotAGraph() ) exit; // Get the front window and group #'s. GetFrontGroup( window, group ); // Ask the user for the analysis range. GetRange( window, "Measure Coastline", coastlineMin, coastlineMax ); // Set up. SetArraySize( coastlineArray, nEpisodes( window ) ); episodeCount = 0;
// Loop through every episode. for ( episode=1; episode<=nEpisodesInGroup( window, group ); episode++ ) { // Skip if the episode is masked. if ( EpisodeIsMasked( window, episode ) ) continue; // Retrieve the specified section of a data trace into an array. anArray = eRange( window, group, episode, coastlineMin, coastlineMax ); // Calculate the difference between each pair of points in the array deltaArray( anArray ); // Calculate the sum of the differences coastline = sum( abs( anArray ) ); coastlineArray[ episodeCount ] = coastline; episodeCount++; } SetArraySize( coastlineArray, episodeCount ); GetGroupTitle( window, group, yTitle ); GetGroupUnits( window, group, yUnits ); // Create a new graph window, and plot the coastline measurements theName = NewFileName( concat( WindowTitle( window ), " Coastline" ) ); window = NewGraph( theName ); yData( window, 1 ) = coastlineArray; FillArray( coastlineArray, 1, 1 ); xData( window ) = coastlineArray; SetXTitle( window, "Event #" ); SetYTitle( window, 1, yTitle ); SetYUnits( window, 1, yUnits ); }
Hope can help.
I would prefer to use Origin instead of export\import in other ambient, having more confidence in this software. Once find the right formula, I will try to write an add-on with sliding bars, button and windows where to read the interval among the two bars, very important point knowing that to compare different waveforms it is mandatory to measure the coastline using identical time-windows.
Thanks for the assistance reserved to my boring request, but I'm still thinking that adding this function will be greatly appreciated.
Best Mario Barbieri |
|
|
betab3
USA
8 Posts |
Posted - 09/19/2011 : 11:49:08 AM
|
ok, files added in the \incoming directory of ftp.originlab |
|
|
Hideo Fujii
USA
1582 Posts |
Posted - 09/21/2011 : 10:45:20 AM
|
Hi,
Your .ABF file, after importing to Origin, has a "hidden" X column, just as holding ONLY the initial X value ("EvenX Initial value") and the X increment value ("EvenX Increment") as example 1.abf has 0 and 1 respectively. This information can be shown by left-click the small yellow icon "[i]" at the left corner of the (short) column name header("Ch0(Y)").
To show the X column, you can highlight this Ch0(Y) column, and select "Column: Show X Column" menu.
Didn't you miss correct X values when you obtained your source data file??
--Hideo Fujii OriginLab
|
|
|
betab3
USA
8 Posts |
Posted - 09/22/2011 : 04:58:16 AM
|
Thank you for the hint. Now I can see also the x axis. Than I added another column where I subtract the x axis value form the value of the 3th column, where has been calculated the coastline. Doing this I get the net deflection value on the y axis. The final line of this 4th column returns the key resulting coastline index. At this point should be very nice to write a add-on with sliding bars and a window where it's possible to read the amplitude of the window between bars and a button which calculates the coastline index as above shown. I'll try.... in some months!
Thanks Hideo for assistance. |
|
|
betab3
USA
8 Posts |
Posted - 09/22/2011 : 06:53:04 AM
|
Btw, I wonder if it is possible to incorporate this subtraction directly into the coastline formula. This could turn the whole job into something more handly.
thanks for attention. |
|
|
Hideo Fujii
USA
1582 Posts |
Posted - 09/22/2011 : 6:11:44 PM
|
Hi betab3,
It sounds a typical application of Origin's "Analysis Template". You save a worksheet or the whole project as an analysis template, where all settings of Set Column Values tool (or other analyses or statistics) where the "Recalculation mode" is set to "Auto" (or "Manual"); later you can load the analysis template, and replace the source data in the worksheet to repeat the same calculations over and over.
For example, see the web tutorial: http://www.originlab.com/www/helponline/Origin/en/UserGuide/Analysis_Templates.html or its corresponding Origin help.
--Hideo Fujii OriginLab
|
|
|
betab3
USA
8 Posts |
Posted - 09/23/2011 : 05:16:34 AM
|
fantastic. |
|
|
|
Topic |
|
|
|