Author |
Topic  |
|
dean.pask
UK
Posts |
Posted - 10/11/2005 : 06:20:11 AM
|
Origin Version (Select Help-->About Origin): 7.5 pro Operating System: xp
Easy I am sure but what is the command to plot a simple x-y graph from Data1 (2 columns) from the script window?
Many thanks as ever.
Dean |
|
Mike Buess
USA
3037 Posts |
Posted - 10/11/2005 : 10:13:28 AM
|
This is probably easiest...
win -a Data1; // activate Data1 worksheet -s 2 0 2 0; // select column 2 worksheet -p 200 Origin; // plot selected column as 200=line plot, 201=scatter plot, 202=line+symbol, etc. layer -a; // rescale graph layer to show all data
If you use a custom graph template use its name instead of Origin in the third line. See the worksheet command for other plot codes.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 10/11/2005 10:23:32 AM |
 |
|
dean.pask
UK
Posts |
Posted - 10/11/2005 : 5:11:04 PM
|
Excellent Thanks Mike,
All works great but when I run the script the 'plot setup' menu pops up and requires the x and y to be defined for the graph.
How do I define this in the script you provided me.
Many thanks.
Dean |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/11/2005 : 5:25:28 PM
|
Plot Setup should not pop up if everything is set up correctly.
1. Is Data1 really the name of the wks? 2. Is first column an X column... A(X)? 3. Is second column a Y column... B(Y)?
Possibly an mistake with copy/paste to script window. Try this version w/o the comments...
win -a Data1; worksheet -s 2 0 2 0; worksheet -p 200 Origin; layer -a;
Execute by selecting all four lines in the script window and pressing Enter.
Mike Buess Origin WebRing Member |
 |
|
dean.pask
UK
Posts |
Posted - 10/11/2005 : 5:39:47 PM
|
Great... I had the first column as Y and second as X...
I am looing now to run the FFT command on this data. Is this a simple task to complete?
Many Thanks
Dean |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/11/2005 : 11:13:42 PM
|
There's an example in the manual that you might be able to use out of the box... Help > Programming > LabTalk Language Reference > Object Reference > FFT
If you feel like trying your hand at Origin C you can look at the FFT Using NAG example here... http://www.originlab.com/index.aspx?s=8&lm=243
Mike Buess Origin WebRing Member |
 |
|
dean.pask
UK
Posts |
Posted - 10/12/2005 : 10:12:31 AM
|
Mike,
Excellent advise as ever. I have managed to use the example and created the FFT worksheet from there I used your advise on plotting.
From here I used the 'layer1.x.from =' command to rescale my graph. Does this actually filter the data or just plot the area you specify?
This is important when I ask for my next bit of advise which is - I need to now peak pick from my FFT graph and output the result into a worksheet?
Many thanks in advance.
Dean
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/12/2005 : 1:54:16 PM
|
Hi Dean,
1. layer.x.from/to do not change the wks data.
2. The simplest method for obtaining the peak position is with LabTalk's peaks() function...
LabTalk Language Reference > Function Reference > Dataset Manipulation Functions > peaks()
The curve object does the same thing but provides more control over the peak-picking criterion. You will find an example here...
LabTalk Language Reference > Object Reference > Curve
Mike Buess Origin WebRing Member |
 |
|
dean.pask
UK
Posts |
Posted - 10/12/2005 : 6:55:21 PM
|
Mike,
Many thanks I am still struggling but I will battle on.
How do I get these to work from my FFT worksheet?
Dean |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/13/2005 : 09:06:17 AM
|
This modification of the curve example picks peaks from the Real column of the active wks. Note that the string variable %H always holds the name of the active window.
wks.addcol(Pki); wks.addcol(Pkx); wks.col$(wks.ncols).type=4; wks.addcol(Pky); %B=%H_Real; // name of fft dataset curve.reset(); curve.data$=%B; curve.peakIndex$ = %H_Pki; curve.pickPeaks.rectHeight = .05; curve.pickPeaks.rectWidth = .05; curve.pickPeaks.minHeight = .05; curve.pickPeaks(1); get %H_Pki -e end; // how many peaks? for (ii = 1; ii <= end; ii += 1) { index = %H_Pki[ii]; %H_Pkx[ii] = xvalue(index,%B); %H_Pky[ii] = %B[index]; }
Mike Buess Origin WebRing Member |
 |
