Fixed 1st order loop filter

This commit is contained in:
ha7ilm 2016-05-10 22:59:14 +02:00
parent 33a8cf0482
commit c0b4706592
3 changed files with 14 additions and 10 deletions

6
csdr.c
View file

@ -1986,11 +1986,11 @@ int main(int argc, char *argv[])
{
FEOF_CHECK;
FREAD_C;
//pll_cc(&pll, (complexf*)input_buffer, NULL, (complexf*)output_buffer, the_bufsize);
fprintf(stderr, "| i");
fprintf(stderr, "| ai");
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(float), the_bufsize, stdout);
// 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;
}

View file

@ -1363,17 +1363,17 @@ void pll_cc_init_1st_order_IIR(pll_t* p, float alpha)
}
void pll_cc(pll_t* p, complexf* input, float* output_dphase, complexf* output_vco, int input_size)
void pll_cc(pll_t* p, complexf* input, float* output_dphase, complexf* output_nco, int input_size)
{
for(int i=0;i<input_size;i++)
{
p->output_phase += p->dphase;
while(p->output_phase>PI) p->output_phase-=2*PI;
while(p->output_phase<-PI) p->output_phase+=2*PI;
if(output_vco) //we don't output anything if it is a NULL pointer
if(output_nco) //we don't output anything if it is a NULL pointer
{
iof(output_vco,i) = sin(p->output_phase);
qof(output_vco,i) = cos(p->output_phase);
iof(output_nco,i) = sin(p->output_phase);
qof(output_nco,i) = cos(p->output_phase);
}
//ket komplex szam szorzataval inkabb
@ -1397,15 +1397,19 @@ void pll_cc(pll_t* p, complexf* input, float* output_dphase, complexf* output_vc
p->last_filter_outputs[1]=p->dphase;
p->last_filter_inputs[0]=p->last_filter_inputs[1];
p->last_filter_inputs[1]=new_dphase;
//static float lasttemp;
//lasttemp = p->beta *
//p->dphase = new_dphase * p->alpha;
while(p->dphase>PI) p->dphase-=2*PI; //ez nem fog kelleni
while(p->dphase<-PI) p->dphase+=2*PI;
}
else if(p->pll_type == PLL_1ST_ORDER_IIR_LOOP_FILTER)
{
p->dphase = /*p->dphase * (1-p->alpha) +*/ new_dphase * p->alpha;
p->dphase = new_dphase * p->alpha;
}
else return;
if(output_dphase) output_dphase[i] = -p->dphase/10;
if(output_dphase) output_dphase[i] = -p->dphase;
// if(output_dphase) output_dphase[i] = new_dphase/10;
}
}

View file

@ -262,4 +262,4 @@ typedef struct pll_s
void pll_cc_init_2nd_order_IIR(pll_t* p, float bandwidth, float gain, float dampling_factor);
void pll_cc_init_1st_order_IIR(pll_t* p, float alpha);
void pll_cc(pll_t* p, complexf* input, float* output_dphase, complexf* output_vco, int input_size);
void pll_cc(pll_t* p, complexf* input, float* output_dphase, complexf* output_nco, int input_size);