- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Phase shifting to normalise sine wave data
I am trying to phase shift sine wave data so that all the minimum peaks are shifted to lie along the x axis. I have been trying with this code but running into an error with "Should be list or number in access or evaluation of 'Matrix' , Matrix/*###*/(sineCol < < Get Values)"
Any help would be appreciated.
// Load data
dt = Current Data Table();
// Specify column with sine wave data
sineCol = dt << Column("PITCH");
// Convert sineCol to matrix
sineMat = Matrix(sineCol << Get Values);
// Calculate the index of the minimum peak
minIndex = Loc Min(sineMat);
// Calculate the number of points to shift the data
shiftPoints = N Rows(sineMat) - minIndex;
// Shift the data
shiftedSineCol = J(N Rows(sineMat), 1, .);
For(i = 1, i <= N Rows(sineMat), i++,
shiftedSineCol[i] = If(i <= shiftPoints,
sineMat[shiftPoints - i + 1],
sineMat[N Rows(sineMat) - i + shiftPoints + 1]
)
);
// Create table of shifted data
newTable = New Table("PITCH Shifted", Add Rows(N Rows(dt)));
newTable["PITCH Shifted"] = shiftedSineCol;
newTable["TIME"] = dt:column("TIME");
// Save table
newTable << Save("PITCH Shifted.jmp");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Phase shifting to normalise sine wave data
Reference to sineCol isn't correct
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
sineCol = dt << Column("name");
show(sineCol);
sineCol2 = Column(dt, "name");
show(sineCol2);
here are few optional ways of getting values to matrix from continuous column
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
sineMat1 = Column(dt, "height") << get values;
sineMat2 = dt[0, "height"];
show(sineMat1, sineMat2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Phase shifting to normalise sine wave data
Hi thank you for this, I am not very experienced with script writing, are you able to explain to me where I put these updated lines into the script. And what is the difference between sineMat1 and sineMat2.
Thankyou
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Phase shifting to normalise sine wave data
I would very strongly to try and get familiar enough with scripting that you can use this so you understand what it does (using printing to debug scripts, referring column from datatable and getting values from that column). sineMat1 and sineMat2 are same but the method how the values are retrieved from datatable differ.
You would replace the code used for your sineCol and sineMat with corresponding datatable and column names, below is example using Big Class and height column.
Names Default To Here(1);
dt = open("$SAMPLE_DATA/Big Class.jmp");
sineCol = Column(dt, "height");
sineMat = Column(dt, "height") << get values;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Phase shifting to normalise sine wave data
Thank you, this is not my area of expertise I am trying to find a way to visualise my data for my PhD. I have this error and I have tried to fix it but can't seem to.
Would you have any advice?
invalid subscript (must be number or list of numbers){395} in access or evaluation of 'Assign' , newTable["PITCH Shifted"] = /*###*/shiftedSineCol/*###*/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Phase shifting to normalise sine wave data
Syntax after creating the new table seems to be wrong when you are trying to create a column? I would suggest checking out JMP Scripting Index (found from JMP help menu) and Scripting Guide (jmp.com). Both have good examples (sometimes) on the .jsl syntax
Scripting index:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Phase shifting to normalise sine wave data
Do you have JMP Pro? If so, then the Functional Data Explorer might be useful. It provides many data processing functions and fits spline basis functions to analyze cyclic data. You might not need to code as much.