Sei sulla pagina 1di 99

University of Mumbai

Second Stage Project report on

Computational Modelling of Knee Joint for Deep


Squat Activities
Submitted in the partial fulfillment of the requirements

for the degree of

Masters in Engineering
by

Saylee Patkar
Roll No: 1705005
University Registration No.

Guide: Dr. Ramesh Lekurwale


Co-Guide: Dr. Sonali Patil
External Guide: Dr. Rajani Mullerpatan

Department of Mechanical Engineering


K. J. Somaiya College of Engineering
Mumbai 400077
Batch 2017 -2019
University of Mumbai

K. J. Somaiya College of Engineering, Mumbai-77

Certificate

This is to certify that the second stage project report on dissertation entitled
“Computational Modelling of Knee Joint for Deep Squat Activities” is bonafide
record of the dissertation work done by Saylee Patkar in the year 2017-19 under
the guidance of Dr. Ramesh Lekurwale of Department of Mechanical Engineering
in partial fulfillment of requirement for the Master’s degree in CAD/CAM &
Robotics Engineering of University of Mumbai.

_________________ _____________________
Guide / Co-Guide Head of the Department

_________________
Principal

Date:
Place: Mumbai-77

1
University of Mumbai

K. J. Somaiya College of Engineering, Mumbai-77

Certificate of Approval of Examiners

This is to certify that the second stage project report on dissertation entitled
“Computational Modelling of Knee Joint for Deep Squat Activities” is bonafide
record of the dissertation work done by Saylee Patkar in partial fulfillment of
requirement for the Master’s degree in CAD/CAM & Robotics Engineering of
University of Mumbai.

_________________ _________________

Expert / External Examiner Internal Examiner / Guide

Date:
Place: Mumbai-77

ii
Abstract
Computational Modelling is technique used when the system is complex and cannot be studied
by mathematical modelling, It uses mathematics, physics, computer science and statistics to
study the mechanism and behavior of system like human body or any biological system at their
cellular levels. The parameters and their effects on the system can be determined by
computational modelling by using computer simulation.

Gait is walking pattern of any musculoskeletal system referred mostly for human beings. Each
human being has a unique gait pattern with unique posture as well as pace of walking. This
pattern changes with every little change in person’s life. The gait of the person indicates the
health as well as lifestyle of the person. Study of this walking pattern is known as Gait Analysis.
Gait analysis serves a major role in bio-mechanics.

For this study, literature survey on gait and gait analysis is done which shows that a lot of
research has been going on based on gait of the subject where the evaluation is used for
exploring various areas of biotechnology. Also the literature survey on knee joint analysis shows
that there is exhaustive research is done on analysis for different postures. But the area of deep
squatting where maximum possible knee flexion occurs, is not explored much since it is not that
necessary for western countries. Whereas, in India the mostly used posture for daily living is
deep squat. Therefore, the need for this analysis is much higher for designing a new prosthesis as
well planning knee replacement surgeries for Indians.

In this study, computational modelling will be used to determine the forces on knee joint during
deep squat activities, incorporating thigh-calf contact. The Vicon Nexus Motion Capture
0Software will be used for collection of data and motion occurring during the Gait Analysis of
subject. The experimental Electromyography muscle forces will be calculated using DELSYS
software integrated with the Vicon Nexus Motion Capture Software. For Gait Analysis full
possible knee flexion will be considered, which will be participant specific. The Kinematic
Analysis Data will be captured using retroreflective markers placed on participant’s body.
Calculation of muscle forces will be done by Opensim 4.0 , a simulation software.

1
The forces calculated by Opensim will be validated by experimental forces calculated using
MATLAB. To validate all the forces incorporating Thigh-Calf muscle contact force and their
effect on knee joint during deep squat activities, Finite Element Modelling and Analysis will be
done.

Key words: Deep squat activities, Knee joint analysis, Gait analysis, Computational modeling

ii
Contents

Abstract ........................................................................................................................................... i

List of Figures ................................................................................................................................ v

List of Tables .............................................................................................................................. viii

Nomenclature ............................................................................................................................... ix

Introduction ................................................................................................................................... 1

1.1 Introduction ...................................................................................................................... 1

1.2 Motivation ........................................................................................................................ 2

1.3 Scope ................................................................................................................................ 2

1.4 Objectives ......................................................................................................................... 2

1.5 Organization of Report ..................................................................................................... 3

Literature Survey .......................................................................................................................... 4

2.1 Literature Survey on Gait Analysis .................................................................................. 4

2.2 Literature Survey on Knee Joint Analysis........................................................................ 5

2.3 Literature Survey on Finite Element Analysis of Bone ................................................... 6

2.4 Literature review .............................................................................................................. 7

Fundamental Concepts ................................................................................................................. 9

3.1 Human Anatomy .............................................................................................................. 9

3.1.1 Coordinate axes and planes ....................................................................................... 9

3.1.2 Joint Coordinate system .......................................................................................... 11

3.2 Vicon Nexus Motion Capture System ............................................................................ 11

3.2.1 MoCap System ........................................................................................................ 12

3.2.2 AMTI Force Plate ................................................................................................... 13

iii
3.2.3 Electromyography ................................................................................................... 13

3.3 Opensim 4.0 Software .................................................................................................... 14

Methodology ................................................................................................................................ 19

4.1 Methodology .................................................................................................................. 19

4.1.1 Data Collection ....................................................................................................... 19

4.1.2 Opensim Analysis ................................................................................................... 22

Implementation of Opensim Methodology ............................................................................... 25

5.1 Implementation of Methodology.................................................................................... 25

5.2 Results ............................................................................................................................ 30

Implementation of FEA .............................................................................................................. 40

6.1 Creating Free Body Diagram ......................................................................................... 40

6.2 Material Properties of Bone and Articular Cartilage ..................................................... 49

6.3 Conversion of MRI to 3D model.................................................................................... 50

6.4 Finite Element Analysis Results .................................................................................... 51

Conclusion and Future Scope .................................................................................................... 53

1. Conclusion ......................................................................................................................... 53

2. Future Scope ...................................................................................................................... 53

References .................................................................................................................................... 55

Appendix A .................................................................................................................................. 58

Opensim Matlab Utilities .......................................................................................................... 58

Motion Analysis ........................................................................................................................ 67

Muscle force validation ............................................................................................................. 79

iv
List of Figures
Figure 3. 1 Anatomical Axes and Reference Planes [17] ............................................................. 10

Figure 3. 2 Movements of Lower Limb [17] ................................................................................ 10

Figure 3. 3 Joint Coordinate System [18] ..................................................................................... 11

Figure 3. 4 Vicon Nexus Motion Capture System [19] ................................................................ 11

Figure 3. 5 Principle of Retro-Reflection [20] .............................................................................. 12

Figure 3. 6 Retro-Reflective Markers [20] ................................................................................... 12

Figure 3. 7 AMTI Force-Plates .................................................................................................... 13

Figure 3. 8 Opensim 4.0 GUI........................................................................................................ 14

Figure 3. 9 Scaling Principle ......................................................................................................... 16

Figure 3. 10 IK Principle .............................................................................................................. 17

Figure 4. 1 Work Flow of Thesis .................................................................................................. 19

Figure 4. 2 Data Collection Procedure .......................................................................................... 19

Figure 4. 3 Marker Placement ....................................................................................................... 20

Figure 4. 4 Data Collection-Gait Analysis .................................................................................... 21

Figure 4. 5 Static Position 1 .......................................................................................................... 21

Figure 4. 6 Static Position 2 .......................................................................................................... 21

Figure 4. 7 Walk Trial ................................................................................................................... 22

Figure 4. 8 Squat Trial .................................................................................................................. 22

Figure 4. 9 Opensim Analysis Methodology ................................................................................ 22

Figure 4. 10 Scale Tool Overview [20] ........................................................................................ 23

Figure 4. 11 IK Tool Overview [20] ............................................................................................. 23

Figure 4. 12 CMC Tool Overview ................................................................................................ 24

v
Figure 5. 1 Scaled Model .............................................................................................................. 26

Figure 5. 2 Inverse Kinematics: Squatter Model .......................................................................... 26

Figure 5. 3 Inverse Kinematics: Non-Squatter Model .................................................................. 27

Figure 5. 4 Squatter Model(Front View) ...................................................................................... 27

Figure 5. 5 Squatter Model(Sagittal View) .................................................................................. 28

Figure 5. 6 Non- Squatter Model(Front View) ............................................................................ 28

Figure 5. 7 Non- Squatter Model(Sagittal View)......................................................................... 29

Figure 5. 8 Validation of Left Knee Flexion Angle using MATlab ............................................. 30

Figure 5. 9 Validation of Right Knee Flexion Angle using MATlab ........................................... 31

Figure 5. 10 RMS Error for Knee Flexion Angles Validation ...................................................... 31

Figure 5. 11 Validation of Right Knee Flexion Angle using MATlab ......................................... 32

Figure 5. 12 Validation of left Knee Flexion Angle using MATlab ............................................. 33

Figure 5. 13 Line Diagram Sagittal View: Non-Squatter Model .................................................. 34

Figure 5. 14 Line Diagram Front View: Non-Squatter Model ..................................................... 34

Figure 5. 15 Erector Spinae Muscle .............................................................................................. 35

Figure 5. 16 Gastrocnemius Muscle ............................................................................................. 35

Figure 5. 17 Gluteus Maximus Muscle ......................................................................................... 36

Figure 5. 18 Gluteus Medius Muscle ............................................................................................ 36

Figure 5. 19 Hamstring Muscle .................................................................................................... 37

Figure 5. 20 Rectus Femoris ......................................................................................................... 37

Figure 5. 21 RMS Error for Muscle Force Validation .................................................................. 39

vi
Figure 6. 1 Forces acting on lower limb ....................................................................................... 40

Figure 6. 2 Epicondylar Axis in Femur: Tibial Surface................................................................ 41

Figure 6. 3 FBD- Lateral View ..................................................................................................... 42

Figure 6. 4 FBD- Medial View ..................................................................................................... 42

Figure 6. 5 FBD- Top View .......................................................................................................... 43

Figure 6. 6 FBD with Thigh-Calf Contact Force .......................................................................... 43

Figure 6. 7 Gastrocnemius ............................................................................................................ 46

Figure 6. 8 Gracilis ....................................................................................................................... 46

Figure 6. 9 Hamstring ................................................................................................................... 47

Figure 6. 10 Rectus Femoris ......................................................................................................... 47

Figure 6. 11 Sartoris ...................................................................................................................... 48

Figure 6. 12 Tensor Fasciae Latae ................................................................................................ 48

Figure 6. 13 Total deformation after knee flexion for right knee ................................................. 52

vii
List of Tables
Table 6. 1 Properties of femur Bone ............................................................................................. 49

Table 6. 2 Material Properties for FEA ........................................................................................ 51

viii
Nomenclature
MoCap Motion Capture

EMG Electromyography

SEMG Surface Electromyography

IK Inverse Kinematics

CMC Computed Muscle Control

RKNE Right Knee Marker Label

LKNE Left Knee Marker Label

ix
Chapter 1

Introduction
This chapter presents the brief introduction about the project and motivation behind
selecting this topic. The scope of the project is also mentioned in this chapter with the
detailed objectives defined for the work. Finally the chapter ends with the organization of
the report briefly explained.

1.1 Introduction
Gait of the person is the posture and pattern of walking. There are numerous factors which affect
the gait which are physical as well as psychological. The requirement of the examination of this
gait pattern is necessary for diagnosis of most of the orthopedic disorder such as misalignment of
bones or osteoarthritis. Also for replacements with implants or prosthesis the gait pattern changes
are need to be examined. This evaluation of gait is known as gait analysis. In gait analysis,
kinetic as well as kinematic analysis is done to create a model for a person’s gait pattern.

The clinical need for the knee joint analysis has become important nowadays, since the knee
joint related problems have become major issue for every age group. Since the research on knee
joint analysis for deep squatting is not done much, there is no reference healthy gait pattern is
available to compare the data with the patients’ data. This analysis is needed for designing a new
knee prosthesis which will allow the maximum possible knee flexion. The need to plan and
perform surgeries for osteoarthritis to reduce the after effects is also the need for this analysis
since current solution to this problem is doctor’s experience and knowledge only.

There are different gait analysis techniques available. For this study, we have used integration of
different techniques at a gait lab. The system consists of Motion Capture System(MoCap
System), AMTI Force Plate, Electromyography(EMG). Two healthy participants(Subjects), out
of which one is ADL(Activiies of Daily Living) Squatter and the other is non-squatter, are
examined for data collection and the data will analyzed on Opensim and Matlab software to get
the final results. For stress analysis, the Finite Element Analysis will be done on subject specific
knee joint 3D model which will be created using MRI files. For that, MRI file will be converted
to 3D model using MIMICS software.
1
1.2 Motivation
Indian folks are adapted to lifestyle where deep squat activities are mostly used. There
are various knee prosthesis available today but none of them provide full possible knee flexion
for these activities. Also, the different surgeries or treatments required for knee joint problems
like osteoarthritis are difficult because there are after effects of these surgeries, like early onset
arthritis or loosening of knee due to wear. By this study we can determine the causes for these
after effects and can develop the treatments to reduce the risk of causing them.

1.3 Scope
The scope of the thesis work is as follows:
• Kinematic Analysis of Knee joint during deep squat-Participant Specific
• Joint Angles
• Velocity and Acceleration of squatting
• Kinetic analysis of Knee joint during deep squat-Participant Specific
• Forces-Muscles and Bone on Bone
• Motions
• Finite Element Analysis of Knee joint
• Stress Analysis

