Chris Kirtley

05-19-2004, 09:43 PM

Deart all resamplers,

Thanks to everyone for the responses to my query about resampling. Most

people suggested the MATLAB function, and I forgot to ask people not to

refer to MATLAB. Whilst I agree that it's a good solution, I personally

prefer to know what algorithm I am using - more intellectually

satisfying and perhaps safer. But it's a personal bette noire of mine

:-)

Some people did suggest algorithms involving linear interpolation. I

have used these in the past with good results. This necessarily involves

increasing the sampling rate of the kinematics to equal that of the

force data (which will result in big, clumsy files) - does anyone know

if it is possible to go the other way (i.e. reduce the sampling rate)?

Or, in other words, does anyone know how MATLAB does it?

I should also have said that I was hoping for a solution that could be

implemented in Excel - perhaps this is impossible?...

Chris

--- responses begin...

Chris,

I did some work on this matter a few years back when trying to

determine joint moments in sprinting from kinematic data collected at

50Hz and GRF data collected at 1000Hz. We hypothesised that the GRF

rather than segmental accelerations would be the major cause of joint

moment. Thus, rather than loose anything from our GRF data, we

interpolated our kinematic data using quintic splines. We tested our

hypothesis by recalculating moment data with segmental accelerations

set to zero. You can read the specific details in:

Johnson MD and Buckley JG. (2001) The Biomechanics of Sprinting.

Post-start Performance. Journal of Sport Sciences, 19:263-272.

hope this helps

John Buckley, PhD

Research Associate (biomechanics)

Dept of Optometry

University of Bradford

Bradford BD7 1DP

---

Chris,

I use the attached MATLAB function, written by a friend of mine, to

evenly sample signals. I think

it may do what you want.

Eric Westervelt

%************************************************* **********************

%

% CONVERTS A RANDOMLY SAMPLED SIGNAL SET INTO AN EVENLY SAMPLED

% SIGNAL SET (by interpolation)

%

% By : Haldun KOMSUOGLU

% Start : 07/23/1999

% Last : 07/23/1999

% Statue : Neural Model Research Material

%

% Inputs:

% t : A column vector that contains the time values for the

% corresponding computed state trajectory points

% x : A matrix in which each row is a state value on the

% solution trajectory that corresponds to the time

value in

% vector t with the same row value. Format of each row:

% row = [x1 x2 ... xN]

% Fs: The sampling frequency (1/sec) for the evenly sampled

% set to be generated.

%

% Outputs:

% Et : Even sampling instants. This is a column vector in

the

% same format with "t".

% Ex : A matrix of the same form with "x" that contains the

% state values corresponding to the time instants in

Et

%

%************************************************* **********************

function [Et, Ex] = even_sample(t, x, Fs);

% Obtain the process related parameters

N = size(x, 2); % number of signals to be interpolated

M = size(t, 1); % Number of samples provided

t0 = t(1,1); % Initial time

tf = t(M,1); % Final time

EM = (tf-t0)*Fs; % Number of samples in the evenly sampled case with

% the specified sampling frequency

Et = linspace(t0, tf,round(EM))'; % ROUND ADDED TO GET TRULY EVEN

SAMPLING.

% Using linear interpolation (used to be cubic spline interpolation)

% and re-sample each signal to obtain the evenly sampled forms

for s = 1:N,

Ex(:,s) = interp1(t(:,1), x(:,s), Et(:,1));

end

---

I have used two different solutions. One is to do linear interpolation

the equation for this is quite simple (see below). A better

solution is to use the Shannon algorithm. This gives a curvilinear fit

to the data. The following paper outlines the procedure:

Hamill, J.; Caldwell, G.E. & Derrick, T.R. (1997) A method for

reconstructing digital signals using Shannon's sampling theorem.

Journal of Applied Biomechanics, 13: 226-238.

Linear interpolation routine (in C):

(ndata = number of original data)

(normbase = number of time intervals of normalized data = number

of normalized data -1)

duration = (ndata - 1) / rate

Fx = (ndata - 1) / normbase

'Normalize the data and place in array Y.

Y(1) = data(1)

Y(normbase + 1) = data(ndata)

dx = 1.0

For j = 2 To normbase

dx = dx + Fx

ix = Int(dx)

