mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2025-06-16 13:32:25 -04:00
Further work on signal subtraction. wsprd_exp now has subtraction and two-pass options.
git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@5617 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
parent
cecb01b446
commit
1fb652ddf2
@ -194,9 +194,9 @@ void sync_and_demodulate(double *id, double *qd, long np,
|
|||||||
float dt=1.0/375.0, df=375.0/256.0, fbest=0.0;
|
float dt=1.0/375.0, df=375.0/256.0, fbest=0.0;
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
double pi=4.*atan(1.0),twopidt;
|
double pi=4.*atan(1.0),twopidt;
|
||||||
float f0=0.0,fp,fplast=-10000.0,ss;
|
float f0=0.0,fp,ss;
|
||||||
int lag;
|
int lag;
|
||||||
|
static float fplast=-10000.0;
|
||||||
double i0[162],q0[162],i1[162],q1[162],i2[162],q2[162],i3[162],q3[162];
|
double i0[162],q0[162],i1[162],q1[162],i2[162],q2[162],i3[162],q3[162];
|
||||||
double p0,p1,p2,p3,cmet,totp,syncmax,fac;
|
double p0,p1,p2,p3,cmet,totp,syncmax,fac;
|
||||||
double c0[256],s0[256],c1[256],s1[256],c2[256],s2[256],c3[256],s3[256];
|
double c0[256],s0[256],c1[256],s1[256],c2[256],s2[256],c3[256],s3[256];
|
||||||
@ -220,7 +220,7 @@ void sync_and_demodulate(double *id, double *qd, long np,
|
|||||||
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 + ((float)*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=2*pi*(fp-1.5*df)*dt;
|
dphi0=twopidt*(fp-1.5*df);
|
||||||
cdphi0=cos(dphi0);
|
cdphi0=cos(dphi0);
|
||||||
sdphi0=sin(dphi0);
|
sdphi0=sin(dphi0);
|
||||||
|
|
||||||
@ -343,16 +343,16 @@ void subtract_signal(double *id, double *qd, long np,
|
|||||||
for (i=0; i<162; i++) {
|
for (i=0; i<162; i++) {
|
||||||
fp = f0 + ((float)drift0/2.0)*((float)i-81.0)/81.0;
|
fp = f0 + ((float)drift0/2.0)*((float)i-81.0)/81.0;
|
||||||
|
|
||||||
dphi=twopidt*(fp+((float)channel_symbols[i]-1.5)*df);
|
dphi=twopidt*(fp+((float)channel_symbols[i]-1.5)*df);
|
||||||
cdphi=cos(dphi);
|
cdphi=cos(dphi);
|
||||||
sdphi=sin(dphi);
|
sdphi=sin(dphi);
|
||||||
|
|
||||||
c0[0]=1; s0[0]=0;
|
c0[0]=1; s0[0]=0;
|
||||||
|
|
||||||
for (j=1; j<256; j++) {
|
for (j=1; j<256; j++) {
|
||||||
c0[j]=c0[j-1]*cdphi - s0[j-1]*sdphi;
|
c0[j]=c0[j-1]*cdphi - s0[j-1]*sdphi;
|
||||||
s0[j]=c0[j-1]*sdphi + s0[j-1]*cdphi;
|
s0[j]=c0[j-1]*sdphi + s0[j-1]*cdphi;
|
||||||
}
|
}
|
||||||
|
|
||||||
i0=0.0; q0=0.0;
|
i0=0.0; q0=0.0;
|
||||||
|
|
||||||
@ -366,27 +366,17 @@ void subtract_signal(double *id, double *qd, long np,
|
|||||||
|
|
||||||
// subtract the signal here.
|
// subtract the signal here.
|
||||||
|
|
||||||
i0=i0/256.0;
|
i0=i0/256.0; //will be wrong for partial symbols at the edges...
|
||||||
q0=q0/256.0;
|
q0=q0/256.0;
|
||||||
double p0=i0*i0+q0*q0;
|
|
||||||
double is=0, qs=0;
|
|
||||||
|
|
||||||
for (j=0; j<256; j++) {
|
for (j=0; j<256; j++) {
|
||||||
k=shift0+i*256+j;
|
k=shift0+i*256+j;
|
||||||
if( (k>0) & (k<np) ) {
|
if( (k>0) & (k<np) ) {
|
||||||
id[k]=id[k]- (i0*c0[j] - q0*s0[j]);
|
id[k]=id[k]- (i0*c0[j] - q0*s0[j]);
|
||||||
qd[k]=qd[k]- (q0*c0[j] + i0*s0[j]);
|
qd[k]=qd[k]- (q0*c0[j] + i0*s0[j]);
|
||||||
is=is+id[k];
|
|
||||||
qs=qs+qd[k];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is=is/256.0;
|
|
||||||
qs=qs/256.0;
|
|
||||||
double p1=is*is+qs*qs;
|
|
||||||
// printf("symbol %d i0: %f q0: %f is: %f qs: %f\n",i,i0,q0,is,qs);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,7 +428,8 @@ void usage(void)
|
|||||||
printf(" -m decode wspr-15 .wav file\n");
|
printf(" -m decode wspr-15 .wav file\n");
|
||||||
printf(" -n write noise estimates to file noise.dat\n");
|
printf(" -n write noise estimates to file noise.dat\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 slow mode - much slower, yields a few more decodes\n");
|
printf(" -s signal subtraction mode\n");
|
||||||
|
printf(" -t signal subtraction followed by a second pass\n");
|
||||||
printf(" -v verbose mode\n");
|
printf(" -v verbose mode\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.42)\n");
|
||||||
@ -452,15 +443,16 @@ int main(int argc, char *argv[])
|
|||||||
int i,j,k;
|
int i,j,k;
|
||||||
unsigned char *symbols, *decdata;
|
unsigned char *symbols, *decdata;
|
||||||
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,*grid,*grid6, *call_loc_pow, *cdbm;
|
char *callsign, *call_loc_pow;
|
||||||
char *ptr_to_infile,*ptr_to_infile_suffix;
|
char *ptr_to_infile,*ptr_to_infile_suffix;
|
||||||
char *data_dir=NULL;
|
char *data_dir=NULL;
|
||||||
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,writenoise=0,usehashtable=1,wspr_type=2;
|
int c,delta,maxpts=65536,verbose=0,quickmode=0;
|
||||||
|
int writenoise=0,usehashtable=1,wspr_type=2, subtraction=0, ipass, npasses=1;
|
||||||
int shift1, lagmin, lagmax, lagstep, worth_a_try, not_decoded;
|
int shift1, lagmin, lagmax, lagstep, worth_a_try, not_decoded;
|
||||||
unsigned int nbits;
|
unsigned int nbits=81;
|
||||||
unsigned int npoints, metric, maxcycles, cycles, maxnp;
|
unsigned int npoints, metric, maxcycles, 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];
|
||||||
@ -469,12 +461,27 @@ int main(int argc, char *argv[])
|
|||||||
double dialfreq_cmdline=0.0, dialfreq, freq_print;
|
double dialfreq_cmdline=0.0, dialfreq, freq_print;
|
||||||
float dialfreq_error=0.0;
|
float dialfreq_error=0.0;
|
||||||
float fmin=-110, fmax=110;
|
float fmin=-110, fmax=110;
|
||||||
float f1, fstep, sync1, drift1, tblank=0, fblank=0;
|
float f1, fstep, sync1, drift1;
|
||||||
|
float psavg[512];
|
||||||
double *idat, *qdat;
|
double *idat, *qdat;
|
||||||
clock_t t0,t00;
|
clock_t t0,t00;
|
||||||
double tfano=0.0,treadwav=0.0,tcandidates=0.0,tsync0=0.0;
|
double tfano=0.0,treadwav=0.0,tcandidates=0.0,tsync0=0.0;
|
||||||
double tsync1=0.0,tsync2=0.0,ttotal=0.0;
|
double tsync1=0.0,tsync2=0.0,ttotal=0.0;
|
||||||
|
|
||||||
|
char hashtab[32768][13];
|
||||||
|
memset(hashtab,0,sizeof(char)*32768*13);
|
||||||
|
int nh;
|
||||||
|
symbols=malloc(sizeof(char)*nbits*2);
|
||||||
|
decdata=malloc((nbits+7)/8);
|
||||||
|
callsign=malloc(sizeof(char)*13);
|
||||||
|
call_loc_pow=malloc(sizeof(char)*23);
|
||||||
|
float allfreqs[100];
|
||||||
|
char allcalls[100][13];
|
||||||
|
memset(allfreqs,0,sizeof(float)*100);
|
||||||
|
memset(allcalls,0,sizeof(char)*100*13);
|
||||||
|
|
||||||
|
int uniques=0, noprint=0;
|
||||||
|
|
||||||
// Parameters used for performance-tuning:
|
// Parameters used for performance-tuning:
|
||||||
maxcycles=10000; //Fano timeout limit
|
maxcycles=10000; //Fano timeout limit
|
||||||
double minsync1=0.10; //First sync limit
|
double minsync1=0.10; //First sync limit
|
||||||
@ -495,14 +502,11 @@ int main(int argc, char *argv[])
|
|||||||
idat=malloc(sizeof(double)*maxpts);
|
idat=malloc(sizeof(double)*maxpts);
|
||||||
qdat=malloc(sizeof(double)*maxpts);
|
qdat=malloc(sizeof(double)*maxpts);
|
||||||
|
|
||||||
while ( (c = getopt(argc, argv, "a:b:e:f:Hmnqst:wvz:")) !=-1 ) {
|
while ( (c = getopt(argc, argv, "a:b:e:f:Hmnqstwvz:")) !=-1 ) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a':
|
||||||
data_dir = optarg;
|
data_dir = optarg;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
|
||||||
fblank = strtof(optarg,NULL);
|
|
||||||
break;
|
|
||||||
case 'e':
|
case 'e':
|
||||||
dialfreq_error = strtof(optarg,NULL); // units of Hz
|
dialfreq_error = strtof(optarg,NULL); // units of Hz
|
||||||
// dialfreq_error = dial reading - actual, correct frequency
|
// dialfreq_error = dial reading - actual, correct frequency
|
||||||
@ -523,11 +527,11 @@ int main(int argc, char *argv[])
|
|||||||
quickmode = 1;
|
quickmode = 1;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
maxcycles=20000;
|
subtraction = 1;
|
||||||
iifac=1;
|
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
tblank = strtof(optarg,NULL);
|
subtraction = 1;
|
||||||
|
npasses = 2; //npasses defaults to 1
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
@ -636,192 +640,6 @@ int main(int argc, char *argv[])
|
|||||||
w[i]=sin(0.006147931*i);
|
w[i]=sin(0.006147931*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(ps,0.0, sizeof(float)*512*nffts);
|
|
||||||
for (i=0; i<nffts; i++) {
|
|
||||||
for(j=0; j<512; j++ ) {
|
|
||||||
k=i*128+j;
|
|
||||||
fftin[j][0]=idat[k] * w[j];
|
|
||||||
fftin[j][1]=qdat[k] * w[j];
|
|
||||||
}
|
|
||||||
fftw_execute(PLAN3);
|
|
||||||
for (j=0; j<512; j++ ) {
|
|
||||||
k=j+256;
|
|
||||||
if( k>511 )
|
|
||||||
k=k-512;
|
|
||||||
ps[j][i]=fftout[k][0]*fftout[k][0]+fftout[k][1]*fftout[k][1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fftw_free(fftin);
|
|
||||||
fftw_free(fftout);
|
|
||||||
|
|
||||||
// Compute average spectrum
|
|
||||||
float psavg[512];
|
|
||||||
memset(psavg,0.0, sizeof(float)*512);
|
|
||||||
for (i=0; i<nffts; i++) {
|
|
||||||
for (j=0; j<512; j++) {
|
|
||||||
psavg[j]=psavg[j]+ps[j][i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Smooth with 7-point window and limit spectrum to +/-150 Hz
|
|
||||||
int window[7]={1,1,1,1,1,1,1};
|
|
||||||
float smspec[411];
|
|
||||||
for (i=0; i<411; i++) {
|
|
||||||
smspec[i]=0.0;
|
|
||||||
for(j=-3; j<=3; j++) {
|
|
||||||
k=256-205+i+j;
|
|
||||||
smspec[i]=smspec[i]+window[j+3]*psavg[k];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort spectrum values, then pick off noise level as a percentile
|
|
||||||
float tmpsort[411];
|
|
||||||
for (j=0; j<411; j++) {
|
|
||||||
tmpsort[j]=smspec[j];
|
|
||||||
}
|
|
||||||
qsort(tmpsort, 411, sizeof(float), floatcomp);
|
|
||||||
|
|
||||||
// Noise level of spectrum is estimated as 123/411= 30'th percentile
|
|
||||||
float noise_level = tmpsort[122];
|
|
||||||
|
|
||||||
/* Renormalize spectrum so that (large) peaks represent an estimate of snr.
|
|
||||||
* We know from experience that threshold snr is near -7dB in wspr bandwidth,
|
|
||||||
* corresponding to -7-26.3=-33.3dB in 2500 Hz bandwidth.
|
|
||||||
* The corresponding threshold is -42.3 dB in 2500 Hz bandwidth for WSPR-15. */
|
|
||||||
|
|
||||||
float min_snr, snr_scaling_factor;
|
|
||||||
min_snr = pow(10.0,-7.0/10.0); //this is min snr in wspr bw
|
|
||||||
if( wspr_type == 2 ) {
|
|
||||||
snr_scaling_factor=26.3;
|
|
||||||
} else {
|
|
||||||
snr_scaling_factor=35.3;
|
|
||||||
}
|
|
||||||
for (j=0; j<411; j++) {
|
|
||||||
smspec[j]=smspec[j]/noise_level - 1.0;
|
|
||||||
if( smspec[j] < min_snr) smspec[j]=0.1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find all local maxima in smoothed spectrum.
|
|
||||||
for (i=0; i<200; i++) {
|
|
||||||
freq0[i]=0.0;
|
|
||||||
snr0[i]=0.0;
|
|
||||||
drift0[i]=0.0;
|
|
||||||
shift0[i]=0;
|
|
||||||
sync0[i]=0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int npk=0;
|
|
||||||
for(j=1; j<410; j++) {
|
|
||||||
if((smspec[j]>smspec[j-1]) && (smspec[j]>smspec[j+1]) && (npk<200)) {
|
|
||||||
freq0[npk]=(j-205)*df;
|
|
||||||
snr0[npk]=10*log10(smspec[j])-snr_scaling_factor;
|
|
||||||
npk++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compute corrected fmin, fmax, accounting for dial frequency error
|
|
||||||
fmin += dialfreq_error; // dialfreq_error is in units of Hz
|
|
||||||
fmax += dialfreq_error;
|
|
||||||
|
|
||||||
// Don't waste time on signals outside of the range [fmin,fmax].
|
|
||||||
i=0;
|
|
||||||
for( j=0; j<npk; j++) {
|
|
||||||
if( freq0[j] >= fmin && freq0[j] <= fmax ) {
|
|
||||||
freq0[i]=freq0[j];
|
|
||||||
snr0[i]=snr0[j];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
npk=i;
|
|
||||||
|
|
||||||
t0=clock();
|
|
||||||
/* Make coarse estimates of shift (DT), freq, and drift
|
|
||||||
|
|
||||||
* Look for time offsets up to +/- 8 symbols (about +/- 5.4 s) relative
|
|
||||||
to nominal start time, which is 2 seconds into the file
|
|
||||||
|
|
||||||
* Calculates shift relative to the beginning of the file
|
|
||||||
|
|
||||||
* Negative shifts mean that signal started before start of file
|
|
||||||
|
|
||||||
* The program prints DT = shift-2 s
|
|
||||||
|
|
||||||
* Shifts that cause sync vector to fall off of either end of the data
|
|
||||||
vector are accommodated by "partial decoding", such that missing
|
|
||||||
symbols produce a soft-decision symbol value of 128
|
|
||||||
|
|
||||||
* The frequency drift model is linear, deviation of +/- drift/2 over the
|
|
||||||
span of 162 symbols, with deviation equal to 0 at the center of the
|
|
||||||
signal vector.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int idrift,ifr,if0,ifd,k0;
|
|
||||||
int kindex;
|
|
||||||
float smax,ss,pow,p0,p1,p2,p3;
|
|
||||||
for(j=0; j<npk; j++) { //For each candidate...
|
|
||||||
smax=-1e30;
|
|
||||||
if0=freq0[j]/df+256;
|
|
||||||
for (ifr=if0-1; ifr<=if0+1; ifr++) { //Freq search
|
|
||||||
for( k0=-10; k0<22; k0++) { //Time search
|
|
||||||
for (idrift=-maxdrift; idrift<=maxdrift; idrift++) { //Drift search
|
|
||||||
ss=0.0;
|
|
||||||
pow=0.0;
|
|
||||||
for (k=0; k<162; k++) { //Sum over symbols
|
|
||||||
ifd=ifr+((float)k-81.0)/81.0*( (float)idrift )/(2.0*df);
|
|
||||||
kindex=k0+2*k;
|
|
||||||
if( kindex < nffts ) {
|
|
||||||
p0=ps[ifd-3][kindex];
|
|
||||||
p1=ps[ifd-1][kindex];
|
|
||||||
p2=ps[ifd+1][kindex];
|
|
||||||
p3=ps[ifd+3][kindex];
|
|
||||||
|
|
||||||
p0=sqrt(p0);
|
|
||||||
p1=sqrt(p1);
|
|
||||||
p2=sqrt(p2);
|
|
||||||
p3=sqrt(p3);
|
|
||||||
|
|
||||||
ss=ss+(2*pr3[k]-1)*((p1+p3)-(p0+p2));
|
|
||||||
pow=pow+p0+p1+p2+p3;
|
|
||||||
sync1=ss/pow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( sync1 > smax ) { //Save coarse parameters
|
|
||||||
smax=sync1;
|
|
||||||
shift0[j]=128*(k0+1);
|
|
||||||
drift0[j]=idrift;
|
|
||||||
freq0[j]=(ifr-256)*df;
|
|
||||||
sync0[j]=sync1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tcandidates += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
|
||||||
|
|
||||||
nbits=81;
|
|
||||||
symbols=malloc(sizeof(char)*nbits*2);
|
|
||||||
memset(symbols,0,sizeof(char)*nbits*2);
|
|
||||||
decdata=malloc((nbits+7)/8);
|
|
||||||
grid=malloc(sizeof(char)*5);
|
|
||||||
grid6=malloc(sizeof(char)*7);
|
|
||||||
callsign=malloc(sizeof(char)*13);
|
|
||||||
call_loc_pow=malloc(sizeof(char)*23);
|
|
||||||
cdbm=malloc(sizeof(char)*3);
|
|
||||||
float allfreqs[npk];
|
|
||||||
memset(allfreqs,0,sizeof(float)*npk);
|
|
||||||
char allcalls[npk][13];
|
|
||||||
memset(allcalls,0,sizeof(char)*npk*13);
|
|
||||||
memset(grid,0,sizeof(char)*5);
|
|
||||||
memset(grid6,0,sizeof(char)*7);
|
|
||||||
memset(callsign,0,sizeof(char)*13);
|
|
||||||
memset(call_loc_pow,0,sizeof(char)*23);
|
|
||||||
memset(cdbm,0,sizeof(char)*3);
|
|
||||||
char hashtab[32768][13];
|
|
||||||
memset(hashtab,0,sizeof(char)*32768*13);
|
|
||||||
int nh;
|
|
||||||
|
|
||||||
if( usehashtable ) {
|
if( usehashtable ) {
|
||||||
char line[80], hcall[12];
|
char line[80], hcall[12];
|
||||||
if( (fhash=fopen(hash_fname,"r+")) ) {
|
if( (fhash=fopen(hash_fname,"r+")) ) {
|
||||||
@ -835,163 +653,360 @@ int main(int argc, char *argv[])
|
|||||||
fclose(fhash);
|
fclose(fhash);
|
||||||
}
|
}
|
||||||
|
|
||||||
int uniques=0, noprint=0;
|
//*************** main loop starts here *****************
|
||||||
/*
|
for (ipass=0; ipass<npasses; ipass++) {
|
||||||
Refine the estimates of freq, shift using sync as a metric.
|
|
||||||
Sync is calculated such that it is a float taking values in the range
|
|
||||||
[0.0,1.0].
|
|
||||||
|
|
||||||
Function sync_and_demodulate has three modes of operation
|
memset(ps,0.0, sizeof(float)*512*nffts);
|
||||||
mode is the last argument:
|
for (i=0; i<nffts; i++) {
|
||||||
|
for(j=0; j<512; j++ ) {
|
||||||
|
k=i*128+j;
|
||||||
|
fftin[j][0]=idat[k] * w[j];
|
||||||
|
fftin[j][1]=qdat[k] * w[j];
|
||||||
|
}
|
||||||
|
fftw_execute(PLAN3);
|
||||||
|
for (j=0; j<512; j++ ) {
|
||||||
|
k=j+256;
|
||||||
|
if( k>511 )
|
||||||
|
k=k-512;
|
||||||
|
ps[j][i]=fftout[k][0]*fftout[k][0]+fftout[k][1]*fftout[k][1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
0 = no frequency or drift search. find best time lag.
|
// Compute average spectrum
|
||||||
1 = no time lag or drift search. find best frequency.
|
memset(psavg,0.0, sizeof(float)*512);
|
||||||
2 = no frequency or time lag search. Calculate soft-decision
|
for (i=0; i<nffts; i++) {
|
||||||
symbols using passed frequency and shift.
|
for (j=0; j<512; j++) {
|
||||||
|
psavg[j]=psavg[j]+ps[j][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NB: best possibility for OpenMP may be here: several worker threads
|
// Smooth with 7-point window and limit spectrum to +/-150 Hz
|
||||||
could each work on one candidate at a time.
|
int window[7]={1,1,1,1,1,1,1};
|
||||||
*/
|
float smspec[411];
|
||||||
|
for (i=0; i<411; i++) {
|
||||||
|
smspec[i]=0.0;
|
||||||
|
for(j=-3; j<=3; j++) {
|
||||||
|
k=256-205+i+j;
|
||||||
|
smspec[i]=smspec[i]+window[j+3]*psavg[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (j=0; j<npk; j++) {
|
// Sort spectrum values, then pick off noise level as a percentile
|
||||||
f1=freq0[j];
|
float tmpsort[411];
|
||||||
drift1=drift0[j];
|
for (j=0; j<411; j++) {
|
||||||
shift1=shift0[j];
|
tmpsort[j]=smspec[j];
|
||||||
sync1=sync0[j];
|
}
|
||||||
|
qsort(tmpsort, 411, sizeof(float), floatcomp);
|
||||||
|
|
||||||
// Fine search for best sync lag (mode 0)
|
// Noise level of spectrum is estimated as 123/411= 30'th percentile
|
||||||
fstep=0.0;
|
float noise_level = tmpsort[122];
|
||||||
lagmin=shift1-144;
|
|
||||||
lagmax=shift1+144;
|
|
||||||
lagstep=8;
|
|
||||||
if(quickmode) lagstep=16;
|
|
||||||
t0 = clock();
|
|
||||||
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, fstep, &shift1,
|
|
||||||
lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 0);
|
|
||||||
tsync0 += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
|
||||||
|
|
||||||
// Fine search for frequency peak (mode 1)
|
/* Renormalize spectrum so that (large) peaks represent an estimate of snr.
|
||||||
fstep=0.1;
|
* We know from experience that threshold snr is near -7dB in wspr bandwidth,
|
||||||
t0 = clock();
|
* corresponding to -7-26.3=-33.3dB in 2500 Hz bandwidth.
|
||||||
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, fstep, &shift1,
|
* The corresponding threshold is -42.3 dB in 2500 Hz bandwidth for WSPR-15. */
|
||||||
lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 1);
|
|
||||||
tsync1 += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
|
||||||
|
|
||||||
if( sync1 > minsync1 ) {
|
float min_snr, snr_scaling_factor;
|
||||||
worth_a_try = 1;
|
min_snr = pow(10.0,-7.0/10.0); //this is min snr in wspr bw
|
||||||
|
if( wspr_type == 2 ) {
|
||||||
|
snr_scaling_factor=26.3;
|
||||||
} else {
|
} else {
|
||||||
worth_a_try = 0;
|
snr_scaling_factor=35.3;
|
||||||
|
}
|
||||||
|
for (j=0; j<411; j++) {
|
||||||
|
smspec[j]=smspec[j]/noise_level - 1.0;
|
||||||
|
if( smspec[j] < min_snr) smspec[j]=0.1;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int idt=0, ii=0, jiggered_shift;
|
// Find all local maxima in smoothed spectrum.
|
||||||
double y,sq,rms;
|
for (i=0; i<200; i++) {
|
||||||
not_decoded=1;
|
freq0[i]=0.0;
|
||||||
|
snr0[i]=0.0;
|
||||||
|
drift0[i]=0.0;
|
||||||
|
shift0[i]=0;
|
||||||
|
sync0[i]=0.0;
|
||||||
|
}
|
||||||
|
|
||||||
while ( worth_a_try && not_decoded && idt<=(128/iifac)) {
|
int npk=0;
|
||||||
ii=(idt+1)/2;
|
for(j=1; j<410; j++) {
|
||||||
if( idt%2 == 1 ) ii=-ii;
|
if((smspec[j]>smspec[j-1]) && (smspec[j]>smspec[j+1]) && (npk<200)) {
|
||||||
ii=iifac*ii;
|
freq0[npk]=(j-205)*df;
|
||||||
jiggered_shift=shift1+ii;
|
snr0[npk]=10*log10(smspec[j])-snr_scaling_factor;
|
||||||
|
npk++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Use mode 2 to get soft-decision symbols
|
// Compute corrected fmin, fmax, accounting for dial frequency error
|
||||||
|
fmin += dialfreq_error; // dialfreq_error is in units of Hz
|
||||||
|
fmax += dialfreq_error;
|
||||||
|
|
||||||
|
// Don't waste time on signals outside of the range [fmin,fmax].
|
||||||
|
i=0;
|
||||||
|
for( j=0; j<npk; j++) {
|
||||||
|
if( freq0[j] >= fmin && freq0[j] <= fmax ) {
|
||||||
|
freq0[i]=freq0[j];
|
||||||
|
snr0[i]=snr0[j];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
npk=i;
|
||||||
|
|
||||||
|
// bubble sort on snr, bringing freq along for the ride
|
||||||
|
int pass;
|
||||||
|
float tmp;
|
||||||
|
for (pass = 1; pass <= npk - 1; pass++) {
|
||||||
|
for (k = 0; k < npk - pass ; k++) {
|
||||||
|
if (snr0[k] < snr0[k+1]) {
|
||||||
|
tmp = snr0[k];
|
||||||
|
snr0[k] = snr0[k+1];
|
||||||
|
snr0[k+1] = tmp;
|
||||||
|
tmp = freq0[k];
|
||||||
|
freq0[k] = freq0[k+1];
|
||||||
|
freq0[k+1] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t0=clock();
|
||||||
|
/* Make coarse estimates of shift (DT), freq, and drift
|
||||||
|
|
||||||
|
* Look for time offsets up to +/- 8 symbols (about +/- 5.4 s) relative
|
||||||
|
to nominal start time, which is 2 seconds into the file
|
||||||
|
|
||||||
|
* Calculates shift relative to the beginning of the file
|
||||||
|
|
||||||
|
* Negative shifts mean that signal started before start of file
|
||||||
|
|
||||||
|
* The program prints DT = shift-2 s
|
||||||
|
|
||||||
|
* Shifts that cause sync vector to fall off of either end of the data
|
||||||
|
vector are accommodated by "partial decoding", such that missing
|
||||||
|
symbols produce a soft-decision symbol value of 128
|
||||||
|
|
||||||
|
* The frequency drift model is linear, deviation of +/- drift/2 over the
|
||||||
|
span of 162 symbols, with deviation equal to 0 at the center of the
|
||||||
|
signal vector.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int idrift,ifr,if0,ifd,k0;
|
||||||
|
int kindex;
|
||||||
|
float smax,ss,pow,p0,p1,p2,p3;
|
||||||
|
for(j=0; j<npk; j++) { //For each candidate...
|
||||||
|
smax=-1e30;
|
||||||
|
if0=freq0[j]/df+256;
|
||||||
|
for (ifr=if0-1; ifr<=if0+1; ifr++) { //Freq search
|
||||||
|
for( k0=-10; k0<22; k0++) { //Time search
|
||||||
|
for (idrift=-maxdrift; idrift<=maxdrift; idrift++) { //Drift search
|
||||||
|
ss=0.0;
|
||||||
|
pow=0.0;
|
||||||
|
for (k=0; k<162; k++) { //Sum over symbols
|
||||||
|
ifd=ifr+((float)k-81.0)/81.0*( (float)idrift )/(2.0*df);
|
||||||
|
kindex=k0+2*k;
|
||||||
|
if( kindex < nffts ) {
|
||||||
|
p0=ps[ifd-3][kindex];
|
||||||
|
p1=ps[ifd-1][kindex];
|
||||||
|
p2=ps[ifd+1][kindex];
|
||||||
|
p3=ps[ifd+3][kindex];
|
||||||
|
|
||||||
|
p0=sqrt(p0);
|
||||||
|
p1=sqrt(p1);
|
||||||
|
p2=sqrt(p2);
|
||||||
|
p3=sqrt(p3);
|
||||||
|
|
||||||
|
ss=ss+(2*pr3[k]-1)*((p1+p3)-(p0+p2));
|
||||||
|
pow=pow+p0+p1+p2+p3;
|
||||||
|
sync1=ss/pow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( sync1 > smax ) { //Save coarse parameters
|
||||||
|
smax=sync1;
|
||||||
|
shift0[j]=128*(k0+1);
|
||||||
|
drift0[j]=idrift;
|
||||||
|
freq0[j]=(ifr-256)*df;
|
||||||
|
sync0[j]=sync1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tcandidates += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Refine the estimates of freq, shift using sync as a metric.
|
||||||
|
Sync is calculated such that it is a float taking values in the range
|
||||||
|
[0.0,1.0].
|
||||||
|
|
||||||
|
Function sync_and_demodulate has three modes of operation
|
||||||
|
mode is the last argument:
|
||||||
|
|
||||||
|
0 = no frequency or drift search. find best time lag.
|
||||||
|
1 = no time lag or drift search. find best frequency.
|
||||||
|
2 = no frequency or time lag search. Calculate soft-decision
|
||||||
|
symbols using passed frequency and shift.
|
||||||
|
|
||||||
|
NB: best possibility for OpenMP may be here: several worker threads
|
||||||
|
could each work on one candidate at a time.
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (j=0; j<npk; j++) {
|
||||||
|
|
||||||
|
memset(symbols,0,sizeof(char)*nbits*2);
|
||||||
|
memset(callsign,0,sizeof(char)*13);
|
||||||
|
memset(call_loc_pow,0,sizeof(char)*23);
|
||||||
|
|
||||||
|
f1=freq0[j];
|
||||||
|
drift1=drift0[j];
|
||||||
|
shift1=shift0[j];
|
||||||
|
sync1=sync0[j];
|
||||||
|
|
||||||
|
// Fine search for best sync lag (mode 0)
|
||||||
|
fstep=0.0;
|
||||||
|
lagmin=shift1-144;
|
||||||
|
lagmax=shift1+144;
|
||||||
|
lagstep=8;
|
||||||
|
if(quickmode) lagstep=16;
|
||||||
t0 = clock();
|
t0 = clock();
|
||||||
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, fstep,
|
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, fstep, &shift1,
|
||||||
&jiggered_shift, lagmin, lagmax, lagstep, &drift1, symfac,
|
lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 0);
|
||||||
&sync1, 2);
|
tsync0 += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
tsync2 += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
|
||||||
|
|
||||||
sq=0.0;
|
// Fine search for frequency peak (mode 1)
|
||||||
for(i=0; i<162; i++) {
|
fstep=0.1;
|
||||||
y=(double)symbols[i] - 128.0;
|
t0 = clock();
|
||||||
sq += y*y;
|
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, fstep, &shift1,
|
||||||
|
lagmin, lagmax, lagstep, &drift1, symfac, &sync1, 1);
|
||||||
|
tsync1 += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
|
if( sync1 > minsync1 ) {
|
||||||
|
worth_a_try = 1;
|
||||||
|
} else {
|
||||||
|
worth_a_try = 0;
|
||||||
}
|
}
|
||||||
rms=sqrt(sq/162.0);
|
|
||||||
|
|
||||||
if((sync1 > minsync2) && (rms > minrms)) {
|
int idt=0, ii=0, jiggered_shift;
|
||||||
deinterleave(symbols);
|
double y,sq,rms;
|
||||||
|
not_decoded=1;
|
||||||
|
|
||||||
|
while ( worth_a_try && not_decoded && idt<=(128/iifac)) {
|
||||||
|
ii=(idt+1)/2;
|
||||||
|
if( idt%2 == 1 ) ii=-ii;
|
||||||
|
ii=iifac*ii;
|
||||||
|
jiggered_shift=shift1+ii;
|
||||||
|
|
||||||
|
// Use mode 2 to get soft-decision symbols
|
||||||
t0 = clock();
|
t0 = clock();
|
||||||
not_decoded = fano(&metric,&cycles,&maxnp,decdata,symbols,nbits,
|
sync_and_demodulate(idat, qdat, npoints, symbols, &f1, fstep,
|
||||||
mettab,delta,maxcycles);
|
&jiggered_shift, lagmin, lagmax, lagstep, &drift1, symfac,
|
||||||
tfano += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
&sync1, 2);
|
||||||
|
tsync2 += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
/* ### Used for timing tests:
|
sq=0.0;
|
||||||
if(not_decoded) fprintf(fdiag,
|
for(i=0; i<162; i++) {
|
||||||
"%6s %4s %4.1f %3.0f %4.1f %10.7f %-18s %2d %5u %4d %6.1f %2d\n",
|
y=(double)symbols[i] - 128.0;
|
||||||
date,uttime,sync1*10,snr0[j], shift1*dt-2.0, dialfreq+(1500+f1)/1e6,
|
sq += y*y;
|
||||||
"@ ", (int)drift1, cycles/81, ii, rms, maxnp);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
idt++;
|
|
||||||
if( quickmode ) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( worth_a_try && !not_decoded ) {
|
|
||||||
for(i=0; i<11; i++) {
|
|
||||||
if( decdata[i]>127 ) {
|
|
||||||
message[i]=decdata[i]-256;
|
|
||||||
} else {
|
|
||||||
message[i]=decdata[i];
|
|
||||||
}
|
}
|
||||||
}
|
rms=sqrt(sq/162.0);
|
||||||
|
|
||||||
// Unpack the decoded message, update the hashtable, apply
|
if((sync1 > minsync2) && (rms > minrms)) {
|
||||||
// sanity checks on grid and power, and return
|
deinterleave(symbols);
|
||||||
// call_loc_pow string and also callsign (for de-duping).
|
t0 = clock();
|
||||||
noprint=unpk_(message,hashtab,call_loc_pow,callsign);
|
not_decoded = fano(&metric,&cycles,&maxnp,decdata,symbols,nbits,
|
||||||
|
mettab,delta,maxcycles);
|
||||||
|
tfano += (double)(clock()-t0)/CLOCKS_PER_SEC;
|
||||||
|
|
||||||
unsigned char channel_symbols[162];
|
/* ### Used for timing tests:
|
||||||
get_wspr_channel_symbols(call_loc_pow, channel_symbols);
|
if(not_decoded) fprintf(fdiag,
|
||||||
|
"%6s %4s %4.1f %3.0f %4.1f %10.7f %-18s %2d %5u %4d %6.1f %2d\n",
|
||||||
subtract_signal(idat, qdat, npoints, f1, shift1, drift1, channel_symbols);
|
date,uttime,sync1*10,snr0[j], shift1*dt-2.0, dialfreq+(1500+f1)/1e6,
|
||||||
|
"@ ", (int)drift1, cycles/81, ii, rms, maxnp);
|
||||||
// Remove dupes (same callsign and freq within 1 Hz)
|
*/
|
||||||
int dupe=0;
|
|
||||||
for (i=0; i<npk; i++) {
|
|
||||||
if(!strcmp(callsign,allcalls[i]) &&
|
|
||||||
(fabs(f1-allfreqs[i]) <1.0)) dupe=1;
|
|
||||||
}
|
|
||||||
if( (verbose || !dupe) && !noprint) {
|
|
||||||
uniques++;
|
|
||||||
strcpy(allcalls[uniques],callsign);
|
|
||||||
allfreqs[uniques]=f1;
|
|
||||||
// Add an extra space at the end of each line so that wspr-x doesn't
|
|
||||||
// truncate the power (TNX to DL8FCL!)
|
|
||||||
|
|
||||||
if( wspr_type == 15 ) {
|
|
||||||
freq_print=dialfreq+(1500+112.5+f1/8.0)/1e6;
|
|
||||||
dt_print=shift1*8*dt-2.0;
|
|
||||||
} else {
|
|
||||||
freq_print=dialfreq+(1500+f1)/1e6;
|
|
||||||
dt_print=shift1*dt-2.0;
|
|
||||||
}
|
}
|
||||||
printf("%4s %3.0f %4.1f %10.6f %2d %-s \n",
|
idt++;
|
||||||
uttime, snr0[j],dt_print,freq_print,
|
if( quickmode ) break;
|
||||||
(int)drift1, call_loc_pow);
|
}
|
||||||
|
|
||||||
fprintf(fall_wspr,
|
if( worth_a_try && !not_decoded ) {
|
||||||
"%6s %4s %3.0f %3.0f %4.1f %10.7f %-22s %2d %5u %4d\n",
|
|
||||||
date,uttime,sync1*10,snr0[j],
|
|
||||||
dt_print, freq_print,
|
|
||||||
call_loc_pow, (int)drift1, cycles/81, ii);
|
|
||||||
|
|
||||||
fprintf(fwsprd,"%6s %4s %3d %3.0f %4.1f %10.6f %-22s %2d %5u %4d\n",
|
for(i=0; i<11; i++) {
|
||||||
date,uttime,(int)(sync1*10),snr0[j],
|
|
||||||
dt_print, freq_print,
|
|
||||||
call_loc_pow, (int)drift1, cycles/81, ii);
|
|
||||||
|
|
||||||
/* For timing tests
|
if( decdata[i]>127 ) {
|
||||||
|
message[i]=decdata[i]-256;
|
||||||
|
} else {
|
||||||
|
message[i]=decdata[i];
|
||||||
|
}
|
||||||
|
|
||||||
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],
|
// Unpack the decoded message, update the hashtable, apply
|
||||||
shift1*dt-2.0, dialfreq+(1500+f1)/1e6,
|
// sanity checks on grid and power, and return
|
||||||
call_loc_pow, (int)drift1, cycles/81, ii, rms);
|
// call_loc_pow string and also callsign (for de-duping).
|
||||||
*/
|
noprint=unpk_(message,hashtab,call_loc_pow,callsign);
|
||||||
|
|
||||||
|
if( subtraction ) {
|
||||||
|
|
||||||
|
unsigned char channel_symbols[162];
|
||||||
|
|
||||||
|
if( get_wspr_channel_symbols(call_loc_pow, channel_symbols) ) {
|
||||||
|
subtract_signal(idat, qdat, npoints, f1, shift1, drift1, channel_symbols);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove dupes (same callsign and freq within 3 Hz)
|
||||||
|
int dupe=0;
|
||||||
|
for (i=0; i<uniques; i++) {
|
||||||
|
if(!strcmp(callsign,allcalls[i]) &&
|
||||||
|
(fabs(f1-allfreqs[i]) <3.0)) dupe=1;
|
||||||
|
}
|
||||||
|
if( (verbose || !dupe) && !noprint) {
|
||||||
|
uniques++;
|
||||||
|
strcpy(allcalls[uniques],callsign);
|
||||||
|
allfreqs[uniques]=f1;
|
||||||
|
// Add an extra space at the end of each line so that wspr-x doesn't
|
||||||
|
// truncate the power (TNX to DL8FCL!)
|
||||||
|
|
||||||
|
if( wspr_type == 15 ) {
|
||||||
|
freq_print=dialfreq+(1500+112.5+f1/8.0)/1e6;
|
||||||
|
dt_print=shift1*8*dt-2.0;
|
||||||
|
} else {
|
||||||
|
freq_print=dialfreq+(1500+f1)/1e6;
|
||||||
|
dt_print=shift1*dt-2.0;
|
||||||
|
}
|
||||||
|
printf("%4s %3.0f %4.1f %10.6f %2d %-s \n",
|
||||||
|
uttime, snr0[j],dt_print,freq_print,
|
||||||
|
(int)drift1, call_loc_pow);
|
||||||
|
|
||||||
|
fprintf(fall_wspr,
|
||||||
|
"%6s %4s %3.0f %3.0f %4.1f %10.7f %-22s %2d %5u %4d\n",
|
||||||
|
date,uttime,sync1*10,snr0[j],
|
||||||
|
dt_print, freq_print,
|
||||||
|
call_loc_pow, (int)drift1, cycles/81, ii);
|
||||||
|
|
||||||
|
fprintf(fwsprd,"%6s %4s %3d %3.0f %4.1f %10.6f %-22s %2d %5u %4d\n",
|
||||||
|
date,uttime,(int)(sync1*10),snr0[j],
|
||||||
|
dt_print, freq_print,
|
||||||
|
call_loc_pow, (int)drift1, cycles/81, 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);
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("<DecodeFinished>\n");
|
printf("<DecodeFinished>\n");
|
||||||
|
|
||||||
|
fftw_free(fftin);
|
||||||
|
fftw_free(fftout);
|
||||||
|
|
||||||
if ((fp_fftw_wisdom_file = fopen(wisdom_fname, "w"))) {
|
if ((fp_fftw_wisdom_file = fopen(wisdom_fname, "w"))) {
|
||||||
fftw_export_wisdom_to_file(fp_fftw_wisdom_file);
|
fftw_export_wisdom_to_file(fp_fftw_wisdom_file);
|
||||||
fclose(fp_fftw_wisdom_file);
|
fclose(fp_fftw_wisdom_file);
|
||||||
@ -1032,13 +1047,13 @@ int main(int argc, char *argv[])
|
|||||||
fclose(fhash);
|
fclose(fhash);
|
||||||
}
|
}
|
||||||
|
|
||||||
char c2filename[15];
|
// char c2filename[15];
|
||||||
double carrierfreq=dialfreq;
|
// double carrierfreq=dialfreq;
|
||||||
int wsprtype=2;
|
// int wsprtype=2;
|
||||||
strcpy(c2filename,"000000_0001.c2");
|
// strcpy(c2filename,"000000_0001.c2");
|
||||||
printf("Writing %s\n",c2filename);
|
// printf("Writing %s\n",c2filename);
|
||||||
writec2file(c2filename, wsprtype, carrierfreq, idat, qdat);
|
// writec2file(c2filename, wsprtype, carrierfreq, idat, qdat);
|
||||||
|
|
||||||
if(fblank+tblank+writenoise == 999) return -1; //Silence compiler warning
|
if(writenoise == 999) return -1; //Silence compiler warning
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -124,22 +124,27 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
extern int optind;
|
extern int optind;
|
||||||
int i, c, printchannel=0;
|
int i, c, printchannel=0, writec2=0;
|
||||||
float snr=50.0;
|
float snr=50.0;
|
||||||
char *message, *c2filename;
|
char *message, *c2filename;
|
||||||
|
c2filename=malloc(sizeof(char)*15);
|
||||||
|
|
||||||
// message length is 22 characters
|
// message length is 22 characters
|
||||||
message=malloc(sizeof(char)*23);
|
message=malloc(sizeof(char)*23);
|
||||||
c2filename=malloc(sizeof(char)*15);
|
|
||||||
memset(c2filename,0,sizeof(char)*15);
|
|
||||||
|
|
||||||
|
strcpy(c2filename,"000000_0001.c2");
|
||||||
|
printf("%s\n",c2filename);
|
||||||
while ( (c = getopt(argc, argv, "cdo:s:")) !=-1 ) {
|
while ( (c = getopt(argc, argv, "cdo:s:")) !=-1 ) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
printchannel=1;
|
printchannel=1;
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
printdata=1;
|
printdata=1;
|
||||||
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
c2filename = optarg;
|
c2filename = optarg;
|
||||||
|
writec2=1;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
snr = (float)atoi(optarg);
|
snr = (float)atoi(optarg);
|
||||||
@ -187,14 +192,10 @@ int main(int argc, char *argv[])
|
|||||||
f0=0.0;
|
f0=0.0;
|
||||||
t0=1.0;
|
t0=1.0;
|
||||||
add_signal_vector(f0, t0, snr, channel_symbols, isig, qsig);
|
add_signal_vector(f0, t0, snr, channel_symbols, isig, qsig);
|
||||||
|
if( writec2) {
|
||||||
if( strlen(c2filename) >0 ) {
|
|
||||||
// write a .c2 file
|
// write a .c2 file
|
||||||
double carrierfreq=10.1387;
|
double carrierfreq=10.1387;
|
||||||
int wsprtype=2;
|
int wsprtype=2;
|
||||||
if( strlen(c2filename) != 14 ) {
|
|
||||||
strcpy(c2filename,"000000_0001.c2");
|
|
||||||
}
|
|
||||||
printf("Writing %s\n",c2filename);
|
printf("Writing %s\n",c2filename);
|
||||||
writec2file(c2filename, wsprtype, carrierfreq, isig, qsig);
|
writec2file(c2filename, wsprtype, carrierfreq, isig, qsig);
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,6 @@ int get_wspr_channel_symbols(char* rawmessage, unsigned char* symbols) {
|
|||||||
}
|
}
|
||||||
grid6[5]=grid[0];
|
grid6[5]=grid[0];
|
||||||
n=pack_call(grid6);
|
n=pack_call(grid6);
|
||||||
printf("Callsign %s hash %d\n",callsign,ihash);
|
|
||||||
} else if ( i2 < mlen ) { // just looks for a right slash
|
} else if ( i2 < mlen ) { // just looks for a right slash
|
||||||
// Type 2: PJ4/K1ABC 37
|
// Type 2: PJ4/K1ABC 37
|
||||||
callsign=strtok(message," ");
|
callsign=strtok(message," ");
|
||||||
@ -251,7 +250,7 @@ int get_wspr_channel_symbols(char* rawmessage, unsigned char* symbols) {
|
|||||||
m=128*ng+ntype+64;
|
m=128*ng+ntype+64;
|
||||||
n=n1;
|
n=n1;
|
||||||
} else {
|
} else {
|
||||||
printf("Error: bad message format\n");
|
// printf("Error: bad message format\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user