|
dean.pask
UK
Posts |
Posted - 10/13/2005 : 09:38:10 AM
|
Mike,
So I have completed my FFT which gives me Freq(X) Real (Y) Imag (Y) r(Y) Phi(Y) and Power (Y) (Held in FFT1)
I need the peaks for r (one at the moment but may need more i.e 5)
With the code you kindly provided me do I replace the instances of %H with FFT1_r?
Also where do I add the number of peaks required in the line (get %H_Pki -e end; // how many peaks?)
Many thanks again for your patience and advise.
Dean |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/13/2005 : 10:48:51 AM
|
quote: do I replace the instances of %H with FFT1_r?
If you begin the script with the command win -a FFT1; then the string variable %H will have the value FFT1 until another window is activated. Then you need only replace %B=%H_Real with %B=%H_r.
quote: where do I add the number of peaks required
curve.pickPeaks() finds all peaks that satisfy the given height and width criteria. The following script outputs the peak info to a temporary wks and copies the nPeaks largest peaks back to FFT1...
nPeaks=5; // number of peaks you want win -t D; // create a wks %W=%H; // save its name wks.addcol(Pki); // add a column for peak indices win -a FFT1; // activate FFT1 wks wks.addCol(Pkx); // add Pkx col wks.addCol(Pky); // add Pky col %B=%H_r; // name of fft dataset curve.reset(); curve.data$=%B; curve.peakIndex$ = %W_Pki; curve.pickPeaks.rectHeight = 0.05; // adjust for your data curve.pickPeaks.rectWidth = 0.05; // adjust for your data curve.pickPeaks.minHeight = 0.05; // adjust for your data curve.pickPeaks(1); get %W_Pki -e end; // end is # peaks found for(ii=1;ii<=end;ii++) { index = %W_Pki[ii]; %W_A[ii] = xvalue(index,%B); %W_B[ii] = %B[index]; } sort -wd %W %W_B; // sort %W by pk height (descending order) set %W -er nPeaks; // truncate %W to nPeaks rows sort -w %W %W_A; // sort by pk position (ascending order) copy %W_A %H_Pkx; // copy pk positions to FFT1 copy %W_B %H_Pky; // copy pk heights to FFT1 win -cd %W; // delete pk info wks
Mike Buess Origin WebRing Member |
 |
|
dean.pask
UK
Posts |
Posted - 10/13/2005 : 11:16:55 AM
|
Mike,
Many thanks again,
I run the script and get a new woksheet with A(X) B(Y) and Pki(Y)+ FFT1 gets Pkx(Y) and Pky(Y) added.
No data is added and I get a #command error! in the script window!! any ideas.
Dean
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/13/2005 : 12:25:36 PM
|
My first guess is that no peaks were found. Insert these lines after the line with get %W_Pki -e end...
type -a $(end) peaks were found; if(end==0) { win -cd %W; del col(Pky); del col(Pkx); return; };
If you see the message "0 peaks were found" in the script window you must change the curve.pickpeaks.rectheight/rectwidth and minheight parameters to suit you data. See Curve Object Properties Specific to Baseline Operations and Peak Selection for details.
...Another thought: curve.reset() sets the property curve.pickpeaks.simple to 0, which means use a baseline. I think curve.pickpeaks(1) sets that property to 1 internally, but you might preceed that command with curve.pickpeaks.simple=1 to be sure.
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 10/13/2005 12:50:07 PM |
 |
|
dean.pask
UK
Posts |
Posted - 10/13/2005 : 5:27:49 PM
|
Mike,
Just finished jumping around the room in joy.... many many thanks for all the help.
Just a few more questions sorry :-)
I now gain 3 peaks two negative (x) and the one I want positive (x). How can I filter my data so I have only +x data.
Also for presentation purposes I would like to take the values and display them on the graph similar to what happens when you pick peaks from the menu.
Super Thanks,
Dean Pask
|
 |
|
dean.pask
UK
Posts |
Posted - 10/14/2005 : 06:40:05 AM
|
Duplicate of next message
Edited by - dean.pask on 10/14/2005 06:43:00 AM |
 |