Y(j) = data(ix) + (data(ix + 1) - data(ix)) * (dx - ix)

Next j

I have used two different solutions. One is to do linear interpolation

the equation for this is quite simple (see below). A better

solution is to use the Shannon algorithm. This gives a curvilinear fit

to the data. The following paper outlines the procedure:

Hamill, J.; Caldwell, G.E. & Derrick, T.R. (1997) A method for

reconstructing digital signals using Shannon's sampling theorem.

Journal of Applied Biomechanics, 13: 226-238.

Linear interpolation routine (in C):

(ndata = number of original data)

(normbase = number of time intervals of normalized data = number

of normalized data -1)

duration = (ndata - 1) / rate

Fx = (ndata - 1) / normbase

'Normalize the data and place in array Y.

Y(1) = data(1)

Y(normbase + 1) = data(ndata)

dx = 1.0

For j = 2 To normbase

dx = dx + Fx

ix = Int(dx)

Y(j) = data(ix) + (data(ix + 1) - data(ix)) * (dx - ix)

Next j

D. Gordon E. Robertson, Ph.D., FCSB

Professor of Biomechanics

School of Human Kinetics, University of Ottawa

Ottawa, ON, Canada, K1N 6N5

mailto:dger@uottawa.ca

+1-613-562-5800 Off: 4253 Lab: 4246 Fax: +1-613-562-5149

Webpage: http://www.health.uottawa.ca/biomech/lab

Personal: http://myprofile.cos.com/dger

--

Hi Chris,

Given that resampling data to a lower data rate is a form of

sampling,

would you be better to take the approach of upsampling the lower sample

rate data to match the faster data? I'll admit that I haven't thought

about this much but it would seem to be a much safer (data integrity

wise) method than downsampling. Upsampling both data sets also offers

the possibility of a "perfect" sample match too.

How much call is there for this sort of thing? My first guess is

that

it's relatively uncommon but maybe people just give up when faced with

the

problem.

FWIW - the C3Deditor provides upsample capabilities but I get very

few

calls about this.

Regards,

Edmund Cramp

--

Motion Lab Systems, Inc.

15045 Old Hammond Hwy, Baton Rouge LA 70816

Tel: +1 225 272-7364, Fax: +1 225 272-7336

---

Chris,

I collect kinematic (Polhemus) and analog data at different sampling

rates in labview. I basically time stamp each data point and then

interpolate the analog data to match the time on the kinematic data. I

use a linear interpolation scheme, but if you were worried about sharp

gradients, you could certainly use a non-linear scheme. I realize that

this is an overly simplistic approach, but it works fairly well,

especially if you don't need to differentiate your data.

Andrew Karduna

---

Dear Chris,

I am not an expert but for my research I have used resample function in

Matlab. See www.mathworks.com for more details.

Good luck and please send me resume.

Andrzej

"AS Przybyla, Anatomy"

---

Hi Chris and all, we use Matlab and it contains a RESAMPLE function.

You feed

in the data for a gait cycle and it is resampled over your selected

number of

points. so for force in stance phase you would have to look at the

number of

samples for the 60 Hz kinematic data and resample the force data over

that

number of points.

Its a suggestion!

Cheers

Cathy

Dr Cathy Holt

Lecturer in Biomechanics and Materials

Division of Materials and Minerals Engineering

Cardiff School of Engineering

PO Box 925

Newport Rd

Cardiff CF24 0YF

00 44 0(29) 2087 4533

fax 00 44 0(29) 2087 4939

http://www.engin.cf.ac.uk/whoswho/profile.asp?RecordNo=198

---

Chris,

I have two data sets (moments and power) taken for two different

groups. Of course the stance phase data is normalized to different

values - 200 and 120 respectively. To look at phase shifts between

groups, I am having to decimate to come down in sample

number, and interpolate (of sort) to come up to an in between number of

150 points. Matlab has an intrinsic that has worked well so

far. I am pasting below.....

Hope this helps. I have not had a chance to compare reduced graphs of

any real "messy" data, but my angles (ankle, knee, and hip),

moments and power figures look good.

Regards Dwight

DECIMATE Resample data at a lower rate after lowpass filtering.

Y = DECIMATE(X,R) resamples the sequence in vector X at 1/R times

the

original sample rate. The resulting resampled vector Y is R times

shorter,

