Estimate the frequency of a drifting oscillator from noisy gated measurements.
More...
Estimate the frequency of a drifting oscillator from noisy gated measurements.
A scalar Kalman filter on the frequency: the state random walks with density rw and each measurement, a gate of T seconds, reads it with white frequency noise wfm / sqrt(T) plus wander, the short-term fluctuation that a gate samples at one instant. All three are fractional, measured for the oscillator at hand. A measurement further than reject_sigma standard deviations from the prediction is dropped, at most max_rejects in a row; then the filter restarts from the next one.
.
wfm = 7.2e-6, .wander = 8e-6, .rw = 1.1e-6, .reject_sigma = 5.0, .max_rejects = 3,
};
uint64_t pbl_uptime_ms(void)
Get the time since the scheduler started, in milliseconds.
double wfm
White frequency noise, fractional times square root of seconds.
Definition freq_track.h:36
Tracker state.
Definition freq_track.h:48
Noise model of an oscillator and its measurements.
Definition freq_track.h:34
int pbl_freq_track_update(struct pbl_freq_track *ft, double hz, double gate_s, uint64_t t_ms)
Feed a measurement.
void pbl_freq_track_init(struct pbl_freq_track *ft, const struct pbl_freq_track_params *params)
Initialize a tracker with no estimate.
double pbl_freq_track_get(const struct pbl_freq_track *ft)
Get the estimate.
◆ pbl_freq_track_params
| struct pbl_freq_track_params |
Noise model of an oscillator and its measurements.
| Data Fields |
|
uint8_t |
max_rejects |
Consecutive rejections before restarting. |
|
double |
reject_sigma |
Rejection threshold, in standard deviations of the innovation. |
|
double |
rw |
Frequency random walk density, fractional per square root of seconds. |
|
double |
wander |
Short-term wander a gate samples at one instant, fractional. |
|
double |
wfm |
White frequency noise, fractional times square root of seconds. |
◆ pbl_freq_track
◆ pbl_freq_track_get()
Get the estimate.
- Parameters
-
- Returns
- Frequency, or 0 before the first measurement or seed.
◆ pbl_freq_track_get_dev()
Get the standard deviation of the estimate.
- Parameters
-
- Returns
- Fractional standard deviation, or 0 before the first measurement or seed.
◆ pbl_freq_track_init()
Initialize a tracker with no estimate.
- Parameters
-
| ft | Tracker. |
| params | Noise model; must stay valid. |
◆ pbl_freq_track_seed()
| void pbl_freq_track_seed |
( |
struct pbl_freq_track * |
ft, |
|
|
double |
hz, |
|
|
double |
gate_s, |
|
|
uint64_t |
t_ms |
|
) |
| |
Start from a known frequency, e.g.
one kept across a reset.
- Parameters
-
| ft | Tracker. |
| hz | Frequency. |
| gate_s | Gate length the frequency is as good as, in seconds. |
| t_ms | Current time, in milliseconds. |
◆ pbl_freq_track_update()
| int pbl_freq_track_update |
( |
struct pbl_freq_track * |
ft, |
|
|
double |
hz, |
|
|
double |
gate_s, |
|
|
uint64_t |
t_ms |
|
) |
| |
Feed a measurement.
- Parameters
-
| ft | Tracker. |
| hz | Measured frequency. |
| gate_s | Gate length, in seconds. |
| t_ms | Time of the measurement, in milliseconds, not before the previous one. |
- Returns
- 0 if used,
-ERANGE if rejected.