/* * Atpdec * Copyright (c) 2003 by Thierry Leconte (F4DWV) * * $Id$ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include #include #include #define Fe 11025 #define PixelLine 2080 #define Fp (2*PixelLine) #define RSMULT 10 #define Fi (Fp*RSMULT) static double FreqOsc=2400.0/Fe; static double FreqLine=1.0; extern int getsample(float *inbuff ,int nb); static float pll(float In) { /* pll coeff */ #define K1 5e-3 #define K2 3e-6 static double PhaseOsc=0.0; static iirbuff_t Ifilterbuff,Qfilterbuff; double Io,Qo; double Ip,Qp; double DPhi; double DF; /* quadrature oscillator */ Io=cos(PhaseOsc); Qo=sin(PhaseOsc); /* phase detector */ Ip=iir(In*Io,&Ifilterbuff,&PhaseFilterCf); Qp=iir(In*Qo,&Qfilterbuff,&PhaseFilterCf); DPhi=-atan2(Qp,Ip)/M_PI; /* loop filter */ DF=K1*DPhi+FreqOsc; FreqOsc+=K2*DPhi; PhaseOsc+=2.0*M_PI*DF; if (PhaseOsc > M_PI) PhaseOsc-=2.0*M_PI; if (PhaseOsc <= -M_PI) PhaseOsc+=2.0*M_PI; return (float)(In*Io); } static double fr=2400.0/Fe; static double offset=0.0; getamp(float *ambuff,int nb) { #define BLKIN 1024 float inbuff[BLKIN]; int n; int res; res=getsample(inbuff,nb>BLKIN?BLKIN:nb); for(n=0;n0) memmove(pixelv,pixels,npv*sizeof(float)); if(npvmax) { mshift=shift; max=corr; } } if(mshift !=0) { memmove(pixelv,&(pixelv[mshift]),(npv-mshift)*sizeof(float)); npv-=mshift; synced=0; FreqLine=1.0; } else synced+=1; } if(npv