LENGTH(Y) = LENGTH(X)/R.

DECIMATE filters the data with an eighth order Chebyshev Type I

lowpass

filter with cutoff frequency .8*(Fs/2)/R, before resampling.

Y = DECIMATE(X,R,N) uses an N'th order Chebyshev filter.

Y = DECIMATE(X,R,'FIR') uses the 30 point FIR filter generated by

FIR1(30,1/R) to filter the data.

Y = DECIMATE(X,R,N,'FIR') uses the N-point FIR filter.

Note: For large R, the Chebyshev filter design might be incorrect

due to numeric precision limitations. In this case, DECIMATE will

use a lower filter order. For better anti-aliasing performance, try

breaking R up into its factors and calling DECIMATE several times..

Dwight E. Waddell, Ph.D.

School of Applied Physiology

Center for Human Movement Studies

Georgia Institute of Technology

Atlanta, GA 30332-0356 USA

dwight.waddell@ap.gatech.edu

Office: (404) 385-1559

Fax : (404) 894-7593

---

As to your question to the Biomch-l, why not use the Resample function

in Matlab. Have a look at the enclosed figure where I took the raw data

of

an accelerometry sequence (arbitrary units) sampled at 128 Hz, and did

two resamplings at 55 and 20 Hz. Matlab chooses appropriate

anti-aliasing

filters. You can manipulate the filter coefficients which is not my

field.

Take care!

Rolf Moe-Nilssen

--

Dr. Chris Kirtley MD PhD

Associate Professor

Dept. of Biomedical Engineering

Catholic University of America

620 Michigan Ave NE, Washington, DC 20064

Tel. 202-319-6134, fax 202-319-4287

Email: kirtley@cua.edu

http://faculty.cua.edu/kirtley

In May 2004 I am at STAPS, University of Reims, France

Tel. 06-77944628

-----------------------------------------------------------------

To unsubscribe send SIGNOFF BIOMCH-L to LISTSERV@nic.surfnet.nl

For information and archives: http://isb.ri.ccf.org/biomch-l

Please consider posting your message to the Biomch-L Web-based

Discussion Forum: http://movement-analysis.com/biomch_l

-----------------------------------------------------------------

Thanks to everyone for the responses to my query about resampling. Most

people suggested the MATLAB function, and I forgot to ask people not to

refer to MATLAB. Whilst I agree that it's a good solution, I personally

prefer to know what algorithm I am using - more intellectually

satisfying and perhaps safer. But it's a personal bette noire of mine

:-)

Some people did suggest algorithms involving linear interpolation. I

have used these in the past with good results. This necessarily involves

increasing the sampling rate of the kinematics to equal that of the

force data (which will result in big, clumsy files) - does anyone know

if it is possible to go the other way (i.e. reduce the sampling rate)?

Or, in other words, does anyone know how MATLAB does it?

I should also have said that I was hoping for a solution that could be

implemented in Excel - perhaps this is impossible?...

Chris

--- responses begin...

Chris,

I did some work on this matter a few years back when trying to

determine joint moments in sprinting from kinematic data collected at

50Hz and GRF data collected at 1000Hz. We hypothesised that the GRF

rather than segmental accelerations would be the major cause of joint

moment. Thus, rather than loose anything from our GRF data, we

interpolated our kinematic data using quintic splines. We tested our

hypothesis by recalculating moment data with segmental accelerations

set to zero. You can read the specific details in:

Johnson MD and Buckley JG. (2001) The Biomechanics of Sprinting.

Post-start Performance. Journal of Sport Sciences, 19:263-272.

hope this helps

John Buckley, PhD

Research Associate (biomechanics)

Dept of Optometry

University of Bradford

Bradford BD7 1DP

---

Chris,

I use the attached MATLAB function, written by a friend of mine, to

evenly sample signals. I think

it may do what you want.

Eric Westervelt

%************************************************* **********************

%

% CONVERTS A RANDOMLY SAMPLED SIGNAL SET INTO AN EVENLY SAMPLED

% SIGNAL SET (by interpolation)

%

% By : Haldun KOMSUOGLU

% Start : 07/23/1999

% Last : 07/23/1999

% Statue : Neural Model Research Material

%

% Inputs:

% t : A column vector that contains the time values for the

% corresponding computed state trajectory points