1.4 Objectives
• Calculation of muscle forces for knee joint incorporating the effect of thigh-calf contact
force using Opensim simulation software
• Validation of forces calculated using Opensim with experimental forces calculated using
MATLAB
• Creating Free body Diagrams for forces on knee joint including muscle forces and Bone
on Bone forces
• Finite Element Modelling and Analysis of knee joint

2
1.5 Organization of Report
Section 2 of this report covers literature survey part of the topic. Section 3 covers Fundamental
concepts used for the methodology. Section 4 includes the methodology defined for the main
topic i.e. Computational modeling of knee joint for deep squat activities and the implementation
of the methodology. Section 5 concludes the work done and future work.

This chapter presented the brief introduction about the project and motivation behind
selecting this topic. The scope and objectives of the project are explained. The organization
of the report is briefly explained at the end of the chapter. The next chapter will present brief
literature review on the previous work done related to the project topic.
3
Chapter 2

Literature Survey
This chapter presents the Literature survey about Gait Analysis techniques used for data
collection. The second part of the chapter consists of review on previous research on knee
joint analysis.

2.1 Literature Survey on Gait Analysis


The research in gait analysis techniques is still going on. The researchers have been working on
application of gait analysis in various areas including medical as well as engineering.

R. B. Davis et al, 1991[1] has given a standard protocol for data collection technique. The paper
has compared the then available commercial motion system with developed video based system.
The now used motion capture system with markers was analyzed in this study. Vasilios Kyriazis,
2001[2] has explained the different types of gait analysis techniques according to different
constraints such as kinetic and kinematic analysis, parameters calculated by those techniques and
furthermore by the tools used for experimentation.

The gait analysis technology is used for person identification by L. Lee et al, 2002[3]. The
authors have given the gender classification using the silhouette of the subject where each
silhouette is divided into seven ellipse for gait appearance representation. The person recognition
was done based on appearance feature of the subjects.

Kaiyu Tong et al, 1999[4] explained the use of gyroscopic gait analysis system for evaluation of
inclination and joint angles of lower limbs. The uni-axial gyroscope was used for this
experimentation and it was strapped on thigh and shank and the subject was asked to perform the
activity. The results found were satisfactory and can be correlated with the data from motion
analysis system.

The alternative for traditional gait laboratory was explained by Stacy J. Morris Bamberg et al,
2008[5] with wearable wireless system. This shoe-integrated sensor system is a new approach for
gait analysis where a subject can be examined over a long period with repetitive dad collection.
Also this can be used in home environment as authors have suggested, hence the possibilities of
4
the errors due to subject’s psychological circumstances can be avoided. Moreover, the
integration of multiple sources has given the advantage of real time and different outputs from a
single system with distinguishing between healthy gait and Parkinson’s gait. Tao Liu et al,
2009[6] developed a wearable sensor system with inertial sensors of gyroscope and
accelerometer. Quantitative analysis was implemented with this system for lower limb with
intelligent calibration.

George Beckham et al, 2014[7] showed that how force plates can be used not only for clinical
practice but also for performance measuring in sports. The paper explains the different
mechanisms and the working of force plates and data collection process.

E.A. Clancy et al, 2002[8] has showed how to reduce the noise and interference in case of
recording SEMG data. The authors have explained where the noise reduction is possible while
recording the EMG and the process to estimate the amplitude of EMG to enhance the output of
the experiment. Mario Cifrek et al, 2009[9]has reviewed the SEMG technique for muscle fatigue
evaluation. The authors have explained how inter-disciplinary approach of bioengineering
provides the quantitative information about muscle fatigue using gait analysis and also stated that
the use of multiple techniques with integration can give the validation for outputs collected from
the same system.

2.2 Literature Survey on Knee Joint Analysis


A. hemmerich et al, 2006[10] studied the joint kinematics for non-western people. They
generated kinematic data at the hip, knee, and ankle joints of healthy Indian subjects during non-
Western activities of daily living, including squatting, kneeling, and cross-legged sitting. It was
observed in the experiment that the maximum knee flexion attained by the participants was 165o.
From these results the authors concluded that the range of motion required for all these activities
is more than the available prosthesis and it demands for the design of new prosthesis.

J.zelle et al, 2007[11] explained the of thigh-calf contact force measurement in deep flexion.
They showed that the thigh-calf contact occurs after 130o of knee flexion. For this study the
authors examined two activities kneeling and squatting, which requires deep knee flexion. It is
observed that the average maximal forces for each leg was 34.2% of the body weight for

5
squatting whereas for kneeling it was 30% of the body weight. Also the maximum knee flexion
was 151.8o in squatting and 156.4o in kneeling activity.

Michiko fukunga and Shunji Hirokawa, 2009[12] examined the deep knee flexion activities such
as kneeling. They used the 2D mathematical model simulation method to calculate the knee joint
forces for double leg and single leg ascending motion from these activities. They included the
muscle forces in the analysis and compared between forces on dominant and supporting leg in
single leg ascending with that of double leg ascending. It was observed that the muscle forces
were high in dominant leg in single leg ascending than the forces in double leg ascending. The
supporting leg experienced the least of muscle force.

Michiko fukunga et al, 2015[13] calculated tibiofemoral and patellofemoral forces at deep knee
flexion, kneeling and seiza position which is Japanese sedentary sitting position. They also
calculated the thigh-calf muscle contact force in these activities. They mentioned that the future
work for these analysis is to create a relation between joint forces and thigh-calf contact forces.

2.3 Literature Survey on Finite Element Analysis of Bone

Authors J.W. Fernandez et al,2005[14] explained use of MRI, X-Ray in studying human
movement. They used MRI data to create a 3D model of bones, muscle and cartilage and X-ray
fluoroscopy to calculate the relative motion of the bone for specific movement. The simulation
using both the outputs were carried out and the forces obtained from the simulation was used as
input to Finite Element Analysis.

Bozidar Potocnik et al, 2008[15] developed a optical force measurement system to calculate
compressive load during MRI process of 0o to 40o Knee flexion angle. The same compressive
load was given to the model created from MRI file and the outputs were compared. The main
aim was to find kinematics data in MRI process with non-invasive methods.

H.H. Rachmat and other authors, 2014[16] explained in brief the accuracy of MRI scans. In this
study they tested how accurately one can determine the origin and insertion of ligaments from
MRI data.

6
2.4 Literature review

Sr. Title Author Year Conclusion Remarks


No.

1 Forces during N. J. Dahlkvist, 1982 Considering 2D The authors analyzed


squatting and P. Mayo, model the outputs the forces for transition
rising B. B. Seedhom for joint forces and positions only when
muscle forces were there is no thigh calf
found. Data contact force. Even
collected using cine though the results were
films and EMG satisfactory, the
technique. fluctuations in the
muscle excitation may
have affected the
output.

2 Hip, Knee, A. Hemmerich, 2006 The authors Kinetic analysis for


and Ankle H. Brown, observed in the high knee flexion
Kinematics of S. Smith, experiment that the activity was not done.
High Range S.S.K. maximum knee But the kinematic data
of Motion Marthandam, flexion attained by obtained explains the
Activities of U.P. Wyss the Indian need for analysis for
Daily Living participants was high knee flexion
165o. They activity. Since, the
generated kinematic Computational data is
data at the hip, not available for the
knee, and ankle same.
joints.

3 Thigh–calf J. Zelle , 2007 Authors calculated Only the measurements


contact force M. Barink, the thigh calf were done for the
measurements R. Loeffen, contact force for contact force.
in deep knee M. De Waal kneeling and deep
flexion Malefijt, squatting and the
N. Verdonschot knee flexion angle
at which the contact
occurs.

7
4 Tibiofemoral Stacey M. Smith, 2008 New data collection Even though the data
joint contact Robert A. technique used and collection procedure
forces and Cockburn, Joint contact forces comparatively easy and
knee Andrea for High knee less time consuming
kinematics Hemmerich, flexion activities the author did not
during Rebecca M. Li, were calculated. include the thigh-calf
squatting Urs P. Wyss contact force, which
plays a major role for
balancing in this
position.

5 The Model Michihiko 2009 The experiment was The experiment only
Analysis of Fukunaga, done for ascending included the calculation
Lower Limb Shunji Hirokawa from kneeling of forces for two
at Ascending position in two methods of ascending
from Deep ways. And the and their correlation.
Knee Flexion forces on legs are
calculated and
compared for both
methods.

6 Calculation of Michihiko 2015 Authors calculated The future work of this


the knee joint Fukunaga, tibiofemoral, study includes the
force at deep Kentaro patellofemoral and discovery of relation
squatting and Morimoto thigh-calf muscle between joint forces
kneeling contact force forces and thigh calf contact
at deep knee forces.
flexion, kneeling
and seiza position
which is Japanese
sedentary sitting
position.

From above literature survey, the research gap was found and the problem was defined. The
main objective of this study is to analyze the effect of thigh-calf contact force on knee joint
forces during high flexion activity like deep squatting.

Based on the literature survey the research gap was found. In next chapter fundamental
concepts about human anatomy and software used are explained. Also the techniques of
Gait Analysis used for data collection are described in brief.
8
Chapter 3

Fundamental Concepts

This chapter presents the brief details about the human anatomical study done for this
analysis. The chapter also includes the details of software and tools used for analysis.

3.1 Human Anatomy

3.1.1 Coordinate axes and planes


There are six axes and three planes which defines the basic human anatomy. These are
described as follows and shown in Figure 3.1:

• The frontal part is anterior and the rear part is known as posterior. The plane which
divides the anterior and posterior of the body is coronal plane.

• The plane which differentiates the left and right part of the body is sagittal plane.

• The upper part of the body is superior whereas the lower part is defined as inferior.
The horizontal plane divides these parts.

There are few more terms used to define the position of any body part in the human
anatomy.

• The body part which is near to the midline is defined as medial whereas the part
which is away from the midline is described as the Lateral.

• The position of body part which is near to the other reference part is described as
proximal while the one which is away is described as distal.

The movement of the lower limb is defined by different terms which is explained in the
Figure 3.2. For analysis mostly flexion and extension are considered which are motions
in sagittal planes.

9
Figure 3. 1 Anatomical Axes and Reference Planes [17]

Figure 3. 2 Movements of Lower Limb [17]

10
3.1.2 Joint Coordinate system
The joint coordinate system was modeled by E. S Grood and W. J. Suntay as four link
kinematic chain[18]. This system consists of all three cylindrical joints. Tibia and femur
are considered as first and last link whereas the connecting links are imaginary. The four
link kinematic chain is shown in Figure 3.3.

Figure 3. 3 Joint Coordinate System [18]

3.2 Vicon Nexus Motion Capture System


A vicon nexus motion capture system is used for data collection in integration with force plates
and EMG. The capture volume is the area in which the gait analysis takes place. Figure 3.4
capture volume by Vicon Nexus.

Figure 3. 4 Vicon Nexus Motion Capture System [19]


11
3.2.1 MoCap System
The MoCap system consists of:

• Vicon Camera- Bonita Optical Camera

This is an Optical Motion Capture Camera which contains 68 LEDs which illuminates
the marker in captures volume effectively.

• Retro-Reflective Markers

These are the markers(Figure 3.6) which are placed on subject’s body to capture the
location and trajectories of the movements. The markers follow the principle of retro
reflection(Figure 3.5) which makes the capturing process effective.

Figure 3. 5 Principle of Retro-Reflection [20]

Figure 3. 6 Retro-Reflective Markers [20]

• Synchronization Box

It is a Single Communication point between components and host pc with vicon nexus
software.

12
3.2.2 AMTI Force Plate
In gait analysis using force plate, a platform is placed on the ground with the surface
leveled uniformly. A subject is asked to walk or run or do the required activity on that
surface and the measurements are taken. When a person stands or walks across the force
plate, it gives the reaction force. Balance analysis can be done by using the gait
parameters generated by this technique.

Figure 3. 7 AMTI Force-Plates [21]

There are two types of mechanisms for sensing technologies used for force plates
manufacturing. One of which uses Hall Effect and other contains strain gauges[21].A
force plate with Hall Effect consists of spring elements, sensors, magnets, signal
amplifier(Figure 3.7). Multiple Hall Effect sensors and magnets are integrated inside a
force transducer and this is used to measures all six force components- 3 Forces(Fx, Fy,
Fz) & 3 Moments(Mx, My, Mz). These force plates produces the output which can be
directly analyzed on computer system.

3.2.3 Electromyography
Electromyography is the process used in gait analysis which evaluates the muscle health
condition and examines the nerve cells controlling those muscle. A tiny electrical signal
is generated by the muscles when those muscles are activated by nerves which controls
them. This electrical activity produced by muscle is examined and recorded by EMG.
The machine used for EMG is known as Electromyograph whereas the recorded data
produced by EMG is known as Electromyogram.[22]

13
For this analysis ,surface EMG or SEMG is used. In this technique, the electrodes are
places on the skin over the muscle for which the electrical activity is to be studied.
Though it is noninvasive procedure it is not used commonly since it produces less
accurate output than intramuscular EMG. For EMG, the muscle strength is first assessed
by physiotherapist using dynamometer and the standardized protocols for clinicians. This
is done in integration with SEMG to optimize the results.

3.3 Opensim 4.0 Software[23]


