2016-05-03 16:30:49 -04:00
|
|
|
subroutine sh65(cx,n5,mode65,ntol,xdf,nspecial,snrdb)
|
2020-05-07 13:54:02 -04:00
|
|
|
parameter(NFFT=2048,NH=NFFT/2)
|
|
|
|
complex cx(n5) !Centered on nfqso, sample rate 1378.125
|
2016-05-03 16:30:49 -04:00
|
|
|
complex c(0:NFFT-1)
|
|
|
|
real s(-NH+1:NH)
|
2020-05-07 13:54:02 -04:00
|
|
|
real ss(-NH+1:NH,16)
|
|
|
|
real sigmax(16)
|
|
|
|
integer ipk(16)
|
2016-05-03 16:30:49 -04:00
|
|
|
|
|
|
|
ss=0.
|
|
|
|
|
2020-05-07 13:54:02 -04:00
|
|
|
jstep=NFFT/8
|
|
|
|
nblks=272
|
2016-05-03 16:30:49 -04:00
|
|
|
ia=-jstep+1
|
|
|
|
do iblk=1,nblks
|
2020-05-07 13:54:02 -04:00
|
|
|
n=mod(iblk-1,16) + 1
|
2016-05-03 16:30:49 -04:00
|
|
|
ia=ia+jstep
|
|
|
|
ib=ia+NFFT-1
|
|
|
|
c=cx(ia:ib)
|
|
|
|
call four2a(c,nfft,1,1,1) !c2c FFT
|
|
|
|
do i=0,NFFT-1
|
|
|
|
j=i
|
|
|
|
if(j.gt.NH) j=j-NFFT
|
2020-05-07 13:54:02 -04:00
|
|
|
ss(j,n)=ss(j,n) + real(c(i))**2 + aimag(c(i))**2
|
2016-05-03 16:30:49 -04:00
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
|
2020-05-07 13:54:02 -04:00
|
|
|
s=1.e-5*s
|
|
|
|
ss=1.e-5*ss
|
2016-05-03 16:30:49 -04:00
|
|
|
df=1378.1285/NFFT
|
|
|
|
nfac=40*mode65
|
|
|
|
dtstep=0.25/df
|
|
|
|
|
2020-05-07 13:54:02 -04:00
|
|
|
do i=1,2*mode65
|
|
|
|
call smo121(ss,16*NFFT)
|
|
|
|
enddo
|
|
|
|
|
|
|
|
! do i=-NH+1,NH
|
|
|
|
! write(72,3072) i*df,(ss(i,j),j=1,16)
|
|
|
|
!3072 format(17f7.1)
|
|
|
|
! enddo
|
|
|
|
|
|
|
|
! Define freq range to be searched. Upper tone is at sync freq + 4*nfac*df Hz
|
2016-05-03 16:30:49 -04:00
|
|
|
fa=-ntol
|
|
|
|
fb=ntol
|
|
|
|
ia2=max(-NH+1,nint(fa/df))
|
2016-10-18 13:27:06 -04:00
|
|
|
ib2=min(NH,nint(fb/df + 4.1*nfac))
|
2016-05-03 16:30:49 -04:00
|
|
|
|
2020-05-07 13:54:02 -04:00
|
|
|
! Find strongest line in each of the 16 phases
|
2016-05-03 16:30:49 -04:00
|
|
|
sbest=0.
|
|
|
|
snrbest=0.
|
|
|
|
nbest=1
|
|
|
|
ipk=0
|
2020-05-07 13:54:02 -04:00
|
|
|
do n=1,16
|
2016-05-03 16:30:49 -04:00
|
|
|
sigmax(n)=0.
|
|
|
|
do i=ia2,ib2
|
|
|
|
sig=ss(i,n)
|
|
|
|
if(sig.ge.sigmax(n)) then
|
|
|
|
ipk(n)=i
|
|
|
|
sigmax(n)=sig
|
|
|
|
if(sig.ge.sbest) then
|
|
|
|
sbest=sig
|
|
|
|
nbest=n
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
enddo
|
2020-05-07 13:54:02 -04:00
|
|
|
n2best=nbest+8
|
|
|
|
if(n2best.gt.16) n2best=nbest-8
|
2016-05-03 16:30:49 -04:00
|
|
|
xdf=min(ipk(nbest),ipk(n2best))*df
|
|
|
|
nspecial=0
|
2016-05-04 14:16:09 -04:00
|
|
|
if(abs(xdf).le.ntol) then
|
|
|
|
idiff=abs(ipk(nbest)-ipk(n2best))
|
|
|
|
xk=float(idiff)/nfac
|
|
|
|
k=nint(xk)
|
|
|
|
iderr=nint((xk-k)*nfac)
|
2016-10-18 13:27:06 -04:00
|
|
|
! maxerr=nint(0.008*abs(idiff) + 0.51)
|
|
|
|
maxerr=nint(0.02*abs(idiff) + 0.51) !### Better test ??? ###
|
2020-05-07 13:54:02 -04:00
|
|
|
! write(71,3001) nbest,n2best,idiff,iderr,maxerr,k, &
|
|
|
|
! ipk(nbest)*df,ipk(n2best)*df,sbest
|
|
|
|
!3001 format(6i4,2f7.1,f7.2)
|
2016-05-04 14:16:09 -04:00
|
|
|
if(abs(iderr).le.maxerr .and. k.ge.2 .and. k.le.4) nspecial=k
|
|
|
|
snrdb=-30.0
|
|
|
|
if(nspecial.gt.0) then
|
|
|
|
call sh65snr(ss(ia2,nbest),ib2-ia2+1,snr1)
|
|
|
|
call sh65snr(ss(ia2,n2best),ib2-ia2+1,snr2)
|
|
|
|
snr=0.5*(snr1+snr2)
|
|
|
|
snrdb=db(snr) - db(2500.0/df) - db(sqrt(nblks/4.0)) + 8.0
|
2016-05-03 16:30:49 -04:00
|
|
|
endif
|
2016-05-04 14:16:09 -04:00
|
|
|
if(snr1.lt.4.0 .or. snr2.lt.4.0 .or. snr.lt.5.0) nspecial=0
|
2016-05-03 16:30:49 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
return
|
|
|
|
end subroutine sh65
|