# How to estimate a mass-spring-damper parameters in MATLAB using RLS and OLS?

Assume that we have the differential equation of a mass-spring-damper model as follows: $$m\frac{d^2y}{dt^2}+c\frac{dy}{dt}+ky(t)=F(t)$$

How it could be implemented in MATLAB to do the following steps:

First, convert the differential equation to a difference equation.

Second, finding the discrete-time transfer function of it.

Third, finding the regression equation of this system.

Finally deriving Recursive Least Squares (RLS) and Ordinary Least Squares (OLS) to estimate the free parameters of the system ($m$,$c$, and $k$).

More information on this system is available at Mass-Spring-Damper System Excited by Force F(t)

Any help is greatly appreciated

• This sounds like homework to me. What have you tried? What are you having trouble with? – Chuck Jan 17 '16 at 1:29
• Do you need to follow this approach or can you do it differently? Is it a theoretical question or do you want to identify the parameters with a physical set-up? – Karlo Feb 16 '16 at 9:36

Matlab with some tips

A good method is using the Billinear transform (Tustin's method).

s = tf('s')
Hc = 1/(m*s^2+c*s+k)   % Tf continuous-time


Observation.: First declare your variables: m, c and k.

Matlab provides some functions that help with the transformation. The function c2d().

Ts = 0.1;
Hd = c2d(Hc,Ts,'tustin')
step(Hc,'--',Hd,'-')


where Ts is the sample time.

• To find the difference equation, apply the inverse Z transform after using tusting method in your equation. Remember that you need to use Laplace transform first!

$\hspace{2.5em}$ $Y(s)\big(ms^{2}+cs+k\big) = \mathcal{L}\{F(t)\}$

• You can find good info about OLS here.