js8call/lib/ft8/sync8.f90
Jordan Sherer 15bf364e5e Squashed commit of the following:
commit dbca224ee15f598ba86b860c19e902b594f6b888
Author: Jordan Sherer <jordan@widefido.com>
Date:   Wed Aug 14 21:10:17 2019 -0400

    Cleanup decoder with easy parameters

commit 427a6ac6bf02a7de80e76b921bbd48ec23dab0c4
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 13 22:56:32 2019 -0400

    Working on downsampling

commit ef5e1fb9cdafb6069b6f67377c3bc9e073d2785e
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 13 22:01:34 2019 -0400

    Fixed NN parameters

commit 216dbc83a931127540fb028d3365a205b4ef1d28
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 13 21:40:20 2019 -0400

    Fixed dupe during sync

commit 9505d50ba6c42b05e5fff1a059864a643d9e7558
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 13 16:54:37 2019 -0400

    Tweaking downsampling

commit 86cd07e1ac8ce8d64cdd2d4321cf295cd867f80e
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 13 10:11:07 2019 -0400

    Working with logging

commit 0de3849a442d20081f545c6fef5fadf2def6e0d2
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 13 03:46:51 2019 -0400

    250 millisecond startup delay

commit a35cc5302b6f8532a424d504a4e2feaacf74ef99
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 13 03:39:20 2019 -0400

    1200 sps, 10 seconds, 80Hz

commit 6f36db20f90c510336b497605d9d7667d6f0f44f
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 13 03:27:12 2019 -0400

    Working word count

commit 741c55ac0840512d68e1fbdb2f1fff6adfcd4612
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 13 02:40:40 2019 -0400

    Updated LDPC simulator

commit ce0992644315402503f44bdae4131bacf2cc3e21
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 13 02:34:01 2019 -0400

    Weird. Apparently symbol stop is the only way to get decodes to work in app...need to figure out why

commit 8b330fbff6574f2ee6d7a471dd93a2cb57b492dd
Author: Jordan Sherer <jordan@widefido.com>
Date:   Tue Aug 13 01:50:37 2019 -0400

    More parameter fixups (downsampling) and first decode

commit 37c780b45e6579294b5a4692b8e8d0602d9bd8b1
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Aug 12 23:20:58 2019 -0400

    More params fixing

commit bc8547e1e8f55bfb4bce5f95890f3cf6798e36d7
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Aug 12 22:48:00 2019 -0400

    Fixed params in fortran code

commit 10fbf9f4a78c6244e0082a31819ee26aeae39325
Author: Jordan Sherer <jordan@widefido.com>
Date:   Mon Aug 12 16:08:32 2019 -0400

    Using constants in place of literals in a few places to make it easier to change
2019-08-14 21:11:06 -04:00

145 lines
3.8 KiB
Fortran

