mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-07-29 15:59:14 +02:00
experiment with the pll
This commit is contained in:
+5
-2
@@ -20,17 +20,18 @@ void init_pll(PLL *pll, float freq, float loop_filter_bandwidth, int quadrature_
|
||||
pll->loop_filter_state = 0.0f;
|
||||
pll->kp = M_2PI * loop_filter_bandwidth;
|
||||
pll->ki = 0.25f * pll->kp * pll->kp;
|
||||
pll->last_output = 0.0f;
|
||||
pll->sample_rate = sample_rate;
|
||||
pll->quadrature_mode = quadrature_mode;
|
||||
}
|
||||
|
||||
float apply_pll(PLL *pll, float ref_sample, float input_sample) {
|
||||
float apply_pll(PLL *pll, float ref_sample) {
|
||||
float phase_error;
|
||||
|
||||
float vco_output = sinf(pll->phase);
|
||||
if (pll->quadrature_mode) vco_output = sinf(pll->phase + (M_PI / 2.0f)); // 90 degrees
|
||||
|
||||
phase_error = ref_sample * input_sample;
|
||||
phase_error = ref_sample * pll->last_output;
|
||||
|
||||
pll->loop_filter_state += pll->ki * phase_error / pll->sample_rate;
|
||||
float loop_output = pll->loop_filter_state + pll->kp * phase_error;
|
||||
@@ -47,5 +48,7 @@ float apply_pll(PLL *pll, float ref_sample, float input_sample) {
|
||||
pll->phase += M_2PI;
|
||||
}
|
||||
|
||||
pll->last_output = vco_output;
|
||||
|
||||
return vco_output;
|
||||
}
|
||||
+2
-1
@@ -22,8 +22,9 @@ typedef struct {
|
||||
float loop_filter_state;
|
||||
float kp;
|
||||
float ki;
|
||||
float last_output;
|
||||
int sample_rate;
|
||||
int quadrature_mode;
|
||||
} PLL;
|
||||
void init_pll(PLL *pll, float freq, float loop_filter_bandwidth, int quadrature_mode, int sample_rate);
|
||||
float apply_pll(PLL *pll, float ref_sample, float input_sample);
|
||||
float apply_pll(PLL *pll, float ref_sample);
|
||||
Reference in New Issue
Block a user