|
dean.pask
UK
Posts |
Posted - 10/14/2005 : 06:41:10 AM
|
Mike,
Hope you had a relaxing evening.
Just a quick one I hope.. My code is below (well more your code than mine) which works top dollar for one run... My problem is if I run the program say twice only the first run is duplicated... I imagine the code needs some way of changing which data it looks at for each complete run (something using %H a guess?). Hope you can help me yet again. Dean
wks.col1.type=4
win -a Data1; worksheet -s 2 0 2 0; worksheet -p 200 Origin; layer -a;
fft.reset(); fft.forward = 1; fft.forward.timeData$ = Data1_A fft.forward.tdelta = Data1_A[2] - Data1_A[1]; fft.forward.realData$ = Data1_B window -t W FFT1; fft.output.samplingdata$ = FFT1_Freq; fft.output.realdata$ = FFT1_Real; fft.output.imagdata$ = FFT1_Imag; fft.output.ampdata$ = FFT1_r; fft.output.phasedata$ = FFT1_Phi; fft.output.powerdata$ = FFT1_Power; fft.real = 1; fft.normalize = 1; fft.shifted = 1; fft.winddowing = 1; fft.spectrum = 1; fft.unwrap = 1; fft.forward();
win -a FFT1 worsheet -s 4 0 4 0; worksheet -p 200 Origin; layer -a;
Layer1.y.from = 0; Layer1.y.to = 10; Layer1.x.from = 0; Layer1.x.from = 3E9;
win -a FFT1; nPeaks=5; win -t D; %W=%H; wks.addcol(Pki); win -a FFT1; wks.addCol(Pkx); wks.addCol(Pky); %B=%H_r; curve.pickpeaks.simple=1; curve.reset(); curve.data$=%B; curve.peakIndex$ = %W_Pki; curve.pickPeaks.rectHeight = 0.005; curve.pickPeaks.rectWidth = 0.005; curve.pickPeaks.minHeight = 0.005; curve.pickPeaks(1); get %W_Pki -e end; type -a $(end) peaks were found; if(end==0) { win -cd %W; del col(Pky); del col(Pkx); return; } for(ii=1;ii<=end;ii++) { index = %W_Pki[ii]; %W_A[ii] = xvalue(index,%B); %W_B[ii] = %B[index]; } sort -wd %W %W_B; set %W -er nPeaks; sort -w %W %W_A; copy %W_A %H_Pkx; copy %W_B %H_Pky; win -cd %W;
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/14/2005 : 07:50:42 AM
|
Hi Dean,
quote: How can I filter my data so I have only +x data.
Change the peak info loop to this...
nn=0; for(ii=1;ii<=end;ii++) { index = %W_Pki[ii]; xx=xvalue(index,%B); if( xx<0 ) continue; nn++; %W_A[nn] = xx; %W_B[nn] = %B[index]; }
quote: I would like to take the values and display them on the graph similar to what happens when you pick peaks from the menu.
That can be done but I think it deserves a separate topic.
quote: if I run the program say twice only the first run is duplicated
I need some details about how you plan to use this script because that statement doesn't make sense on its own.
1. Will the starting wks be Data1 each time you run the script? 2. Do you want to create a new wks (FFT2, FFT3...) for the FFT/peaks data each time you run the script or do you want to overwrite FFT1?
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 10/14/2005 09:08:11 AM |
 |
|
dean.pask
UK
Posts |
Posted - 10/14/2005 : 11:26:06 AM
|
Mike,
Maybe some background mayhelp...
I am currently using an interferometer technique for measuring distances. I use Labview to gather the waveform which gives me Data1 (can be called what ever this just comes up as default). I plot this as a visual check and then FFT the data and from the peaks I can calculate the distance of an object.
I want to scan hundreds of sensors in which I need to keep at least the peak values although I would like to keep the oringal Data1 plot and the FFT plot.
So yes I want to create new wks and plots (graph) each loop..
Is this doable?
Many thanks as ever and have a great weekend if we dont speak before.
Dean
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/14/2005 : 1:43:58 PM
|
Hi Dean,
So you send data to Origin from Labview and put it in a new wks. Then you run the script above (or something like it) to process the data. I hope you are not sending the entire script from LabView because your VI is probably getting crowded. Much easier to put the script in a section of a text file and execute the command run.section(fileName,sectionName) from Labview. The script will also be much easier to edit from a text file.
Another comment in the vein of "things to watch out for"... In your latest script several command lines (ignoring comments) do not end with a semicolon. Omitting the semicolon has unpredictable results and often ends in disaster. Likewise, duplicate semicolons (;;) should be avoided.
That said, a newly created worksheet or graph window is active by default and you can get its name from the string variable %H. The following version of your latest script should be repeatable.
# Labview's wks should be active %L=%H; // save its name wks.col1.type=4;
# plot Labview data worksheet -s 2 0 2 0; worksheet -p 200 Origin; layer -a;
# create FFT wks window -t W FFT; %F=%H; // save its name page.label$=FFT of %L; // identify Labview data in label page.title=3; // show label
# perform FFT fft.reset(); fft.forward = 1; fft.forward.timeData$ = %L_A; fft.forward.tdelta = %L_A[2] - %L_A[1]; fft.forward.realData$ = %L_B; fft.output.samplingdata$ = %F_Freq; fft.output.realdata$ = %F_Real; fft.output.imagdata$ = %F_Imag; fft.output.ampdata$ = %F_r; fft.output.phasedata$ = %F_Phi; fft.output.powerdata$ = %F_Power; fft.real = 1; fft.normalize = 1; fft.shifted = 1; //fft.winddowing = 1; // misspelled fft.windowing = 1; fft.spectrum = 1; fft.unwrap = 1; fft.forward();
# plot FFT data worsheet -s 4 0 4 0; worksheet -p 200 Origin; Layer1.y.from = 0; Layer1.y.to = 10; Layer1.x.from = 0; Layer1.x.from = 3E9;
# pick peaks nPeaks=5; win -t D; // create temporary wks %W=%H; // save its name wks.addcol(Pki); win -a %F; // activate FFT wks wks.addCol(Pkx); wks.addCol(Pky); curve.pickpeaks.simple=1; curve.reset(); curve.data$=%F_r; curve.peakIndex$ = %W_Pki; curve.pickPeaks.rectHeight = 0.005; curve.pickPeaks.rectWidth = 0.005; curve.pickPeaks.minHeight = 0.005; curve.pickPeaks(1); get %W_Pki -e end; type -a $(end) peaks were found; if(end==0) { win -cd %W; del col(Pky); del col(Pkx); return; }; nn=0; for(ii=1;ii<=end;ii++) { index = %W_Pki[ii]; xx = xvalue(index,%B); if( xx<0 ) continue; nn++; %W_A[nn] = xx; %W_B[nn] = %F_R[index]; }; sort -wd %W %W_B; set %W -er nPeaks; sort -w %W %W_A; copy %W_A %H_Pkx; copy %W_B %H_Pky; win -cd %W;
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 10/15/2005 10:07:42 AM |
 |