OpenSim is a freely available software package that enables us to build, exchange, and analyze
computer models of the musculoskeletal system and dynamic simulations of movement. The
software provides a platform on which the biomechanics community can build a library of
simulations that can be exchanged, tested, analyzed, and improved through multi-institutional
collaboration. We can analyze existing models and simulations and develop new models and
simulations from within the GUI (Figure 3.8).

Figure 3. 8 Opensim 4.0 GUI

14
I. C3D to Opensim Conversion

C3D files generated from vicon nexus system are needed to extracted to get the Opensim
readable files which are

6.1.trc file: A file containing marker set information

6.2.mot file: A file containing force plate information

For this different tools are available. Also, with new updates in software a Matlab
example and utilities form Opensim 4.0 resource package are provided. But we need to
check and make necessary changes in the local version of the scripts according to our
requirements. The Matlab scripts for required extraction are given at the end of this
section.

II. Co-ordinate system check

The co-ordinate system of MoCap system and Opensim software can be different.
Therefore, before starting the analysis, it is necessary to check the coordinate systems in
the Opensim. A transformation is required if there is any rotational or translational
difference in the axes.

III. Scaling

The Scale Tool alters the anthropometry of a model so that it matches a particular subject
as closely as possible. Scaling is typically performed by comparing experimental marker
data to virtual markers placed on a model. In addition to scaling a model, the Scale Tool
can be used to adjust the locations of virtual markers so that they better match the
experimental data.

Scaling is performed based on a combination of measured distances between x-y-z


marker locations and manually-specified scale factors. The marker locations are usually
obtained using motion capture equipment. The unscaled model has a set of virtual
markers placed in the same anatomical locations as the experimental markers.

15
Figure 3. 9 Scaling Principle

The dimensions of each segment in the model are scaled so that the distances between the
virtual markers match the distances between the experimental markers. Once the
dimensions of the segments have been scaled to match the subject, the Scale Tool can be
used to move some or all of the virtual markers on the model so that they coincide with
the experimental marker locations. The principle for Scale Tool is explained in Figure
3.9.

IV. Inverse Kinematics

The Inverse Kinematics (IK) Tool steps through each time frame of experimental data
and positions the model in a pose that "best matches" experimental marker and coordinate
data for that time step. This "best match" is the pose that minimizes a sum of weighted
squared errors of markers and/or coordinates. Experimental markers are matched by
model markers throughout the motion by varying the joint angles (generalized
coordinates) through time. The principle for getting Kinematic data using IK tool is
shown in the Figure 3.10.

16
Figure 3. 10 IK Principle

V. Computed Muscle Control

The purpose of Computed Muscle Control (CMC) is to compute a set of muscle


excitations (or, more generally, actuator controls) that will drive a dynamic
musculoskeletal model to track a set of desired kinematics in the presence of applied
external forces (if applicable).

Before starting the CMC algorithm, initial states for the model are computed. The states
comprise the generalized coordinates (joint angles), generalized speeds (joint angular
velocities), plus any muscle states (e.g., muscle activation levels and fiber lengths). While
the initial values of the generalized coordinates and speeds can be taken from the desired
kinematics that can be specified, the initial values of the muscle states are generally
unknown.

Once CMC finishes execution, we can compare the computed muscle excitation patterns
with measured electromyographical measurements.

17
VI. Plotting

The plot tool allows us to run a set of standard analyses given in the tools menu on a
model and plot the results. The results can be either for visual inspection within OpenSim
or to export the them into other applications.

Human anatomy is briefly explained in this chapter with details about the software used.
The MatLab scripts used for analysis are added in this chapter. The next chapter will
explain about the methodology defined for the work and implementation of the same.
18
Chapter 4
Methodology

This chapter presents the methodology for the work to be done. The methodology for using
the Opensim software tools is also defined. The section ends with results obtained from the
analysis.

4.1 Methodology
The methodology used for analysis to achieve defined objectives is as shown in Figure 4.1.

Figure 4. 1 Work Flow of Thesis

4.1.1 Data Collection

Figure 4. 2 Data Collection Procedure


19
i. The data collection procedure is followed as defined in the Figure 4.2
ii. The subject’s history is taken by the physiotherapists.
iii. Preliminary tests are done.
a. The VO2 submax test is done to check the oxygen consumption. For this
subject is asked to walk on treadmill.
b. Blood pressure is checked before and after VO2
submax test.
iv. Markers are placed on subject according to defined marker
set (Figure 4.3) and EMG sensors are also placed at
required muscle position according to analysis to be
done.
v. The standardized protocols for muscle strength calculation is
done using dynamometer and experimental
assessment.
(there should be appropriate time gap between preliminary test

and muscle strength calculation so that the effect of VO2 submax Figure 4. 3 Marker
test) Placement

vi. After this the actual gait analysis starts. The subject is asked
to follow the instructions:
c. Stand on the force plate(static) (Figure 4.5 and 4.6)
d. Walk across the force plate(walk trial)(Figure 4.7)
e. Deep squat on the force plate(squat trial)(Figure 4.8)
f. Maximum possible number of deep squats in specific time(for balance
analysis)
Using these protocols the data is collected for every subject in Gait Lab(Figure 4.4).
vii. The output produced by the all the sensors is recorded for multiple gait cycles.

20
Figure 4. 4 Data Collection-Gait Analysis

Figure 4. 5 Static Position 1

Figure 4. 6 Static Position 2

21
Figure 4. 7 Walk Trial

Figure 4. 8 Squat Trial

4.1.2 Opensim Analysis

• Opensim Analysis Methodology

Figure 4. 9 Opensim Analysis Methodology

22
For Opensim Analysis, we defined the methodology to get required outputs as shown in Figure
4.9. For that, we used data of a subject with static, walk and squat trial. We converted the C3D
filed using MatLab-Opensim Example. The changes made in the codes to match the coordinate
axis of the MoCap system. The marker data stored in the .trc file of static data is used for scaling.
On the scaled model, IK tools is applied to get the kinematic values of the walk as well as squat
trial. For this, .trc as well as .mot files of walk and squat trials are used. The IK solver generated
a desired kinematic file which is used to calculate the muscle excitation in the CMC tool. The
input and outputs for the tools are as shown in following Figures 4.10, 4.11, 4.12 for Scaling, IK
and CMC tool respectively:

• Scale Tool

Figure 4. 10 Scale Tool Overview [20]

• Inverse Kinematic tool

Figure 4. 11 IK Tool Overview [20]

23
• CMC tool

Figure 4. 12 CMC Tool Overview

The methodology defined for the work flow of the project and Opensim Analysis is explained
in the chapter. Next chapter will explain the implementation and results obtained from
Opensim Methodology.
24
Chapter 5
Implementation of Opensim Methodology

