mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2025-05-24 10:22:26 -04:00
Rename wsprd_exp.c to wsprd.c and eliminate wsprd_exp.c.
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6572 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
bf5195414a
commit
0574251ff0
@ -470,6 +470,7 @@ set (wsprd_CSRCS
|
|||||||
lib/wsprd/wsprsim_utils.c
|
lib/wsprd/wsprsim_utils.c
|
||||||
lib/wsprd/wsprd_utils.c
|
lib/wsprd/wsprd_utils.c
|
||||||
lib/wsprd/fano.c
|
lib/wsprd/fano.c
|
||||||
|
lib/wsprd/jelinek.c
|
||||||
lib/wsprd/tab.c
|
lib/wsprd/tab.c
|
||||||
lib/wsprd/nhash.c
|
lib/wsprd/nhash.c
|
||||||
lib/init_random_seed.c
|
lib/init_random_seed.c
|
||||||
@ -775,7 +776,7 @@ endif ()
|
|||||||
find_package (OpenMP)
|
find_package (OpenMP)
|
||||||
|
|
||||||
#
|
#
|
||||||
# fftw3 single precsion library
|
# fftw3 single precision library
|
||||||
#
|
#
|
||||||
find_package (FFTW3 COMPONENTS double single threads REQUIRED)
|
find_package (FFTW3 COMPONENTS double single threads REQUIRED)
|
||||||
|
|
||||||
|
@ -37,16 +37,16 @@
|
|||||||
#include <fftw3.h>
|
#include <fftw3.h>
|
||||||
|
|
||||||
#include "fano.h"
|
#include "fano.h"
|
||||||
|
#include "jelinek.h"
|
||||||
#include "nhash.h"
|
#include "nhash.h"
|
||||||
#include "wsprd_utils.h"
|
#include "wsprd_utils.h"
|
||||||
#include "wsprsim_utils.h"
|
#include "wsprsim_utils.h"
|
||||||
//#include "lib/init_random_seed.h"
|
|
||||||
|
|
||||||
#define max(x,y) ((x) > (y) ? (x) : (y))
|
#define max(x,y) ((x) > (y) ? (x) : (y))
|
||||||
// Possible PATIENCE options: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT,
|
// Possible PATIENCE options: FFTW_ESTIMATE, FFTW_ESTIMATE_PATIENT,
|
||||||
// FFTW_MEASURE, FFTW_PATIENT, FFTW_EXHAUSTIVE
|
// FFTW_MEASURE, FFTW_PATIENT, FFTW_EXHAUSTIVE
|
||||||
#define PATIENCE FFTW_ESTIMATE
|
#define PATIENCE FFTW_ESTIMATE
|
||||||
fftw_plan PLAN1,PLAN2,PLAN3;
|
fftwf_plan PLAN1,PLAN2,PLAN3;
|
||||||
|
|
||||||
unsigned char pr3[162]=
|
unsigned char pr3[162]=
|
||||||
{1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0,
|
{1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0,
|
||||||
@ -64,15 +64,18 @@ unsigned long nr;
|
|||||||
int printdata=0;
|
int printdata=0;
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
unsigned long readc2file(char *ptr_to_infile, double *idat, double *qdat,
|
unsigned long readc2file(char *ptr_to_infile, float *idat, float *qdat,
|
||||||
double *freq, int *wspr_type)
|
double *freq, int *wspr_type)
|
||||||
{
|
{
|
||||||
float buffer[2*65536];
|
float *buffer;
|
||||||
double dfreq;
|
double dfreq;
|
||||||
int i,ntrmin;
|
int i,ntrmin;
|
||||||
char *c2file[15];
|
char *c2file[15];
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
|
|
||||||
|
buffer=malloc(sizeof(float)*2*65536);
|
||||||
|
memset(buffer,0,sizeof(float)*2*65536);
|
||||||
|
|
||||||
fp = fopen(ptr_to_infile,"rb");
|
fp = fopen(ptr_to_infile,"rb");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile);
|
fprintf(stderr, "Cannot open data file '%s'\n", ptr_to_infile);
|
||||||
@ -96,12 +99,13 @@ unsigned long readc2file(char *ptr_to_infile, double *idat, double *qdat,
|
|||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
free(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
unsigned long readwavfile(char *ptr_to_infile, int ntrmin, double *idat, double *qdat )
|
unsigned long readwavfile(char *ptr_to_infile, int ntrmin, float *idat, float *qdat )
|
||||||
{
|
{
|
||||||
int i, j, npoints;
|
unsigned long i, j, npoints;
|
||||||
int nfft1, nfft2, nh2, i0;
|
int nfft1, nfft2, nh2, i0;
|
||||||
double df;
|
double df;
|
||||||
|
|
||||||
@ -123,8 +127,8 @@ unsigned long readwavfile(char *ptr_to_infile, int ntrmin, double *idat, double
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
double *realin;
|
float *realin;
|
||||||
fftw_complex *fftin, *fftout;
|
fftwf_complex *fftin, *fftout;
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
short int *buf2;
|
short int *buf2;
|
||||||
@ -139,9 +143,9 @@ unsigned long readwavfile(char *ptr_to_infile, int ntrmin, double *idat, double
|
|||||||
nr=fread(buf2,2,npoints,fp); //Read raw data
|
nr=fread(buf2,2,npoints,fp); //Read raw data
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
realin=(double*) fftw_malloc(sizeof(double)*nfft1);
|
realin=(float*) fftwf_malloc(sizeof(float)*nfft1);
|
||||||
fftout=(fftw_complex*) fftw_malloc(sizeof(fftw_complex)*nfft1);
|
fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*nfft1);
|
||||||
PLAN1 = fftw_plan_dft_r2c_1d(nfft1, realin, fftout, PATIENCE);
|
PLAN1 = fftwf_plan_dft_r2c_1d(nfft1, realin, fftout, PATIENCE);
|
||||||
|
|
||||||
for (i=0; i<npoints; i++) {
|
for (i=0; i<npoints; i++) {
|
||||||
realin[i]=buf2[i]/32768.0;
|
realin[i]=buf2[i]/32768.0;
|
||||||
@ -152,10 +156,10 @@ unsigned long readwavfile(char *ptr_to_infile, int ntrmin, double *idat, double
|
|||||||
}
|
}
|
||||||
|
|
||||||
free(buf2);
|
free(buf2);
|
||||||
fftw_execute(PLAN1);
|
fftwf_execute(PLAN1);
|
||||||
fftw_free(realin);
|
fftwf_free(realin);
|
||||||
|
|
||||||
fftin=(fftw_complex*) fftw_malloc(sizeof(fftw_complex)*nfft2);
|
fftin=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*nfft2);
|
||||||
|
|
||||||
for (i=0; i<nfft2; i++) {
|
for (i=0; i<nfft2; i++) {
|
||||||
j=i0+i;
|
j=i0+i;
|
||||||
@ -164,24 +168,24 @@ unsigned long readwavfile(char *ptr_to_infile, int ntrmin, double *idat, double
|
|||||||
fftin[i][1]=fftout[j][1];
|
fftin[i][1]=fftout[j][1];
|
||||||
}
|
}
|
||||||
|
|
||||||
fftw_free(fftout);
|
fftwf_free(fftout);
|
||||||
fftout=(fftw_complex*) fftw_malloc(sizeof(fftw_complex)*nfft2);
|
fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*nfft2);
|
||||||
PLAN2 = fftw_plan_dft_1d(nfft2, fftin, fftout, FFTW_BACKWARD, PATIENCE);
|
PLAN2 = fftwf_plan_dft_1d(nfft2, fftin, fftout, FFTW_BACKWARD, PATIENCE);
|
||||||
fftw_execute(PLAN2);
|
fftwf_execute(PLAN2);
|
||||||
|
|
||||||
for (i=0; i<nfft2; i++) {
|
for (i=0; i<nfft2; i++) {
|
||||||
idat[i]=fftout[i][0]/1000.0;
|
idat[i]=fftout[i][0]/1000.0;
|
||||||
qdat[i]=fftout[i][1]/1000.0;
|
qdat[i]=fftout[i][1]/1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fftw_free(fftin);
|
fftwf_free(fftin);
|
||||||
fftw_free(fftout);
|
fftwf_free(fftout);
|
||||||
return nfft2;
|
return nfft2;
|
||||||
}
|
}
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
void sync_and_demodulate(double *id, double *qd, long np,
|
void sync_and_demodulate(float *id, float *qd, long np,
|
||||||
unsigned char *symbols, float *f1, float fstep,
|
unsigned char *symbols, float *f1, int ifmin, int ifmax, float fstep,
|
||||||
int *shift1, int lagmin, int lagmax, int lagstep,
|
int *shift1, int lagmin, int lagmax, int lagstep,
|
||||||
float *drift1, int symfac, float *sync, int mode)
|
float *drift1, int symfac, float *sync, int mode)
|
||||||
{
|
{
|
||||||
@ -192,24 +196,23 @@ void sync_and_demodulate(double *id, double *qd, long np,
|
|||||||
* symbols using passed frequency and shift. *
|
* symbols using passed frequency and shift. *
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
float dt=1.0/375.0, df=375.0/256.0, fbest=0.0;
|
|
||||||
int i, j, k;
|
|
||||||
double pi=4.*atan(1.0),twopidt;
|
|
||||||
float f0=0.0,fp,ss;
|
|
||||||
int lag;
|
|
||||||
static float fplast=-10000.0;
|
static float fplast=-10000.0;
|
||||||
double i0[162],q0[162],i1[162],q1[162],i2[162],q2[162],i3[162],q3[162];
|
static float dt=1.0/375.0, df=375.0/256.0;
|
||||||
double p0,p1,p2,p3,cmet,totp,syncmax,fac;
|
static float pi=3.14159265358979323846;
|
||||||
double c0[256],s0[256],c1[256],s1[256],c2[256],s2[256],c3[256],s3[256];
|
float twopidt, df15=df*1.5, df05=df*0.5;
|
||||||
double dphi0, cdphi0, sdphi0, dphi1, cdphi1, sdphi1, dphi2, cdphi2, sdphi2,
|
|
||||||
|
int i, j, k, lag;
|
||||||
|
float i0[162],q0[162],i1[162],q1[162],i2[162],q2[162],i3[162],q3[162];
|
||||||
|
float p0,p1,p2,p3,cmet,totp,syncmax,fac;
|
||||||
|
float c0[256],s0[256],c1[256],s1[256],c2[256],s2[256],c3[256],s3[256];
|
||||||
|
float dphi0, cdphi0, sdphi0, dphi1, cdphi1, sdphi1, dphi2, cdphi2, sdphi2,
|
||||||
dphi3, cdphi3, sdphi3;
|
dphi3, cdphi3, sdphi3;
|
||||||
float fsum=0.0, f2sum=0.0, fsymb[162];
|
float f0=0.0, fp, ss, fbest=0.0, fsum=0.0, f2sum=0.0, fsymb[162];
|
||||||
int best_shift = 0, ifreq;
|
int best_shift = 0, ifreq;
|
||||||
int ifmin=0, ifmax=0;
|
|
||||||
|
|
||||||
syncmax=-1e30;
|
syncmax=-1e30;
|
||||||
if( mode == 0 ) {ifmin=0; ifmax=0; fstep=0.0; f0=*f1;}
|
if( mode == 0 ) {ifmin=0; ifmax=0; fstep=0.0; f0=*f1;}
|
||||||
if( mode == 1 ) {lagmin=*shift1;lagmax=*shift1;ifmin=-5;ifmax=5;f0=*f1;}
|
if( mode == 1 ) {lagmin=*shift1;lagmax=*shift1;f0=*f1;}
|
||||||
if( mode == 2 ) {lagmin=*shift1;lagmax=*shift1;ifmin=0;ifmax=0;f0=*f1;}
|
if( mode == 2 ) {lagmin=*shift1;lagmax=*shift1;ifmin=0;ifmax=0;f0=*f1;}
|
||||||
|
|
||||||
twopidt=2*pi*dt;
|
twopidt=2*pi*dt;
|
||||||
@ -219,21 +222,21 @@ void sync_and_demodulate(double *id, double *qd, long np,
|
|||||||
ss=0.0;
|
ss=0.0;
|
||||||
totp=0.0;
|
totp=0.0;
|
||||||
for (i=0; i<162; i++) {
|
for (i=0; i<162; i++) {
|
||||||
fp = f0 + ((float)*drift1/2.0)*((float)i-81.0)/81.0;
|
fp = f0 + (*drift1/2.0)*((float)i-81.0)/81.0;
|
||||||
if( i==0 || (fp != fplast) ) { // only calculate sin/cos if necessary
|
if( i==0 || (fp != fplast) ) { // only calculate sin/cos if necessary
|
||||||
dphi0=twopidt*(fp-1.5*df);
|
dphi0=twopidt*(fp-df15);
|
||||||
cdphi0=cos(dphi0);
|
cdphi0=cos(dphi0);
|
||||||
sdphi0=sin(dphi0);
|
sdphi0=sin(dphi0);
|
||||||
|
|
||||||
dphi1=twopidt*(fp-0.5*df);
|
dphi1=twopidt*(fp-df05);
|
||||||
cdphi1=cos(dphi1);
|
cdphi1=cos(dphi1);
|
||||||
sdphi1=sin(dphi1);
|
sdphi1=sin(dphi1);
|
||||||
|
|
||||||
dphi2=twopidt*(fp+0.5*df);
|
dphi2=twopidt*(fp+df05);
|
||||||
cdphi2=cos(dphi2);
|
cdphi2=cos(dphi2);
|
||||||
sdphi2=sin(dphi2);
|
sdphi2=sin(dphi2);
|
||||||
|
|
||||||
dphi3=twopidt*(fp+1.5*df);
|
dphi3=twopidt*(fp+df15);
|
||||||
cdphi3=cos(dphi3);
|
cdphi3=cos(dphi3);
|
||||||
sdphi3=sin(dphi3);
|
sdphi3=sin(dphi3);
|
||||||
|
|
||||||
@ -262,7 +265,7 @@ void sync_and_demodulate(double *id, double *qd, long np,
|
|||||||
|
|
||||||
for (j=0; j<256; j++) {
|
for (j=0; j<256; j++) {
|
||||||
k=lag+i*256+j;
|
k=lag+i*256+j;
|
||||||
if( (k>0) & (k<np) ) {
|
if( (k>0) && (k<np) ) {
|
||||||
i0[i]=i0[i] + id[k]*c0[j] + qd[k]*s0[j];
|
i0[i]=i0[i] + id[k]*c0[j] + qd[k]*s0[j];
|
||||||
q0[i]=q0[i] - id[k]*s0[j] + qd[k]*c0[j];
|
q0[i]=q0[i] - id[k]*s0[j] + qd[k]*c0[j];
|
||||||
i1[i]=i1[i] + id[k]*c1[j] + qd[k]*s1[j];
|
i1[i]=i1[i] + id[k]*c1[j] + qd[k]*s1[j];
|
||||||
@ -285,18 +288,18 @@ void sync_and_demodulate(double *id, double *qd, long np,
|
|||||||
|
|
||||||
totp=totp+p0+p1+p2+p3;
|
totp=totp+p0+p1+p2+p3;
|
||||||
cmet=(p1+p3)-(p0+p2);
|
cmet=(p1+p3)-(p0+p2);
|
||||||
ss=ss+cmet*(2*pr3[i]-1);
|
ss = (pr3[i] == 1) ? ss+cmet : ss-cmet;
|
||||||
if( mode == 2) { //Compute soft symbols
|
if( mode == 2) { //Compute soft symbols
|
||||||
if(pr3[i]) {
|
if(pr3[i]==1) {
|
||||||
fsymb[i]=p3-p1;
|
fsymb[i]=p3-p1;
|
||||||
} else {
|
} else {
|
||||||
fsymb[i]=p2-p0;
|
fsymb[i]=p2-p0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ss=ss/totp;
|
||||||
if( ss/totp > syncmax ) { //Save best parameters
|
if( ss > syncmax ) { //Save best parameters
|
||||||
syncmax=ss/totp;
|
syncmax=ss;
|
||||||
best_shift=lag;
|
best_shift=lag;
|
||||||
fbest=f0;
|
fbest=f0;
|
||||||
}
|
}
|
||||||
@ -330,16 +333,16 @@ void sync_and_demodulate(double *id, double *qd, long np,
|
|||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
symbol-by-symbol signal subtraction
|
symbol-by-symbol signal subtraction
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
void subtract_signal(double *id, double *qd, long np,
|
void subtract_signal(float *id, float *qd, long np,
|
||||||
float f0, int shift0, float drift0, unsigned char* channel_symbols)
|
float f0, int shift0, float drift0, unsigned char* channel_symbols)
|
||||||
{
|
{
|
||||||
float dt=1.0/375.0, df=375.0/256.0;
|
float dt=1.0/375.0, df=375.0/256.0;
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
double pi=4.*atan(1.0),twopidt, fp;
|
float pi=4.*atan(1.0),twopidt, fp;
|
||||||
|
|
||||||
double i0,q0;
|
float i0,q0;
|
||||||
double c0[256],s0[256];
|
float c0[256],s0[256];
|
||||||
double dphi, cdphi, sdphi;
|
float dphi, cdphi, sdphi;
|
||||||
|
|
||||||
twopidt=2*pi*dt;
|
twopidt=2*pi*dt;
|
||||||
|
|
||||||
@ -386,30 +389,30 @@ void subtract_signal(double *id, double *qd, long np,
|
|||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
Fully coherent signal subtraction
|
Fully coherent signal subtraction
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
void subtract_signal2(double *id, double *qd, long np,
|
void subtract_signal2(float *id, float *qd, long np,
|
||||||
float f0, int shift0, float drift0, unsigned char* channel_symbols)
|
float f0, int shift0, float drift0, unsigned char* channel_symbols)
|
||||||
{
|
{
|
||||||
double dt=1.0/375.0, df=375.0/256.0;
|
float dt=1.0/375.0, df=375.0/256.0;
|
||||||
double pi=4.*atan(1.0), twopidt, phi=0, dphi, cs;
|
float pi=4.*atan(1.0), twopidt, phi=0, dphi, cs;
|
||||||
int i, j, k, ii, nsym=162, nspersym=256, nfilt=256; //nfilt must be even number.
|
int i, j, k, ii, nsym=162, nspersym=256, nfilt=256; //nfilt must be even number.
|
||||||
int nsig=nsym*nspersym;
|
int nsig=nsym*nspersym;
|
||||||
int nc2=45000;
|
int nc2=45000;
|
||||||
|
|
||||||
double *refi, *refq, *ci, *cq, *cfi, *cfq;
|
float *refi, *refq, *ci, *cq, *cfi, *cfq;
|
||||||
|
|
||||||
refi=malloc(sizeof(double)*nc2);
|
refi=malloc(sizeof(float)*nc2);
|
||||||
refq=malloc(sizeof(double)*nc2);
|
refq=malloc(sizeof(float)*nc2);
|
||||||
ci=malloc(sizeof(double)*nc2);
|
ci=malloc(sizeof(float)*nc2);
|
||||||
cq=malloc(sizeof(double)*nc2);
|
cq=malloc(sizeof(float)*nc2);
|
||||||
cfi=malloc(sizeof(double)*nc2);
|
cfi=malloc(sizeof(float)*nc2);
|
||||||
cfq=malloc(sizeof(double)*nc2);
|
cfq=malloc(sizeof(float)*nc2);
|
||||||
|
|
||||||
memset(refi,0,sizeof(double)*nc2);
|
memset(refi,0,sizeof(float)*nc2);
|
||||||
memset(refq,0,sizeof(double)*nc2);
|
memset(refq,0,sizeof(float)*nc2);
|
||||||
memset(ci,0,sizeof(double)*nc2);
|
memset(ci,0,sizeof(float)*nc2);
|
||||||
memset(cq,0,sizeof(double)*nc2);
|
memset(cq,0,sizeof(float)*nc2);
|
||||||
memset(cfi,0,sizeof(double)*nc2);
|
memset(cfi,0,sizeof(float)*nc2);
|
||||||
memset(cfq,0,sizeof(double)*nc2);
|
memset(cfq,0,sizeof(float)*nc2);
|
||||||
|
|
||||||
twopidt=2.0*pi*dt;
|
twopidt=2.0*pi*dt;
|
||||||
|
|
||||||
@ -425,18 +428,18 @@ void subtract_signal2(double *id, double *qd, long np,
|
|||||||
//
|
//
|
||||||
for (i=0; i<nsym; i++) {
|
for (i=0; i<nsym; i++) {
|
||||||
|
|
||||||
cs=(double)channel_symbols[i];
|
cs=(float)channel_symbols[i];
|
||||||
|
|
||||||
dphi=twopidt*
|
dphi=twopidt*
|
||||||
(
|
(
|
||||||
f0 + ((float)drift0/2.0)*((float)i-(float)nsym/2.0)/((float)nsym/2.0)
|
f0 + (drift0/2.0)*((float)i-(float)nsym/2.0)/((float)nsym/2.0)
|
||||||
+ (cs-1.5)*df
|
+ (cs-1.5)*df
|
||||||
);
|
);
|
||||||
|
|
||||||
for ( j=0; j<nspersym; j++ ) {
|
for ( j=0; j<nspersym; j++ ) {
|
||||||
ii=nspersym*i+j;
|
ii=nspersym*i+j;
|
||||||
refi[ii]=refi[ii]+cos(phi); //cannot precompute sin/cos because dphi is changing
|
refi[ii]=cos(phi); //cannot precompute sin/cos because dphi is changing
|
||||||
refq[ii]=refq[ii]+sin(phi);
|
refq[ii]=sin(phi);
|
||||||
phi=phi+dphi;
|
phi=phi+dphi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -448,15 +451,15 @@ void subtract_signal2(double *id, double *qd, long np,
|
|||||||
// leave nfilt zeros as a pad at the beginning of the unfiltered reference signal
|
// leave nfilt zeros as a pad at the beginning of the unfiltered reference signal
|
||||||
for (i=0; i<nsym*nspersym; i++) {
|
for (i=0; i<nsym*nspersym; i++) {
|
||||||
k=shift0+i;
|
k=shift0+i;
|
||||||
if( (k>0) & (k<np) ) {
|
if( (k>0) && (k<np) ) {
|
||||||
ci[i+nfilt] = id[k]*refi[i] + qd[k]*refq[i];
|
ci[i+nfilt] = id[k]*refi[i] + qd[k]*refq[i];
|
||||||
cq[i+nfilt] = qd[k]*refi[i] - id[k]*refq[i];
|
cq[i+nfilt] = qd[k]*refi[i] - id[k]*refq[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//quick and dirty filter - may want to do better
|
//lowpass filter and remove startup transient
|
||||||
double w[nfilt], norm=0, partialsum[nfilt];
|
float w[nfilt], norm=0, partialsum[nfilt];
|
||||||
memset(partialsum,0,sizeof(double)*nfilt);
|
memset(partialsum,0,sizeof(float)*nfilt);
|
||||||
for (i=0; i<nfilt; i++) {
|
for (i=0; i<nfilt; i++) {
|
||||||
w[i]=sin(pi*(float)i/(float)(nfilt-1));
|
w[i]=sin(pi*(float)i/(float)(nfilt-1));
|
||||||
norm=norm+w[i];
|
norm=norm+w[i];
|
||||||
@ -491,7 +494,7 @@ void subtract_signal2(double *id, double *qd, long np,
|
|||||||
}
|
}
|
||||||
k=shift0+i;
|
k=shift0+i;
|
||||||
j=i+nfilt;
|
j=i+nfilt;
|
||||||
if( (k>0) & (k<np) ) {
|
if( (k>0) && (k<np) ) {
|
||||||
id[k]=id[k] - (cfi[j]*refi[i]-cfq[j]*refq[i])/norm;
|
id[k]=id[k] - (cfi[j]*refi[i]-cfq[j]*refq[i])/norm;
|
||||||
qd[k]=qd[k] - (cfi[j]*refq[i]+cfq[j]*refi[i])/norm;
|
qd[k]=qd[k] - (cfi[j]*refq[i]+cfq[j]*refi[i])/norm;
|
||||||
}
|
}
|
||||||
@ -508,7 +511,7 @@ void subtract_signal2(double *id, double *qd, long np,
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned long writec2file(char *c2filename, int trmin, double freq
|
unsigned long writec2file(char *c2filename, int trmin, double freq
|
||||||
, double *idat, double *qdat)
|
, float *idat, float *qdat)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float *buffer;
|
float *buffer;
|
||||||
@ -550,15 +553,18 @@ void usage(void)
|
|||||||
printf("Options:\n");
|
printf("Options:\n");
|
||||||
printf(" -a <path> path to writeable data files, default=\".\"\n");
|
printf(" -a <path> path to writeable data files, default=\".\"\n");
|
||||||
printf(" -c write .c2 file at the end of the first pass\n");
|
printf(" -c write .c2 file at the end of the first pass\n");
|
||||||
|
printf(" -C maximum number of decoder cycles per bit, default 10000\n");
|
||||||
|
printf(" -d deeper search. Slower, a few more decodes\n");
|
||||||
printf(" -e x (x is transceiver dial frequency error in Hz)\n");
|
printf(" -e x (x is transceiver dial frequency error in Hz)\n");
|
||||||
printf(" -f x (x is transceiver dial frequency in MHz)\n");
|
printf(" -f x (x is transceiver dial frequency in MHz)\n");
|
||||||
printf(" -H do not use (or update) the hash table\n");
|
printf(" -H do not use (or update) the hash table\n");
|
||||||
|
printf(" -J use the stack decoder instead of Fano decoder\n");
|
||||||
printf(" -m decode wspr-15 .wav file\n");
|
printf(" -m decode wspr-15 .wav file\n");
|
||||||
printf(" -q quick mode - doesn't dig deep for weak signals\n");
|
printf(" -q quick mode - doesn't dig deep for weak signals\n");
|
||||||
printf(" -s single pass mode, no subtraction (same as original wsprd)\n");
|
printf(" -s single pass mode, no subtraction (same as original wsprd)\n");
|
||||||
printf(" -v verbose mode (shows dupes)\n");
|
printf(" -v verbose mode (shows dupes)\n");
|
||||||
printf(" -w wideband mode - decode signals within +/- 150 Hz of center\n");
|
printf(" -w wideband mode - decode signals within +/- 150 Hz of center\n");
|
||||||
printf(" -z x (x is fano metric table bias, default is 0.42)\n");
|
printf(" -z x (x is fano metric table bias, default is 0.45)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
//***************************************************************************
|
//***************************************************************************
|
||||||
@ -567,7 +573,7 @@ int main(int argc, char *argv[])
|
|||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
extern int optind;
|
extern int optind;
|
||||||
int i,j,k;
|
int i,j,k;
|
||||||
unsigned char *symbols, *decdata;
|
unsigned char *symbols, *decdata, *channel_symbols;
|
||||||
signed char message[]={-9,13,-35,123,57,-39,64,0,0,0,0};
|
signed char message[]={-9,13,-35,123,57,-39,64,0,0,0,0};
|
||||||
char *callsign, *call_loc_pow;
|
char *callsign, *call_loc_pow;
|
||||||
char *ptr_to_infile,*ptr_to_infile_suffix;
|
char *ptr_to_infile,*ptr_to_infile_suffix;
|
||||||
@ -575,38 +581,39 @@ int main(int argc, char *argv[])
|
|||||||
char wisdom_fname[200],all_fname[200],spots_fname[200];
|
char wisdom_fname[200],all_fname[200],spots_fname[200];
|
||||||
char timer_fname[200],hash_fname[200];
|
char timer_fname[200],hash_fname[200];
|
||||||
char uttime[5],date[7];
|
char uttime[5],date[7];
|
||||||
int c,delta,maxpts=65536,verbose=0,quickmode=0;
|
int c,delta,maxpts=65536,verbose=0,quickmode=0,more_candidates=0, stackdecoder=0;
|
||||||
int writenoise=0,usehashtable=1,wspr_type=2, ipass;
|
int writenoise=0,usehashtable=1,wspr_type=2, ipass;
|
||||||
int writec2=0, npasses=2, subtraction=1;
|
int writec2=0, npasses=2, subtraction=1;
|
||||||
int shift1, lagmin, lagmax, lagstep, worth_a_try, not_decoded;
|
int shift1, lagmin, lagmax, lagstep, ifmin, ifmax, worth_a_try, not_decoded;
|
||||||
unsigned int nbits=81;
|
unsigned int nbits=81, stacksize=200000;
|
||||||
unsigned int npoints, metric, maxcycles, cycles, maxnp;
|
unsigned int npoints, metric, cycles, maxnp;
|
||||||
float df=375.0/256.0/2;
|
float df=375.0/256.0/2;
|
||||||
float freq0[200],snr0[200],drift0[200],sync0[200];
|
float freq0[200],snr0[200],drift0[200],sync0[200];
|
||||||
int shift0[200];
|
int shift0[200];
|
||||||
float dt=1.0/375.0, dt_print;
|
float dt=1.0/375.0, dt_print;
|
||||||
double dialfreq_cmdline=0.0, dialfreq, freq_print;
|
double dialfreq_cmdline=0.0, dialfreq, freq_print;
|
||||||
float dialfreq_error=0.0;
|
double dialfreq_error=0.0;
|
||||||
float fmin=-110, fmax=110;
|
float fmin=-110, fmax=110;
|
||||||
float f1, fstep, sync1, drift1;
|
float f1, fstep, sync1, drift1;
|
||||||
float psavg[512];
|
float psavg[512];
|
||||||
double *idat, *qdat;
|
float *idat, *qdat;
|
||||||
clock_t t0,t00;
|
clock_t t0,t00;
|
||||||
double tfano=0.0,treadwav=0.0,tcandidates=0.0,tsync0=0.0;
|
float tfano=0.0,treadwav=0.0,tcandidates=0.0,tsync0=0.0;
|
||||||
double tsync1=0.0,tsync2=0.0,ttotal=0.0;
|
float tsync1=0.0,tsync2=0.0,ttotal=0.0;
|
||||||
|
|
||||||
struct result { char date[7]; char time[5]; float sync; float snr;
|
struct result { char date[7]; char time[5]; float sync; float snr;
|
||||||
float dt; double freq; char message[23]; float drift;
|
float dt; float freq; char message[23]; float drift;
|
||||||
unsigned int cycles; int jitter; };
|
unsigned int cycles; int jitter; };
|
||||||
struct result decodes[50];
|
struct result decodes[50];
|
||||||
|
|
||||||
char *hashtab;
|
char *hashtab;
|
||||||
hashtab=malloc(sizeof(char)*32768*13);
|
hashtab=malloc(sizeof(char)*32768*13);
|
||||||
memset(hashtab,0,sizeof(char)*32768*13);
|
memset(hashtab,0,sizeof(char)*32768*13);
|
||||||
|
|
||||||
int nh;
|
int nh;
|
||||||
symbols=malloc(sizeof(char)*nbits*2);
|
symbols=malloc(sizeof(char)*nbits*2);
|
||||||
decdata=malloc((nbits+7)/8);
|
decdata=malloc(sizeof(char)*11);
|
||||||
|
channel_symbols=malloc(sizeof(char)*nbits*2);
|
||||||
|
|
||||||
callsign=malloc(sizeof(char)*13);
|
callsign=malloc(sizeof(char)*13);
|
||||||
call_loc_pow=malloc(sizeof(char)*23);
|
call_loc_pow=malloc(sizeof(char)*23);
|
||||||
float allfreqs[100];
|
float allfreqs[100];
|
||||||
@ -614,31 +621,29 @@ int main(int argc, char *argv[])
|
|||||||
memset(allfreqs,0,sizeof(float)*100);
|
memset(allfreqs,0,sizeof(float)*100);
|
||||||
memset(allcalls,0,sizeof(char)*100*13);
|
memset(allcalls,0,sizeof(char)*100*13);
|
||||||
|
|
||||||
int uniques=0, noprint=0;
|
int uniques=0, noprint=0, ndecodes_pass=0;
|
||||||
|
|
||||||
// init_random_seed();
|
|
||||||
|
|
||||||
// Parameters used for performance-tuning:
|
// Parameters used for performance-tuning:
|
||||||
maxcycles=10000; //Fano timeout limit
|
unsigned int maxcycles=10000; //Decoder timeout limit
|
||||||
double minsync1=0.10; //First sync limit
|
float minsync1=0.10; //First sync limit
|
||||||
double minsync2=0.12; //Second sync limit
|
float minsync2=0.12; //Second sync limit
|
||||||
int iifac=3; //Step size in final DT peakup
|
int iifac=8; //Step size in final DT peakup
|
||||||
int symfac=50; //Soft-symbol normalizing factor
|
int symfac=50; //Soft-symbol normalizing factor
|
||||||
int maxdrift=4; //Maximum (+/-) drift
|
int maxdrift=4; //Maximum (+/-) drift
|
||||||
double minrms=52.0 * (symfac/64.0); //Final test for plausible decoding
|
float minrms=52.0 * (symfac/64.0); //Final test for plausible decoding
|
||||||
delta=60; //Fano threshold step
|
delta=60; //Fano threshold step
|
||||||
|
float bias=0.45; //Fano metric bias (used for both Fano and stack algorithms)
|
||||||
|
|
||||||
t00=clock();
|
t00=clock();
|
||||||
fftw_complex *fftin, *fftout;
|
fftwf_complex *fftin, *fftout;
|
||||||
#include "./metric_tables.c"
|
#include "./metric_tables.c"
|
||||||
|
|
||||||
int mettab[2][256];
|
int mettab[2][256];
|
||||||
float bias=0.42;
|
|
||||||
|
|
||||||
idat=malloc(sizeof(double)*maxpts);
|
idat=malloc(sizeof(float)*maxpts);
|
||||||
qdat=malloc(sizeof(double)*maxpts);
|
qdat=malloc(sizeof(float)*maxpts);
|
||||||
|
|
||||||
while ( (c = getopt(argc, argv, "a:ce:f:Hmqstwvz:")) !=-1 ) {
|
while ( (c = getopt(argc, argv, "a:cC:de:f:HJmqstwvz:")) !=-1 ) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a':
|
||||||
data_dir = optarg;
|
data_dir = optarg;
|
||||||
@ -646,8 +651,14 @@ int main(int argc, char *argv[])
|
|||||||
case 'c':
|
case 'c':
|
||||||
writec2=1;
|
writec2=1;
|
||||||
break;
|
break;
|
||||||
|
case 'C':
|
||||||
|
maxcycles=(unsigned int) strtoul(optarg,NULL,10);
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
more_candidates=1;
|
||||||
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
dialfreq_error = strtof(optarg,NULL); // units of Hz
|
dialfreq_error = strtod(optarg,NULL); // units of Hz
|
||||||
// dialfreq_error = dial reading - actual, correct frequency
|
// dialfreq_error = dial reading - actual, correct frequency
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
@ -656,14 +667,17 @@ int main(int argc, char *argv[])
|
|||||||
case 'H':
|
case 'H':
|
||||||
usehashtable = 0;
|
usehashtable = 0;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'J': //Stack (Jelinek) decoder, Fano decoder is the default
|
||||||
|
stackdecoder = 1;
|
||||||
|
break;
|
||||||
|
case 'm': //15-minute wspr mode
|
||||||
wspr_type = 15;
|
wspr_type = 15;
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q': //no shift jittering
|
||||||
quickmode = 1;
|
quickmode = 1;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's': //single pass mode (same as original wsprd)
|
||||||
subtraction = 0; //single pass mode (same as original wsprd)
|
subtraction = 0;
|
||||||
npasses = 1;
|
npasses = 1;
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
@ -674,7 +688,7 @@ int main(int argc, char *argv[])
|
|||||||
fmax=150.0;
|
fmax=150.0;
|
||||||
break;
|
break;
|
||||||
case 'z':
|
case 'z':
|
||||||
bias=strtof(optarg,NULL); //fano metric bias (default is 0.42)
|
bias=strtod(optarg,NULL); //fano metric bias (default is 0.45)
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
usage();
|
usage();
|
||||||
@ -682,6 +696,10 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( stackdecoder ) {
|
||||||
|
stack=malloc(stacksize*sizeof(struct snode));
|
||||||
|
}
|
||||||
|
|
||||||
if( optind+1 > argc) {
|
if( optind+1 > argc) {
|
||||||
usage();
|
usage();
|
||||||
return 1;
|
return 1;
|
||||||
@ -695,7 +713,7 @@ int main(int argc, char *argv[])
|
|||||||
mettab[1][i]=round( 10*(metric_tables[2][255-i]-bias) );
|
mettab[1][i]=round( 10*(metric_tables[2][255-i]-bias) );
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *fp_fftw_wisdom_file, *fall_wspr, *fwsprd, *fhash, *ftimer;
|
FILE *fp_fftwf_wisdom_file, *fall_wspr, *fwsprd, *fhash, *ftimer;
|
||||||
strcpy(wisdom_fname,".");
|
strcpy(wisdom_fname,".");
|
||||||
strcpy(all_fname,".");
|
strcpy(all_fname,".");
|
||||||
strcpy(spots_fname,".");
|
strcpy(spots_fname,".");
|
||||||
@ -713,9 +731,9 @@ int main(int argc, char *argv[])
|
|||||||
strncat(spots_fname,"/wspr_spots.txt",20);
|
strncat(spots_fname,"/wspr_spots.txt",20);
|
||||||
strncat(timer_fname,"/wspr_timer.out",20);
|
strncat(timer_fname,"/wspr_timer.out",20);
|
||||||
strncat(hash_fname,"/hashtable.txt",20);
|
strncat(hash_fname,"/hashtable.txt",20);
|
||||||
if ((fp_fftw_wisdom_file = fopen(wisdom_fname, "r"))) { //Open FFTW wisdom
|
if ((fp_fftwf_wisdom_file = fopen(wisdom_fname, "r"))) { //Open FFTW wisdom
|
||||||
fftw_import_wisdom_from_file(fp_fftw_wisdom_file);
|
fftwf_import_wisdom_from_file(fp_fftwf_wisdom_file);
|
||||||
fclose(fp_fftw_wisdom_file);
|
fclose(fp_fftwf_wisdom_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
fall_wspr=fopen(all_fname,"a");
|
fall_wspr=fopen(all_fname,"a");
|
||||||
@ -725,7 +743,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if((ftimer=fopen(timer_fname,"r"))) {
|
if((ftimer=fopen(timer_fname,"r"))) {
|
||||||
//Accumulate timing data
|
//Accumulate timing data
|
||||||
nr=fscanf(ftimer,"%lf %lf %lf %lf %lf %lf %lf",
|
nr=fscanf(ftimer,"%f %f %f %f %f %f %f",
|
||||||
&treadwav,&tcandidates,&tsync0,&tsync1,&tsync2,&tfano,&ttotal);
|
&treadwav,&tcandidates,&tsync0,&tsync1,&tsync2,&tfano,&ttotal);
|
||||||
fclose(ftimer);
|
fclose(ftimer);
|
||||||
}
|
}
|
||||||
@ -736,7 +754,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
t0 = clock();
|
t0 = clock();
|
||||||
npoints=readwavfile(ptr_to_infile, wspr_type, idat, qdat);
|
npoints=readwavfile(ptr_to_infile, wspr_type, idat, qdat);
|
||||||
treadwav += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
treadwav += (float)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
if( npoints == 1 ) {
|
if( npoints == 1 ) {
|
||||||
return 1;
|
return 1;
|
||||||
@ -763,9 +781,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Do windowed ffts over 2 symbols, stepped by half symbols
|
// Do windowed ffts over 2 symbols, stepped by half symbols
|
||||||
int nffts=4*floor(npoints/512)-1;
|
int nffts=4*floor(npoints/512)-1;
|
||||||
fftin=(fftw_complex*) fftw_malloc(sizeof(fftw_complex)*512);
|
fftin=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*512);
|
||||||
fftout=(fftw_complex*) fftw_malloc(sizeof(fftw_complex)*512);
|
fftout=(fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex)*512);
|
||||||
PLAN3 = fftw_plan_dft_1d(512, fftin, fftout, FFTW_FORWARD, PATIENCE);
|
PLAN3 = fftwf_plan_dft_1d(512, fftin, fftout, FFTW_FORWARD, PATIENCE);
|
||||||
|
|
||||||
float ps[512][nffts];
|
float ps[512][nffts];
|
||||||
float w[512];
|
float w[512];
|
||||||
@ -789,10 +807,8 @@ int main(int argc, char *argv[])
|
|||||||
//*************** main loop starts here *****************
|
//*************** main loop starts here *****************
|
||||||
for (ipass=0; ipass<npasses; ipass++) {
|
for (ipass=0; ipass<npasses; ipass++) {
|
||||||
|
|
||||||
if( ipass == 1 && uniques == 0 ) break;
|
if( ipass > 0 && ndecodes_pass == 0 ) break;
|
||||||
if( ipass == 1 ) { //otherwise we bog down on the second pass
|
ndecodes_pass=0;
|
||||||
quickmode = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(ps,0.0, sizeof(float)*512*nffts);
|
memset(ps,0.0, sizeof(float)*512*nffts);
|
||||||
for (i=0; i<nffts; i++) {
|
for (i=0; i<nffts; i++) {
|
||||||
@ -801,7 +817,7 @@ int main(int argc, char *argv[])
|
|||||||
fftin[j][0]=idat[k] * w[j];
|
fftin[j][0]=idat[k] * w[j];
|
||||||
fftin[j][1]=qdat[k] * w[j];
|
fftin[j][1]=qdat[k] * w[j];
|
||||||
}
|
}
|
||||||
fftw_execute(PLAN3);
|
fftwf_execute(PLAN3);
|
||||||
for (j=0; j<512; j++ ) {
|
for (j=0; j<512; j++ ) {
|
||||||
k=j+256;
|
k=j+256;
|
||||||
if( k>511 )
|
if( k>511 )
|
||||||
@ -853,7 +869,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
for (j=0; j<411; j++) {
|
for (j=0; j<411; j++) {
|
||||||
smspec[j]=smspec[j]/noise_level - 1.0;
|
smspec[j]=smspec[j]/noise_level - 1.0;
|
||||||
if( smspec[j] < min_snr) smspec[j]=0.1;
|
if( smspec[j] < min_snr) smspec[j]=0.1*min_snr;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -867,11 +883,26 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
int npk=0;
|
int npk=0;
|
||||||
for(j=1; j<410; j++) {
|
unsigned char candidate;
|
||||||
if((smspec[j]>smspec[j-1]) && (smspec[j]>smspec[j+1]) && (npk<200)) {
|
if( more_candidates ) {
|
||||||
freq0[npk]=(j-205)*df;
|
for(j=0; j<411; j=j+2) {
|
||||||
snr0[npk]=10*log10(smspec[j])-snr_scaling_factor;
|
candidate = (smspec[j]>min_snr) && (npk<200);
|
||||||
npk++;
|
if ( candidate ) {
|
||||||
|
freq0[npk]=(j-205)*df;
|
||||||
|
snr0[npk]=10*log10(smspec[j])-snr_scaling_factor;
|
||||||
|
npk++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for(j=1; j<410; j++) {
|
||||||
|
candidate = (smspec[j]>smspec[j-1]) &&
|
||||||
|
(smspec[j]>smspec[j+1]) &&
|
||||||
|
(npk<200);
|
||||||
|
if ( candidate ) {
|
||||||
|
freq0[npk]=(j-205)*df;
|
||||||
|
snr0[npk]=10*log10(smspec[j])-snr_scaling_factor;
|
||||||
|
npk++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -907,6 +938,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
t0=clock();
|
t0=clock();
|
||||||
|
|
||||||
/* Make coarse estimates of shift (DT), freq, and drift
|
/* Make coarse estimates of shift (DT), freq, and drift
|
||||||
|
|
||||||
* Look for time offsets up to +/- 8 symbols (about +/- 5.4 s) relative
|
* Look for time offsets up to +/- 8 symbols (about +/- 5.4 s) relative
|
||||||
@ -933,7 +965,7 @@ int main(int argc, char *argv[])
|
|||||||
for(j=0; j<npk; j++) { //For each candidate...
|
for(j=0; j<npk; j++) { //For each candidate...
|
||||||
smax=-1e30;
|
smax=-1e30;
|
||||||
if0=freq0[j]/df+256;
|
if0=freq0[j]/df+256;
|
||||||
for (ifr=if0-1; ifr<=if0+1; ifr++) { //Freq search
|
for (ifr=if0-2; ifr<=if0+2; ifr++) { //Freq search
|
||||||
for( k0=-10; k0<22; k0++) { //Time search
|
for( k0=-10; k0<22; k0++) { //Time search
|
||||||
for (idrift=-maxdrift; idrift<=maxdrift; idrift++) { //Drift search
|
for (idrift=-maxdrift; idrift<=maxdrift; idrift++) { //Drift search
|
||||||
ss=0.0;
|
ss=0.0;
|
||||||
@ -954,9 +986,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
ss=ss+(2*pr3[k]-1)*((p1+p3)-(p0+p2));
|
ss=ss+(2*pr3[k]-1)*((p1+p3)-(p0+p2));
|
||||||
pow=pow+p0+p1+p2+p3;
|
pow=pow+p0+p1+p2+p3;
|
||||||
sync1=ss/pow;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sync1=ss/pow;
|
||||||
if( sync1 > smax ) { //Save coarse parameters
|
if( sync1 > smax ) { //Save coarse parameters
|
||||||
smax=sync1;
|
smax=sync1;
|
||||||
shift0[j]=128*(k0+1);
|
shift0[j]=128*(k0+1);
|
||||||
@ -968,7 +1000,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tcandidates += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
tcandidates += (float)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Refine the estimates of freq, shift using sync as a metric.
|
Refine the estimates of freq, shift using sync as a metric.
|
||||||
@ -986,7 +1018,6 @@ int main(int argc, char *argv[])
|
|||||||
NB: best possibility for OpenMP may be here: several worker threads
|
NB: best possibility for OpenMP may be here: several worker threads
|
||||||
could each work on one candidate at a time.
|
could each work on one candidate at a time.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (j=0; j<npk; j++) {
|
for (j=0; j<npk; j++) {
|
||||||
memset(symbols,0,sizeof(char)*nbits*2);
|
memset(symbols,0,sizeof(char)*nbits*2);
|
||||||
memset(callsign,0,sizeof(char)*13);
|
memset(callsign,0,sizeof(char)*13);
|
||||||
@ -997,32 +1028,66 @@ int main(int argc, char *argv[])
|
|||||||
shift1=shift0[j];
|
shift1=shift0[j];
|
||||||
sync1=sync0[j];
|
sync1=sync0[j];
|
||||||
|
|
||||||
// Fine search for best sync lag (mode 0)
|
|
||||||
fstep=0.0;
|
// coarse-grid lag and freq search, then if sync>minsync1 continue
|
||||||
lagmin=shift1-144;
|
fstep=0.0; ifmin=0; ifmax=0;
|
||||||
lagmax=shift1+144;
|
lagmin=shift1-128;
|
||||||
lagstep=8;
|
lagmax=shift1+128;
|
||||||
if(quickmode) lagstep=16;
|
lagstep=64;
|
||||||
t0 = clock();
|
t0 = clock();
|
||||||
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, fstep, &shift1,
|
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1,
|
||||||
lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 0);
|
lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 0);
|
||||||
tsync0 += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
tsync0 += (float)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
// Fine search for frequency peak (mode 1)
|
fstep=0.25; ifmin=-2; ifmax=2;
|
||||||
fstep=0.1;
|
|
||||||
t0 = clock();
|
t0 = clock();
|
||||||
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, fstep, &shift1,
|
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1,
|
||||||
lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 1);
|
lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 1);
|
||||||
tsync1 += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
|
||||||
|
|
||||||
|
// refine drift estimate
|
||||||
|
fstep=0.0; ifmin=0; ifmax=0;
|
||||||
|
float driftp,driftm,syncp,syncm;
|
||||||
|
driftp=drift1+0.5;
|
||||||
|
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1,
|
||||||
|
lagmin, lagmax, lagstep, &driftp, symfac, &syncp, 1);
|
||||||
|
|
||||||
|
driftm=drift1-0.5;
|
||||||
|
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1,
|
||||||
|
lagmin, lagmax, lagstep, &driftm, symfac, &syncm, 1);
|
||||||
|
|
||||||
|
if(syncp>sync1) {
|
||||||
|
drift1=driftp;
|
||||||
|
sync1=syncp;
|
||||||
|
} else if (syncm>sync1) {
|
||||||
|
drift1=driftm;
|
||||||
|
sync1=syncm;
|
||||||
|
}
|
||||||
|
|
||||||
|
tsync1 += (float)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
// fine-grid lag and freq search
|
||||||
if( sync1 > minsync1 ) {
|
if( sync1 > minsync1 ) {
|
||||||
|
|
||||||
|
lagmin=shift1-32; lagmax=shift1+32; lagstep=16;
|
||||||
|
t0 = clock();
|
||||||
|
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1,
|
||||||
|
lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 0);
|
||||||
|
tsync0 += (float)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
// fine search over frequency
|
||||||
|
fstep=0.05; ifmin=-2; ifmax=2;
|
||||||
|
t0 = clock();
|
||||||
|
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep, &shift1,
|
||||||
|
lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 1);
|
||||||
|
tsync1 += (float)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
worth_a_try = 1;
|
worth_a_try = 1;
|
||||||
} else {
|
} else {
|
||||||
worth_a_try = 0;
|
worth_a_try = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idt=0, ii=0, jiggered_shift;
|
int idt=0, ii=0, jiggered_shift;
|
||||||
double y,sq,rms;
|
float y,sq,rms;
|
||||||
not_decoded=1;
|
not_decoded=1;
|
||||||
|
|
||||||
while ( worth_a_try && not_decoded && idt<=(128/iifac)) {
|
while ( worth_a_try && not_decoded && idt<=(128/iifac)) {
|
||||||
@ -1033,14 +1098,14 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Use mode 2 to get soft-decision symbols
|
// Use mode 2 to get soft-decision symbols
|
||||||
t0 = clock();
|
t0 = clock();
|
||||||
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, fstep,
|
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, ifmin, ifmax, fstep,
|
||||||
&jiggered_shift, lagmin, lagmax, lagstep, &drift1, symfac,
|
&jiggered_shift, lagmin, lagmax, lagstep, &drift1, symfac,
|
||||||
&sync1, 2);
|
&sync1, 2);
|
||||||
tsync2 += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
tsync2 += (float)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
sq=0.0;
|
sq=0.0;
|
||||||
for(i=0; i<162; i++) {
|
for(i=0; i<162; i++) {
|
||||||
y=(double)symbols[i] - 128.0;
|
y=(float)symbols[i] - 128.0;
|
||||||
sq += y*y;
|
sq += y*y;
|
||||||
}
|
}
|
||||||
rms=sqrt(sq/162.0);
|
rms=sqrt(sq/162.0);
|
||||||
@ -1049,22 +1114,23 @@ int main(int argc, char *argv[])
|
|||||||
deinterleave(symbols);
|
deinterleave(symbols);
|
||||||
t0 = clock();
|
t0 = clock();
|
||||||
|
|
||||||
not_decoded = fano(&metric,&cycles,&maxnp,decdata,symbols,nbits,
|
if ( stackdecoder ) {
|
||||||
mettab,delta,maxcycles);
|
not_decoded = jelinek(&metric, &cycles, decdata, symbols, nbits,
|
||||||
tfano += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
stacksize, stack, mettab,maxcycles);
|
||||||
|
} else {
|
||||||
|
not_decoded = fano(&metric,&cycles,&maxnp,decdata,symbols,nbits,
|
||||||
|
mettab,delta,maxcycles);
|
||||||
|
}
|
||||||
|
|
||||||
|
tfano += (float)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
/* ### Used for timing tests:
|
|
||||||
if(not_decoded) fprintf(fdiag,
|
|
||||||
"%6s %4s %4.1f %3.0f %4.1f %10.7f %-18s %2d %5u %4d %6.1f %2d\n",
|
|
||||||
date,uttime,sync1*10,snr0[j], shift1*dt-2.0, dialfreq+(1500+f1)/1e6,
|
|
||||||
"@ ", (int)drift1, cycles/81, ii, rms, maxnp);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
idt++;
|
idt++;
|
||||||
if( quickmode ) break;
|
if( quickmode ) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( worth_a_try && !not_decoded ) {
|
if( worth_a_try && !not_decoded ) {
|
||||||
|
ndecodes_pass++;
|
||||||
|
|
||||||
for(i=0; i<11; i++) {
|
for(i=0; i<11; i++) {
|
||||||
|
|
||||||
@ -1081,10 +1147,8 @@ int main(int argc, char *argv[])
|
|||||||
// call_loc_pow string and also callsign (for de-duping).
|
// call_loc_pow string and also callsign (for de-duping).
|
||||||
noprint=unpk_(message,hashtab,call_loc_pow,callsign);
|
noprint=unpk_(message,hashtab,call_loc_pow,callsign);
|
||||||
|
|
||||||
if( subtraction && (ipass == 0) && !noprint ) {
|
// subtract even on last pass
|
||||||
|
if( subtraction && (ipass < npasses ) && !noprint ) {
|
||||||
unsigned char channel_symbols[162];
|
|
||||||
|
|
||||||
if( get_wspr_channel_symbols(call_loc_pow, hashtab, channel_symbols) ) {
|
if( get_wspr_channel_symbols(call_loc_pow, hashtab, channel_symbols) ) {
|
||||||
subtract_signal2(idat, qdat, npoints, f1, shift1, drift1, channel_symbols);
|
subtract_signal2(idat, qdat, npoints, f1, shift1, drift1, channel_symbols);
|
||||||
} else {
|
} else {
|
||||||
@ -1109,10 +1173,10 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if( wspr_type == 15 ) {
|
if( wspr_type == 15 ) {
|
||||||
freq_print=dialfreq+(1500+112.5+f1/8.0)/1e6;
|
freq_print=dialfreq+(1500+112.5+f1/8.0)/1e6;
|
||||||
dt_print=shift1*8*dt-2.0;
|
dt_print=shift1*8*dt-1.0;
|
||||||
} else {
|
} else {
|
||||||
freq_print=dialfreq+(1500+f1)/1e6;
|
freq_print=dialfreq+(1500+f1)/1e6;
|
||||||
dt_print=shift1*dt-2.0;
|
dt_print=shift1*dt-1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(decodes[uniques-1].date,date);
|
strcpy(decodes[uniques-1].date,date);
|
||||||
@ -1125,15 +1189,6 @@ int main(int argc, char *argv[])
|
|||||||
decodes[uniques-1].drift=drift1;
|
decodes[uniques-1].drift=drift1;
|
||||||
decodes[uniques-1].cycles=cycles;
|
decodes[uniques-1].cycles=cycles;
|
||||||
decodes[uniques-1].jitter=ii;
|
decodes[uniques-1].jitter=ii;
|
||||||
|
|
||||||
/* For timing tests
|
|
||||||
|
|
||||||
fprintf(fdiag,
|
|
||||||
"%6s %4s %4.1f %3.0f %4.1f %10.7f %-18s %2d %5u %4d %6.1f\n",
|
|
||||||
date,uttime,sync1*10,snr0[j],
|
|
||||||
shift1*dt-2.0, dialfreq+(1500+f1)/1e6,
|
|
||||||
call_loc_pow, (int)drift1, cycles/81, ii, rms);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1180,15 +1235,15 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
printf("<DecodeFinished>\n");
|
printf("<DecodeFinished>\n");
|
||||||
|
|
||||||
fftw_free(fftin);
|
fftwf_free(fftin);
|
||||||
fftw_free(fftout);
|
fftwf_free(fftout);
|
||||||
|
|
||||||
if ((fp_fftw_wisdom_file = fopen(wisdom_fname, "w"))) {
|
if ((fp_fftwf_wisdom_file = fopen(wisdom_fname, "w"))) {
|
||||||
fftw_export_wisdom_to_file(fp_fftw_wisdom_file);
|
fftwf_export_wisdom_to_file(fp_fftwf_wisdom_file);
|
||||||
fclose(fp_fftw_wisdom_file);
|
fclose(fp_fftwf_wisdom_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
ttotal += (double)(clock()-t00)/CLOCKS_PER_SEC;
|
ttotal += (float)(clock()-t00)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
fprintf(ftimer,"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n\n",
|
fprintf(ftimer,"%7.2f %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n\n",
|
||||||
treadwav,tcandidates,tsync0,tsync1,tsync2,tfano,ttotal);
|
treadwav,tcandidates,tsync0,tsync1,tsync2,tfano,ttotal);
|
||||||
@ -1201,7 +1256,7 @@ int main(int argc, char *argv[])
|
|||||||
fprintf(ftimer,"sync_and_demod(0) %7.2f %7.2f\n",tsync0,tsync0/ttotal);
|
fprintf(ftimer,"sync_and_demod(0) %7.2f %7.2f\n",tsync0,tsync0/ttotal);
|
||||||
fprintf(ftimer,"sync_and_demod(1) %7.2f %7.2f\n",tsync1,tsync1/ttotal);
|
fprintf(ftimer,"sync_and_demod(1) %7.2f %7.2f\n",tsync1,tsync1/ttotal);
|
||||||
fprintf(ftimer,"sync_and_demod(2) %7.2f %7.2f\n",tsync2,tsync2/ttotal);
|
fprintf(ftimer,"sync_and_demod(2) %7.2f %7.2f\n",tsync2,tsync2/ttotal);
|
||||||
fprintf(ftimer,"Fano decoder %7.2f %7.2f\n",tfano,tfano/ttotal);
|
fprintf(ftimer,"Stack/Fano decoder %7.2f %7.2f\n",tfano,tfano/ttotal);
|
||||||
fprintf(ftimer,"-----------------------------------\n");
|
fprintf(ftimer,"-----------------------------------\n");
|
||||||
fprintf(ftimer,"Total %7.2f %7.2f\n",ttotal,1.0);
|
fprintf(ftimer,"Total %7.2f %7.2f\n",ttotal,1.0);
|
||||||
|
|
||||||
@ -1209,9 +1264,9 @@ int main(int argc, char *argv[])
|
|||||||
fclose(fwsprd);
|
fclose(fwsprd);
|
||||||
// fclose(fdiag);
|
// fclose(fdiag);
|
||||||
fclose(ftimer);
|
fclose(ftimer);
|
||||||
fftw_destroy_plan(PLAN1);
|
fftwf_destroy_plan(PLAN1);
|
||||||
fftw_destroy_plan(PLAN2);
|
fftwf_destroy_plan(PLAN2);
|
||||||
fftw_destroy_plan(PLAN3);
|
fftwf_destroy_plan(PLAN3);
|
||||||
|
|
||||||
if( usehashtable ) {
|
if( usehashtable ) {
|
||||||
fhash=fopen(hash_fname,"w");
|
fhash=fopen(hash_fname,"w");
|
||||||
@ -1223,6 +1278,10 @@ int main(int argc, char *argv[])
|
|||||||
fclose(fhash);
|
fclose(fhash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( stackdecoder ) {
|
||||||
|
free(stack);
|
||||||
|
}
|
||||||
|
|
||||||
if(writenoise == 999) return -1; //Silence compiler warning
|
if(writenoise == 999) return -1; //Silence compiler warning
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user