The Schwartz-Smith 2-factor model decomposes the log spot price of a commodity into two components: 
- Long-term equilibrium level (non-stationary, modelled as Brownian motion with drift) 
 - Short-term deviations (mean-reverting component) 
 
The original code uses a custom Kalman filter for parameter estimation and filtering. To adapt this into MATLAB's SSM (State-Space Model) framework, the model needs to be expressed in the standard linear Gaussian state-space form: 
SSM Formulation Overview 
State Equation: 
Let the state vector be: 
xt=[χt 
      ξt] 
- χt : long-term (non-stationary) 
 - ξt: short-term (mean-reverting) 
 
The dynamics are: 
χt+1=χt+μ+ηt 
ξt+1=χt+μ+ηt=ϕξt+ϵt  
 where ηt∼N(0,ση2) and ϵt∼N(0,σϵ2) 
Observation Equation: 
yt=χt+ξt+εt , εt∼N(0,σε2) 
Please refer the MATLAB pseudo-code for the same: 
A = @(params) [1 0; 0 params(2)];       
D = @(params) eye(2) .* [params(3); params(4)];  
    @(params) deal(A(params), B(params) * params(1), C(params), E(params), D(params) * D(params)')); 
param0 = [0.1, 0.9, 0.1, 0.1, 0.1]; 
[estModel, estParams, estSE] = estimate(ssmModel, logPrices, param0); 
Please refer these MATLAB documentations for more details: 
Hope this is beneficial!