This chapter presents the implementation of Opensim Analysis. The brief description of steps
used in analysis are explained. The section ends with results obtained from the analysis and
valoidation of Opensim out[uts using MATlab.

5.1 Implementation of Methodology


• The C3D files were converted using Opensim-MatLab utility. To match the coordinate
axes the rotation matrix added to the local version of ‘c3dExport.m’. Also, changes were
made in the script ‘osimTableToStruct.m’ to solve the illegal column label error.

• The next step was Opensim Analysis for which Gait2354 model was loaded in the
software and Marker set file(.xml) was loaded to apply markers to the model.

• For this, two new markers were added in the marker set model for better scaling result
viz. L_Femur3(Left Knee Medial Marker) and R_Femur3(Right Knee Medial Marker).
Also, two markers were renamed for detection in the .TRC file viz, LILC and RILC.

• After this, Opensim Analysis was carried out according to defined methodology for ADL
Squatter Subject and Non-Squatter Subject. And outputs were generated.

• In Opensim analysis, measurement based scaling was used for scaling. The difference
between length of line joining two markers of model markers and corresponding
experimental markers was considered as scale factor.

• The static pose weight was defined higher for boney markers whereas the other markers
were given the less weights for scaling.

• The scale tool is then executed to get scaled model as shown in the Figure 5.1.

25
Figure 5. 1 Scaled Model

• The other tools such as Inverse Kinematics and CMC, as defined in methodology, were
implemented to get kinematic as well as kinetic outputs.

• From Figure 5.2 and 5.3 we can see that the knee flexion angle for Squatter Subject is
higher than Non-Squatter Subject.

Figure 5. 2 Inverse Kinematics: Squatter Model


26
Figure 5. 3 Inverse Kinematics: Non-Squatter Model

• For CMC tool, the standard constraints and actuator files were used for Gait2354 model.
After execution of CMC Tool, we can see in Figure 5.4-5.7 the muscles actuated in red
and purple color according to force induced in them.

• From Figures 5.4 and 5.5 we can see the muscles actuated in squat position for Squatter
Subject. Whereas we can see the different muscles getting actuated with higher forces in
Non-Squatter model (Figure 5.6 and 5.7).

Figure 5. 4 Squatter Model(Front View)

27
Figure 5. 5 Squatter Model(Sagittal View)

Figure 5. 6 Non- Squatter Model(Front View)

28
Figure 5. 7 Non- Squatter Model(Sagittal View)

• After Opensim Analysis, all the required outputs were plotted from the output files (.sto)
generated.

• The knee flexion angles for both knee obtained from Opensim Analysis were compared
with the corresponding Vicon Nexus output to check the feasibility of the Opensim
Analysis, using MATlab.

• To validate muscle forces, the EMG activity was compared with the muscle forces to
check the onset and offset time.

29
5.2 Results
• Correlation between Opensim Output and Vicon Nexus Output

o For Squatter Subject

Figure 5. 8 Validation of Left Knee Flexion Angle using MATlab

Figure 5.8 shows the MATlab output for validation of Left Knee Flexion Angles
generated from Opensim Analysis by comparing it with Vicon Nexus Output.

30
Figure 5. 9 Validation of Right Knee Flexion Angle using MATlab

Figure 5.9 shows the MATlab output for validation of Right Knee Flexion Angles
generated from Opensim Analysis by comparing it with Vicon Nexus Output.

Figure 5. 10 RMS Error for Knee Flexion Angles Validation

31
Figure 5.10 shows that, RMS Error between Opensim Output and Vicon Nexus
Output for both knee angles is less than 5%. Therefore, the feasibility of the
Opensim Output for kinematic outputs was considered optimum.

o For Non-Squatter

Figure 5.11 and 5.12 shows the output graphs generated from MATlab validation
of Opensim analysis.

Figure 5. 11 Validation of Right Knee Flexion Angle using MATlab

32
Figure 5. 12 Validation of left Knee Flexion Angle using MATlab

The difference between left knee flexion angle of Opensim Output and Vicon
Nexus Output is large (Figure 5.12) since the algorithm used to get angles in
Vicon considers Center of Mass as well as Soft tissue assumption whereas the
Opensim software only tracks markers to give kinematic outputs.

The Non-Squatter subject has fat accumulation in thigh and calf. Also, the subject
was bearing weight more on left side. This results in Vicon Nexus Algorithm to
give more flexion angle than the angle between line joining.

The line diagram for Sagittal View (Figure 5.13) and Front View (Figure 5.14) in
Vicon Nexus GUI shows the angle between line joining the markers are same for
both knees which we can see in Opensim output.

33
Figure 5. 13 Line Diagram Sagittal View: Non-Squatter Model

Figure 5. 14 Line Diagram Front View: Non-Squatter Model

34
• Correlation between Opensim Output and EMG activity

o For Squatter File

Figure 5. 15 Erector Spinae Muscle

Figure 5. 16 Gastrocnemius Muscle


35
Figure 5. 17 Gluteus Maximus Muscle

Figure 5. 18 Gluteus Medius Muscle

36
Figure 5. 19 Hamstring Muscle

Figure 5. 20 Rectus Femoris

The above graphs are Outputs generated from MATlab for validation of muscle forces with
EMG output.

37
Figure 5.15- Validation of EMG with Erector Spinae muscle force generated from Opensim
Analysis

Figure 5.16- Validation of EMG with Gastrocnemius muscle force generated from Opensim
Analysis

Figure 5.17- Validation of EMG with Gluteus Maximus muscle force generated from Opensim
Analysis

Figure 5.18- Validation of EMG with Gluteus Medius muscle force generated from Opensim
Analysis

Figure 5.19- Validation of EMG with Hamstring muscle force generated from Opensim Analysis

Figure 5.20- Validation of EMG with Rectus Femoris muscle force generated from Opensim
Analysis

The output of EMG is in millivolts and the muscle force output from Opensim is in newtons.
Therefore we cannot compare the amplitudes but we can compare the nature of two graphs for
validation. From above plots we can see that EMG activity for each muscle starts 0.75 to 1 sec
before the force generation, which validates the force generation and onset/offset time of
EMG[24].

Also, from Figure 5.21we can see that, RMS error value between two plots is below 5%. This
occurs because EMG activity is affected by several factors such as sweat or dirt. Therefore we
can conclude that the muscle forces generated from CMC are validated.

38
Figure 5. 21 RMS Error for Muscle Force Validation

After the validation the muscles which intersects or originated at knee joints were noted and the
corresponding muscle forces were plotted from the Opensim outputs.

The muscle which are considered for further analysis are as follows:

• Gastrocnemius

• Gracilis

• Sartoris

• Tensor Fasciae Latae

• Hamstring- Bicep Femoris

• Rectus Femoris

• Vastus Intermedius

The results obtained from the Opensim output were plotted and validated using MATlab.
Next chapter will explain the FBD creation which will be required for the FEA.
39
Chapter 6
Implementation of FEA

This chapter presents the creation of Free Body Diagram from the outputs generated from
the Opensim Analysis and Literature.

6.1 Creating Free Body Diagram

• Authors M. Fukunaga and S. Hirokawa[12] used mathematical modeling method for


calculating the forces in lower limb while ascending from deep knee flexion position.

• For this they generated a 2d model of lower limb as shown below.

Figure 6. 1 Forces acting on lower limb[12]

• With help of this model and the force outputs generated in the Opensim software, the
Free Body Diagram will be created.

40
• Authors J. Zelle, et al,[11] measured the Thigh-Calf contact force using pressure mapping
sensor and relative parameters such as knee flexion angles were calculated by MoCap
system.

• They calculated location and magnitude of resultant Thigh-Calf contact force for 10
subjects with respect to epicondylar axis (figure6.2).

Figure 6. 2 Epicondylar Axis in Femur: Tibial Surface

• We considered the knee flexion angle to assume the location of resultant contact force
and the magnitude of the force is assumed to be 30% of body weight as mentioned in the
literature.

• The tangential and normal component of Tibio-femoral joint force is also considered in
the FBD.

• Figures 6.3, 6.4, and 6.5 shows Lateral, Medial and Top view of FBD drawn for right leg.

• Terms used in FBD

Ft- Tangential Component of Knee Joint Force

Fn- Normal Component of Knee Joint Force

GAS- Gastrocnemius Muscle force

TFL- Tensor Fasciae Latae Muscle force

41
SAR- Sartoris Muscle force

GRA- Gracilis Muscle force

Rect_Fem- Rectus Femoris Muscle force

Vast_In- Vastus Intermedius Muscle force

HAM- Hamstring Muscle force

Figure 6. 3 FBD- Lateral View

Figure 6. 4 FBD- Medial View

42
Figure 6. 5 FBD- Top View

Figure 6. 6 FBD with Thigh-Calf Contact Force

• The Figure 6.6 shows location of resultant thigh calf contact force in Lateral view of right
leg. The location of resultant thigh calf contact force is calculated from literature. The
data collected is extrapolated for the required knee flexion angle and corresponding
distance from the epicondylar axis is calculated[11].

• The distance of location of resultant force

o For left limb= 0.1708m (knee flexion angle=165.2799o)

o For right limb= 0.1630m (knee flexion angle=160.6181o)

43
• From above diagrams the muscle forces in FBD were represented on the bone geometry
from Opensim Software for better understanding.

• Figure 6.7 gives the nomenclature and color coding used for showing muscle forces in
FBD representation.

• Figure 6.8 shows lateral view, Figure 6.9 shows Medial View and Figure 6.10 shows Top
View of FBD representation.

Figure 6. 1 Muscle Force Nomenclature in FBD

Figure 6. 2 Lateral View

44
Figure 6. 3 Medial View

Figure 6. 4 Top View

45
Muscle forces considered for analysis:

Figure 6. 7 Gastrocnemius

Figure 6.7 shows that Gastrocnemius muscle gives high output in squat position.

Figure 6. 8 Gracilis

Figure 6.8 shows that Gracilis muscle gives high output in transition state than in squat position.

46
Figure 6. 9 Hamstring

Figure 6.9 shows that Hamstring muscle gives high output transition state while the forces in
squat position are comparatively higher than in stand position.

Figure 6. 10 Rectus Femoris

Figure 6.10 shows that Rectus Femoris muscle gives high output in ascent and descent state
whereas the force becomes negligible in the squat position.

47
Figure 6. 11 Sartoris

Figure 6.11 shows that Sartoris muscle generates higher forces in squat position.

Figure 6. 12 Tensor Fasciae Latae

Figure 6.12 shows that Gastrocnemius muscle gives varying output in stand and transition stage
whereas it becomes negligible in squat position.

48
6.2 Material Properties of Bone and Articular Cartilage
The internal structure of human bone typically long bones such as femur or tibia consist of hard
outer layer which is composed of cortical bone whereas internal spongy layer as cancellous
bone[31]. The porosity of cortical bone ranges from 5% to 10% whereas the cancellous bone is
much porous with porosity is anywhere between 50% to 90%[32]. Also human bone shows
anisotropic behavior. The ratio of cortical bone to cancellous bone can be calculated using CT.

The properties of Femur Cortical bone are as follows[33]:

Properties Cortical Bone

Density 2.000 g/cm3

Elastic Modulus Longitudinal 17.9±3.9 GPa

Elastic Modulus Transvers 10.1±2.4 GPa

Shear Modulus 3.3±0.4 GPa

Poisson’s Ratio Longitudinal 0.4±0.16

Poisson’s Ratio Transverse 0.62±0.26

Ultimate Tensile Stress Longitudinal 135±15.6 MPa

Ultimate Compressive Stress Longitudinal 205±17.3 MPa

Ultimate Tensile Stress Transverse 53±10.7 MPa

Ultimate Compressive Stress Transverse 131±20.7 MPa

Ultimate Shear Stress 65±4.0 MPa

Table 6. 1 Properties of femur Bone

A heterogeneous porous cellular solid, trabecular bone or cancellous bone has anisotropic
mechanical properties that depend on the porosity of the specimen as well as the architectural
arrangement of the individual trabeculae. Typically the Young’s modulus of human cancellous

49
bone ranges from 10 to 3000 MPa. The compressive strength of cancellous bone increases with
the age and decreasing density.

Articular cartilage is the highly specialized connective tissue of knee joint. Unlike most tissues,
articular cartilage does not have blood vessels, nerves, or lymphatics[34]. It has typical thickness
of 2 to 4 mm. Its principal function is to provide a smooth, lubricated surface for low friction
articulation and to facilitate the transmission of loads to the underlying subchondral bone. It
tends to stiffen with increased strain. Therefore we cannot describe it by single Young’s
modulus. Rather, the modulus of the tissue depends on the time at which the force measurement
was taken during a stress-relaxation test, which was common practice in the preliminary studies
of mechanical testing on articular cartilage.

6.3 Conversion of MRI to 3D model


• The MRI data will be used to create subject specific 3D model which can be used for
Finite Element Analysis.

• This is done using software MIMICS which creates 3D model based on thresholding.

• The MRI images(slices) are uploaded in the software and out of 3 views the view which
defines the required body to be modelled properly is selected as primary view.

• The thresholding value is set such as the maximum surface of required is selected.

• Then it is converted to 3D model using generate tool.

• The Output of the MIMICS software is .stl file.

• The optimum output can be achieved with the minimum slice thickness(less than 0.5mm).

MIMICS software works best for CT data since it only has boney structures which are well
defined. It becomes difficult to work with MRI file since, the soft tissue are accounted in the
MRI and light is not reflected by bones with as much intensity as CT.

50
6.4 Finite Element Analysis Results
We performed Transient structural analysis on tibiofemoral joint in Ansys Workbench. The
material used with user input material properties as follows[34].

Properties Cortical Bone Trabecular Bone

Density(g/cm3) 2.0208 1.3712

Young’s Modulus(MPa) Ex=6982.9 Ex=2029.4

Ey=18155 Ey=3195.3

Ez=6982.9 Ez=2029.4

Poisson’s Ratio υxy=0.25 υxy=0.25

υyz=0.25 υyz=0.25

υxz=0.4 υxz=0.4

Shear Modulus(Gpa) Gxy=7.68 Gxy=7.68

Gyz=5.61 Gyz=5.61

Gxz=4.69 Gxz=4.69

Table 6. 2 Material Properties for FEA

We considered the material to be orthotropic in nature. The distal head of femur has more
cortical part than proximal head which is 20-80%. So, we considered it to be cortical bone
whereas the proximal tibial bone has only outer shell as cortical bone. So, we considered it to be
trabecular bone[35].

The time variant joint load for rotation applied between two bones. The resultant transient
muscle forces were applied on the femoral and tibial surfaces according to anatomy. The analysis
was carried out for total deformation.

The model creation from MRI was not possible because the slice thickness of MRI output was
2mm which resulted in highly distorted model. The model used for this analysis was downloaded
from online sources which was highly distorted in tibial region. Because of this the solution

51
could not converge after 11 seconds. But even after that, partial results were obtained which are
shown in figure 6.13:

Figure 6. 1313 Total deformation after knee flexion for right knee

The FBD was created with the bone geometry from Opensim Software for better
understanding. The location for resultant thigh-calf contact force was assumed from the
literature. Also, the material properties for bone were defined from literature. The next
chapter will conclude the work done.
52
Chapter 7

Conclusion and Future Scope

This section includes the conclusion drawn from the study and the future work to be done.

1. Conclusion
For this project, exhaustive literature survey on different gait analysis techniques, knee joint
analysis and finite element analysis of bones was done. The research done so far, explains that
the analysis for deep knee flexion is done only till partial squatting. For deep squatting, only the
joint forces are calculated in some projects. The thigh calf contact force is measured in some of
the researches but the relation between joint force and thigh calf contact force is not discovered
yet. Therefore finding the effect of thigh calf contact force on knee joint forces is the research
area which is not explored. From this, the problem is defined and methodology is created to
solve the problem.

According to methodology defined, the work is done for Opensim analysis and creation of Free
Body Diagram of knee joint including muscle forces. From Opensim Analysis, we can see that
the Gastrocnemius, Sartoris and Hamstring muscles which are considered for deep squatting
produces high forces while sustaining the squat position whereas, Rectus Femoris, Gracilis and
Vastus Intermedius muscles produce high forces in ascent and descent position. Also the muscle
forces are higher than the bone on bone forces therefore they are needed to be considered while
analyzing for squatting activities.

2. Future Scope
The subject specific Finite Element Analysis can be performed using MRI files to consider effect
on articular cartilage. For this, the optimum slice thickness can be selected to get MRI output for
model creation. The output of Finite Element Analysis can be correlated with the multiple files
to get the better understanding about stresses induced on knee joint for different age groups. Also
the data can be used for subject specific knee joint designing which will allow maximum knee
flexion. We can also determine the stresses on knee joint for osteoarthritis patients before and

53
after the surgery. The surgery for knee replacement can be planned considering all the forces and
stresses on knee joint for better results. The patients with the knee joint problems can be given
proper treatment according to the results generated from Opensim and FEA collectively.

54
References
1. R. B. Davis III, S. Ounpuu, D. Tyburski, J. R. Gage; “A gait analysis data collection and
reduction technique”; Human Movement Science10; 575-587; North Holland; 1991
2. V. Kyriazis; “Gait Analysis Techniques”; J OrthopaedTraumatol ;Volume 1; 1–6 ©
Springer-Verlag; 2001
3. L. Lee, W. E. L. Grimson; “Gait Analysis for Recognition and Classification”; Automatic
Face and Gesture Recognition, Fifth IEEE International Conference; 155-162; 2002
4. K. Tong, M. H. Granat ;“A practical gait analysis system using gyroscopes”; Medical
Engineering & Physics; Volume 21; 87–94; 1999
5. S. J. Morris Bamberg, A. Y. Benbasat, D. M. Scarborough, D. E. Krebs, J. A. Paradiso,
“Gait Analysis Using a Shoe-Integrated Wireless Sensor System”; IEEE transactions on
information technology in biomedicine, Volume 2, No. 4; 2008
6. T. Liu, Y. Inoue, K. Shibata ;“Development of a wearable sensor system for quantitative
gait analysis”; Measurement; Volume 42; 978–988; 2009
7. G. Beckham, T. Suchomel, S. Mizuguchi; “Force Plate Use in Performance Monitoring
and Sport Science Testing”; New Studies in Athletics; Volume 3; 2014
8. E.A. Clancy, E.L. Morin, R. Merletti; “Sampling, noise-reduction and amplitude
estimation issues in surface electromyography”; Journal of Electromyography and
Kinesiology; Volume 12; 1–16; 2002
9. M. Cifrek, V. Medved , S. Tonkovic, S. Ostojic; “Surface EMG based muscle fatigue
evaluation in biomechanics”; Clinical Biomechanics; Volume 24; 327–340; 2009
10. A. Hemmerich, H. Brown, S. Smith, S.S.K. Marthandam, U.P. Wyss; “Hip, Knee, and
Ankle Kinematics of High Range of Motion Activities of Daily Living”; Journal Of
Orthopaedic Research; 770-781; 2006
11. J. Zelle, M. Barink, R. Loeffen, M. De Waal Malefijt, N. Verdonschot; “Thigh–calf
contact force measurements in deep knee flexion”; Clinical Biomechanics; Volume 22;
821–826; 2007
12. M. Fukunaga, S. Hirokawa; “The Model Analysis of Lower Limb at Ascending from
Deep Knee Flexion”; Memoirs of the Faculty of Engineering, Kyushu University,
Volume 69, No.4; 139-148; 2009

55
13. M. Fukunaga, K. Morimoto; “Calculation of the knee joint force at deep squatting and
kneeling”; Journal of Biomechanical Science and Engineering; Volume 10, No.4; 2015
14. J.W. Fernandez, M. G. Pandy; “Integrating modelling and experiments to assess dynamic
musculoskeletal function in humans”; Experimental Physiology; 371-382; 2005
15. B. Potocnik, D. Zazula, B. Cigale, D. Heric, E. Cibula, T. Tomazic; “A Patient-specific
Knee Joint Computer Model Using MRI Data and ‘in vivo’ Compressive Load from the
Optical Force Measuring System”; Journal of Computing and Information Technology;
Volume 3; 209–222; 2008
16. H.H. Rachmat, D. Janssen, W.J. Zevenbergen, G.J. Verkerke, R.L. Diercks, N.
Verdonschot; “Generating finite element models of the knee: how accurate can we
determine ligament attachment sites from MRI scans?”; Journal of Medical Engineering
& Physics; Volume 36, Issue 6; 701-7; 2014
17. M. W. Whittle; “Gait Analysis”; an introduction, Butterworth-Heinemann, 3rd edition
18. E. S. Grood, W. J. Suntay; “A joint coordinate system for the clinical description of three
dimentional motion: Application of the knee”; Journal of Biomechanical Engineering;
136-144; 1983
19. https://www.vicon.com/products/software/nexus
20. http://www.nextstagepro.com/retroreflective-markers.html
21. https://www.amti.biz/fps-guide.aspx
22. https://www.knowyourback.org/KnowYourBack/Treatments/AssessmentTools/Specialize
dNerveTests
23. https://simtk-confluence.stanford.edu:8443/display/OpenSim33/User%27s+Guide
24. J. L. Hicks, T. K. Uchida, A. Seth, A. Rajagopal, S. L. Delp; “Is My Model Good
Enough? Best Practices for Verification and Validation of Musculoskeletal Models and
Simulations of Movement”; Journal of Biomechanical Engineering; Volume 137; 2015
25. S. M. Smith, Robert A. Cockburn, A. Hemmerich, R. M. Li, U. P. Wyss; “Tibiofemoral
joint contact forces and knee kinematics during squatting”; Gait & Posture; Volume 27;
376–386; 2008
26. A. Patil; “Experimental Biomechanics of Human Squatting”; 2016

56
27. N. J. Dahlkvist, P. Mayo, B. B. Seedhom; “Forces during squatting and rising”;
Engineering in Medicine; 69-76; 1982
28. Gary L. Soderberg, Thomas M. Cook; “Electromyography in Biomechanics”; Physical
Therapy; Volume 64 / Number 12; 1984
29. O. Klets ; “Subject-Specific Finite Element Modeling Of The Knee Joint To Study
Osteoarthritis Development And Progression”; 2018
30. S. K. Parashar, J. K. Sharma ;“A review on application of finite element modelling in
bone biomechanics”; Perspectives in Science; Volume 8; 696—698; 2016
31. https://boneandspine.com/cortical-bone-and-cancellous-bone/
32. http://umich.edu/~bme332/ch9bone/bme332bone.htm
33. T. M. Keaveny, E. F. Morgan, O. C. Yeh; “Bone mechanics”; Mechanics of the human
body; Chapter 8; 2004
34. A.E. Yousif, M.Y. Aziz; “Biomechanical Analysis of the human femur bone during
normal walking and standing up”; IOSR Journal of Engineering (IOSRJEN); ISSN:
2250-3021; Volume 2, Issue 8; 13-19; 2012
35. Ricardo Francisco Capozza, Sara Feldman, Pablo Mortarino, Paola Soledad Reina, Hans
Schiess, Jo¨ rn Rittweger, Jose´ Luis Ferretti, Gustavo Roberto Cointry; “Structural
analysis of the human tibia by tomographic(pQCT) serial scans”; Journal of Anatomy;
470–481; 2010
36. https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3445147/
37. A. D. P. Bankoff ; “Biomechanical Characteristics of the Bone”; Human Musculoskeletal
Biomechanics; 61-86; 2012

57
Appendix A
Opensim Matlab Utilities
1. c3dExport.m- C3D extractor

%% Load OpenSim libs


import org.opensim.modeling.*

%% Get the path to a C3D file


[filename, path] = uigetfile('*.c3d');
c3dpath = fullfile(path,filename);

%% Construct an opensimC3D object with input c3d path


% Constructor takes full path to c3d file and an integer for forceplate
% representation (1 = COP).
c3d = osimC3D(c3dpath,1);

%% Get some stats...


% Get the number of marker trajectories
nTrajectories = c3d.getNumTrajectories();
% Get the marker data rate
rMakers = c3d.getRate_marker();
% Get the number of forces
nForces = c3d.getNumForces();
% Get the force data rate
rForces = c3d.getRate_force();

% Get Start and end time


t0 = c3d.getStartTime();
tn = c3d.getEndTime();

%% Rotate the data


c3d.rotateData('x',-90)
c3d.rotateData('y',90)

%% Get the c3d in different forms


% Get OpenSim tables
markerTable = c3d.getTable_markers();
forceTable = c3d.getTable_forces();
% Get as Matlab Structures
[markerStruct forceStruct] = c3d.getAsStructs();

%% Write the marker and force data to file

% Write marker data to trc file.


% c3d.writeTRC() Write to dir of input c3d.
% c3d.writeTRC('Walking.trc') Write to dir of input c3d with defined file name.
% c3d.writeTRC('C:/data/Walking.trc') Write to defined path input path.
58
c3d.writeTRC('test_data_markers.trc');

% Write force data to mot file.


% c3d.writeMOT() Write to dir of input c3d.
% c3d.writeMOT('Walking.mot') Write to dir of input c3d with defined file name.
% c3d.writeMOT('C:/data/Walking.mot') Write to defined path input path.
%
% This function assumes point and torque data are in mm and Nmm and
% converts them to m and Nm. If your C3D is already in M and Nm,
% comment out the internal function convertMillimeters2Meters()
c3d.writeMOT('test_data_forces.mot');

2. osimC3D.m- Matlab utility

classdef osimC3D < matlab.mixin.SetGet


% osimC3D(filepath, ForceLocation)
% C3D data to OpenSim Tables.
% OpenSim Utility Class
% Inputs:
% filepath Full path to the location of the C3D file
% ForceLocation Integer value for representation of force from plate
% 0 = forceplate orgin, 1 = COP, 2 = Point Of Wrench
% Application
properties (Access = private)
path
name
markers
forces
ForceLocation
end
methods
function obj = osimC3D(path2c3d, ForceLocation)
% Class Constructor: input is an absolute path to a C3D file.

% Verify the correct number of inputs


if nargin ~= 2
error('Number of inputs is incorrect. Class requires filepath (string) and ForceLocation
(integer)')
end
% verify the file path is correct
if exist(path2c3d, 'file') == 0
error('File does not exist. Check path is correct')
else
[path, name, ext] = fileparts(path2c3d);
if isempty(path)
error('Input path must be full path to file (C:/data/Walking.mot)')
end
obj.path = path;

59
obj.name = name;
end
% Verify the ForceLocation input is correct
if ~isnumeric(ForceLocation) || ~ismember(ForceLocation,[0:2])
error('ForceLocation must be an integer of value 0, 1, or 2')
end
% load java libs
import org.opensim.modeling.*
% Use a c3dAdapter to read the c3d file
tables = C3DFileAdapter().read(path2c3d, ForceLocation);
% Set the marker and force data into OpenSim tables
obj.markers = tables.get('markers');
obj.forces = tables.get('forces');
% Set the force location specifier in case someone wants to
% check.
switch(ForceLocation)
case 0
location = 'OriginOfForcePlate';
case 1
location = 'CenterOfPressure';
case 2
location = 'PointOfWrenchApplication';
end
obj.ForceLocation = location;
end
function p = getPath(obj)
p = obj.path();
end
function n = getName(obj)
n = obj.name();
end
function location = getForceLocation(obj)
% Get the Force Location
location = obj.ForceLocation();
end
function rate = getRate_marker(obj)
% Get the capture rate used for the Marker Data
rate = str2double(obj.markers.getTableMetaDataAsString('DataRate'));
end
function rate = getRate_force(obj)
% Get the capture rate used for the Force Data
rate = str2double(obj.forces.getTableMetaDataAsString('DataRate'));
end
function n = getNumTrajectories(obj)
% Get the number of markers in the c3d file
n = obj.markers.getNumColumns();
end
function n = getNumForces(obj)
% Get the number of forceplates in the c3d file
n = (obj.forces.getNumColumns())/3;
60
end
function t = getStartTime(obj)
% Get the start time of the c3d file
t = obj.markers.getIndependentColumn().get(0);
end
function t = getEndTime(obj)
% Get the end time of the c3d file
t = obj.markers.getIndependentColumn().get(obj.markers.getNumRows() - 1);
end
function name = getFileName(obj)
% Get the name of the c3d file
[filedirectory, name, extension] = fileparts(obj.path);
end
function filedirectory = getDirectory(obj)
% Get the directory path for the c3d file
[filedirectory, name, extension] = fileparts(obj.path);
end
function table = getTable_markers(obj)
table = obj.markers().clone();
end
function table = getTable_forces(obj)
table = obj.forces().clone();
end
function [markerStruct, forcesStruct] = getAsStructs(obj)
% Convert the OpenSim tables into Matlab Structures
markerStruct = osimTableToStruct(obj.markers);
forcesStruct = osimTableToStruct(obj.forces);
disp('Maker and force data returned as Matlab Structs')
end
function rotateData(obj,axis,value)
% Method for rotating marker and force data stored in osim
% tables.
% c3d.rotateData('x', 90)

if ~ischar(axis)
error('Axis must be either x,y or z')
end
if ~isnumeric(value)
error('value must be numeric (90, -90, 270, ...')
end
% rotate the tables
obj.rotateTable(obj.markers, axis, value);
obj.rotateTable(obj.forces, axis, value);
disp('Marker and Force tables have been rotated')
end
function writeTRC(obj,varargin)
% Write marker data to trc file.
% osimC3d.writeTRC() Write to dir of input c3d.
% osimC3d.writeTRC('Walking.trc') Write to dir of input c3d with defined file
name.
61
% osimC3d.writeTRC('C:/data/Walking.trc') Write to defined path input path.

% Compute an output path to use for writing to file


outputPath = generateOutputPath(obj,varargin,'.trc');

import org.opensim.modeling.*
% Write to file
TRCFileAdapter().write( obj.markers, outputPath)
disp(['Marker file written to ' outputPath]);
end
function writeMOT(obj,varargin)
% Write force data to mot file.
% osimC3d.writeMOT() Write to dir of input c3d.
% osimC3d.writeMOT('Walking.mot') Write to dir of input c3d with defined file name.
% osimC3d.writeMOT('C:/data/Walking.mot') Write to defined path input path.
%
% This function assumes point and torque data are in mm and Nmm and
% converts them to m and Nm. If your C3D is already in M and Nm,
% comment out the internal function convertMillimeters2Meters()

% Compute an output path to use for writing to file


outputPath = generateOutputPath(obj,varargin,'.mot');

import org.opensim.modeling.*
% Get the forces table
forces = obj.getTable_forces();
% Get the column labels
labels = forces.getColumnLabels();
% Make a copy
updlabels = labels;

% Labels from C3DFileAdapter are f1, p1, m1, f2,...


% We edit them to be consistent with requirements of viewing
% forces in the GUI (ground_force_vx, ground_force_px,...)
for i = 0 : labels.size() - 1
% Get the label as a string
label = char(labels.get(i));
% Transform the label depending on force, point, or moment
if ~isempty(strfind(label,'f'))
label = strrep(label,'f', 'ground_force_');
label = [label '_v'];
elseif ~isempty(strfind(label,'p'))
label = strrep(label,'p', 'ground_force_');
label = [label '_p'];
elseif ~isempty(strfind(label,'m'))
label = strrep(label,'m', 'ground_moment_');
label = [label '_m'];
end
% update the label name
updlabels.set(i,label);
62
end

% set the column labels


forces.setColumnLabels(updlabels)

% Flatten the Vec3 force table


postfix = StdVectorString();
postfix.add('x');postfix.add('y');postfix.add('z');
forces_flat = forces.flatten(postfix);

% Change the header in the file to meet Storage conditions


if forces_flat.getTableMetaDataKeys().size() > 0
for i = 0 : forces_flat.getTableMetaDataKeys().size() - 1
% Get the metakey string at index zero. Since the array gets smaller on
% each loop, we just need to keep taking the first one in the array.
metakey = char(forces_flat.getTableMetaDataKeys().get(0));
% Remove the key from the meta data
forces_flat.removeTableMetaDataKey(metakey)
end
end
% Add the column and row data to the meta key

forces_flat.addTableMetaDataString('nColumns',num2str(forces_flat.getNumColumns()+1))
forces_flat.addTableMetaDataString('nRows',num2str(forces_flat.getNumRows()));

% Convert mm to m
forces_flat_m = obj.convertMillimeters2Meters(forces_flat);

% Write to file
STOFileAdapter().write(forces_flat_m, outputPath)
disp(['Forces file written to ' outputPath]);
end
end

methods (Access = private, Hidden = true)


function setMarkers(obj, a)
% Private Method for setting the internal Marker table
obj.markers = a;
end
function setForces(obj, a)
% Private Method for setting the internal Force table
obj.forces = a;
end
function rotateTable(obj, table, axisString, value)
% Private Method for doing the table rotation operations

import org.opensim.modeling.*
% set up the transform
if strcmp(axisString, 'x')
axis = CoordinateAxis(0);
63
elseif strcmp(axisString, 'y')
axis = CoordinateAxis(1);
elseif strcmp(axisString, 'z')
axis = CoordinateAxis(2);
else
error('input axis must ne either x,y, or z')
end

% instantiate a transform object. Rotation() is a Simbody class


R = Rotation( deg2rad(value) , axis ) ;

% Rotation() works on each row.


for iRow = 0 : table.getNumRows() - 1
% get a row from the table
rowVec = table.getRowAtIndex(iRow);
% rotate each Vec3 element of row vector, rowVec, at once
rowVec_rotated = R.multiply(rowVec);
% overwrite row with rotated row
table.setRowAtIndex(iRow,rowVec_rotated)
end
end
function outputPath = generateOutputPath(obj,path, ext)
% Function to generate an output path from no, partial, or fully
% defined user path.

% Validate the output filename


if size(path,2) > 1
% Path object should be of size == 1, any larger and user
% input multiple variables into function.
error([ num2str(size(path,2)) ' inputs, expecting zero or one'])
end

if isempty(path)
% No file path has been input, so use the path and name from
% the c3d file.
filepath = obj.getPath();
name = obj.getName();
else

if ~ischar(path{1})
error('Input must be a sting of characters')
end

if isempty(strfind(path{1}, ext))
error(['Input must be a path to a ' ext ' file']);
end

% User has included a path to write to


[filepath, name, e] = fileparts(path{1});
if isempty(filepath)
64
% Only the file name is given
filepath = obj.getPath();
end
end
% Generate the output path.
outputPath = fullfile(filepath, [name ext]);
end
function table_flat = convertMillimeters2Meters(obj,table_flat)
% Function to convert displacement forceplate measurements made
% in millimeters to meters. This will convert point data (mm)
% to m and Torque data (Nmm) to Nm.

nForces = table_flat.getNumColumns();
nRows = table_flat.getNumRows();
labels = table_flat.getColumnLabels();

for i = 0 : nForces - 1
% Find all point and torque colomns. Force columns will
% have _v in the label, all columns that don't have this
% character will be point and torque columns
if ~contains(char(labels.get(i)),'v')
for u = 0 : nRows - 1
% Get the table value
c = table_flat.getDependentColumnAtIndex(i).get(u);
% set the table value
table_flat.getDependentColumnAtIndex(i).set(u,c/1000);
end
end
end
disp('Point and Torque values convert from mm and Nmm to m and Nm, respectively')
end
end
end

3. osimTableToStruct.m- MatLab utility

function structdata = osimTableToStruct(osimtable)

% Import Java libraries


import org.opensim.modeling.*

%% Type check the input variables


if strcmp( char(osimtable.getClass()), 'class org.opensim.modeling.TimeSeriesTableVec3')
vec3Table = true;

elseif strcmp( char(osimtable.getClass()), 'class org.opensim.modeling.TimeSeriesTable')


vec3Table = false;
65
else
disp(['Input is of type ' char(osimtable.getClass()) ])
error(['This function only converts TimeSeriesTable and TimeSeriesTableVec3']);
end

%% get the number of data columns as label headers and data rows
nLabels = osimtable.getNumColumns();
nRows = osimtable.getNumRows();

%% pre-allocate data arrarys.


structdata = struct();
if vec3Table == true
dataArray = NaN([nRows 3]);
else
dataArray = NaN([nRows 1]);
end

%% cycle through columns and rows to make new arrays, then addd then to struct.
for iLabel = 0 : nLabels - 1
%
if vec3Table == true
% If the data is Vec3 type
for iRow = 0 : nRows - 1
dataArray(iRow+1,1) =
osimtable.getDependentColumnAtIndex(iLabel).get(iRow).get(0);
dataArray(iRow+1,2) =
osimtable.getDependentColumnAtIndex(iLabel).get(iRow).get(1);
dataArray(iRow+1,3) =
osimtable.getDependentColumnAtIndex(iLabel).get(iRow).get(2);
end
else
% If the data is double type
for iRow = 0 : nRows - 1
dataArray(iRow+1,1) = osimtable.getDependentColumnAtIndex(iLabel).getElt(iRow,0);
end
end

% Get the osim table column label


col_label = char(osimtable.getColumnLabels.get(iLabel));
disp_label = col_label;
% MATLAB structs must start with a letter, and can only contain
% letters, digits, and underscores.
illegalChars = [{' '} {'*'} {'.'} {'/'} {'-'} {'|'}];
for i = 1 : length(illegalChars)
if ~isempty(strfind(col_label, illegalChars{i}))
col_label = strrep(col_label,illegalChars{i}, 'm');
end
end
% If the label has changed, inform the User.
66
if ~strcmp(disp_label,col_label)
disp(['Illegal Column label. ' disp_label ' changed to ' col_label ]);
end
% Add the label and data to the data struct
structdata.(col_label) = dataArray;
end
% Get the time
time = NaN([nRows 1]);
% read time data from table
for iRow = 0 : nRows - 1
time(iRow+1,1) = osimtable.getIndependentColumn.get(iRow);
end
% add time field to structure
[structdata.time] = time;
end

Motion Analysis
clc
clear all
RemovePlots
screenrect=get(0,'screensize');
figposition=[0.022*screenrect(3) 0.05*screenrect(4) 0.96*screenrect(3) 0.85*screenrect(4)];
[filename, pathname] = uigetfile('*.c3d','Pick a c3d file','C:\Users\Pc-
3\Desktop\SayleeP\opensim\C3DFiles');
c3dfile1=[ pathname filename ]
offsetInds1 = [];
[Markers1,MLabels1,VideoFrameRate1,AnalogSignals1,ALabels1,AUnits1,AnalogFrameRate1,Event1,P
arameterGroup1,CameraInfo1]=...
readC3D(c3dfile1);
Mass='Enter the mass of the subject';
Mass1=input(Mass)
temp = MLabels1;
temp2 = Markers1;
clear MLabels1 Markers1
for i=1:length(temp)
if strcmp(temp(1,i),'LTOE')==1
LTOEline1=i;
end
if strcmp (temp(1,i),'LAnkleForce')==1
LAnFline1=i;
end
if strcmp (temp(1,i),'RAnkleForce')==1
RAnFline1=i;
end
if strcmp (temp(1,i),'LKneeForce')==1
67
LKnFline1=i;
end
if strcmp (temp(1,i),'RKneeForce')==1
RKnFline1=i;
end
if strcmp (temp(1,i),'LHipForce')==1
LHpFline1=i;
end
if strcmp (temp(1,i),'RHipForce')==1
RHpFline1=i;
end
if strcmp(temp(1,i),'RTOE')==1
RTOEline1=i;
end
if strcmp(temp(1,i),'LHEE')==1
LHEEline1=i;
end
if strcmp(temp(1,i),'RHEE')==1
RHEEline1=i;
end
if strcmp(temp(1,i),'CentreOfMass')==1
COMline1=i;
end
if strcmp(temp(1,i),'RThoraxAngles')==1
ThoraxAline1=i;
end
if strcmp(temp(1,i),'LAnkleMoment')==1
LAnMline1=i;
end
if strcmp(temp(1,i),'RAnkleMoment')==1
RAnMline1=i;
end
if strcmp(temp(1,i),'LKneeMoment')==1
LKnMline1=i;
end
if strcmp(temp(1,i),'RKneeMoment')==1
RKnMline1=i;
end
if strcmp(temp(1,i),'LHipMoment')==1
LHpMline1=i;
end
if strcmp(temp(1,i),'RHipMoment')==1
RHpMline1=i;

68
end
if strcmp(temp(1,i),'LAnklePower')==1
LAnPline1=i;
end
if strcmp(temp(1,i),'RAnklePower')==1
RAnPline1=i;
end
if strcmp(temp(1,i),'LKneePower')==1
LKnPline1=i;
end
if strcmp(temp(1,i),'RKneePower')==1
RKnPline1=i;
end
if strcmp(temp(1,i),'LHipPower')==1
LHpPline1=i;
end
if strcmp(temp(1,i),'RHipPower')==1
RHpPline1=i;
end
if strcmp(temp(1,i),'LAnkleAngles')==1
LAnAline1=i;
end
if strcmp(temp(1,i),'RAnkleAngles')==1
RAnAline1=i;
end
if strcmp(temp(1,i),'LKneeAngles')==1
LKnAline1=i;
end
if strcmp(temp(1,i),'RKneeAngles')==1
RKnAline1=i;
end
if strcmp(temp(1,i),'LHipAngles')==1
LHpAline1=i;
end
if strcmp(temp(1,i),'RHipAngles')==1
RHpAline1=i;
end
if strcmp(temp(1,i),'LPelvisAngles')==1
LPvAline1=i;
end
if strcmp(temp(1,i),'RPelvisAngles')==1
RPvAline1=i;
end

69
if strcmp(temp(1,i),'LFootProgressAngles')==1
LFtPrAline1=i;
end
if strcmp(temp(1,i),'RFootProgressAngles')==1
RFtPrAline1=i;
end
end
DATA1(:,1:3) = temp2(:,(COMline1-1)*3+1:COMline1*3)./1000; % CoM
DATA1(:,4:6) = temp2(:,(LAnMline1-1)*3+1:LAnMline1*3)./1000.*Mass1;
DATA1(:,7:9) = temp2(:,(RAnMline1-1)*3+1:RAnMline1*3)./1000.*Mass1;
DATA1(:,10:12) = temp2(:,(LKnMline1-1)*3+1:LKnMline1*3)./1000.*Mass1;
DATA1(:,13:15) = temp2(:,(RKnMline1-1)*3+1:RKnMline1*3)./1000.*Mass1;
DATA1(:,16:18) = temp2(:,(LHpMline1-1)*3+1:LHpMline1*3)./1000.*Mass1;
DATA1(:,19:21) = temp2(:,(RHpMline1-1)*3+1:RHpMline1*3)./1000.*Mass1;
DATA1(:,22:24) = temp2(:,(LAnPline1-1)*3+1:LAnPline1*3).*Mass1;
DATA1(:,25:27) = temp2(:,(RAnPline1-1)*3+1:RAnPline1*3).*Mass1;
DATA1(:,28:30) = temp2(:,(LKnPline1-1)*3+1:LKnPline1*3).*Mass1;
DATA1(:,31:33) = temp2(:,(RKnPline1-1)*3+1:RKnPline1*3).*Mass1;
DATA1(:,34:36) = temp2(:,(LHpPline1-1)*3+1:LHpPline1*3).*Mass1;
DATA1(:,37:39) = temp2(:,(RHpPline1-1)*3+1:RHpPline1*3).*Mass1;
DATA1(:,40:42) = temp2(:,(LAnAline1-1)*3+1:LAnAline1*3);
DATA1(:,43:45) = temp2(:,(RAnAline1-1)*3+1:RAnAline1*3);
DATA1(:,46:48) = temp2(:,(LKnAline1-1)*3+1:LKnAline1*3);
DATA1(:,49:51) = temp2(:,(RKnAline1-1)*3+1:RKnAline1*3);
DATA1(:,52:54) = temp2(:,(LHpAline1-1)*3+1:LHpAline1*3);
DATA1(:,55:57) = temp2(:,(RHpAline1-1)*3+1:RHpAline1*3);
DATA1(:,58:60) = temp2(:,(ThoraxAline1-1)*3+1:ThoraxAline1*3);
DATA1(:,61:63) = temp2(:,(LPvAline1-1)*3+1:LPvAline1*3);
DATA1(:,64:66) = temp2(:,(RPvAline1-1)*3+1:RPvAline1*3);
DATA1(:,67:69) = temp2(:,(LFtPrAline1-1)*3+1:LFtPrAline1*3);
DATA1(:,70:72) = temp2(:,(RFtPrAline1-1)*3+1:RFtPrAline1*3);
DATA1(:,73:75) = temp2(:,(LAnFline1-1)*3+1:LAnFline1*3).*Mass1;
DATA1(:,76:78) = temp2(:,(RAnFline1-1)*3+1:RAnFline1*3).*Mass1;
DATA1(:,79:81)= temp2(:,(LKnFline1-1)*3+1:LKnFline1*3).*Mass1;
DATA1(:,82:84)= temp2(:,(RKnFline1-1)*3+1:RKnFline1*3).*Mass1;
DATA1(:,85:87)= temp2(:,(LHpFline1-1)*3+1:LHpFline1*3).*Mass1;
DATA1(:,88:90)= temp2(:,(RHpFline1-1)*3+1:RHpFline1*3).*Mass1;
% Markers converted to m from mm
LHeel1(:,1:3) = temp2(:,(LHEEline1-1)*3+1:LHEEline1*3)./1000;
RHeel1(:,1:3) = temp2(:,(RHEEline1-1)*3+1:RHEEline1*3)./1000;
if length(AnalogSignals1)>30000
DATA1=DATA1(20:length(DATA1)-20,:);
AnalogSignals1=AnalogSignals1(200:length(AnalogSignals1)-200,:);

70
end
Fx11=-AnalogSignals1(:,1);
Fy11=AnalogSignals1(:,2);
Fz11=-AnalogSignals1(:,3);
Mx11=AnalogSignals1(:,4)./1000;
My11=AnalogSignals1(:,5)./1000;
Mz11=AnalogSignals1(:,6)./1000;
Fx12=AnalogSignals1(:,7);
Fy12=-AnalogSignals1(:,8);
Fz12=-AnalogSignals1(:,9);
Mx12=AnalogSignals1(:,10)./1000;
My12=AnalogSignals1(:,11)./1000;
Mz12=AnalogSignals1(:,12)./1000;
dz=0.04;
dz3=0.06;
CoPx11=(Fx11.*dz-My11)./Fz11;
CoPy11=(Fy11.*dz+Mx11)./Fz11;
CoPx12=(Fx12.*dz-My12)./Fz12;
CoPy12=(Fy12.*dz+Mx12)./Fz12;
Prompt1=('Enter End Time in Seconds')
ET=input(Prompt1)
EndTime=seconds(ET);
normtime = 0:milliseconds(1):EndTime;
Prompt2=('Enter Start Time of the phase in seconds')
StrtT=input(Prompt2)
A=1000*StrtT;
Prompt3=('Enter End Time of the phase in seconds')
EndT=input(Prompt3)
B=1000*EndT;
Time=A:B;
NoF1=0;
NoF2=0;
Squat1=0;
Squat2=0;
Threshold=20;
if Fz11(1)<1 && max(Fz11)>Threshold
St11=find(Fz11>Threshold);
Start11=St11(1);
End11=St11(length(St11));
elseif Fz11(1)>0
Start11=50;
End11=length(Fz11)-50;
else

71
Start11=50;
End11=length(Fz11)-50;
NoF1=1;
end
if NoF1==0
if End11-Start11>2000
Squat1=1;
end
end
if Fz12(1)<1 && max(Fz12)>Threshold
St12=find(Fz12>Threshold);
Start12=St12(1);
End12=St12(length(St12));
elseif Fz12(1)>0
Start12=50;
End12=length(Fz12)-50;
else
Start11=50;
End11=length(Fz11)-50;
NoF2=1;
end
if NoF2==0
if End12-Start12>2000
Squat2=1;
end
end
if Squat1==1 && Squat2==1
if Start11>Start12
Start12=Start11;
else
Start11=Start12;
end
if End11>End12
End11=End12;
else
End12=End11;
end
end
Start11=round(Start11/10);
Start12=round(Start12/10);
End11=round(End11/10);
End12=round(End12/10);
hfig30 = figure('position',figposition,'numbertitle','off','name','Left Pelvic angles');

72
subplot(1,3,1)
DATA11(:,61) = resample (DATA1(1:length(DATA1),61),length(normtime),length(DATA1));
DATA11(:,64) = resample (DATA1(1:length(DATA1),64),length(normtime),length(DATA1));
DATA12(:,1)=DATA11(A:B,61);
plot(Time,DATA12(:,1),'b')
title('Left Pelvic Tilt','Fontsize',14)
ylabel('deg','Rotation',pi/2)
subplot(1,3,2)
DATA11(:,62) = resample (DATA1(1:length(DATA1),62),length(normtime),length(DATA1));
DATA11(:,65) = resample (DATA1(1:length(DATA1),65),length(normtime),length(DATA1));
DATA12(:,2)=DATA11(A:B,62);
plot(Time,DATA12(:,2),'b')
title('Left Pelvic Obliquity','Fontsize',14)
ylabel('deg','Rotation',pi/2)
subplot(1,3,3)
DATA11(:,63) = resample (DATA1(1:length(DATA1),63),length(normtime),length(DATA1));
DATA11(:,66) = resample (DATA1(1:length(DATA1),66),length(normtime),length(DATA1));
DATA12(:,3)=DATA11(A:B,63);
plot(Time,DATA12(:,3),'b')
title('Left Pelvic Rotation','Fontsize',14)
ylabel('deg','Rotation',pi/2)
hfig3 = figure('position',figposition,'numbertitle','off','name','Left Hip');
subplot(1,3,1)
DATA11(:,52) = resample (DATA1(1:length(DATA1),52),length(normtime),length(DATA1));
DATA11(:,55) = resample (DATA1(1:length(DATA1),55),length(normtime),length(DATA1));
DATA12(:,4)=DATA11(A:B,52);
plot(Time,DATA12(:,4),'b')
title('Hip Flexion/Extension','Fontsize',14)
ylabel('deg','Rotation',pi/2)
text(-14,40,'Flex')
text(-14,-10,'Ext')
subplot(1,3,2)
DATA11(:,53) = resample (DATA1(1:length(DATA1),53),length(normtime),length(DATA1));
DATA11(:,56) = resample (DATA1(1:length(DATA1),56),length(normtime),length(DATA1));
DATA12(:,5)=DATA11(A:B,53);
plot(Time,DATA12(:,5),'b')
title('Hip Ab/Adduction','Fontsize',14)
ylabel('deg','Rotation',pi/2)
text(-14,20,'Abd')
text(-14,-10,'Add')
subplot(1,3,3)
DATA11(:,54) = resample (DATA1(1:length(DATA1),54),length(normtime),length(DATA1));
DATA11(:,57) = resample (DATA1(1:length(DATA1),57),length(normtime),length(DATA1));

73
DATA12(:,6)=DATA11(A:B,54);
plot(Time,DATA12(:,6),'b')
title('Thigh Rotation','Fontsize',14)
ylabel('deg','Rotation',pi/2)
text(-14,25,'Int')
text(-14,-15,'Ext')
hfig4 = figure('position',figposition,'numbertitle','off','name','Left Knee Angles');
DATA11(:,46) = resample (DATA1(1:length(DATA1),46),length(normtime),length(DATA1));
DATA11(:,49) = resample (DATA1(1:length(DATA1),49),length(normtime),length(DATA1));
DATA12(:,7)=DATA11(A:B,46);
plot(Time,DATA12(:,7),'b')
hold on
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\Angle\KneeFlexionL.csv';
delimiter = ',';
startRow = 8;
formatSpec = '%f%f%f%*s%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1,
'ReturnOnError', false);
fclose(fileID);
UNKNOWN = dataArray{:, 1};
time1 = dataArray{:, 2};
kneeanglel = dataArray{:, 3};
DistTime= linspace(0, ET, ET*1000);
Angle1=interp1(time1, kneeanglel, DistTime, 'linear');
Angle11=Angle1';
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
kneeanglelLE = resample (Angle11,length(normtime),length(Angle11));
DATA12(:,27)=kneeanglelLE(A:B,1);
plot(Time,DATA12(:,27),'r')
hold off
title('Left Knee Flexion/Extension','Fontsize',14)
ylabel('deg','Rotation',pi/2)
text(-14,60,'Flex')
text(-14,-10,'Ext')
legend('BLUE=Vicon Nexus Output','RED=Opensim Output')
hfig5 = figure('position',figposition,'numbertitle','off','name','Left Ankle angles');
DATA11(:,40) = resample (DATA1(1:length(DATA1),40),length(normtime),length(DATA1));
DATA11(:,43) = resample (DATA1(1:length(DATA1),43),length(normtime),length(DATA1));
DATA12(:,8)=DATA11(A:B,40);
plot(Time,DATA12(:,8),'b')
title('Foot Dorsi/Plantar','Fontsize',14)

74
ylabel('deg','Rotation',pi/2)
text(-14,40,'Dors')
text(-14,-30,'Plan')
hfig7 = figure('position',figposition,'numbertitle','off','name','Right Pelvic angles');
subplot(1,3,1)
DATA12(:,9)=DATA11(A:B,64);
plot(Time,DATA12(:,9),'b')
title('Right Pelvic Tilt','Fontsize',14)
ylabel('deg','Rotation',pi/2)
subplot(1,3,2)
DATA12(:,10)=DATA11(A:B,65);
plot(Time,DATA12(:,10),'b')
title('Right Pelvic Obliquity','Fontsize',14)
ylabel('deg','Rotation',pi/2)
subplot(1,3,3)
DATA12(:,11)=DATA11(A:B,66);
plot(Time,DATA12(:,11),'b')
title('Right Pelvic Rotation','Fontsize',14)
ylabel('deg','Rotation',pi/2)
hfig8 = figure('position',figposition,'numbertitle','off','name','Right Hip');
subplot(1,3,1)
DATA12(:,12)=DATA11(A:B,55);
plot(Time,DATA12(:,12),'b')
title('Hip Flexion/Extension','Fontsize',14)
ylabel('deg','Rotation',pi/2)
text(-14,40,'Flex')
text(-14,-10,'Ext')
subplot(1,3,2)
DATA12(:,13)=DATA11(A:B,56);
plot(Time,DATA12(:,13),'b')
title('Hip Ab/Adduction','Fontsize',14)
ylabel('deg','Rotation',pi/2)
text(-14,20,'Abd')
text(-14,-10,'Add')
subplot(1,3,3)
DATA12(:,14)=DATA11(A:B,57);
plot(Time,DATA12(:,14),'b')
title('Thigh Rotation','Fontsize',14)
ylabel('deg','Rotation',pi/2)
text(-14,25,'Int')
text(-14,-15,'Ext')
hfig9 = figure('position',figposition,'numbertitle','off','name','Right Knee Angles');
DATA12(:,15)=DATA11(A:B,49);

75
plot(Time,DATA12(:,27),'b')
hold on
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\Angle\KneeFlexionR.csv';
delimiter = ',';
startRow = 8;
formatSpec = '%f%f%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1,
'ReturnOnError', false);
fclose(fileID);
time = dataArray{:, 1};
time1 = dataArray{:, 2};
kneeangler = dataArray{:, 3};
Angle2=interp1(time1, kneeangler, DistTime, 'linear');
Angle21=Angle2';
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
kneeanglerRE = resample (Angle21,length(normtime),length(Angle21));
DATA12(:,28)=kneeanglerRE(A:B,1);
plot(Time,DATA12(:,28),'r')
hold off
title('Right Knee Flexion/Extension','Fontsize',14)
ylabel('deg','Rotation',pi/2)
text(-14,60,'Flex')
text(-14,-10,'Ext')
legend('BLUE=Vicon Nexus Output','RED=Opensim Output')
%%
hfig10 = figure('position',figposition,'numbertitle','off','name','Right Ankle angles');
DATA12(:,16)=DATA11(A:B,43);
plot(Time,DATA12(:,16),'b')
title('Foot Dorsi/Plantar','Fontsize',14)
ylabel('deg','Rotation',pi/2)
text(-14,40,'Dors')
text(-14,-30,'Plan')
hfig11 = figure('position',figposition,'numbertitle','off','name','Left Ankle Moments');
DATA11(:,4) = resample (DATA1(1:length(DATA1),4),length(normtime),length(DATA1));
DATA11(:,7) = resample (DATA1(1:length(DATA1),7),length(normtime),length(DATA1));
DATA12(:,17)=DATA11(A:B,4);
plot(Time,DATA12(:,17),'b')
title('Left Ankle X Moments','Fontsize',14)
ylabel('N-m','Rotation',pi/2)
hfig12 = figure('position',figposition,'numbertitle','off','name','Right Ankle Moments');
DATA12(:,18)=DATA11(A:B,7);

76
plot(Time,DATA12(:,18),'b')
title('Right Ankle X Moment','Fontsize',14)
ylabel('N-m','Rotation',pi/2)
hfig13 = figure('position',figposition,'numbertitle','off','name','Left Knee Moments');
DATA11(:,10) = resample (DATA1(1:length(DATA1),10),length(normtime),length(DATA1));
DATA11(:,11) = resample (DATA1(1:length(DATA1),11),length(normtime),length(DATA1));
DATA11(:,12) = resample (DATA1(1:length(DATA1),12),length(normtime),length(DATA1));
DATA11(:,13) = resample (DATA1(1:length(DATA1),13),length(normtime),length(DATA1));
DATA11(:,14) = resample (DATA1(1:length(DATA1),14),length(normtime),length(DATA1));
DATA11(:,15) = resample (DATA1(1:length(DATA1),15),length(normtime),length(DATA1));
DATA12(:,19)=DATA11(A:B,10);
plot(Time,DATA12(:,19),'b')
hold on
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\Moments\KneeOnTibiaZ_MomentL.
csv';
delimiter = ',';
startRow = 8;
formatSpec = '%*s%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1,
'ReturnOnError', false);
fclose(fileID);
time2 = dataArray{:, 1};
kneeanglelmoment = dataArray{:, 2};
DistTime1= linspace(0, ET, ET*1000);
Moment1=interp1(time2, kneeanglelmoment, DistTime1, 'linear');
Moment11=Moment1';
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
kneeanglelmomentLE = resample(Moment11,length(normtime),length(Moment11));
DATA12(:,29)=kneeanglelmomentLE(A:B,1);
plot(Time,DATA12(:,29),'r')
hold off
title('Left Knee X Moment','Fontsize',14)
ylabel('N-m','Rotation',pi/2)
legend('BLUE=Vicon Nexus Output','RED=Opensim Output')
hfig14 = figure('position',figposition,'numbertitle','off','name','Right Knee Moment');
DATA12(:,20)=DATA11(A:B,13);
plot(Time,DATA12(:,20),'b')
hold on
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\Moments\2\KneeRY.csv';
delimiter = ',';

