diff --git a/CMakeLists.txt b/CMakeLists.txt index 385e30c39..6c38ac422 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -335,6 +335,7 @@ set (wsjt_FSRCS lib/chkss2.f90 lib/coord.f90 lib/fsk4hf/cpolyfit.f90 + lib/fsk4hf/cpolyfitw.f90 lib/db.f90 lib/decode4.f90 lib/decode65a.f90 @@ -392,8 +393,11 @@ set (wsjt_FSRCS lib/genmsk144.f90 lib/genmsk40.f90 lib/fsk4hf/genmskhf.f90 + lib/fsk4hf/genwsprlf.f90 lib/fsk4hf/getfc1.f90 lib/fsk4hf/getfc2.f90 + lib/fsk4hf/getfc1w.f90 + lib/fsk4hf/getfc2w.f90 lib/genqra64.f90 lib/genwspr.f90 lib/geodist.f90 @@ -443,6 +447,7 @@ set (wsjt_FSRCS lib/fsk4hf/mskhfsim.f90 lib/mskrtd.f90 lib/fsk4hf/msksoftsym.f90 + lib/fsk4hf/msksoftsymw.f90 lib/pctile.f90 lib/peakdt9.f90 lib/peakup.f90 @@ -496,6 +501,7 @@ set (wsjt_FSRCS lib/xcor.f90 lib/xcor4.f90 lib/wqencode.f90 + lib/fsk4hf/wsprlfsim.f90 lib/wspr_downsample.f90 lib/zplot9.f90 ) @@ -1125,6 +1131,9 @@ target_link_libraries (ldpcsim168 wsjt_fort wsjt_cxx) add_executable (fsk4hf lib/fsk4hf/fsk4hf.f90 wsjtx.rc) target_link_libraries (fsk4hf wsjt_fort wsjt_cxx) +add_executable (wsprlfsim lib/fsk4hf/wsprlfsim.f90 wsjtx.rc) +target_link_libraries (wsprlfsim wsjt_fort wsjt_cxx) + add_executable (mskhfsim lib/fsk4hf/mskhfsim.f90 wsjtx.rc) target_link_libraries (mskhfsim wsjt_fort wsjt_cxx) diff --git a/lib/fsk4hf/cpolyfitw.f90 b/lib/fsk4hf/cpolyfitw.f90 new file mode 100644 index 000000000..82cd88061 --- /dev/null +++ b/lib/fsk4hf/cpolyfitw.f90 @@ -0,0 +1,76 @@ +subroutine cpolyfitw(c,pp,id,maxn,aa,bb,zz,nhardsync) + + parameter (KK=60) !Information bits (50 + CRC10) + parameter (ND=300) !Data symbols: LDPC (300,60), r=1/5 + parameter (NS=109) !Sync symbols (2 x 48 + Barker 13) + parameter (NR=3) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (412) + parameter (NSPS=16) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (N13=13*N2) !Samples in central sync vector (416) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (6592) + parameter (NFFT1=4*NSPS,NH1=NFFT1/2) + + complex c(0:NZ-1) !Complex waveform + complex zz(NS+ND) !Complex symbol values (intermediate) + complex z,z0 + real x(NS),yi(NS),yq(NS) !For complex polyfit + real pp(2*NSPS) !Shaped pulse for OQPSK + real aa(20),bb(20) !Fitted polyco's + integer id(NS+ND) !NRZ values (+/-1) for Sync and Data + + ib=NSPS-1 + ib2=N2-1 + n=0 + do j=1,205 !First-pass demodulation + ia=ib+1 + ib=ia+N2-1 + zz(j)=sum(pp*c(ia:ib))/NSPS + if(abs(id(j)).eq.2) then !Save all sync symbols + n=n+1 + x(n)=float(ia+ib)/NZ - 1.0 + yi(n)=real(zz(j))*0.5*id(j) + yq(n)=aimag(zz(j))*0.5*id(j) +! write(54,1225) n,x(n),yi(n),yq(n) +!1225 format(i5,3f12.4) + endif + if(j.le.204) then + zz(j+205)=sum(pp*c(ia+NSPS:ib+NSPS))/NSPS + endif + enddo + + aa=0. + bb=0. + nterms=0 + chisqa=0. + chisqb=0. + if(maxn.gt.0) then + npts=n + mode=0 + nterms=maxn + call polyfit4(x,yi,yi,npts,nterms,mode,aa,chisqa) + call polyfit4(x,yq,yq,npts,nterms,mode,bb,chisqb) + endif + + nhardsync=0 + do j=1,205 + if(abs(id(j)).ne.2) cycle + xx=j*2.0/205.0 - 1.0 + yii=1. + yqq=0. + if(nterms.gt.0) then + yii=aa(1) + yqq=bb(1) + do i=2,nterms + yii=yii + aa(i)*xx**(i-1) + yqq=yqq + bb(i)*xx**(i-1) + enddo + endif + z0=cmplx(yii,yqq) + z=zz(j)*conjg(z0) + p=real(z) + if(p*id(j).lt.0) nhardsync=nhardsync+1 + enddo + + return +end subroutine cpolyfitw diff --git a/lib/fsk4hf/genwsprlf.f90 b/lib/fsk4hf/genwsprlf.f90 new file mode 100644 index 000000000..bd9e2472e --- /dev/null +++ b/lib/fsk4hf/genwsprlf.f90 @@ -0,0 +1,129 @@ +subroutine genwsprlf(msgbits,id,icw,cbb,csync) + +!Encode a WSPR-LF message, produce baseband waveform and sync vector. + + parameter (KK=60) !Information bits (50 + CRC10) + parameter (ND=300) !Data symbols: LDPC (300,60), r=1/5 + parameter (NS=109) !Sync symbols (2 x 48 + Barker 13) + parameter (NR=3) !Ramp up/down (2 x half-length symbols) + parameter (NN=NR+NS+ND) !Total symbols (410) + parameter (NSPS=16) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (N13=13*N2) !Samples in central sync vector (416) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (6560) + parameter (NFFT1=4*NSPS,NH1=NFFT1/2) + + complex cbb(0:NZ-1) + complex csync(0:NZ-1) + real x(0:NZ-1) + real y(0:NZ-1) + real pp(N2) + logical first + integer*1 msgbits(KK),codeword(ND) + integer icw(ND) + integer id(NS+ND) + integer isync(48) !Long sync vector + integer ib13(13) !Barker 13 code + integer*8 n8 + data ib13/1,1,1,1,1,-1,-1,1,1,-1,1,-1,1/ + data first/.true./ + save first,isync,twopi,pp + + if(first) then + n8=z'cbf089223a51' + do i=1,48 + isync(i)=-1 + if(iand(n8,1).eq.1) isync(i)=1 + n8=n8/2 + enddo + + twopi=8.0*atan(1.0) + do i=1,N2 !Half-sine shaped pulse + pp(i)=sin(0.5*(i-1)*twopi/N2) + enddo + first=.false. + endif + + call encode300(msgbits,codeword) !Encode the test message + icw=2*codeword - 1 + +! Message structure: R1 48*(S1+D1) S13 48*(D1+S1) R1 +! Generate QPSK without any offset; then shift the y array to get OQPSK. + +! Do the I channel first: results in array x + n=0 + k=0 + ia=0 + ib=NSPS-1 + x(ia:ib)=0. !Ramp up (half-symbol; shape TBD) + do j=1,48 !Insert group of 48*(S1+D1) + ia=ib+1 + ib=ia+N2-1 + n=n+1 + id(n)=2*isync(j) + x(ia:ib)=isync(j)*pp !Insert Sync bit + ia=ib+1 + ib=ia+N2-1 + k=k+1 + n=n+1 + id(n)=icw(k) + x(ia:ib)=id(n)*pp !Insert data bit + enddo + + do j=1,13 !Insert Barker 13 code + ia=ib+1 + ib=ia+N2-1 + n=n+1 + id(n)=2*ib13(j) + x(ia:ib)=ib13(j)*pp + enddo + + do j=1,48 !Insert group of 48*(S1+D1) + ia=ib+1 + ib=ia+N2-1 + k=k+1 + n=n+1 + id(n)=icw(k) + x(ia:ib)=id(n)*pp !Insert data bit + ia=ib+1 + ib=ia+N2-1 + n=n+1 + id(n)=2*isync(j) + x(ia:ib)=isync(j)*pp !Insert Sync bit + enddo + ia=ib+1 + ib=ia+NSPS-1 + x(ia:ib)=0. !Ramp down (half-symbol; shape TBD) + +! Now do the Q channel: results in array y + ia=0 + ib=NSPS-1 + y(ia:ib)=0. !Ramp up (half-symbol; shape TBD) + do j=1,204 + ia=ib+1 + ib=ia+N2-1 + k=k+1 + n=n+1 + id(n)=icw(k) + y(ia:ib)=id(n)*pp + enddo + ia=ib+1 + ib=ia+NSPS-1 + y(ia:ib)=0. !Ramp down (half-symbol; shape TBD) + y=cshift(y,-NSPS) !Shift Q array to get OQPSK + cbb=cmplx(x,y) !Complex baseband waveform + + ib=NSPS-1 + ib2=NSPS-1+64*N2 + do j=1,48 !Zero all data symbols in x + ia=ib+1+N2 + ib=ia+N2-1 + x(ia:ib)=0. + ia2=ib2+1+N2 + ib2=ia2+N2-1 + x(ia2:ib2)=0. + enddo + csync=x + + return +end subroutine genwsprlf diff --git a/lib/fsk4hf/getfc1w.f90 b/lib/fsk4hf/getfc1w.f90 new file mode 100644 index 000000000..c7eb76e68 --- /dev/null +++ b/lib/fsk4hf/getfc1w.f90 @@ -0,0 +1,57 @@ +subroutine getfc1w(c,fs,fc1) + + parameter (KK=60) !Information bits (50 + CRC10) + parameter (ND=300) !Data symbols: LDPC (300,60), r=1/5 + parameter (NS=109) !Sync symbols (2 x 48 + Barker 13) + parameter (NR=3) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (412) + parameter (NSPS=16) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (N13=13*N2) !Samples in central sync vector (416) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (6592) + parameter (NFFT1=4*NSPS,NH1=NFFT1/2) + + complex c(0:NZ-1) !Complex waveform + complex c2(0:NFFT1-1) !Short spectra + real s(-NH1+1:NH1) !Coarse spectrum + + nspec=NZ/NFFT1 + df1=fs/NFFT1 + s=0. + do k=1,nspec + ia=(k-1)*N2 + ib=ia+N2-1 + c2(0:N2-1)=c(ia:ib) + c2(N2:)=0. + call four2a(c2,NFFT1,1,-1,1) + do i=0,NFFT1-1 + j=i + if(j.gt.NH1) j=j-NFFT1 + s(j)=s(j) + real(c2(i))**2 + aimag(c2(i))**2 + enddo + enddo +! call smo121(s,NFFT1) + smax=0. + ipk=0 + fc1=0. + ia=nint(10.0/df1) + do i=-ia,ia + f=i*df1 + if(s(i).gt.smax) then + smax=s(i) + ipk=i + fc1=f + endif +! write(51,3001) f,s(i),db(s(i)) +! 3001 format(f10.3,e12.3,f10.3) + enddo + +! The following is for testing SNR calibration: +! sp3n=(s(ipk-1)+s(ipk)+s(ipk+1)) !Sig + 3*noise +! base=(sum(s)-sp3n)/(NFFT1-3.0) !Noise per bin +! psig=sp3n-3*base !Sig only +! pnoise=(2500.0/df1)*base !Noise in 2500 Hz +! xsnrdb=db(psig/pnoise) + + return +end subroutine getfc1w diff --git a/lib/fsk4hf/getfc2w.f90 b/lib/fsk4hf/getfc2w.f90 new file mode 100644 index 000000000..6e30c4165 --- /dev/null +++ b/lib/fsk4hf/getfc2w.f90 @@ -0,0 +1,73 @@ +subroutine getfc2w(c,csync,fs,fc1,fc2,fc3) + + parameter (KK=60) !Information bits (50 + CRC10) + parameter (ND=300) !Data symbols: LDPC (300,60), r=1/5 + parameter (NS=109) !Sync symbols (2 x 48 + Barker 13) + parameter (NR=3) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (412) + parameter (NSPS=16) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (N13=13*N2) !Samples in central sync vector (416) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (6592) + parameter (NFFT1=4*NSPS,NH1=NFFT1/2) + + complex c(0:NZ-1) !Complex waveform + complex cs(0:NZ-1) !For computing spectrum + complex csync(0:NZ-1) !Sync symbols only, from cbb + real a(5) + + df=fs/NZ + baud=fs/NSPS + a(1)=-fc1 + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,cs) !Mix down by fc1 + +! Filter, square, then FFT to get refined carrier frequency fc2. + call four2a(cs,NZ,1,-1,1) !To freq domain + ia=nint(0.75*baud/df) + cs(ia:NZ-1-ia)=0. !Save only freqs around fc1 + call four2a(cs,NZ,1,1,1) !Back to time domain + cs=cs/NZ + cs=cs*cs !Square the data + call four2a(cs,NZ,1,-1,1) !Compute squared spectrum + +! Find two peaks separated by baud + pmax=0. + fc2=0. + ic=nint(baud/df) + ja=nint(0.5*baud/df) + do j=-ja,ja + f2=j*df + ia=nint((f2-0.5*baud)/df) + if(ia.lt.0) ia=ia+NZ + ib=nint((f2+0.5*baud)/df) + p=real(cs(ia))**2 + aimag(cs(ia))**2 + & + real(cs(ib))**2 + aimag(cs(ib))**2 + if(p.gt.pmax) then + pmax=p + fc2=0.5*f2 + endif +! write(52,1200) f2,p,db(p) +!1200 format(f10.3,2f15.3) + enddo + + a(1)=-fc1 + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,cs) !Mix down by fc1 + cs=cs*conjg(csync) + call four2a(cs,NZ,1,-1,1) !To freq domain + pmax=0. + do i=0,NZ-1 + f=i*df + if(i.gt.NZ/2) f=(i-NZ)*df + p=real(cs(i))**2 + aimag(cs(i))**2 +! write(51,3001) f,p,db(p) +!3001 format(f10.3,e12.3,f10.3) + if(p.gt.pmax) then + pmax=p + fc3=f + endif + enddo + + return +end subroutine getfc2w diff --git a/lib/fsk4hf/msksoftsymw.f90 b/lib/fsk4hf/msksoftsymw.f90 new file mode 100644 index 000000000..80f021dca --- /dev/null +++ b/lib/fsk4hf/msksoftsymw.f90 @@ -0,0 +1,85 @@ +subroutine msksoftsymw(zz,aa,bb,id,nterms,ierror,rxdata,nhard0,nhardsync0) + + parameter (KK=60) !Information bits (50 + CRC10) + parameter (ND=300) !Data symbols: LDPC (300,60), r=1/5 + parameter (NS=109) !Sync symbols (2 x 48 + Barker 13) + parameter (NR=3) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (412) + parameter (NSPS=16) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (N13=13*N2) !Samples in central sync vector (416) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (6592) + parameter (NFFT1=4*NSPS,NH1=NFFT1/2) + + complex zz(NS+ND) !Complex symbol values (intermediate) + complex z,z0 + real rxdata(ND) !Soft symbols + real aa(20),bb(20) !Fitted polyco's + integer id(NS+ND) !NRZ values (+/-1) for Sync and Data + integer ierror(NS+ND) + + n=0 + ierror=0 + ierr=0 + do j=1,205 + xx=j*2.0/205.0 - 1.0 + yii=1. + yqq=0. + if(nterms.gt.0) then + yii=aa(1) + yqq=bb(1) + do i=2,nterms + yii=yii + aa(i)*xx**(i-1) + yqq=yqq + bb(i)*xx**(i-1) + enddo + endif + z0=cmplx(yii,yqq) + z=zz(j)*conjg(z0) + p=real(z) + if(abs(id(j)).eq.2) then + if(real(z)*id(j).lt.0) then !Sync bit + nhardsync0=nhardsync0+1 + ierror(j)=2 + endif + else + n=n+1 !Data bit + rxdata(n)=p + ierr=0 + if(id(j)*p.lt.0) then + ierr=1 + ierror(j)=1 + endif + nhard0=nhard0+ierr + endif +! write(41,3301) j,id(j),ierror(j),ierr,p*id(j) +!3301 format(4i6,f10.3) + enddo + + do j=206,409 + xx=(j-204.5)*2.0/205.0 - 1.0 + yii=1. + yqq=0. + if(nterms.gt.0) then + yii=aa(1) + yqq=bb(1) + do i=2,nterms + yii=yii + aa(i)*xx**(i-1) + yqq=yqq + bb(i)*xx**(i-1) + enddo + endif + z0=cmplx(yii,yqq) + z=zz(j)*conjg(z0) + p=aimag(z) + n=n+1 + rxdata(n)=p + ierr=0 + if(id(j)*p.lt.0) then + ierr=1 + ierror(j)=1 + endif + nhard0=nhard0+ierr +! write(41,3301) j,id(j),ierror(j),ierr,p*id(j) + enddo + + return +end subroutine msksoftsymw diff --git a/lib/fsk4hf/watterson.f90 b/lib/fsk4hf/watterson.f90 index 8230ccca8..f1afc9068 100644 --- a/lib/fsk4hf/watterson.f90 +++ b/lib/fsk4hf/watterson.f90 @@ -1,6 +1,6 @@ subroutine watterson(c,nz,fs,delay,fspread) - parameter (NZMAX=3776) + parameter (NZMAX=6592) complex c(0:nz-1) complex c2(0:NZMAX-1) complex cs1(0:NZMAX-1) diff --git a/lib/fsk4hf/wsprlfsim.f90 b/lib/fsk4hf/wsprlfsim.f90 new file mode 100644 index 000000000..b27b9f9ba --- /dev/null +++ b/lib/fsk4hf/wsprlfsim.f90 @@ -0,0 +1,218 @@ +program wsprlfsim + +! Simulate characteristics of a potential "WSPR-LF" mode using LDPC (300,60) +! code, OQPSK modulation, and 5 minute T/R sequences. + +! Reception and Demodulation algorithm: +! 1. Compute coarse spectrum; find fc1 = approx carrier freq +! 2. Mix from fc1 to 0; LPF at +/- 0.75*R +! 3. Square, FFT; find peaks near -R/2 and +R/2 to get fc2 +! 4. Mix from fc2 to 0 +! 5. Fit cb13 (central part of csync) to c -> lag, phase +! 6. Fit complex ploynomial for channel equalization +! 7. Get soft bits from equalized data + + parameter (KK=60) !Information bits (50 + CRC10) + parameter (ND=300) !Data symbols: LDPC (300,60), r=1/5 + parameter (NS=109) !Sync symbols (2 x 48 + Barker 13) + parameter (NR=3) !Ramp up/down + parameter (NN=NR+NS+ND) !Total symbols (412) + parameter (NSPS=16) !Samples per MSK symbol (16) + parameter (N2=2*NSPS) !Samples per OQPSK symbol (32) + parameter (N13=13*N2) !Samples in central sync vector (416) + parameter (NZ=NSPS*NN) !Samples in baseband waveform (6592) + parameter (NFFT1=4*NSPS,NH1=NFFT1/2) + +! Q: Would it be better for central Sync array to use both I and Q channels? + + character*8 arg + complex cbb(0:NZ-1) !Complex baseband waveform + complex csync(0:NZ-1) !Sync symbols only, from cbb + complex cb13(0:N13-1) !Barker 13 waveform + complex c(0:NZ-1) !Complex waveform + complex c0(0:NZ-1) !Complex waveform + complex zz(NS+ND) !Complex symbol values (intermediate) + complex z + real xnoise(0:NZ-1) !Generated random noise + real ynoise(0:NZ-1) !Generated random noise + real rxdata(ND),llr(ND) !Soft symbols + real pp(2*NSPS) !Shaped pulse for OQPSK + real a(5) !For twkfreq1 + real aa(20),bb(20) !Fitted polyco's + integer id(NS+ND) !NRZ values (+/-1) for Sync and Data + integer ierror(NS+ND) + integer icw(NN) + integer*1 msgbits(KK),decoded(KK),apmask(ND),cw(ND) +! integer*1 codeword(ND) + data msgbits/0,0,1,0,0,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,1, & + 1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,1,1,0,1,1,0,1,0,1,1,0,0,1,1/ + nargs=iargc() + if(nargs.ne.6) then + print*,'Usage: wsprlfsim f0(Hz) delay(ms) fspread(Hz) maxn iters snr(dB)' + print*,'Example: wsprlfsim 0 0 0 5 10 -20' + print*,'Set snr=0 to cycle through a range' + go to 999 + endif + call getarg(1,arg) + read(arg,*) f0 !Generated carrier frequency + call getarg(2,arg) + read(arg,*) delay !Delta_t (ms) for Watterson model + call getarg(3,arg) + read(arg,*) fspread !Fspread (Hz) for Watterson model + call getarg(4,arg) + read(arg,*) maxn !Max nterms for polyfit + call getarg(5,arg) + read(arg,*) iters !Iterations at each SNR + call getarg(6,arg) + read(arg,*) snrdb !Specified SNR_2500 + + twopi=8.0*atan(1.0) + fs=12000.0/540.0 !Sample rate = 22.2222... Hz + dt=1.0/fs !Sample interval (s) + tt=NSPS*dt !Duration of "itone" symbols (s) + ts=2*NSPS*dt !Duration of OQPSK symbols (s) + baud=1.0/tt !Keying rate for "itone" symbols (baud) + txt=NZ*dt !Transmission length (s) + bandwidth_ratio=2500.0/(fs/2.0) + write(*,1000) f0,delay,fspread,maxn,iters,baud,3*baud,txt +1000 format('f0:',f5.1,' Delay:',f4.1,' fSpread:',f5.2,' maxn:',i3, & + ' Iters:',i6/'Baud:',f7.3,' BW:',f5.1,' TxT:',f5.1,f5.2/) + write(*,1004) +1004 format(/' SNR sync data ser ber fer fsigma tsigma'/60('-')) + + do i=1,N2 !Half-sine pulse shape + pp(i)=sin(0.5*(i-1)*twopi/(2*NSPS)) + enddo + + call genwsprlf(msgbits,id,icw,cbb,csync)!Generate baseband waveform and csync + cb13=csync(3088:3503) !Copy the Barker 13 waveform + a=0. + a(1)=f0 + call twkfreq1(cbb,NZ,fs,a,cbb) !Mix to specified frequency + +! write(*,3101) id +!3101 format(20i3) + + isna=-20 + isnb=-40 + if(snrdb.ne.0.0) then + isna=nint(snrdb) + isnb=isna + endif + do isnr=isna,isnb,-1 !Loop over SNR range + if(isna.ne.isnb) snrdb=isnr + sig=sqrt(bandwidth_ratio) * 10.0**(0.05*snrdb) + if(snrdb.gt.90.0) sig=1.0 + nhard=0 + nhardsync=0 + nfe=0 + sqf=0. + sqt=0. + do iter=1,iters !Loop over requested iterations + c=cbb + if(delay.ne.0.0 .or. fspread.ne.0.0) then + call watterson(c,NZ,fs,delay,fspread) + endif + c=sig*c !Scale to requested SNR + if(snrdb.lt.90) then + do i=0,NZ-1 !Generate gaussian noise + xnoise(i)=gran() + ynoise(i)=gran() + enddo + c=c + cmplx(xnoise,ynoise) !Add AWGN noise + endif + + call getfc1w(c,fs,fc1) !First approx for freq + call getfc2w(c,csync,fs,fc1,fc2,fc3) !Refined freq + sqf=sqf + (fc1+fc2-f0)**2 + +!NB: Measured performance is about equally good using fc2 or fc3 here: + a(1)=-(fc1+fc2) + a(2:5)=0. + call twkfreq1(c,NZ,fs,a,c) !Mix c down by fc1+fc2 + +! The following may not be necessary? +! z=sum(c(3088:3503)*cb13)/208.0 !Get phase from Barker 13 vector +! z0=z/abs(z) +! c=c*conjg(z0) + +!---------------------------------------------------------------- DT +! Not presently used: + amax=0. + jpk=0 + iaa=0 + ibb=NZ-1 + do j=-20*NSPS,20*NSPS !Get jpk +! z=sum(c(3088+j:3503+j)*conjg(cb13))/208.0 + ia=j + ib=NZ-1+j + if(ia.lt.0) then + ia=0 + iaa=-j + else + iaa=0 + endif + if(ib.gt.NZ-1) then + ib=NZ-1 + ibb=NZ-1-j + endif + z=sum(c(ia:ib)*conjg(csync(iaa:ibb))) + if(abs(z).gt.amax) then + amax=abs(z) + jpk=j + endif + enddo + xdt=jpk/fs + sqt=sqt + xdt**2 +!----------------------------------------------------------------- + + nterms=maxn + c0=c + do itry=1,20 + idf=itry/2 + if(mod(itry,2).eq.0) idf=-idf + nhard0=0 + nhardsync0=0 + ifer=1 + a(1)=idf*0.00085 + a(2:5)=0. + call twkfreq1(c0,NZ,fs,a,c) !Mix c0 into c + call cpolyfitw(c,pp,id,maxn,aa,bb,zz,nhs) + call msksoftsymw(zz,aa,bb,id,nterms,ierror,rxdata,nhard0,nhardsync0) + if(nhardsync0.gt.35) cycle + rxav=sum(rxdata)/ND + rx2av=sum(rxdata*rxdata)/ND + rxsig=sqrt(rx2av-rxav*rxav) + rxdata=rxdata/rxsig + ss=0.84 + llr=2.0*rxdata/(ss*ss) + apmask=0 + max_iterations=40 + ifer=0 + call bpdecode300(llr,apmask,max_iterations,decoded,niterations,cw) + nbadcrc=0 + if(niterations.ge.0) call chkcrc10(decoded,nbadcrc) + if(niterations.lt.0 .or. count(msgbits.ne.decoded).gt.0 .or. & + nbadcrc.ne.0) ifer=1 + if(ifer.eq.0) exit + enddo !Freq dither loop + nhard=nhard+nhard0 + nhardsync=nhardsync+nhardsync0 + nfe=nfe+ifer + if(nhardsync0+nhard0+niterations+ifer.gt.0) write(42,1045) snrdb, & + nhardsync0,nhard0,niterations,ifer,xdt +1045 format(f6.1,4i6,f8.2) + enddo + + fsigma=sqrt(sqf/iters) + tsigma=sqrt(sqt/iters) + ser=float(nhardsync)/(NS*iters) + ber=float(nhard)/(ND*iters) + fer=float(nfe)/iters + write(*,1050) snrdb,nhardsync,nhard,ser,ber,fer,fsigma,tsigma +1050 format(f6.1,2i7,2f8.4,f7.3,2f8.2) + enddo + write(*,1060) NS*iters,ND*iters +1060 format(60('-')/6x,2i7) + +999 end program wsprlfsim