WIP in q65 sync scheme for superfox.

This commit is contained in:
Joe Taylor 2024-02-26 12:32:25 -05:00
parent 6d4372cafe
commit 391536f35a
3 changed files with 93 additions and 117 deletions

View File

@ -1,4 +1,4 @@
subroutine sfox_gen(idat,f0,fsample,isync,cdat)
subroutine sfox_gen(idat,f0,fsample,isync,itone,cdat)
use sfox_mod
complex cdat(NMAX) !Generated complex waveform
@ -21,17 +21,16 @@ subroutine sfox_gen(idat,f0,fsample,isync,cdat)
itone(i)=idat(k) + 1 !Symbol value 0 is transmitted at tone 1, etc.
endif
enddo
! print*,'aaa',NN,k,NS,isync(NS),NDS
df=fsample/NSPS
w=1.0
j=0
i0=NQ/2
! Generate the waveform
do k=1,NDS
do k=1,NDS !Loop over all symbols
dphi=(f0 + (itone(k)-i0)*df)*(twopi/fsample)
wstep=cmplx(cos(dphi),sin(dphi))
do i=1,NSPS
do i=1,NSPS !NSPS samples per symbol
j=j+1
w=w*wstep
cdat(j)=w

View File

@ -1,23 +1,31 @@
subroutine sfox_sync(iwave,fsample,isync,f,t)
use sfox_mod
parameter (NSTEPS=8)
parameter (NSTEP=8)
integer*2 iwave(NMAX)
integer isync(44)
integer ipeak(1)
complex, allocatable :: c(:) !Work array
real x(171)
real, allocatable :: s(:,:) !Symbol spectra, stepped by NSTEPS
real, allocatable :: s(:,:) !Symbol spectra, stepped by NSTEP
real, allocatable :: savg(:) !Average spectrum
real, allocatable :: ccf(:,:) !
character*1 line(-15:15),mark(0:6),c1
data mark/' ','.','-','+','X','$','#'/
real, allocatable :: ccf(:,:)
! character*1 line(-15:15),mark(0:6),c1
! data mark/' ','.','-','+','X','$','#'/
nh=NFFT1/2
istep=NSPS/NSTEPS
istep=NSPS/NSTEP
jz=(13.5*fsample)/istep
df=fsample/NFFT1
tstep=istep/fsample
dtstep=istep/fsample
fsync=1500.0-bw/2
ftol=20.0
ia=nint((fsync-ftol)/df)
ib=nint((fsync+ftol)/df)
lagmax=1.0/dtstep
lag1=0
lag2=lagmax
x=0.
do i=1,NS
x(isync(i))=1.0
@ -26,11 +34,13 @@ subroutine sfox_sync(iwave,fsample,isync,f,t)
allocate(s(0:nh/2,jz))
allocate(savg(0:nh/2))
allocate(c(0:NFFT1-1))
allocate(ccf(ia:ib,lag1:lag2))
s=0.
savg=0.
fac=1.0/NFFT1
! Compute symbol spectra with df=baud/2 and NSTEPS steps per symbol.
! Compute symbol spectra with df=baud/2 and NSTEP steps per symbol.
do j=1,jz
k=(j-1)*istep
do i=0,nh-1
@ -43,105 +53,53 @@ subroutine sfox_sync(iwave,fsample,isync,f,t)
s(i,j)=p
savg(i)=savg(i) + p
enddo
ipeak=maxloc(s(ia:ib,j))
! print*,j,ipeak(1)+ia-1
enddo
pmax=maxval(s(82:112,1:jz))
s=s/pmax
do j=jz,1,-1
do i=-15,15
k=6.001*s(97+i,j)
line(i)=mark(k)
enddo
c1=' '
k=j/NSTEPS + 1
if(k.le.171) then
if(x(k).ne.0.0) c1='*'
endif
! write(*,2001) j,c1,line
!2001 format(i3,2x,a1,' |',31a1,'|')
xx=0
if(c1.eq.'*') xx=1
write(44,3044) j*tstep,xx,3.5*s(96:98,j)
3044 format(f10.4,4f10.4)
enddo
savg=savg/jz
ipeak=maxloc(savg(82:112))
i0=ipeak(1)+81
dxi=0.
! if(i0.gt.0 .and. i0.lt.nh/2) then
! call peakup(savg(i0-1),savg(i0),savg(i0+1),dxi)
! endif
f=(i0+dxi)*df + bw/2.0
do j=1,jz
k=j/NSTEPS + 1
xx=0
if(k.le.171) xx=x(k)
write(43,3043) j,s(i0,j),xx
3043 format(i5,2f12.3)
enddo
lagmax=1.0/tstep + 1
pmax=0.
lagpk=-99
! print*,i0,jz,tstep,lagmax
do lag=0,lagmax
p=0.
do i=1,NS
k=NSTEPS*(isync(i)-1) + 1 + lag
p=p + s(i0,k)
enddo
p=p/NS
if(p.gt.pmax) then
pmax=p
lagpk=lag
endif
write(42,3042) lag,lag*tstep,p
3042 format(i5,2f15.3)
enddo
t=lagpk*tstep
! print*,f,t
if(NS.ne.-99) return
!###
ccfbest=0.
ibest=0
lagpk=0
lagbest=0
j0=0.5/dtstep !Nominal start-signal index
nsz=(nint(3.0*fsample) + NS*NSPS)/istep
pmax=0.
ntol=100
iz=nint(ntol/df)
i0=nint(1500.0/df)
ipk=-999
jpk=-999
jz=nsz-NSTEPS*NS
allocate(ccf(-iz:iz,1:jz))
ccf=0.
do j=1,jz
do i=-iz,iz
p=0.
do k=1,NS
ii=i0+i+(2*(isync(k)-NQ/2))
jj=j + NSTEPS*(k-1)
p=p + s(ii,jj)
enddo
ccf(i,j)=p
if(p.gt.pmax) then
pmax=p
ipk=i
jpk=j
do i=ia,ib
ccfmax=0.
do lag=lag1,lag2
ccft=0.
do kk=1,NS
k=isync(kk)
n=NSTEP*(k-1) + 1
j=n+lag+j0
if(j.ge.1 .and. j.le.jz) ccft=ccft + s(i,j)
enddo ! kk
ccft=ccft - NS*savg(i)
ccf(i,lag)=ccft
if(ccft.gt.ccfmax) then
ccfmax=ccft
lagpk=lag
endif
enddo
enddo ! lag
if(ccfmax.gt.ccfbest) then
ccfbest=ccfmax
ibest=i
lagbest=lagpk
endif
enddo ! i
f=ibest*df + bw/2
t=lagbest*dtstep
! write(*,4100) ibest,lagbest,f,t
!4100 format(2i6,f10.1,f10.3)
! print*,'aaa',ibest,lagbest
do lag=lag1,lag2
write(51,3051) lag*dtstep,ccf(ibest,lag)
3051 format(2f12.4)
enddo
dxi=0.
dxj=0.
if(jpk.gt.1 .and. jpk.lt.jz .and. abs(ipk).lt.iz) then
call peakup(ccf(ipk-1,jpk),ccf(ipk,jpk),ccf(ipk+1,jpk),dxi)
call peakup(ccf(ipk,jpk-1),ccf(ipk,jpk),ccf(ipk,jpk+1),dxj)
endif
dfreq=(ipk+dxi)*df
f=1500.0+dfreq
t=(jpk+dxj-201.0)*istep/fsample
return
end subroutine sfox_sync