77
startRow = 8;
formatSpec = '%*s%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1,
'ReturnOnError', false);
fclose(fileID);
time3 = dataArray{:, 1};
kneeanglermoment = dataArray{:, 2};
DistTime2= linspace(0, ET, ET*1000);
Moment2=interp1(time3, kneeanglermoment, DistTime2, 'linear');
Moment21=Moment2';
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
kneeanglermomentRE = resample(Moment21,length(normtime),length(Moment21));
DATA12(:,30)=kneeanglermomentRE(A:B,1);
plot(Time,DATA12(:,30),'r')
hold off
title('Right Knee X Moment','Fontsize',14)
ylabel('N-m','Rotation',pi/2)
hfig15 = figure('position',figposition,'numbertitle','off','name','Left Hip Moments');
DATA11(:,16) = resample (DATA1(1:length(DATA1),16),length(normtime),length(DATA1));
DATA11(:,19) = resample (DATA1(1:length(DATA1),19),length(normtime),length(DATA1));
subplot(1,3,1)
DATA12(:,21)=DATA11(A:B,16);
plot(Time,DATA12(:,21),'b')
title('Left Hip X Moment','Fontsize',14)
ylabel('N-m','Rotation',pi/2)
legend('BLUE=Vicon Nexus Output','RED=Opensim Output')
DATA11(:,20) = resample (DATA1(1:length(DATA1),20),length(normtime),length(DATA1));
DATA11(:,17) = resample (DATA1(1:length(DATA1),17),length(normtime),length(DATA1));
subplot(1,3,2)
DATA12(:,22)=DATA11(A:B,17);
plot(Time,DATA12(:,22),'b')
title('Left Hip Y Moment','Fontsize',14)
ylabel('N-m','Rotation',pi/2)
DATA11(:,21) = resample (DATA1(1:length(DATA1),21),length(normtime),length(DATA1));
DATA11(:,18) = resample (DATA1(1:length(DATA1),18),length(normtime),length(DATA1));
subplot(1,3,3)
DATA12(:,26)=DATA11(A:B,18);
plot(Time,DATA12(:,26),'b')
title('Left Hip Z Moment','Fontsize',14)
ylabel('N-m','Rotation',pi/2)
hfig16 = figure('position',figposition,'numbertitle','off','name','Right Hip Moments');
subplot(1,3,1)