|
dean.pask
UK
Posts |
Posted - 10/15/2005 : 3:03:18 PM
|
Mike.
Can't get this version to work yet although it appears to have the same problem as a step back the add on section to filter data -
nn=0; for(ii=1; ii<=end; ii++) { index = %W_Pki[ii]; xx = xvalue(index,%B); if (xx<0) continue; nn++; %W_A[nn] = xx ; %W_B[nn] = %B[index]; };
The temp Data5 stays open and the values are not inputed into the FFT1 as happens in the unfiltered version....
Any ideas?
Dean
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/15/2005 : 3:19:28 PM
|
I forgot to define %B. Add %B = %F_r; before the loop you quoted.
...The workaround to restrict peak positions to x>0 will fail similarly if no such peaks are found. The peak-picking script below tidies that up a bit.
# pick peaks nPeaks=5; %B=%F_r; win -t D; // create temporary wks %W=%H; // save its name wks.addcol(Pki); // add col for peak indices curve.pickpeaks.simple=1; curve.reset(); curve.data$=%B; curve.peakIndex$ = %W_Pki; curve.pickPeaks.rectHeight = 0.005; curve.pickPeaks.rectWidth = 0.005; curve.pickPeaks.minHeight = 0.005; curve.pickPeaks(1);
# stop if no pks found get %W_Pki -e end; if(end==0) { type -a No peaks were found.; win -cd %W; return; };
# extract pk values for X > 0 nn=0; for(ii=1;ii<=end;ii++) { index = %W_Pki[ii]; xx = xvalue(index,%B); if( xx<0 ) continue; nn++; %W_A[nn] = xx; %W_B[nn] = %B[index]; }; type -a $(nn) peaks were found;
# keep only the nPeaks highest pks if(nn>nPeaks) { sort -wd %W %W_B; set %W -er nPeaks; sort -w %W %W_A; };
# copy peak info (if any) to FFT wks if(nn>0) { win -a %F; // activate FFT wks wks.addCol(Pki); wks.addCol(Pkx); wks.addCol(Pky); copy %W_Pki %H_Pki; copy %W_A %H_Pkx; copy %W_B %H_Pky; };
win -cd %W; // delete temporary wks
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 10/15/2005 3:22:17 PM
Edited by - Mike Buess on 10/16/2005 08:32:22 AM |
 |
|
dean.pask
UK
Posts |
Posted - 10/18/2005 : 09:48:40 AM
|
Mike,
Excellent Help A+++ for this.
Is there a method for each run to copy the +peaks into a seperate wks to save me clicking through one by one?
Also after looking at my Data it looks like I need to start looking into curve fitting techniques (looks like my data may be squewed left/right due to lack of data points).
Should I start a new thread for this problem?
Many thanks as ever.
Dean
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 10/18/2005 : 10:11:04 AM
|
Dean,
You could either copy the peaks to a common wks or to the Results log. (Or both.) Perhaps it would be best to start a new thread. This one is rather long and it takes a while to scroll through it. I suggest that you post your working script and tell us what you want to do next.
Mike Buess Origin WebRing Member |
 |
|
|
Topic  |
|