% x : A matrix in which each row is a state value on the

% solution trajectory that corresponds to the time

value in

% vector t with the same row value. Format of each row:

% row = [x1 x2 ... xN]

% Fs: The sampling frequency (1/sec) for the evenly sampled

% set to be generated.

%

% Outputs:

% Et : Even sampling instants. This is a column vector in

the

% same format with "t".

% Ex : A matrix of the same form with "x" that contains the

% state values corresponding to the time instants in

Et

%

%************************************************* **********************

function [Et, Ex] = even_sample(t, x, Fs);

% Obtain the process related parameters

N = size(x, 2); % number of signals to be interpolated

M = size(t, 1); % Number of samples provided

t0 = t(1,1); % Initial time

tf = t(M,1); % Final time

EM = (tf-t0)*Fs; % Number of samples in the evenly sampled case with

% the specified sampling frequency

Et = linspace(t0, tf,round(EM))'; % ROUND ADDED TO GET TRULY EVEN

SAMPLING.

% Using linear interpolation (used to be cubic spline interpolation)

% and re-sample each signal to obtain the evenly sampled forms

for s = 1:N,

Ex(:,s) = interp1(t(:,1), x(:,s), Et(:,1));

end

---

I have used two different solutions. One is to do linear interpolation

the equation for this is quite simple (see below). A better

solution is to use the Shannon algorithm. This gives a curvilinear fit

to the data. The following paper outlines the procedure:

Hamill, J.; Caldwell, G.E. & Derrick, T.R. (1997) A method for

reconstructing digital signals using Shannon's sampling theorem.

Journal of Applied Biomechanics, 13: 226-238.

Linear interpolation routine (in C):

(ndata = number of original data)

(normbase = number of time intervals of normalized data = number

of normalized data -1)

duration = (ndata - 1) / rate

Fx = (ndata - 1) / normbase

'Normalize the data and place in array Y.

Y(1) = data(1)

Y(normbase + 1) = data(ndata)

dx = 1.0

For j = 2 To normbase

dx = dx + Fx

ix = Int(dx)

Y(j) = data(ix) + (data(ix + 1) - data(ix)) * (dx - ix)

Next j

I have used two different solutions. One is to do linear interpolation

the equation for this is quite simple (see below). A better

solution is to use the Shannon algorithm. This gives a curvilinear fit

to the data. The following paper outlines the procedure:

Hamill, J.; Caldwell, G.E. & Derrick, T.R. (1997) A method for

reconstructing digital signals using Shannon's sampling theorem.

Journal of Applied Biomechanics, 13: 226-238.

Linear interpolation routine (in C):

(ndata = number of original data)

(normbase = number of time intervals of normalized data = number

of normalized data -1)

duration = (ndata - 1) / rate

Fx = (ndata - 1) / normbase

'Normalize the data and place in array Y.

Y(1) = data(1)

Y(normbase + 1) = data(ndata)

dx = 1.0

For j = 2 To normbase

dx = dx + Fx

ix = Int(dx)

Y(j) = data(ix) + (data(ix + 1) - data(ix)) * (dx - ix)

Next j

D. Gordon E. Robertson, Ph.D., FCSB

Professor of Biomechanics

School of Human Kinetics, University of Ottawa

Ottawa, ON, Canada, K1N 6N5

mailto:dger@uottawa.ca

+1-613-562-5800 Off: 4253 Lab: 4246 Fax: +1-613-562-5149

Webpage: http://www.health.uottawa.ca/biomech/lab

Personal: http://myprofile.cos.com/dger

--

Hi Chris,

Given that resampling data to a lower data rate is a form of

sampling,

would you be better to take the approach of upsampling the lower sample

rate data to match the faster data? I'll admit that I haven't thought

about this much but it would seem to be a much safer (data integrity

wise) method than downsampling. Upsampling both data sets also offers

the possibility of a "perfect" sample match too.

How much call is there for this sort of thing? My first guess is

that

it's relatively uncommon but maybe people just give up when faced with

the

problem.

FWIW - the C3Deditor provides upsample capabilities but I get very

few

calls about this.

Regards,

Edmund Cramp

--

Motion Lab Systems, Inc.

15045 Old Hammond Hwy, Baton Rouge LA 70816

Tel: +1 225 272-7364, Fax: +1 225 272-7336