78
DATA12(:,23)=DATA11(A:B,19);
plot(Time,DATA12(:,23),'b')
title('Right Hip X Moment','Fontsize',14)
ylabel('N-m','Rotation',pi/2)
subplot(1,3,2)
DATA12(:,24)=DATA11(A:B,20);
plot(Time,DATA12(:,24),'b')
title('Right Hip Y Moment','Fontsize',14)
ylabel('N-m','Rotation',pi/2)
subplot(1,3,3)
DATA12(:,25)=DATA11(A:B,21);
plot(Time,DATA12(:,25),'b')
title('Right Hip Z Moment','Fontsize',14)
ylabel('N-m','Rotation',pi/2)
%Error Analysis for Knee Angles
for i=1:1:A:B
C(i) = ((DATA11(i,46) - kneeanglelLE(i))/DATA11(i,46))*100;
D = sum ((C(i))*(C(i)));
end
Error1 = sqrt(D/(length(normtime)+1));
disp(Error1)
sprintf('Percentage RMS Error for Left Knee = %f',Error1)
for i=1:1:1:101
E(i) = ((DATA11(i,49) - kneeanglerRE(i))/DATA11(i,49))*100;
F = sum ((E(i))*(E(i)));
end
Error2 = sqrt(F/(length(normtime)+1));
disp(Error2)
sprintf('Percentage RMS Error for right Knee = %f',Error2)