View File

@ -11,6 +11,8 @@ program sfoxtest
integer*2 iwave(NMAX) !Generated i*2 waveform
integer param(0:8)
integer isync(44)
integer jsync(171)
integer itone(171)
real*4 xnoise(NMAX) !Random noise
real*4 dat(NMAX) !Generated real data
complex cdat(NMAX) !Generated complex waveform
@ -100,6 +102,27 @@ program sfoxtest
allocate(rxprob2(0:NN-1))
allocate(correct(0:NN-1))
idum=-1
jsync=0
jsync(1)=1
jsync(NDS)=1
ms=2
do i=1,100000
j=1 + (NDS-1)*ran1(idum)
if(jsync(j).eq.0) then
jsync(j)=1
ms=ms+1
if(ms.eq.NS) exit
endif
enddo
j=0
do i=1,NDS
if(jsync(i).eq.1) then
j=j+1
isync(j)=i
endif
enddo
rms=100.
baud=fsample/nsps !Keying rate, 11.719 baud for nsps=1024
bandwidth_ratio=2500.0/fsample
@ -116,10 +139,6 @@ program sfoxtest
chansym0(0:kk-1)=msg0(1:kk)
chansym0(kk:nn-1)=parsym(1:nn-kk)
! Generate cdat, the SuperFox waveform
call timer('gen ',0)
call sfox_gen(chansym0,f0,fsample,isync,cdat)
call timer('gen ',1)
isnr0=-8
do isnr=isnr0,-20,-1
@ -150,26 +169,26 @@ program sfoxtest
f1=f0
if(f0.eq.0.0) then
f1=1500.0 + 20.0*(ran1(idum)-0.5)
xdt=0.3*ran1(idum)
call timer('gen ',0)
call sfox_gen(chansym0,f1,fsample,isync,cdat)
call timer('gen ',1)
! xdt=0.3*ran1(idum)
endif
call timer('gen ',0)
! Generate cdat, the SuperFox waveform
call sfox_gen(chansym0,f1,fsample,isync,itone,cdat)
call timer('gen ',1)
crcvd=0.
crcvd(1:NMAX)=cshift(cdat(1:NMAX),-nint(xdt*fsample))
crcvd(1:NMAX)=cshift(cdat(1:NMAX),-nint((0.5+xdt)*fsample))
call timer('watterso',0)
if(fspread.ne.0 .or. delay.ne.0) call watterson(crcvd,NMAX,NZ,fsample,&
delay,fspread)
call timer('watterso',1)
crcvd=sig*crcvd+cnoise
! dat=aimag(sigr*cdat(1:NMAX)) + xnoise !Add generated AWGN noise
dat=aimag(sigr*crcvd(1:NMAX)) + xnoise !Add generated AWGN noise
dat=aimag(sigr*crcvd(1:NMAX)) + xnoise !Add generated AWGN noise
fac=32767.0
if(snr.ge.90.0) iwave(1:NMAX)=nint(fac*dat(1:NMAX))
if(snr.lt.90.0) iwave(1:NMAX)=nint(rms*dat(1:NMAX))
crcvd=sig*crcvd+cnoise
if(hard_sync) then
f=f1 ! + 5.0*(ran1(idum)-0.5)
t=xdt ! + 0.01*(ran1(idum)-0.5)