---

Chris,

I collect kinematic (Polhemus) and analog data at different sampling

rates in labview. I basically time stamp each data point and then

interpolate the analog data to match the time on the kinematic data. I

use a linear interpolation scheme, but if you were worried about sharp

gradients, you could certainly use a non-linear scheme. I realize that

this is an overly simplistic approach, but it works fairly well,

especially if you don't need to differentiate your data.

Andrew Karduna

---

Dear Chris,

I am not an expert but for my research I have used resample function in

Matlab. See www.mathworks.com for more details.

Good luck and please send me resume.

Andrzej

"AS Przybyla, Anatomy"

---

Hi Chris and all, we use Matlab and it contains a RESAMPLE function.

You feed

in the data for a gait cycle and it is resampled over your selected

number of

points. so for force in stance phase you would have to look at the

number of

samples for the 60 Hz kinematic data and resample the force data over

that

number of points.

Its a suggestion!

Cheers

Cathy

Dr Cathy Holt

Lecturer in Biomechanics and Materials

Division of Materials and Minerals Engineering

Cardiff School of Engineering

PO Box 925

Newport Rd

Cardiff CF24 0YF

00 44 0(29) 2087 4533

fax 00 44 0(29) 2087 4939

http://www.engin.cf.ac.uk/whoswho/profile.asp?RecordNo=198

---

Chris,

I have two data sets (moments and power) taken for two different

groups. Of course the stance phase data is normalized to different

values - 200 and 120 respectively. To look at phase shifts between

groups, I am having to decimate to come down in sample

number, and interpolate (of sort) to come up to an in between number of

150 points. Matlab has an intrinsic that has worked well so

far. I am pasting below.....

Hope this helps. I have not had a chance to compare reduced graphs of

any real "messy" data, but my angles (ankle, knee, and hip),

moments and power figures look good.

Regards Dwight

DECIMATE Resample data at a lower rate after lowpass filtering.

Y = DECIMATE(X,R) resamples the sequence in vector X at 1/R times

the

original sample rate. The resulting resampled vector Y is R times

shorter,

LENGTH(Y) = LENGTH(X)/R.

DECIMATE filters the data with an eighth order Chebyshev Type I

lowpass

filter with cutoff frequency .8*(Fs/2)/R, before resampling.

Y = DECIMATE(X,R,N) uses an N'th order Chebyshev filter.

Y = DECIMATE(X,R,'FIR') uses the 30 point FIR filter generated by

FIR1(30,1/R) to filter the data.

Y = DECIMATE(X,R,N,'FIR') uses the N-point FIR filter.

Note: For large R, the Chebyshev filter design might be incorrect

due to numeric precision limitations. In this case, DECIMATE will

use a lower filter order. For better anti-aliasing performance, try

breaking R up into its factors and calling DECIMATE several times..

Dwight E. Waddell, Ph.D.

School of Applied Physiology

Center for Human Movement Studies

Georgia Institute of Technology

Atlanta, GA 30332-0356 USA

dwight.waddell@ap.gatech.edu

Office: (404) 385-1559

Fax : (404) 894-7593

---

As to your question to the Biomch-l, why not use the Resample function

in Matlab. Have a look at the enclosed figure where I took the raw data

of

an accelerometry sequence (arbitrary units) sampled at 128 Hz, and did

two resamplings at 55 and 20 Hz. Matlab chooses appropriate

anti-aliasing

filters. You can manipulate the filter coefficients which is not my

field.

Take care!

Rolf Moe-Nilssen

--

Dr. Chris Kirtley MD PhD

Associate Professor

Dept. of Biomedical Engineering

Catholic University of America

620 Michigan Ave NE, Washington, DC 20064

Tel. 202-319-6134, fax 202-319-4287

Email: kirtley@cua.edu

http://faculty.cua.edu/kirtley

In May 2004 I am at STAPS, University of Reims, France

Tel. 06-77944628

-----------------------------------------------------------------

To unsubscribe send SIGNOFF BIOMCH-L to LISTSERV@nic.surfnet.nl

For information and archives: http://isb.ri.ccf.org/biomch-l

Please consider posting your message to the Biomch-L Web-based

Discussion Forum: http://movement-analysis.com/biomch_l

-----------------------------------------------------------------