computing second derivative from txt/csv file based on existing excel algorithm

Hi everyone,
I am new to Matlab. I have trouble finding anwsers to my problem. I decided to try Matlab for faster computing of my problem. I am working on my PhD from biomechanics as physiotherapist. I haave captured data from c3d files and by mokka software it can be exported for selected markers to txt file. In excel, each time I need to paste exported data to excel algoritm which I attached in a file here. Then I need to find max velocity of each move (three kicks captured for one file). It is time consuming in excel. i need to do it about 400 times. Each time it gave me only 3 results and takes around 10-15 minutes to do it. I had idea of making macro in Matlab. I want to write an alogrithm for skipping some steps. I want to import file, compute second derivative (t time, xyz -marker positions), and then find max values from 3 sectors -rows 0-700, 701-1400, 1401-2100. I cannot find commands for computing this in a same manner as it is in this excel file. Can you at least guide me how do I compute columns values row to corresponding row?

1 commentaire

"how do I compute columns values row to corresponding row?"
Can you explain what, precisely, you mean by the above?
A short example with inputs and expected outputs and how the output follows from the input would be best...

Connectez-vous pour commenter.

 Réponse acceptée

dpb
dpb le 16 Avr 2019
Modifié(e) : dpb le 16 Avr 2019
Here's perfect example why Matlab excels over Excel... :)
txyz=importdata('B0264_dollyo_air_P_T01 rtoe.txt',',',8); % read the text file
txyz=txyz.data; % all data in array time,x,y,z
dxyz=diff(txyz); % first differences of all columns
vxyz=dxyz(:,2:end)./dxyz(:,1)/1000; % compute velocity components
v=sqrt(sum(vxyz.^2,2)); % and the total velocity
One doesn't need to keep all the intermediary variables unless there's other need for them; kept here so can look at them and see how matches up.
The text file and the Excel file aren't the same data and the Excel file has the European "," for the decimal point so it's hard to read here in the US w/o other machinations so couldn't directly illustrate it does give identical result...
BTW, despite the Q? title, there's only a first derivative, not second...if need the second, you just "rinse and repeat" the above or use the second, optional argument to diff to compute it directly if don't need the first but this was just a step along the way...

1 commentaire

Thank you very much! This will help me a lot.
I propably made a mistake translating math terms.
Best wishes for you

Connectez-vous pour commenter.

Plus de réponses (1)

Please see the excel file. There is T value for time X, Y, Z for position in time for markers. =(B4/1000-B3/1000)/($A4-$A3) for example (x4/1000-x3/100)/(t4-t3). I do not know how to adress colums and values as it is in excel. If I state in matlab t2 = varx(:, 2) to have x value column and the same matter t column, what should I write to compute the same pattern as in excel? I am providing sample of txt file.

12 commentaires

