MAOS
Multithreaded Adaptive Optics Simulator
kalman.h File Reference

Data Structures

struct  kalman_t
 

Functions

real sde_fit (dmat **pcoeff, const dmat *psdin, real tmax_fit, int vibid)
 
real sde_fit_auto (dmat **pcoeff, const_anyarray psdin, real tfit)
 Fit PSD to SHO by maximum the damping ratio while keeping it less than. More...
 
void sde_psd (dmat **psd, const dmat *f, const real *coeff, int ncoeff, int nmod)
 
dmatsde_psd2 (const dmat *ff, const dmat *coeff)
 
real reccati (dmat **Kinf, dmat **Pout, const dmat *A, const dmat *Qn, const dmat *C, const dmat *Rn)
 Compute the reccati equation. When noise (Rn) is too large, the iteration will fail to converge. More...
 
kalman_tsde_kalman (const dmat *coeff, const real dthi, const lmat *dtrat_wfs, const lmat *mdirect, const dcell *Gwfs, const dcell *Cnn, const dmat *Proj)
 Kalman filter based on SDE model. More...
 
void kalman_free (kalman_t *kalman)
 
dmatkalman_test (kalman_t *kalman, const dcell *goff, const dmat *input, int flag)
 
dmatkalman_test2 (const dmat *coeff, const real dthi, const lmat *dtrat, const lmat *mdirect, const dcell *Gwfs, const dcell *Cnn, const dmat *Proj, const dcell *goff, const dmat *input, int flag)
 
dmatkalman_test3 (const dmat *input, int flag, const char *fn)
 
void kalman_init (kalman_t *kalman)
 
void kalman_update (kalman_t *kalman, dcell *meas, int idtrat)
 
void kalman_output (kalman_t *kalman, dmat **out, real alpha, real beta, int idtrat)
 
void kalman_write (kalman_t *kalman, const char *format,...)
 
kalman_tkalman_read (const char *format,...)
 

Data Structure Documentation

◆ kalman_t

struct kalman_t
+ Collaboration diagram for kalman_t:
Data Fields
dmat * AdM

discrete state propagation at dthi

dmat * BM

From discrete state to averaged mode for dthi

lmat * dtrat_wfs

WFS sampling period over dthi

lmat * dtrats

uniq dtrats

lmat * mdirect

Modes that are directly controlled by the slow loop

dcell * Ad

discrete state propagation at dT

dcell * Cd

From discrete state to WFS measurement

dcell * Gwfs

WFS measurement from modes. Can be identity.

dcell * Cnn

WFS measurement noise covariance due to photon and RoN.

dcell * Rn

Total WFS measurement error due to signal evolution and Rwfs.

dcell * M

M is innovation gain.

dcell * P

Sigma_infty: Error covariance matrix

dccell * Rlsq

least squares reconstructor

real dthi

Sampling period of control loop

dcell * xhat

stores x_k+1|k

dcell * xhat2

stores x_k+(1+j)/M|k

dmat * xhat3

temporary

dcell * xout

output

dcell * psol

current correction for psol

Function Documentation

◆ sde_fit()

real sde_fit ( dmat **  pcoeff,
const dmat psdin,
real  tmax_fit,
int  vibid 
)

Estiamte the total PSD power for vibration peaks using FWHM*peak If coeff0 is not null, use it immediately, otherwise, do vibration identification

◆ sde_fit_auto()

real sde_fit_auto ( dmat **  pcoeff,
const_anyarray  psdin_,
real  tfit 
)

Fit PSD to SHO by maximum the damping ratio while keeping it less than.

  1. Does not support vibration identification which have different damping characteristics.
    Parameters
    [in,out]pcoeffReturn the SHO coefficients
    psdin_The input PSD
    tfitFor covariance fitting, time span.
    Returns
    real Fitting quality

◆ sde_psd()

void sde_psd ( dmat **  psd,
const dmat f,
const real *  coeff,
int  ncoeff,
int  nmod 
)

Computes PSD of SDE with coefficients (coeff) and frequency (f)

◆ sde_psd2()

dmat* sde_psd2 ( const dmat ff,
const dmat coeff 
)

A convenient wrapper for sde_psd()

◆ reccati()

real reccati ( dmat **  Kinf,
dmat **  Pout,
const dmat A,
const dmat Qn,
const dmat C,
const dmat Rn 
)

Compute the reccati equation. When noise (Rn) is too large, the iteration will fail to converge.

Parameters
Kinf[Out] Asymptotic Kalman gain \(K_\infty\)
Pout[Out] The Sigma_infty: Estimation error covariance matrix
ABlock diagonal stage evolution matrix
QnDiscrete state noise covariance
CMeasurement interaction matrix
RnMeasurement error covariance matrix
Returns
diff Converegence indicator

◆ sde_kalman()

kalman_t* sde_kalman ( const dmat coeff,
const real  dthi,
const lmat dtrat_wfs,
const lmat mdirect,
const dcell Gwfs,
const dcell Cnn,
const dmat Proj 
)

Kalman filter based on SDE model.

Parameters
coeffSDE coefficients
dthiHigh order loop frequency
dtrat_wfsWFS dtrat over high order loop. Each wfs may have a different rate. Only 1 or 2 rates are supported
mdirectMode indices that are directly controlled by the slower loop.
GwfsWFS measurement from modes. Can be identity if reconstructor is already applied.
CnnWFS measurement noise covariance in radian^2. nwfs*ndtrat.
ProjProject modes in statespace to DM/correction space. Can be identity or NULL.
Returns
kalman_t*

◆ kalman_free()

void kalman_free ( kalman_t kalman)

free the struct

◆ kalman_test()

dmat* kalman_test ( kalman_t kalman,
const dcell goff,
const dmat input,
int  flag 
)

Test the performance of kalman filter (LQG controller). Derived from servo_test() Gwfs2 is a different gradient interaction matrix to model the aliasing in system flag controlls the servo type: 0: both LQG 1: both integrator 2: LQG (fast) + integrator (slow)

◆ kalman_test2()

dmat* kalman_test2 ( const dmat coeff,
const real  dthi,
const lmat dtrat,
const lmat mdirect,
const dcell Gwfs,
const dcell Cnn,
const dmat Proj,
const dcell goff,
const dmat input,
int  flag 
)
Parameters
coeffSDE coefficients
dthiLoop frequency
dtratWFS frequency as a fraction of loop
mdirectmask for modes directly controlled by slower loop
GwfsWFS measurement from modes. Can be identity
CnnWFS measurement noise covariance in radian^2
ProjKalman Projection matrix
goffGradient measurement offset (fast loop)
inputTime series
flagflag controlls the servo type: 0: both LQG 1: both integrator 2: LQG (fast) + integrator (slow)

◆ kalman_init()

void kalman_init ( kalman_t kalman)

Initialize kalman filter state

◆ kalman_update()

void kalman_update ( kalman_t kalman,
dcell meas,
int  idtrat 
)

Update state vector when there is a measurement. It modifies meas.

xhat3=xhat+M*(meas-Cd*xhat) //xhat is x_k|k-1. xhat3 is x_k|k xhat =Ad*xhat3; //xhat is now x_k+1|k xhat2=AdM*xhat3; //xhat2 is x_k+1/M|k

◆ kalman_output()

void kalman_output ( kalman_t kalman,
dmat **  out,
real  alpha,
real  beta,
int  idtrat 
)

Output correction xhat2=AdM*xhat2 //evolve correction forward out=out*alpha+(BM*xhat2-psol)*beta

◆ kalman_write()

void kalman_write ( kalman_t kalman,
const char *  format,
  ... 
)

Save kalman_t to file