05-02-2010 07:59 AM - edited 05-02-2010 08:02 AM
I am calculating peak position for several graphs which vary slightly. This slight variation causes the position of peaks to move around. What I want to be able to do is take this peak information and realign it in columns of an array.The way I need to align my peaks is that peaks must not vary more than 5 between each graph. So if this is my raw data:
I want to try and align it something like this. The difference from the previous value must not be more than 5.
0 236.92 281.124 303.104 325.021 366.529 0
51.2476 234.159 0 0 0 366.804 402.156
52.1135 234.633 0 0 0 366.938 404.016
55.8257 234.826 0 0 0 366.99 404.995
49.8949 234.759 276.989 0 0 366.993 407.033
What I want to be able to do I align peaks in such a way that only those peaks with a difference of 5 points or less from the previous sample are in the same column. I am having trouble creating columns for new peaks, and dealing with peaks when they disappear and reappear. If anyone can look at my code and
give me any tips I would be very grateful.
So far I have managed to do this however I am having trouble creating columns for new peaks. If anyone can look over my code and give me any tips I would be very grateful.
Thanks
P.S. Also in a different message someone posted http://forums.ni.com/ni/attachments/ni/170/494181/1/Sort%20Data.png This works well except the column sorting is based on the first row, not the difference between adjacent rows.
Solved! Go to Solution.
05-02-2010 06:38 PM
05-03-2010 02:35 PM
Hi LVStudent,
I'm not quite sure what the pattern is here. Can you provide a few more details?
It looks like in your aligned array, you are pulling from different columns. (ex: 236.92 is coming from the 1st column, and 234.633 is coming fom the 2nd column)
What does the original 2D array represent exactly?
05-03-2010 09:02 PM
Each row in the array contains the position of peaks from a signal. The position of peaks in row 1 are extracted from an acoustic signal at 0 degrees, the position of peaks in row 2 are extracted from an acoustic signal at 1 degree, the position of peaks in row 3 are extracted from an acoustic signal at 2 degrees and so on up to 360 degrees. As these acoustic signals obviously vary slightly with degrees, the position of peaks also move slightly (say no more than 5 points from one signal to the next), or these peaks disappear and reappear. This means if I want to track the behaviour of a certain peak, they don't neatly line up in columns. So basically what I am trying to do is put peak positions into columns where there is no more than a 5 point difference between peaks extracted from adjacent signals. So if there is a peak positon of 236.92 in row 1, and in row 2 their is a value that is within +5 or -5 from 236.92, then it would be put in the same column. Next I would check the value 234.633 in row 2 and see if there is a value in row 3 that is within +5 or -5, then that would also be put in the same column. So 236.92 from row 1 would be in column 1, and 234.633 from row 2 would also be in column 1. Does that kinda make sense?
05-04-2010 03:50 AM
Hi LV,
Your example data of how you want the aligned array to look doesnt appear right. You seem to be moving data from 1 row to another. Are you sure this is what you want. I would of thought that you need to keep the data within its original row but move it according to data within its column.
If this is what you want then this should do it:
I have tested it using the data that you show in your array and it works how i think it should be done.
Rgs,
Lucither
05-04-2010 05:12 AM
Hi LV,
I posted the wrong snippet. Use this one. This one also removes any columns that are all 0's, which can happen once they get shifted around.
Rgs,
Lucither
05-04-2010 06:56 AM
05-04-2010 07:02 AM - edited 05-04-2010 07:03 AM
No Worries, glad its what your after.
05-04-2010 08:50 AM
Hi Lucither,
I was just looking over that code snippet you sent me and its very helpful, however how would I adjust it so I put data into columns where instead of the condition for adding data to a column being a difference of 5 (or whatever value) from the lowest value in the column, values are put into columns based on the difference of a value from 1 row to the next?
05-04-2010 09:00 AM
Hi LV,
Unfortunately i am just on my way out. I will be flying to Singapore tomorrow so wont be able to look at this for you for a couple of days.
I will have a look at what you want though when i get time.
Rgs,
Lucither