subroutine sync8(dd,nfa,nfb,syncmin,nfqso,s,candidate,ncand,sbase)
include 'ft8_params.f90'
complex cx(0:NH1)
real s(NH1,NHSYM)
real savg(NH1)
real sbase(NH1)
real x(NFFT1)
real sync2d(NH1,-JZ:JZ)
real red(NH1)
real candidate0(3,200)
real candidate(3,200)
real dd(NMAX)
integer jpeak(NH1)
integer indx(NH1)
integer ii(1)
integer icos7(0:6)
data icos7/4,2,5,6,1,3,0/ !Costas 7x7 tone pattern
equivalence (x,cx)
! Compute symbol spectra, stepping by NSTEP steps.
savg=0.
tstep=NSTEP/12000.0
df=12000.0/NFFT1 !3.125 Hz
fac=1.0/300.0
do j=1,NHSYM
ia=(j-1)*NSTEP + 1
ib=ia+NSPS-1
x(1:NSPS)=fac*dd(ia:ib)
x(NSPS+1:)=0.
call four2a(x,NFFT1,1,-1,0) !r2c FFT
do i=1,NH1
s(i,j)=real(cx(i))**2 + aimag(cx(i))**2
enddo
savg=savg + s(1:NH1,j) !Average spectrum
enddo
call baseline(savg,nfa,nfb,sbase)
ia=max(1,nint(nfa/df))
ib=nint(nfb/df)
nssy=NSPS/NSTEP ! # steps per symbol
nfos=NFFT1/NSPS ! # frequency bin oversampling factor
jstrt=0.5/tstep
candidate0=0.
k=0
do i=ia,ib
do j=-JZ,+JZ
ta=0.
tb=0.
tc=0.
t0a=0.
t0b=0.
t0c=0.
do n=0,6
k=j+jstrt+nssy*n
if(k.ge.1.and.k.le.NHSYM) then
ta=ta + s(i+nfos*icos7(n),k)
t0a=t0a + sum(s(i:i+nfos*6:nfos,k))
endif
tb=tb + s(i+nfos*icos7(n),k+nssy*36)
t0b=t0b + sum(s(i:i+nfos*6:nfos,k+nssy*36))
if(k+nssy*72.le.NHSYM) then
tc=tc + s(i+nfos*icos7(n),k+nssy*72)
t0c=t0c + sum(s(i:i+nfos*6:nfos,k+nssy*72))
endif
enddo
t=ta+tb+tc
t0=t0a+t0b+t0c
t0=(t0-t)/6.0
sync_abc=t/t0
t=tb+tc
t0=t0b+t0c
t0=(t0-t)/6.0
sync_bc=t/t0
sync2d(i,j)=max(sync_abc,sync_bc)
enddo
enddo
red=0.
do i=ia,ib
ii=maxloc(sync2d(i,-JZ:JZ)) - 1 - JZ
j0=ii(1)
jpeak(i)=j0
red(i)=sync2d(i,j0)
! write(52,3052) i*df,red(i),db(red(i))
!3052 format(3f12.3)
enddo
iz=ib-ia+1
call indexx(red(ia:ib),iz,indx)
ibase=indx(nint(0.40*iz)) - 1 + ia
if(ibase.lt.1) ibase=1
if(ibase.gt.nh1) ibase=nh1
base=red(ibase)
red=red/base
do i=1,min(200,iz)
n=ia + indx(iz+1-i) - 1
if(red(n).lt.syncmin.or.isnan(red(n)).or.k.eq.200) exit
k=k+1
candidate0(1,k)=n*df
candidate0(2,k)=(jpeak(n)-1)*tstep
candidate0(3,k)=red(n)
enddo
ncand=k
! Put nfqso at top of list, and save only the best of near-dupe freqs.
do i=1,ncand
if(abs(candidate0(1,i)-nfqso).lt.10.0) candidate0(1,i)=-candidate0(1,i)
if(i.ge.2) then
do j=1,i-1
fdiff=abs(candidate0(1,i))-abs(candidate0(1,j))
if(abs(fdiff).lt.AZ) then ! note: this dedupe difference is dependent on symbol spacing
if(candidate0(3,i).ge.candidate0(3,j)) candidate0(3,j)=0.
if(candidate0(3,i).lt.candidate0(3,j)) candidate0(3,i)=0.
endif
enddo
endif
enddo
fac=20.0/maxval(s)
s=fac*s
! Sort by sync
! call indexx(candidate0(3,1:ncand),ncand,indx)
! Sort by frequency
call indexx(candidate0(1,1:ncand),ncand,indx)
k=1
! do i=ncand,1,-1
do i=1,ncand
j=indx(i)
! if( candidate0(3,j) .ge. syncmin .and. candidate0(2,j).ge.-1.5 ) then
if( candidate0(3,j) .ge. syncmin ) then
candidate(1,k)=abs(candidate0(1,j))
candidate(2,k)=candidate0(2,j)
candidate(3,k)=candidate0(3,j)
k=k+1
endif
enddo
ncand=k-1
return
end subroutine sync8