2020-12-17 17:02:28 -05:00
|
|
|
subroutine q65_sync(nutc,iwave,nmax,mode_q65,codewords,ncw,nsps,nfqso,ntol, &
|
|
|
|
emedelay,xdt,f0,snr1,dat4,snr2,id1)
|
2020-08-01 09:24:59 -04:00
|
|
|
|
2020-10-25 13:58:18 -04:00
|
|
|
! Detect and align with the Q65 sync vector, returning time and frequency
|
2020-10-13 13:49:09 -04:00
|
|
|
! offsets and SNR estimate.
|
|
|
|
|
2020-10-09 13:16:25 -04:00
|
|
|
! Input: iwave(0:nmax-1) Raw data
|
2020-11-30 09:52:47 -05:00
|
|
|
! mode_q65 Tone spacing 1 2 4 8 16 (A-E)
|
2020-10-09 13:16:25 -04:00
|
|
|
! nsps Samples per symbol at 12000 Sa/s
|
|
|
|
! nfqso Target frequency (Hz)
|
|
|
|
! ntol Search range around nfqso (Hz)
|
|
|
|
! Output: xdt Time offset from nominal (s)
|
|
|
|
! f0 Frequency of sync tone
|
|
|
|
! snr1 Relative SNR of sync signal
|
2020-12-03 14:28:30 -05:00
|
|
|
|
|
|
|
use packjt77
|
2020-10-13 13:49:09 -04:00
|
|
|
parameter (NSTEP=8) !Step size nsps/NSTEP
|
2020-11-23 14:30:36 -05:00
|
|
|
parameter (LN=2176*63) !LN=LL*NN; LL=64*(mode_q65+2), NN=63
|
2020-12-04 15:29:46 -05:00
|
|
|
parameter (PLOG_MIN=-240.0) !List decoding threshold
|
2020-09-25 10:55:21 -04:00
|
|
|
integer*2 iwave(0:nmax-1) !Raw data
|
|
|
|
integer isync(22) !Indices of sync symbols
|
2020-11-23 08:47:37 -05:00
|
|
|
integer itone(85)
|
2020-12-15 11:03:06 -05:00
|
|
|
integer codewords(63,206)
|
2020-11-30 09:52:47 -05:00
|
|
|
integer dat4(13)
|
|
|
|
integer ijpk(2)
|
2020-12-03 14:28:30 -05:00
|
|
|
logical unpk77_success
|
|
|
|
character*77 c77,decoded*37
|
2020-11-28 10:12:12 -05:00
|
|
|
real, allocatable :: s1(:,:) !Symbol spectra, 1/8-symbol steps
|
2020-11-30 09:52:47 -05:00
|
|
|
real, allocatable :: s3(:,:) !Data-symbol energies s3(LL,63)
|
2020-11-03 11:31:21 -05:00
|
|
|
real, allocatable :: ccf(:,:) !CCF(freq,lag)
|
|
|
|
real, allocatable :: ccf1(:) !CCF(freq) at best lag
|
2020-11-30 09:52:47 -05:00
|
|
|
real s3prob(0:63,63) !Symbol-value probabilities
|
2020-11-23 14:30:36 -05:00
|
|
|
real sync(85) !sync vector
|
2020-09-25 12:21:57 -04:00
|
|
|
complex, allocatable :: c0(:) !Complex spectrum of symbol
|
2020-09-25 10:55:21 -04:00
|
|
|
data isync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/
|
2020-08-04 13:13:49 -04:00
|
|
|
data sync(1)/99.0/
|
|
|
|
save sync
|
2020-08-01 09:24:59 -04:00
|
|
|
|
2020-12-09 13:45:05 -05:00
|
|
|
snr1=0.
|
2020-11-30 13:14:18 -05:00
|
|
|
id1=0
|
|
|
|
dat4=0
|
2020-11-30 09:52:47 -05:00
|
|
|
LL=64*(2+mode_q65)
|
2020-11-29 10:00:33 -05:00
|
|
|
nfft=nsps
|
2020-11-30 09:52:47 -05:00
|
|
|
df=12000.0/nfft !Freq resolution = baud
|
2020-08-08 09:14:12 -04:00
|
|
|
istep=nsps/NSTEP
|
2020-09-25 10:55:21 -04:00
|
|
|
iz=5000.0/df !Uppermost frequency bin, at 5000 Hz
|
2020-08-08 13:57:24 -04:00
|
|
|
txt=85.0*nsps/12000.0
|
2020-09-25 10:55:21 -04:00
|
|
|
jz=(txt+1.0)*12000.0/istep !Number of quarter-symbol steps
|
2020-10-13 13:49:09 -04:00
|
|
|
if(nsps.ge.6912) jz=(txt+2.0)*12000.0/istep !For TR 60 s and higher
|
2020-11-03 11:31:21 -05:00
|
|
|
ia=ntol/df
|
2020-12-05 13:46:44 -05:00
|
|
|
nsmo=int(0.7*mode_q65*mode_q65)
|
2020-12-06 08:12:58 -05:00
|
|
|
if(nsmo.lt.1) nsmo=1
|
2020-09-25 10:55:21 -04:00
|
|
|
|
2020-08-08 09:14:12 -04:00
|
|
|
allocate(s1(iz,jz))
|
2020-11-30 09:52:47 -05:00
|
|
|
allocate(s3(-64:LL-65,63))
|
2020-09-25 10:55:21 -04:00
|
|
|
allocate(c0(0:nfft-1))
|
2020-11-03 11:31:21 -05:00
|
|
|
allocate(ccf(-ia:ia,-53:214))
|
|
|
|
allocate(ccf1(-ia:ia))
|
2020-08-08 09:14:12 -04:00
|
|
|
|
2020-10-09 13:16:25 -04:00
|
|
|
if(sync(1).eq.99.0) then !Generate the sync vector
|
|
|
|
sync=-22.0/63.0 !Sync tone OFF
|
2020-08-01 09:24:59 -04:00
|
|
|
do k=1,22
|
2020-10-09 13:16:25 -04:00
|
|
|
sync(isync(k))=1.0 !Sync tone ON
|
2020-08-04 13:13:49 -04:00
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
|
|
|
|
fac=1/32767.0
|
2020-10-13 13:49:09 -04:00
|
|
|
do j=1,jz !Compute symbol spectra at step size
|
2020-08-04 13:13:49 -04:00
|
|
|
ia=(j-1)*istep
|
|
|
|
ib=ia+nsps-1
|
|
|
|
k=-1
|
2020-10-13 13:49:09 -04:00
|
|
|
do i=ia,ib,2 !Load iwave data into complex array c0, for r2c FFT
|
2020-08-04 13:13:49 -04:00
|
|
|
xx=iwave(i)
|
|
|
|
yy=iwave(i+1)
|
|
|
|
k=k+1
|
|
|
|
c0(k)=fac*cmplx(xx,yy)
|
|
|
|
enddo
|
2020-09-25 10:55:21 -04:00
|
|
|
c0(k+1:)=0.
|
2020-08-04 13:13:49 -04:00
|
|
|
call four2a(c0,nfft,1,-1,0) !r2c FFT
|
2020-08-08 13:57:24 -04:00
|
|
|
do i=1,iz
|
2020-08-04 13:13:49 -04:00
|
|
|
s1(i,j)=real(c0(i))**2 + aimag(c0(i))**2
|
|
|
|
enddo
|
2020-10-09 13:16:25 -04:00
|
|
|
! For large Doppler spreads, should we smooth the spectra here?
|
2020-12-05 13:46:44 -05:00
|
|
|
do i=1,nsmo
|
|
|
|
call smo121(s1(1:iz,j),iz)
|
|
|
|
enddo
|
2020-08-04 13:13:49 -04:00
|
|
|
enddo
|
|
|
|
|
2020-10-09 13:16:25 -04:00
|
|
|
i0=nint(nfqso/df) !Target QSO frequency
|
2020-12-09 13:45:05 -05:00
|
|
|
if(i0-64.lt.1 .or. i0-65+LL.gt.iz) go to 900
|
2020-12-03 14:28:30 -05:00
|
|
|
call pctile(s1(i0-64:i0-65+LL,1:jz),LL*jz,40,base)
|
2020-11-30 09:52:47 -05:00
|
|
|
s1=s1/base
|
2020-08-04 13:13:49 -04:00
|
|
|
|
2020-10-09 13:16:25 -04:00
|
|
|
! Apply fast AGC
|
|
|
|
s1max=20.0 !Empirical choice
|
2020-12-03 14:28:30 -05:00
|
|
|
do j=1,jz !### Maybe wrong way? ###
|
|
|
|
smax=maxval(s1(i0-64:i0-65+LL,j))
|
|
|
|
if(smax.gt.s1max) s1(i0-64:i0-65+LL,j)=s1(i0-64:i0-65+LL,j)*s1max/smax
|
2020-09-25 13:31:43 -04:00
|
|
|
enddo
|
2020-09-25 10:55:21 -04:00
|
|
|
|
2020-10-13 13:49:09 -04:00
|
|
|
dtstep=nsps/(NSTEP*12000.0) !Step size in seconds
|
2020-11-03 11:31:21 -05:00
|
|
|
ia=ntol/df
|
2020-10-13 13:49:09 -04:00
|
|
|
lag1=-1.0/dtstep
|
2020-10-30 12:02:15 -04:00
|
|
|
lag2=1.0/dtstep + 0.9999
|
|
|
|
j0=0.5/dtstep
|
2020-12-03 14:28:30 -05:00
|
|
|
if(nsps.ge.7200) then
|
2020-10-30 12:02:15 -04:00
|
|
|
j0=1.0/dtstep !Nominal index for start of signal
|
|
|
|
lag2=4.0/dtstep + 0.9999 !Include EME delays
|
|
|
|
endif
|
2020-10-19 15:24:32 -04:00
|
|
|
|
2020-11-30 11:41:50 -05:00
|
|
|
if(ncw.lt.1) go to 100
|
|
|
|
|
2020-11-30 09:52:47 -05:00
|
|
|
!######################################################################
|
2020-11-30 10:45:52 -05:00
|
|
|
! Try list decoding via "Deep Likelihood".
|
2020-10-22 14:05:20 -04:00
|
|
|
|
2020-11-30 10:45:52 -05:00
|
|
|
ipk=0
|
|
|
|
jpk=0
|
|
|
|
ccf_best=0.
|
2020-12-01 11:23:35 -05:00
|
|
|
imsg_best=-1
|
2020-11-30 11:41:50 -05:00
|
|
|
do imsg=1,ncw
|
|
|
|
i=1
|
|
|
|
k=0
|
|
|
|
do j=1,85
|
|
|
|
if(j.eq.isync(i)) then
|
|
|
|
i=i+1
|
|
|
|
itone(j)=-1
|
|
|
|
else
|
|
|
|
k=k+1
|
|
|
|
itone(j)=codewords(k,imsg)
|
|
|
|
endif
|
2020-11-30 09:52:47 -05:00
|
|
|
enddo
|
|
|
|
! Compute 2D ccf using all 85 symbols in the list message
|
2020-11-30 11:41:50 -05:00
|
|
|
ccf=0.
|
2020-11-23 08:47:37 -05:00
|
|
|
do lag=lag1,lag2
|
|
|
|
do k=1,85
|
|
|
|
j=j0 + NSTEP*(k-1) + 1 + lag
|
|
|
|
if(j.ge.1 .and. j.le.jz) then
|
|
|
|
do i=-ia,ia
|
2020-11-30 15:20:19 -05:00
|
|
|
ii=i0+mode_q65*itone(k)+i
|
2020-12-08 11:53:22 -05:00
|
|
|
if(ii.ge.1 .and. ii.le.iz) ccf(i,lag)=ccf(i,lag) + s1(ii,j)
|
2020-11-23 08:47:37 -05:00
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
enddo
|
2020-11-30 10:45:52 -05:00
|
|
|
ccfmax=maxval(ccf)
|
|
|
|
if(ccfmax.gt.ccf_best) then
|
|
|
|
ccf_best=ccfmax
|
|
|
|
ijpk=maxloc(ccf)
|
|
|
|
ipk=ijpk(1)-ia-1
|
|
|
|
jpk=ijpk(2)-53-1
|
2020-12-04 15:37:54 -05:00
|
|
|
f0=nfqso + (ipk-1)*df
|
2020-11-30 10:45:52 -05:00
|
|
|
xdt=jpk*dtstep
|
2020-12-01 11:23:35 -05:00
|
|
|
imsg_best=imsg
|
2020-12-18 13:31:14 -05:00
|
|
|
ccf1=ccf(-ia:ia,jpk)
|
2020-11-23 14:30:36 -05:00
|
|
|
endif
|
2020-11-30 09:52:47 -05:00
|
|
|
enddo ! imsg
|
|
|
|
|
2020-12-18 13:31:14 -05:00
|
|
|
i1=i0+ipk-64
|
|
|
|
i2=i1+LL-1
|
2020-12-01 11:23:35 -05:00
|
|
|
j=j0+jpk-7
|
2020-11-30 09:52:47 -05:00
|
|
|
n=0
|
|
|
|
do k=1,85
|
|
|
|
j=j+8
|
|
|
|
if(sync(k).gt.0.0) then
|
|
|
|
cycle
|
|
|
|
endif
|
|
|
|
n=n+1
|
2020-12-18 13:31:14 -05:00
|
|
|
if(j.ge.1 .and. j.le.jz) s3(-64:LL-65,n)=s1(i1:i2,j)
|
2020-11-30 09:52:47 -05:00
|
|
|
enddo
|
2020-12-01 11:23:35 -05:00
|
|
|
|
2020-11-30 09:52:47 -05:00
|
|
|
nsubmode=0
|
2020-11-30 15:20:19 -05:00
|
|
|
if(mode_q65.eq.2) nsubmode=1
|
|
|
|
if(mode_q65.eq.4) nsubmode=2
|
|
|
|
if(mode_q65.eq.8) nsubmode=3
|
|
|
|
if(mode_q65.eq.16) nsubmode=4
|
2020-11-30 09:52:47 -05:00
|
|
|
nFadingModel=1
|
|
|
|
baud=12000.0/nsps
|
2020-12-05 13:46:44 -05:00
|
|
|
ibwa=1.8*log(baud*mode_q65) + 2
|
2020-12-06 08:12:58 -05:00
|
|
|
ibwb=min(10,ibwa+4)
|
2020-12-05 13:46:44 -05:00
|
|
|
do ibw=ibwa,ibwb
|
2020-11-30 09:52:47 -05:00
|
|
|
b90=1.72**ibw
|
|
|
|
call q65_intrinsics_ff(s3,nsubmode,b90/baud,nFadingModel,s3prob)
|
2020-11-30 11:41:50 -05:00
|
|
|
call q65_dec_fullaplist(s3,s3prob,codewords,ncw,esnodb,dat4,plog,irc)
|
2020-12-04 15:29:46 -05:00
|
|
|
if(irc.ge.0 .and. plog.ge.PLOG_MIN) then
|
2020-11-30 09:52:47 -05:00
|
|
|
snr2=esnodb - db(2500.0/baud)
|
2020-11-30 13:14:18 -05:00
|
|
|
id1=1
|
2020-12-03 14:28:30 -05:00
|
|
|
write(c77,1000) dat4(1:12),dat4(13)/2
|
|
|
|
1000 format(12b6.6,b5.5)
|
|
|
|
call unpack77(c77,0,decoded,unpk77_success) !Unpack to get msgsent
|
2020-12-15 11:37:48 -05:00
|
|
|
! open(55,file='fort.55',status='unknown',position='append')
|
|
|
|
! write(55,3055) nutc,ibw,xdt,f0,85.0*base,ccfmax,snr2,plog, &
|
|
|
|
! irc,trim(decoded)
|
|
|
|
!3055 format(i6,i3,6f8.2,i5,2x,a)
|
|
|
|
! close(55)
|
2020-12-18 13:31:14 -05:00
|
|
|
base=(sum(ccf1(-ia:-ia+9)) + sum(ccf1(ia-9:ia)))/20.0
|
|
|
|
ccf1=ccf1-base
|
|
|
|
smax=maxval(ccf1)
|
|
|
|
if(smax.gt.10.0) ccf1=10.0*ccf1/smax
|
|
|
|
go to 200
|
|
|
|
! go to 900
|
2020-11-30 09:52:47 -05:00
|
|
|
endif
|
|
|
|
enddo
|
2020-11-23 08:47:37 -05:00
|
|
|
|
2020-11-30 10:45:52 -05:00
|
|
|
!######################################################################
|
|
|
|
! Establish xdt, f0, and snr1 using sync symbols (and perhaps some AP symbols)
|
2020-11-30 11:41:50 -05:00
|
|
|
100 ccf=0.
|
2020-11-30 10:45:52 -05:00
|
|
|
irc=-2
|
|
|
|
dat4=0
|
|
|
|
ia=ntol/df
|
2020-12-16 15:51:46 -05:00
|
|
|
if(i0-ia.lt.1 .or. i0+ia.gt.iz) go to 900
|
2020-11-30 10:45:52 -05:00
|
|
|
do lag=lag1,lag2
|
|
|
|
do k=1,85
|
|
|
|
n=NSTEP*(k-1) + 1
|
|
|
|
j=n+lag+j0
|
|
|
|
if(j.ge.1 .and. j.le.jz) then
|
|
|
|
ccf(-ia:ia,lag)=ccf(-ia:ia,lag) + sync(k)*s1(i0-ia:i0+ia,j)
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
ijpk=maxloc(ccf)
|
|
|
|
ipk=ijpk(1)-ia-1
|
|
|
|
jpk=ijpk(2)-53-1
|
2020-12-18 13:31:14 -05:00
|
|
|
|
2020-11-30 10:45:52 -05:00
|
|
|
f0=nfqso + ipk*df
|
|
|
|
xdt=jpk*dtstep
|
|
|
|
sq=0.
|
|
|
|
nsq=0
|
2020-12-18 13:31:14 -05:00
|
|
|
do i=-ia,ia
|
|
|
|
do j=lag1,lag2
|
|
|
|
if(abs(j-jpk).gt.8 .and. abs(i-ipk).gt.ia/2) then
|
|
|
|
sq=sq + ccf(i,j)**2
|
|
|
|
nsq=nsq+1
|
|
|
|
endif
|
|
|
|
enddo
|
2020-11-30 10:45:52 -05:00
|
|
|
enddo
|
|
|
|
rms=sqrt(sq/nsq)
|
|
|
|
smax=ccf(ipk,jpk)
|
|
|
|
snr1=smax/rms
|
2020-12-18 13:31:14 -05:00
|
|
|
ccf1=ccf(-ia:ia,jpk)/rms
|
|
|
|
if(snr1.gt.10.0) ccf1=(10.0/snr1)*ccf1
|
|
|
|
|
|
|
|
200 do i=-ia,ia
|
|
|
|
freq=nfqso + i*df
|
|
|
|
write(17,1100) freq,ccf1(i)
|
|
|
|
1100 format(2f10.3)
|
|
|
|
enddo
|
|
|
|
close(17)
|
2020-11-30 10:45:52 -05:00
|
|
|
|
2020-12-18 13:31:14 -05:00
|
|
|
if(ia.le.60) call zplot_q65(ccf(-ia:ia,lag1:lag2),ia,lag1,lag2, &
|
|
|
|
rms,dtstep,ntol,smax,emedelay)
|
2020-11-23 08:47:37 -05:00
|
|
|
900 return
|
2020-11-30 09:52:47 -05:00
|
|
|
end subroutine q65_sync
|
2020-12-17 17:02:28 -05:00
|
|
|
|
2020-12-18 13:31:14 -05:00
|
|
|
subroutine zplot_q65(ccf,ia,lag1,lag2,rms,dtstep,ntol,smax,emedelay)
|
2020-12-17 17:02:28 -05:00
|
|
|
|
|
|
|
real ccf(-ia:ia,lag1:lag2)
|
2020-12-18 13:31:14 -05:00
|
|
|
character*1 line(130),mark(0:6)
|
|
|
|
character*60 blanks
|
2020-12-17 17:02:28 -05:00
|
|
|
data mark/' ',' ','.','-','+','X','#'/
|
2020-12-18 13:31:14 -05:00
|
|
|
data blanks/' '/
|
2020-12-17 17:02:28 -05:00
|
|
|
|
|
|
|
! open(35,file='ccf.dat',status='unknown',access='stream')
|
|
|
|
! write(35) ia,lag1,lag2,rms,dtstep
|
|
|
|
! write(35) ccf
|
|
|
|
! close(35)
|
|
|
|
open(34,file='ccf.txt',status='unknown')
|
|
|
|
write(34,1000) -ntol,blanks(1:ia-2),0,blanks(1:ia-2),ntol
|
2020-12-18 13:31:14 -05:00
|
|
|
1000 format(4x,i4,a,i1,a,i3)
|
|
|
|
fac=1.0
|
|
|
|
if(smax/rms.gt.7.0) fac=7.0*rms/smax
|
2020-12-17 17:02:28 -05:00
|
|
|
k=0
|
|
|
|
do j=lag2,lag1,-1
|
|
|
|
t=j*dtstep
|
|
|
|
if(emedelay.eq.0.0 .and. abs(t).gt.1.0) cycle
|
|
|
|
do i=-ia,ia
|
|
|
|
k=i+ia+2
|
2020-12-18 13:31:14 -05:00
|
|
|
n=fac*ccf(i,j)/rms
|
2020-12-17 17:02:28 -05:00
|
|
|
if(n.lt.0) n=0
|
|
|
|
if(n.gt.6) n=6
|
|
|
|
line(k)=mark(n)
|
|
|
|
enddo
|
|
|
|
line(1)='|'
|
|
|
|
line(k+1)='|'
|
|
|
|
write(34,1010) t,line(1:k+1)
|
2020-12-18 13:31:14 -05:00
|
|
|
1010 format(f5.2,1x,132a1)
|
2020-12-17 17:02:28 -05:00
|
|
|
enddo
|
|
|
|
close(34)
|
|
|
|
|
|
|
|
return
|
|
|
|
end subroutine zplot_q65
|