derivative is as x' = dx/dt, to determine dx or dt lower row need to be done by minus upper row value. /1000 is tu use standard unit as txt is in mm. I checked your code with excel computing and it gives proper values.
The last part is getting peak values. There are v is computed speed of three kicks. I am attaching figure to discribe the idea. I need maximum velocity for each kick, so I tried function like this:
v1 = max(v(1:700));
but it returs error. This is crucial part for fast computing of max velocity of each kick.
The second thing is, can I apply this algorithm for multiple files at the same time?
If you are interested there is one of the work from this series of biomechanic analysis.
There's a job for findpeaks
>> [pks,locs]=findpeaks(v,'minpeakheight',6)
pks =
9.5790
10.8706
12.2447
locs =
653
1525
2452
>>
See
doc findpeaks
for details...there are numerous options to help find the ones of interest. I just took the easy route out of looking at the plot and picking a threshold number.
As for multiple files, just put the code in a loop and read each file sequentially...there are any number of threads about processing mutiple files..
ADDENDUM
And, of course, you could string all the various velocity measurements together into a single array or file while doing so for further analyses later on and not have to reprocess the raw data again...if measurements aren't same length, either use cell array or augment shorter with NaN to create array of double...
I am very grateful. You saved me incredible amount of time. I will take your advise and learn how to place this code to loop to compute series of files.
I am amazed that your willing to help others. Best wishes for you. I promise to continue my development.
It's a hobby; there are many on the Answers forum that spend far more time than I but all have a fondness for Matlab itself plus enjoy both the challenge some of the Q?s posed as well as just tutoring newcomers into effective use of the tool--it's enough different in concept as compared to procedural languages that aren't vectorized in their operations or the spreadsheet paradigm it takes some time to understand just what it is good for and how to take advantage of it.
For the multiple files, I recommend to first look at the dir solution under the help topic Import or Export a Sequence of Files -- it's not the easiest topic to find altho one of the most oft-needed functionalities -- there's link under the Standard File Formats topic at the Data Import and Export higher level topic.
With that you simply iterate through the returned list of files retrieving the name of each in sequence from the dir structure name field...it's a "piece o' cake!" that way as long as you can make a suitable wildcard expression to return the wanted list of filenames.
I will work on that. For everyday I am physiotherapist but also reasercher. What I lack is high-tech solutions, which often are expensive, so I want to learn more about useful software to enchance my work. In my filed interdisciplinary approach is requested nowadays. Too bad that after 10 h of normal work I have only few hours to try stuff before I am worn off for a day. Previosly I tried that kind of algorithm in python or R, but even importing file properly was a problem. Matlab excels not only ms excel but other computing systems as well from my point of view for now. Now I need to choose license and continue working.
For that kind of reasearch one txt is for one marker. On one man there is more than 20 markers. I have 15 men and 3 different target of kicking. Marco was needed or else I would need to leave my job for my phd. Great thing that there are people who help other for hobby. I wish I could recompasate for help
ML is definitely expensive outside the student license which sounds like you wouldn't qualify for, unfortunately.
There is the open "workalike" Octave for at least the base functionality; I do not know what all of the toolbox functionality is available (findpeaks is in the ML Signal Processing TB, not the base product).
If I follow your description, it would be pretty easy to group the data by individual incorporating all records for that person in one file...again, if it is simply this velocity that is the end result, then just saving it would be a big reduction in futher processing as long as don't need to do anything with individual velocity components for directional analysis, say.
Good luck...I'm an old fogey back on the family farm for some 20 years now after 30+ yr in consulting gig so my energy level tends to run low pretty early in the evening any more, too!
[DM Answer moved to comment... dpb]
If this computing is accessable via home license I will buy it. Commercial or academic is out of option for now, although I do not understand differences in licenses.
Farm you say? I imagine programmed machines on your field with your expertise:D
Indeed the two major changes since I "left for the big city" back in late '60s are twofold--
  1. Size of operations and equipment -- our operation that was upper quartile back then is now probably in bottom 20% by acreage farmed. What I did with a four-row lister at 3-4 mph planting is now 16-24 row planter at probably 6+ mph
  2. Technology -- GPS and the microprocessor has indeed revolutionized everything from self-guidance systems on the macro level to planters that meter and place individual seeds at nominal spacing in the row to achieve target planting density and dispense starter fertilizer and fungicides, etc., at the same time to harvest monitors that display in real time yield which then can be related back to the soil type and inputs for optimizing net return for making decisions going forward.
Even the most progressive had no way to collect the necessary data what more make use of it back then...
You'll want to talk to Mathworks sales support on options available -- I think there is a new "home user" or somesuch category now that didn't used to be for such cases but I'm not fully aware of all the options, sorry.
If you are using gps for farming you have much acre of fields. I hope weather will be favourable for you. I did not get the anwser from my country distributor about different licences. I learnd about scilab being free. I feel it is worse than matlab. I was unable to covert your code fully. I ask thier community, but their use only mailing list, so even for forum they are inferior. I can afford home license because it is 180 euro but full comiercial is too much for now. Whole month payment for me.
But maths problems and learining is much more fun now than gaming.
I'm not sure on the non-US licensing arrangements, sorry.
I'd think Mathworks US would answer an enquiry e-mail though and be eager to know of any sales associates that aren't responsive so they could take action.
The closest thing I know of altho I've never actually used it is Octave -- as said, I don't know about some of the more esoteric features in toolboxes, but the base product is pretty-much same functionality/syntax.
Thank you very much for recommending Octave. Code runs after I added signal package. It may be sufficient for now and further learning

Connectez-vous pour commenter.

Catégories

En savoir plus sur Historical Contests dans Centre d'aide et File Exchange

Produits

Version

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by