2024-02-25 20:31:21 -05:00
|
|
|
subroutine sfox_sync(iwave,fsample,isync,f,t)
|
2024-01-31 16:38:22 -05:00
|
|
|
|
2024-02-08 10:45:43 -05:00
|
|
|
use sfox_mod
|
2024-02-24 17:06:11 -05:00
|
|
|
parameter (NSTEPS=8)
|
2024-02-25 20:31:21 -05:00
|
|
|
integer*2 iwave(NMAX)
|
|
|
|
integer isync(44)
|
|
|
|
integer ipeak(1)
|
2024-02-22 14:25:17 -05:00
|
|
|
complex, allocatable :: c(:) !Work array
|
2024-02-25 20:31:21 -05:00
|
|
|
real x(171)
|
|
|
|
real, allocatable :: s(:,:) !Symbol spectra, stepped by NSTEPS
|
|
|
|
real, allocatable :: savg(:) !Average spectrum
|
2024-02-23 10:44:49 -05:00
|
|
|
real, allocatable :: ccf(:,:) !
|
2024-02-25 20:31:21 -05:00
|
|
|
character*1 line(-15:15),mark(0:6),c1
|
|
|
|
data mark/' ','.','-','+','X','$','#'/
|
2024-01-31 16:38:22 -05:00
|
|
|
|
2024-02-25 20:31:21 -05:00
|
|
|
nh=NFFT1/2
|
|
|
|
istep=NSPS/NSTEPS
|
|
|
|
jz=(13.5*fsample)/istep
|
|
|
|
df=fsample/NFFT1
|
|
|
|
tstep=istep/fsample
|
|
|
|
x=0.
|
|
|
|
do i=1,NS
|
|
|
|
x(isync(i))=1.0
|
|
|
|
enddo
|
2024-02-22 14:25:17 -05:00
|
|
|
|
2024-02-25 20:31:21 -05:00
|
|
|
allocate(s(0:nh/2,jz))
|
|
|
|
allocate(savg(0:nh/2))
|
|
|
|
allocate(c(0:NFFT1-1))
|
2024-02-22 14:25:17 -05:00
|
|
|
|
2024-02-25 20:31:21 -05:00
|
|
|
s=0.
|
|
|
|
savg=0.
|
2024-02-22 14:25:17 -05:00
|
|
|
fac=1.0/NFFT1
|
2024-02-25 20:31:21 -05:00
|
|
|
! Compute symbol spectra with df=baud/2 and NSTEPS steps per symbol.
|
|
|
|
do j=1,jz
|
|
|
|
k=(j-1)*istep
|
|
|
|
do i=0,nh-1
|
|
|
|
c(i)=cmplx(fac*iwave(k+2*i+1),fac*iwave(k+2*i+2))
|
|
|
|
enddo
|
|
|
|
c(nh:)=0.
|
|
|
|
call four2a(c,NFFT1,1,-1,0) !Forward FFT, r2c
|
|
|
|
do i=0,nh/2
|
|
|
|
p=real(c(i))*real(c(i)) + aimag(c(i))*aimag(c(i))
|
|
|
|
s(i,j)=p
|
|
|
|
savg(i)=savg(i) + p
|
|
|
|
enddo
|
|
|
|
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)
|
2024-01-31 16:38:22 -05:00
|
|
|
enddo
|
2024-02-25 20:31:21 -05:00
|
|
|
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)
|
2024-01-31 16:38:22 -05:00
|
|
|
enddo
|
2024-02-25 20:31:21 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
nsz=(nint(3.0*fsample) + NS*NSPS)/istep
|
|
|
|
|
2024-01-31 16:38:22 -05:00
|
|
|
|
2024-02-22 13:41:09 -05:00
|
|
|
pmax=0.
|
|
|
|
ntol=100
|
2024-02-23 14:52:02 -05:00
|
|
|
iz=nint(ntol/df)
|
2024-02-22 13:41:09 -05:00
|
|
|
i0=nint(1500.0/df)
|
|
|
|
ipk=-999
|
|
|
|
jpk=-999
|
2024-02-24 17:06:11 -05:00
|
|
|
jz=nsz-NSTEPS*NS
|
2024-02-23 15:12:19 -05:00
|
|
|
allocate(ccf(-iz:iz,1:jz))
|
2024-02-23 14:42:09 -05:00
|
|
|
ccf=0.
|
2024-02-23 10:44:49 -05:00
|
|
|
do j=1,jz
|
2024-02-22 13:41:09 -05:00
|
|
|
do i=-iz,iz
|
|
|
|
p=0.
|
|
|
|
do k=1,NS
|
|
|
|
ii=i0+i+(2*(isync(k)-NQ/2))
|
2024-02-24 17:06:11 -05:00
|
|
|
jj=j + NSTEPS*(k-1)
|
2024-02-22 13:41:09 -05:00
|
|
|
p=p + s(ii,jj)
|
2024-01-31 18:59:41 -05:00
|
|
|
enddo
|
2024-02-23 10:44:49 -05:00
|
|
|
ccf(i,j)=p
|
2024-02-22 13:41:09 -05:00
|
|
|
if(p.gt.pmax) then
|
|
|
|
pmax=p
|
|
|
|
ipk=i
|
|
|
|
jpk=j
|
|
|
|
endif
|
2024-01-31 16:38:22 -05:00
|
|
|
enddo
|
2024-02-22 13:41:09 -05:00
|
|
|
enddo
|
|
|
|
|
2024-02-23 15:12:19 -05:00
|
|
|
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
|
2024-02-23 10:44:49 -05:00
|
|
|
|
2024-02-23 14:33:11 -05:00
|
|
|
dfreq=(ipk+dxi)*df
|
|
|
|
f=1500.0+dfreq
|
|
|
|
t=(jpk+dxj-201.0)*istep/fsample
|
2024-02-23 10:44:49 -05:00
|
|
|
|
2024-02-23 14:33:11 -05:00
|
|
|
return
|
2024-02-10 19:51:36 -05:00
|
|
|
end subroutine sfox_sync
|