Muscle force validation


%% Muscle Force Importing
clc
clear all
RemovePlots
screenrect=get(0,'screensize');
figposition=[0.022*screenrect(3) 0.05*screenrect(4) 0.96*screenrect(3) 0.85*screenrect(4)];
%Gastrocnemius
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\EMG\GAST.csv';
delimiter = ',';
startRow = 3;
79
formatSpec = '%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
Time1= dataArray{:, 1};
RMSA = dataArray{:, 2};
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
Prompt1=('Enter End Time in Seconds')
ET=input(Prompt1)
EndTime=seconds(ET);
normtime = 0:milliseconds(10):EndTime;
RMSARE = resample (RMSA,length(normtime),length(RMSA));
% RMSARE = resample (RMSA,length(normtime),length(RMSA));
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\MuscleForce\Gast.csv';
delimiter = ',';
startRow = 8;
formatSpec = '%*s%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
time3 = dataArray{:, 1};
Gast1 = dataArray{:, 2};
DistTime1= linspace(-1, 25.3, 52600);
Gast11=interp1(time3, Gast1, DistTime1, 'linear');
Gast=Gast11';
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
GastRE = resample (Gast,length(normtime),length(Gast));

%Hamstring
%%
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\EMG\HAMSTRING.csv';
delimiter = ',';
startRow = 3;
formatSpec = '%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
Time1= dataArray{:, 1};

