2020-08-09 11:04:49 -04:00
|
|
|
subroutine sync66(iwave,nmax,mode66,nsps,nfqso,ntol,xdt,f0,snr1)
|
2020-08-01 09:24:59 -04:00
|
|
|
|
2020-08-04 13:13:49 -04:00
|
|
|
parameter (NSTEP=4) !Quarter-symbol steps
|
|
|
|
integer*2 iwave(0:nmax-1) !Raw data
|
|
|
|
integer b11(11) !Barker 11 code
|
|
|
|
integer ijpk(2) !Indices i and j at peak of sync_sig
|
2020-08-08 09:14:12 -04:00
|
|
|
real, allocatable :: s1(:,:) !Symbol spectra
|
2020-08-08 13:57:24 -04:00
|
|
|
real, allocatable :: x(:) !Work array; demoduated 2FSK sync signal
|
2020-08-04 13:13:49 -04:00
|
|
|
real sync(4*85) !sync vector
|
|
|
|
real sync_sig(-64:64,-15:15)
|
2020-08-08 09:14:12 -04:00
|
|
|
complex, allocatable :: c0(:) !Complex spectrum of symbol
|
2020-08-04 13:13:49 -04:00
|
|
|
data b11/1,1,1,0,0,0,1,0,0,1,0/ !Barker 11 code
|
|
|
|
data sync(1)/99.0/
|
|
|
|
save sync
|
2020-08-01 09:24:59 -04:00
|
|
|
|
2020-08-08 13:57:24 -04:00
|
|
|
nfft=2*nsps
|
2020-08-08 09:14:12 -04:00
|
|
|
df=12000.0/nfft
|
|
|
|
istep=nsps/NSTEP
|
2020-08-08 13:57:24 -04:00
|
|
|
iz=5000.0/df !Uppermost frequency bin, at 5000 Hz
|
|
|
|
txt=85.0*nsps/12000.0
|
|
|
|
jz=(txt+1.0)*12000.0/istep !Number of quarter-symbol steps
|
|
|
|
if(nsps.ge.7680) jz=(txt+2.0)*12000.0/istep !For TR 60 s and higher
|
2020-08-08 09:14:12 -04:00
|
|
|
allocate(s1(iz,jz))
|
|
|
|
allocate(x(jz))
|
|
|
|
allocate(c0(0:nsps))
|
|
|
|
|
2020-08-04 13:13:49 -04:00
|
|
|
if(sync(1).eq.99.0) then
|
|
|
|
sync=0.
|
2020-08-01 09:24:59 -04:00
|
|
|
do k=1,22
|
2020-08-04 13:13:49 -04:00
|
|
|
kk=k
|
|
|
|
if(kk.gt.11) kk=k-11
|
2020-08-08 13:57:24 -04:00
|
|
|
i=4*NSTEP*(k-1) + 1
|
|
|
|
sync(i)=2.0*b11(kk) - 1.0
|
2020-08-04 13:13:49 -04:00
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
|
|
|
|
fac=1/32767.0
|
2020-08-09 11:04:49 -04:00
|
|
|
do j=1,jz !Compute symbol spectra at quarter-symbol steps
|
2020-08-04 13:13:49 -04:00
|
|
|
ia=(j-1)*istep
|
|
|
|
ib=ia+nsps-1
|
|
|
|
k=-1
|
|
|
|
do i=ia,ib,2
|
|
|
|
xx=iwave(i)
|
|
|
|
yy=iwave(i+1)
|
|
|
|
k=k+1
|
|
|
|
c0(k)=fac*cmplx(xx,yy)
|
|
|
|
enddo
|
|
|
|
c0(k+1:nfft/2)=0.
|
|
|
|
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
|
|
|
|
enddo
|
|
|
|
|
|
|
|
i0=nint(nfqso/df)
|
2020-08-08 13:57:24 -04:00
|
|
|
call pctile(s1(i0-64:i0+192,1:jz),129*jz,40,base)
|
2020-08-04 13:13:49 -04:00
|
|
|
s1=s1/base
|
|
|
|
s1max=20.0
|
|
|
|
|
|
|
|
! Apply AGC
|
2020-08-08 13:57:24 -04:00
|
|
|
do j=1,jz
|
2020-08-04 13:13:49 -04:00
|
|
|
x(j)=maxval(s1(i0-64:i0+192,j))
|
|
|
|
if(x(j).gt.s1max) s1(i0-64:i0+192,j)=s1(i0-64:i0+192,j)*s1max/x(j)
|
|
|
|
enddo
|
|
|
|
|
|
|
|
sync_sig=0.
|
|
|
|
ia=min(64,nint(ntol/df))
|
2020-08-08 13:57:24 -04:00
|
|
|
dt4=nsps/(NSTEP*12000.0) !duration of 1/4 symbol
|
2020-08-09 11:04:49 -04:00
|
|
|
! lag2=nint(0.5/dt4)
|
|
|
|
! if(nsps.ge.7680) lag2=nint(1.0/dt4)
|
|
|
|
! lag1=-lag2
|
2020-08-08 13:57:24 -04:00
|
|
|
|
|
|
|
jadd=11
|
|
|
|
if(nsps.ge.3600) jadd=7
|
|
|
|
if(nsps.ge.7680) jadd=6
|
|
|
|
if(nsps.ge.16000) jadd=3
|
|
|
|
if(nsps.ge.41472) jadd=1
|
|
|
|
|
2020-08-04 13:13:49 -04:00
|
|
|
do i=-ia,ia
|
2020-08-09 11:04:49 -04:00
|
|
|
x=s1(i0+2*mode66+i,:)-s1(i0+i,:) !Do the 2FSK demodulation
|
2020-08-08 13:57:24 -04:00
|
|
|
! do lag=lag1,lag2
|
2020-08-04 13:13:49 -04:00
|
|
|
do lag=-15,15
|
2020-08-08 13:57:24 -04:00
|
|
|
do k=1,22
|
|
|
|
n=4*NSTEP*(k-1) + 1
|
|
|
|
j=n+lag+jadd
|
|
|
|
if(j.ge.1 .and. j.le.jz) sync_sig(i,lag)=sync_sig(i,lag) + sync(n)*x(j)
|
2020-08-04 13:13:49 -04:00
|
|
|
enddo
|
2020-08-01 09:24:59 -04:00
|
|
|
enddo
|
|
|
|
enddo
|
2020-08-04 13:13:49 -04:00
|
|
|
|
|
|
|
ijpk=maxloc(sync_sig)
|
|
|
|
ii=ijpk(1)-65
|
|
|
|
jj=ijpk(2)-16
|
|
|
|
|
|
|
|
! Use peakup() here?
|
|
|
|
f0=nfqso + ii*df
|
|
|
|
jdt=jj
|
2020-08-08 13:57:24 -04:00
|
|
|
|
|
|
|
! j0=0.5/dt4
|
|
|
|
! if(nsps.ge.7680) j0=1.0/dt4
|
|
|
|
|
2020-08-04 13:13:49 -04:00
|
|
|
tsym=nsps/12000.0
|
|
|
|
xdt=jdt*tsym/4.0
|
|
|
|
|
|
|
|
snr1=maxval(sync_sig)/22.0
|
|
|
|
|
|
|
|
! do i=-64,64
|
|
|
|
! write(62,3062) nfqso+i*df,sync_sig(i,jj)
|
|
|
|
!3062 format(2f12.3)
|
|
|
|
! enddo
|
|
|
|
|
|
|
|
! do j=-15,15
|
|
|
|
! write(63,3063) j,j*dt4,sync_sig(ii,j)
|
|
|
|
!3063 format(i5,2f12.3)
|
|
|
|
! enddo
|
2020-08-01 09:24:59 -04:00
|
|
|
|
|
|
|
return
|
|
|
|
end subroutine sync66
|