![]() |
MAOS
Multithreaded Adaptive Optics Simulator
|
Data Structures | |
| struct | servo_t |
| struct | sho_t |
| union | servo_t.__unnamed0__ |
| union | servo_t.__unnamed1__ |
Functions | |
| dcell * | servo_optim (real dt, long dtrat, real al, real pmargin, real f0, real zeta, int servo_type, const dmat *psdin, const dmat *sigma2n) |
| real | servo_optim_margin (real dt, long dtrat, real al, real pmargin, real f0, real zeta) |
| dmat * | servo_cl2ol (const dmat *psdcl, real dt, long dtrat, real al, real gain, real sigma2n) |
| real | servo_residual (real *noise_amp, const dmat *psdin, real dt, long dtrat, real al, const dmat *gain, int servo_type) |
| servo_t * | servo_new (anyarray merr, const dmat *ap, real al, real dt, const dmat *ep) |
| servo_t * | servo_new_scalar (anyarray merr, real ap, real al, real dt, real ep) |
| servo_t * | servo_new_sho (anyarray merr, const dmat *ap, real al, real dt, const dmat *ep, real f0, real zeta) |
| int | servo_filter (servo_t *st, const anyarray merr) |
| void | servo_add (servo_t *st, const anyarray madj, real alpha) |
| void | servo_output (const servo_t *st, panyarray out) |
| dmat * | servo_test (dmat *mideal, real dt, int dtrat, dmat *sigma2n, dmat *gain) |
| void | servo_reset (servo_t *st) |
| void | servo_free (servo_t *st) |
| sho_t * | sho_new (real f0, real zeta) |
| void | sho_free (sho_t *sho) |
| void | sho_step (panyarray xout, sho_t *sho, anyarray xi, real dt, int average) |
| void | sho_reset (sho_t *sho) |
| dmat * | sho_filter (const dmat *xi, real dt, real f0, real zeta, int average) |
Routines for servo optimization, filtering, etc.
| struct servo_t |
Struct for servo filtering
| Data Fields | ||
|---|---|---|
| union servo_t.__unnamed0__ | __unnamed__ | |
| union servo_t.__unnamed1__ | __unnamed__ | |
| cell * | mlead |
lead filter temporary storage |
| cell * | merrlast |
recorded errro signal from last step |
| cell * | merrhist |
Keep a short history of merr |
| int | initialized |
is this data initialized |
| int | alint |
Integral part of latency |
| real | alfrac |
Fractional latency |
| dmat * | ap | |
| dmat * | ep | |
| real | dt | |
| sho_t * | sho | |
| struct sho_t |
| union servo_t.__unnamed0__ |
| union servo_t.__unnamed1__ |
| dcell * servo_optim | ( | real | dt, |
| long | dtrat, | ||
| real | al, | ||
| real | pmargin, | ||
| real | f0, | ||
| real | zeta, | ||
| int | servo_type, | ||
| const dmat * | psdin, | ||
| const dmat * | sigma2n ) |
Optimize the servo gains by balancing errors due to noise and signal propagation.
Written: 2010-06-11
Tested OK: 2010-06-11
2011-01-17: The optimization process is quite slow, but the result is only dependent on the sigma2n and fs. psdin does not change during the simulation. Built a lookup table in skyc using various sigma2n and interpolate to get ress, resn, and gain.
2012-03-28: Cleaned up this routine. groupped similar calculations together. Change g2=a from g=sqrt(a)
2013-06-27: The maximum gain should not be limited to 0.5 beause it is later scaled by sqrt(a);
The upper end of frequency must be nyquist freq so that noise transfer can be computed. But we need to capture the turbulence PSD beyond nyquist freq, which are uncorrectable.
2022-03-04: added SHO response parameter.
| [in] | dt | Simulation time step (s). |
| [in] | dtrat | Number of time steps per loop update. |
| [in] | al | Additional latency in units of dt. |
| [in] | pmargin | Phase margin (radian). 0 means pi/4. |
| [in] | f0 | SHO resonance frequency (Hz). Not used if not positive. |
| [in] | zeta | SHO damping ratio. |
| [in] | servo_type | 1 for integrator, 2 for type II with lead filter. |
| [in] | psdin | Input PSD with frequency in the first column. If NULL, only optimize for phase margin. |
| [in] | sigma2n | Array of all wanted noise variance. May be NULL. |
| real servo_optim_margin | ( | real | dt, |
| long | dtrat, | ||
| real | al, | ||
| real | pmargin, | ||
| real | f0, | ||
| real | zeta ) |
Optimize integrator control with optional SHO response (output) to have correct phase margin when abs(Hol)==1.
| [in] | dt | Simulation time step (s). |
| [in] | dtrat | Number of time steps per loop update. |
| [in] | al | Additional latency in units of dt. |
| [in] | pmargin | Phase margin (radian). 0 means pi/4. |
| [in] | f0 | SHO resonance frequency (Hz). Not used if not positive. |
| [in] | zeta | SHO damping ratio. |
Convert Closed loop residual PSD back to OL psd using rejection transfer function: PSD_OL=PSD_CL/Hrej-sigma2n/F_nyquist; Only implemented for integrator.
| [in] | psdcl | Closed loop PSD with frequency in the first column and one or more PSD columns. |
| [in] | dt | Simulation time step (s). |
| [in] | dtrat | Number of time steps per loop update. |
| [in] | al | Additional latency in units of dt. |
| [in] | gain | Integrator gain. If 0, psdcl is copied. |
| [in] | sigma2n | Noise variance. |
| real servo_residual | ( | real * | noise_amp, |
| const dmat * | psdin, | ||
| real | dt, | ||
| long | dtrat, | ||
| real | al, | ||
| const dmat * | gain, | ||
| int | servo_type ) |
Compute the residual error after servo rejection of a type I or type II servo given the gain.
Written: 2010-06-11
Tested OK: 2010-06-11
| [out] | noise_amp | Noise amplification factor. |
| [in] | psdin | Input PSD with frequency in the first column and PSD in the second. |
| [in] | dt | Simulation time step (s). |
| [in] | dtrat | Number of time steps per loop update. |
| [in] | al | Additional latency in units of dt. |
| [in] | gain | Servo gain: [g] for type I or [g, a, T] for type II. |
| [in] | servo_type | 1 for integrator, 2 for type II. |
Initialize servo_t.
| [in] | merr | Template measurement error used to allocate memory. May be empty. |
| [in] | ap | Coefficients of the modified integrator. NULL means a pure integrator. |
| [in] | al | Additional latency in units of dt. |
| [in] | dt | Simulation time step (s), not the loop update time. |
| [in] | ep | Servo gain. May be NULL if gain is applied externally. |
| servo_t * servo_new_scalar | ( | anyarray | merr, |
| real | ap, | ||
| real | al, | ||
| real | dt, | ||
| real | ep ) |
Initialize servo_t with scalar ap and ep
| [in] | merr | Template measurement error used to allocate memory. May be empty. |
| [in] | ap | Coefficient of the modified integrator. |
| [in] | al | Additional latency in units of dt. |
| [in] | dt | Simulation time step (s). |
| [in] | ep | Servo gain. 0 means gain is applied externally. |
| servo_t * servo_new_sho | ( | anyarray | merr, |
| const dmat * | ap, | ||
| real | al, | ||
| real | dt, | ||
| const dmat * | ep, | ||
| real | f0, | ||
| real | zeta ) |
Initialize servo_t with an sho
| [in] | merr | Template measurement error used to allocate memory. May be empty. |
| [in] | ap | Coefficients of the modified integrator. NULL means a pure integrator. |
| [in] | al | Additional latency in units of dt. |
| [in] | dt | Simulation time step (s). |
| [in] | ep | Servo gain. |
| [in] | f0 | SHO resonance frequency (Hz). SHO is not used if not positive or infinite. |
| [in] | zeta | SHO damping ratio. |
| int servo_filter | ( | servo_t * | st, |
| const anyarray | _merr ) |
Applies type I or type II filter based on number of entries in gain.
| [in,out] | st | Servo struct. |
| [in] | _merr | Measurement error. May be empty. |
| void servo_add | ( | servo_t * | st, |
| const anyarray | madj, | ||
| real | alpha ) |
Adjust integrator content without shift.
| [in,out] | st | Servo struct. |
| [in] | madj | Adjustment to add to the integrator. |
| [in] | alpha | Scaling factor of madj. |
| void servo_output | ( | const servo_t * | st, |
| panyarray | out_ ) |
Create servo output. It handles st->alfrac. and outputs the averaged position over the integration period.
| [in] | st | Servo struct. Its SHO state, if any, is updated. |
| [out] | out_ | Output. Allocated if NULL. |
test type I/II filter with ideal measurement to make sure it is implemented correctly.
| [in,out] | input | Input time series. Each column is a time step. Reshaped in place if it has a single column. |
| [in] | dt | Simulation time step (s). |
| [in] | dtrat | Number of time steps per loop update. |
| [in] | sigma2n | Noise covariance. Noise is not added if its norm is 0. |
| [in] | gain | Servo gain. |
| void servo_reset | ( | servo_t * | st | ) |
reset the data to 0.
| [in,out] | st | Servo struct. |
| void servo_free | ( | servo_t * | st | ) |
Free servo_t struct
| [in] | st | Servo struct to free. May be NULL. |
| sho_t * sho_new | ( | real | f0, |
| real | zeta ) |
Second harmonic oscillator. Initialization. Equation is is d^x/dt^2+c1*dx/dt+c2*x=c2*xi State space model is |x'|' | -c1 -c2 | |x'| |xi| |x | = | 1 0 | | x| + c2 |0 | where x' is dx/dt and written as dx in struct. we use c2*xi so that it is in the same unit and scale as x.
| [in] | f0 | Resonance frequency (Hz). |
| [in] | zeta | Damping ratio. |
| void sho_free | ( | sho_t * | sho | ) |
Free sho_t (second order harmonic oscillator).
| [in] | sho | SHO struct to free. May be NULL. |
| void sho_step | ( | panyarray | xout_, |
| sho_t * | sho, | ||
| anyarray | xi_, | ||
| real | dt, | ||
| int | avg ) |
Second harmonic oscillator state space update. xi is driving position. Second harmonic oscillator state space update. xi is driving position. Update the position after time dt. Also compute the average position between 0 and dt (for WFS integration) if avg is set.
sho->x +=dt*sho->dx;//update position ddx=sho->dx*(-sho->c1)+sho->x*(-sho->c2)+xi;//update speed sho->dx+=dt*ddx; //update speed
| [out] | xout_ | Output position (or average position if avg is set). Allocated if NULL. |
| [in,out] | sho | SHO state. If NULL, xi is copied to xout_. |
| [in] | xi_ | Driving position. |
| [in] | dt | Time to advance (s). |
| [in] | avg | Whether to output the average position over dt instead of the final position. |
| void sho_reset | ( | sho_t * | sho | ) |
Second harmonic oscillator. Reset.
| [in,out] | sho | SHO state. |
Second harmonic oscillator. Filter a time series for testing.
| [in] | x | Input time series. Each column is filtered independently. A row vector is treated as a column. |
| [in] | dt | Input time series sampling (s). |
| [in] | f0 | Resonance frequency (Hz). |
| [in] | zeta | Damping ratio. |
| [in] | avg | Average or not. |