80
RMSB = dataArray{:, 2};
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
RMSBRE = resample (RMSB,length(normtime),length(RMSB));
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\MuscleForce\Hamstring.csv';
delimiter = ',';
startRow = 8;
formatSpec = '%*s%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
time3 = dataArray{:, 1};
Hamstring1 = dataArray{:, 2};
Hamst11=interp1(time3, Hamstring1, DistTime1, 'linear');
Hamstring=Hamst11';
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
HamstRE = resample (Hamstring,length(normtime),length(Hamstring));

%Vast_Lat
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\EMG\VAST_LAT.csv';
delimiter = ',';
startRow = 3;
formatSpec = '%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
Time1= dataArray{:, 1};
RMSC = dataArray{:, 2};
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
RMSCRE = resample (RMSC,length(normtime),length(RMSC));
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\MuscleForce\RctFemR.csv';
delimiter = ',';
startRow = 8;
formatSpec = '%*s%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
time3 = dataArray{:, 1};

81
RectFem1 = dataArray{:, 2};
Rect11=interp1(time3, RectFem1, DistTime1, 'linear');
RectFem=Rect11';
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
RectFemRE = resample (RectFem,length(normtime),length(RectFem));

%G_MED
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\EMG\GMED.csv';
delimiter = ',';
startRow = 3;
formatSpec = '%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
Time1= dataArray{:, 1};
RMSD = dataArray{:, 2};
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
RMSDRE = resample (RMSD,length(normtime),length(RMSD));
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\MuscleForce\GMED2.csv';
delimiter = ',';
startRow = 8;
formatSpec = '%*s%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
time3 = dataArray{:, 1};
GMED1 = dataArray{:, 2};
GMED11=interp1(time3, GMED1, DistTime1, 'linear');
GMED=GMED11';
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
GMEDRE = resample (GMED,length(normtime),length(GMED));

%GMAX
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\EMG\GMAX.csv';
delimiter = ',';
startRow = 3;
formatSpec = '%f%f%[^\n\r]';
fileID = fopen(filename,'r');

82
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
Time1= dataArray{:, 1};
RMSE = dataArray{:, 2};
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
RMSERE = resample (RMSE,length(normtime),length(RMSE));
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\MuscleForce\GMAX2.csv';
delimiter = ',';
startRow = 8;
formatSpec = '%*s%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
time3 = dataArray{:, 1};
GMAX1 = dataArray{:, 2};
GMAX11=interp1(time3, GMAX1, DistTime1, 'linear');
GMAX=GMAX11';
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
GMAXRE = resample (GMAX,length(normtime),length(GMAX));

%
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\EMG\ERC_SPN.csv';
delimiter = ',';
startRow = 3;
formatSpec = '%f%f%[^\n\r]';
fileID = fopen(filename,'r');
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
Time1= dataArray{:, 1};
RMSF = dataArray{:, 2};
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
RMSFRE = resample (RMSF,length(normtime),length(RMSF));
filename = 'C:\Users\Pc-
3\Desktop\SayleeP\opensim\Subject_01\2604\Analysis2\Validation\MuscleForce\ERC_SPN1.csv';
delimiter = ',';
startRow = 8;
formatSpec = '%*s%f%f%[^\n\r]';
fileID = fopen(filename,'r');

83
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'EmptyValue' ,NaN,'HeaderLines'
,startRow-1, 'ReturnOnError', false);
fclose(fileID);
time3 = dataArray{:, 1};
ERCSPN1 = dataArray{:, 2};
ERCSPN11=interp1(time3, ERCSPN1, DistTime1, 'linear');
ERCSPN=ERCSPN11';
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
ERCSPNRE = resample (ERCSPN,length(normtime),length(ERCSPN));

%% Data Processcing for Muscle Forces


%Gastrocnemius
RRFMV = nanmean (RMSARE);
disp(RRFMV)
for i = 1:2631
NRMSARE(i) = RMSARE(i)*100/(RRFMV);
end
RRFMO = nanmean (GastRE);
disp (RRFMO)
for i = 1:2631
NGastRE(i) = GastRE(i)*100/(RRFMO);
end
hfig18 = figure('position',figposition,'numbertitle','off','name','Right Normalised Gastrocnemius ');
plot(normtime,NGastRE,'r')
hold on
plot(normtime,NRMSARE,'b')
hold off
legend('Red=Opensim Output','Blue=EMG Output')

%Hamstring
RRFMV1 = nanmean (RMSBRE);
for i = 1:2631
NRMSBRE(i) = RMSBRE(i)*100/RRFMV1;
end
RRFMO1 = nanmean (HamstRE);
disp (RRFMO1)
for i = 1:2631
NHamstRE(i) = HamstRE(i)*100/(RRFMO1);
end
hfig18 = figure('position',figposition,'numbertitle','off','name','Right Normalised Hamstring ');
plot(normtime,NHamstRE,'r')
hold on

84
plot(normtime,NRMSBRE,'b')
hold off
legend('Red=Opensim Output','Blue=EMG Output')

%Vast_Lat
RRFMV2 = nanmean (RMSCRE);
for i = 1:2631
NRMSCRE(i) = RMSCRE(i)*100/RRFMV2;
end
RRFMO2 = nanmean (RectFemRE);
disp (RRFMO2)
for i = 1:2631
NRectFemRE(i) = RectFemRE(i)*100/RRFMO2;
end
hfig18 = figure('position',figposition,'numbertitle','off','name','Right Normalised RectFem ');
plot(normtime,NRectFemRE,'r')
hold on
plot(normtime,NRMSCRE,'b')
hold off
legend('Red=Opensim Output','Blue=EMG Output')

%GMED
RRFMV3 = nanmean (RMSDRE);
for i = 1:2631
NRMSDRE(i) = RMSDRE(i)*100/RRFMV3;
end
RRFMO3 = nanmean (GMEDRE);
disp (RRFMO3)
for i = 1:2631
NGMEDRE(i) = GMEDRE(i)*100/RRFMO3;
end
hfig18 = figure('position',figposition,'numbertitle','off','name','Right Normalised G_med ');
plot(normtime,NGMEDRE,'r')
hold on
plot(normtime,NRMSDRE,'b')
hold off
legend('Red=Opensim Output','Blue=EMG Output')

%Glut_Max
RRFMV4 = nanmean (RMSERE);
for i = 1:2631
NRMSERE(i) = RMSERE(i)*100/RRFMV4;
end

85
RRFMO4 = nanmean (GMAXRE);
disp (RRFMO4)
for i = 1:2631
NGMAXRE(i) = GMAXRE(i)*100/RRFMO4;
end
hfig18 = figure('position',figposition,'numbertitle','off','name','Right Normalised G_Max ');
plot(normtime,NGMAXRE,'r')
hold on
plot(normtime,NRMSERE,'b')
hold off
legend('Red=Opensim Output','Blue=EMG Output')

%ERC_SPN
RRFMV5 = nanmean (RMSFRE);
for i = 1:2631
NRMSFRE(i) = RMSFRE(i)*100/RRFMV5;
end
RRFMO5 = nanmean (ERCSPNRE);
disp (RRFMO5)
for i = 1:2631
NERCSPNRE(i) = ERCSPNRE(i)*100/RRFMO5;
end
hfig18 = figure('position',figposition,'numbertitle','off','name','Right Normalised ERC_SPN ');
plot(normtime,NERCSPNRE,'r')
hold on
plot(normtime,NRMSFRE,'b')
hold off
legend('Red=Opensim Output','Blue=EMG Output')

%% Error Analysis for Muscle Forces


for i=1:1:1:2631
NErrorr1(i) = ((NRMSARE(i) - NGastRE(i))/NRMSARE(i))*100;
D = sum ((NErrorr1(i))*(NErrorr1(i)));
end
NErrorr1 = sqrt(D/2630);
sprintf('Percentage RMS Error for Right Gastrocnemius= %f %',NErrorr1)

for i=1:1:1:2631
NErrorr2(i) = ((NRMSBRE(i) - NHamstRE(i))/NRMSBRE(i))*100;
E = sum ((NErrorr2(i))*(NErrorr2(i)));
end
NErrorr2 = sqrt(E/2630);
sprintf('Percentage RMS Error for Right Hamstring= %f %',NErrorr2)

86
for i=1:1:1:2631
NErrorr3(i) = ((NRMSCRE(i) - NRectFemRE(i))/NRMSCRE(i))*100;
F = sum ((NErrorr3(i))*(NErrorr3(i)));
end
NErrorr3 = sqrt(F/2630);
sprintf('Percentage RMS Error for Right RectFem= %f %',NErrorr3)

for i=1:1:1:2631
NErrorr4(i) = ((NRMSDRE(i) - NGMEDRE(i))/NRMSDRE(i))*100;
G = sum ((NErrorr4(i))*(NErrorr4(i)));
end
NErrorr4 = sqrt(G/2630);
sprintf('Percentage RMS Error for Right Gluteus Medius= %f %',NErrorr4)

for i=1:1:1:2631
NErrorr5(i) = ((NRMSERE(i) - NGMAXRE(i))/NRMSERE(i))*100;
H = sum ((NErrorr5(i))*(NErrorr5(i)));
end
NErrorr5 = sqrt(H/2630);
sprintf('Percentage RMS Error for Right Gluteus Maximus= %f %',NErrorr5)

for i=1:1:1:2631
NErrorr6(i) = ((NRMSFRE(i) - NERCSPNRE(i))/NRMSFRE(i))*100;
I = sum ((NErrorr6(i))*(NErrorr6(i)));
end
NErrorr6 = sqrt(I/2630);
sprintf('Percentage RMS Error for Right Erector Spinae= %f %',NErrorr6)

87