From 4ecc84eefd3816380b70b190ead86daa6d3bdf50 Mon Sep 17 00:00:00 2001 From: ha7ilm Date: Mon, 9 May 2016 13:58:45 +0200 Subject: [PATCH] Got PLL working with the 1st order IIR loop filter. --- csdr.c | 7 +++++-- libcsdr.c | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/csdr.c b/csdr.c index 17d5b64..bde553e 100644 --- a/csdr.c +++ b/csdr.c @@ -1987,8 +1987,11 @@ int main(int argc, char *argv[]) FEOF_CHECK; FREAD_C; //pll_cc(&pll, (complexf*)input_buffer, NULL, (complexf*)output_buffer, the_bufsize); - pll_cc(&pll, (complexf*)input_buffer, output_buffer, NULL, the_bufsize); - fwrite(output_buffer, sizeof(float), the_bufsize, stdout); + //fprintf(stderr, "| i"); + //pll_cc(&pll, (complexf*)input_buffer, output_buffer, NULL, the_bufsize); + pll_cc(&pll, (complexf*)input_buffer, NULL, (complexf*)output_buffer, the_bufsize); + fwrite(output_buffer, sizeof(complexf), the_bufsize, stdout); + //fprintf(stderr, "| o"); TRY_YIELD; } } diff --git a/libcsdr.c b/libcsdr.c index 2bfbd93..4406e67 100644 --- a/libcsdr.c +++ b/libcsdr.c @@ -1372,7 +1372,8 @@ void pll_cc(pll_t* p, complexf* input, float* output_dphase, complexf* output_vc float input_phase = atan2(iof(input,i),qof(input,i)); float new_dphase = input_phase - p->output_phase; //arg(input[i]/abs(input[i]) * conj(current_output_vco[i])) - + while(new_dphase>PI) new_dphase-=2*PI; + while(new_dphase<-PI) new_dphase+=2*PI; if(p->pll_type == PLL_2ND_ORDER_IIR_LOOP_FILTER) { @@ -1395,6 +1396,7 @@ void pll_cc(pll_t* p, complexf* input, float* output_dphase, complexf* output_vc } else return; if(output_dphase) output_dphase[i] = p->dphase; + //if(output_dphase) output_dphase[i] = new_dphase/3.15; } }