2019-01-26 12:42:07 -05:00
|
|
|
subroutine ft4_decode(cdatetime0,nfqso,iwave,ndecodes,mycall,hiscall,nrx,line)
|
|
|
|
|
|
|
|
use packjt77
|
|
|
|
include 'ft4_params.f90'
|
2019-01-27 00:03:54 -05:00
|
|
|
parameter (NSS=NSPS/NDOWN)
|
2019-01-30 12:22:41 -05:00
|
|
|
|
2019-01-26 12:42:07 -05:00
|
|
|
character message*37
|
|
|
|
character c77*77
|
|
|
|
character*61 line
|
|
|
|
character*37 decodes(100)
|
|
|
|
character*120 data_dir
|
|
|
|
character*17 cdatetime0
|
|
|
|
character*6 mycall,hiscall,hhmmss
|
|
|
|
|
2019-01-27 00:03:54 -05:00
|
|
|
complex cd2(0:NMAX/NDOWN-1) !Complex waveform
|
|
|
|
complex cb(0:NMAX/NDOWN-1)
|
2019-01-30 12:22:41 -05:00
|
|
|
complex cd(0:NN*NSS-1) !Complex waveform
|
2019-01-27 00:03:54 -05:00
|
|
|
complex ctwk(4*NSS),ctwk2(4*NSS)
|
|
|
|
complex csymb(NSS)
|
2019-01-26 12:42:07 -05:00
|
|
|
complex cs(0:3,NN)
|
|
|
|
real s4(0:3,NN)
|
|
|
|
|
2019-01-27 00:03:54 -05:00
|
|
|
real bmeta(2*NN),bmetb(2*NN),bmetc(2*NN)
|
2019-01-26 12:42:07 -05:00
|
|
|
real s(NH1,NHSYM)
|
|
|
|
real a(5)
|
2019-01-27 00:03:54 -05:00
|
|
|
real llr(2*ND),llr2(2*ND),llra(2*ND),llrb(2*ND),llrc(2*ND)
|
2019-01-26 12:42:07 -05:00
|
|
|
real s2(0:255)
|
|
|
|
real candidate(3,100)
|
|
|
|
real savg(NH1),sbase(NH1)
|
2019-01-30 12:22:41 -05:00
|
|
|
|
2019-01-26 12:42:07 -05:00
|
|
|
integer icos4(0:3)
|
|
|
|
integer*2 iwave(NMAX) !Generated full-length waveform
|
2019-01-27 00:03:54 -05:00
|
|
|
integer*1 message77(77),apmask(2*ND),cw(2*ND)
|
|
|
|
integer*1 hbits(2*NN)
|
2019-01-26 12:42:07 -05:00
|
|
|
integer graymap(0:3)
|
|
|
|
integer ip(1)
|
|
|
|
logical unpk77_success
|
2019-01-27 00:03:54 -05:00
|
|
|
logical one(0:255,0:7) ! 256 4-symbol sequences, 8 bits
|
2019-01-26 12:42:07 -05:00
|
|
|
logical first
|
2019-01-30 12:22:41 -05:00
|
|
|
|
2019-01-26 12:42:07 -05:00
|
|
|
data icos4/0,1,3,2/
|
|
|
|
data graymap/0,1,3,2/
|
|
|
|
data first/.true./
|
2019-01-30 12:22:41 -05:00
|
|
|
save one,first
|
2019-01-26 12:42:07 -05:00
|
|
|
|
2019-01-29 10:39:34 -05:00
|
|
|
hhmmss=cdatetime0(8:13)
|
2019-01-30 12:22:41 -05:00
|
|
|
fs=12000.0/NDOWN !Sample rate after downsampling
|
|
|
|
dt=1/fs !Sample interval after downsample (s)
|
|
|
|
tt=NSPS*dt !Duration of "itone" symbols (s)
|
|
|
|
txt=NZ*dt !Transmission length (s) without ramp up/down
|
2019-01-26 12:42:07 -05:00
|
|
|
twopi=8.0*atan(1.0)
|
2019-01-27 00:03:54 -05:00
|
|
|
h=1.0
|
2019-01-26 12:42:07 -05:00
|
|
|
|
|
|
|
if(first) then
|
|
|
|
one=.false.
|
|
|
|
do i=0,255
|
|
|
|
do j=0,7
|
|
|
|
if(iand(i,2**j).ne.0) one(i,j)=.true.
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
first=.false.
|
|
|
|
endif
|
|
|
|
|
|
|
|
candidate=0.0
|
|
|
|
ncand=0
|
2019-01-30 12:22:41 -05:00
|
|
|
syncmin=1.2
|
|
|
|
maxcand=100
|
2019-01-26 12:42:07 -05:00
|
|
|
|
2019-01-30 12:22:41 -05:00
|
|
|
! These are temporary. Correct values should be passed in as arguments.
|
|
|
|
data_dir="."
|
|
|
|
fMHz=7.074
|
2019-01-27 20:28:41 -05:00
|
|
|
fa=400.0
|
2019-01-27 20:19:47 -05:00
|
|
|
fb=3000.0
|
2019-01-26 12:42:07 -05:00
|
|
|
|
2019-01-30 12:22:41 -05:00
|
|
|
call getcandidates4(iwave,fa,fb,syncmin,nfqso,maxcand,savg,candidate, &
|
|
|
|
ncand,sbase)
|
|
|
|
|
2019-01-26 12:42:07 -05:00
|
|
|
ndecodes=0
|
|
|
|
do icand=1,ncand
|
2019-01-27 20:19:47 -05:00
|
|
|
f0=candidate(1,icand)
|
2019-01-29 13:56:04 -05:00
|
|
|
xsnr=10*log10(candidate(3,icand))-18.0
|
2019-01-26 12:42:07 -05:00
|
|
|
if( f0.le.375.0 .or. f0.ge.(5000.0-375.0) ) cycle
|
2019-01-29 16:42:30 -05:00
|
|
|
call ft4_downsample(iwave,f0,cd2) ! downsample from 512 Sa/Symbol to 32 Sa/Symbol
|
2019-01-30 13:47:01 -05:00
|
|
|
sum2=sum(cd2*conjg(cd2))/(real(NMAX)/real(NDOWN))
|
2019-01-26 12:42:07 -05:00
|
|
|
if(sum2.gt.0.0) cd2=cd2/sqrt(sum2)
|
2019-01-30 12:22:41 -05:00
|
|
|
! Sample rate is now 12000/16 = 750 samples/second
|
2019-01-27 20:19:47 -05:00
|
|
|
do isync=1,2
|
|
|
|
if(isync.eq.1) then
|
|
|
|
idfmin=-50
|
|
|
|
idfmax=50
|
|
|
|
idfstp=3
|
|
|
|
ibmin=0
|
|
|
|
ibmax=374
|
|
|
|
ibstp=4
|
|
|
|
else
|
|
|
|
idfmin=idfbest-5
|
|
|
|
idfmax=idfbest+5
|
|
|
|
idfstp=1
|
|
|
|
ibmin=max(0,ibest-5)
|
|
|
|
ibmax=min(ibest+5,NMAX/NDOWN-1)
|
|
|
|
ibstp=1
|
|
|
|
endif
|
|
|
|
ibest=-1
|
|
|
|
smax=-99.
|
|
|
|
idfbest=0
|
|
|
|
do idf=idfmin,idfmax,idfstp
|
|
|
|
a=0.
|
|
|
|
a(1)=real(idf)
|
|
|
|
ctwk=1.
|
|
|
|
call twkfreq1(ctwk,4*NSS,fs,a,ctwk2)
|
|
|
|
do istart=ibmin,ibmax,ibstp
|
2019-01-30 12:22:41 -05:00
|
|
|
call sync4d(cd2,istart,ctwk2,1,sync) !Find sync power
|
2019-01-27 20:19:47 -05:00
|
|
|
if(sync.gt.smax) then
|
|
|
|
smax=sync
|
|
|
|
ibest=istart
|
|
|
|
idfbest=idf
|
|
|
|
endif
|
|
|
|
enddo
|
2019-01-26 12:42:07 -05:00
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
|
2019-01-27 20:19:47 -05:00
|
|
|
f0=f0+real(idfbest)
|
2019-01-30 12:22:41 -05:00
|
|
|
call ft4_downsample(iwave,f0,cb) !Final downsample with corrected f0
|
2019-01-27 00:03:54 -05:00
|
|
|
sum2=sum(abs(cb)**2)/(real(NSS)*NN)
|
2019-01-26 12:42:07 -05:00
|
|
|
if(sum2.gt.0.0) cb=cb/sqrt(sum2)
|
2019-01-27 00:03:54 -05:00
|
|
|
cd=cb(ibest:ibest+NN*NSS-1)
|
2019-01-26 12:42:07 -05:00
|
|
|
do k=1,NN
|
2019-01-27 00:03:54 -05:00
|
|
|
i1=(k-1)*NSS
|
|
|
|
csymb=cd(i1:i1+NSS-1)
|
|
|
|
call four2a(csymb,NSS,1,-1,1)
|
|
|
|
cs(0:3,k)=csymb(1:4)
|
2019-01-26 12:42:07 -05:00
|
|
|
s4(0:3,k)=abs(csymb(1:4))
|
|
|
|
enddo
|
|
|
|
|
2019-01-30 12:22:41 -05:00
|
|
|
! Sync quality check
|
2019-01-26 12:42:07 -05:00
|
|
|
is1=0
|
|
|
|
is2=0
|
|
|
|
is3=0
|
2019-01-27 00:03:54 -05:00
|
|
|
is4=0
|
2019-01-26 12:42:07 -05:00
|
|
|
do k=1,4
|
|
|
|
ip=maxloc(s4(:,k))
|
|
|
|
if(icos4(k-1).eq.(ip(1)-1)) is1=is1+1
|
2019-01-27 00:03:54 -05:00
|
|
|
ip=maxloc(s4(:,k+33))
|
2019-01-26 12:42:07 -05:00
|
|
|
if(icos4(k-1).eq.(ip(1)-1)) is2=is2+1
|
2019-01-27 00:03:54 -05:00
|
|
|
ip=maxloc(s4(:,k+66))
|
2019-01-26 12:42:07 -05:00
|
|
|
if(icos4(k-1).eq.(ip(1)-1)) is3=is3+1
|
2019-01-27 00:03:54 -05:00
|
|
|
ip=maxloc(s4(:,k+99))
|
|
|
|
if(icos4(k-1).eq.(ip(1)-1)) is4=is4+1
|
2019-01-26 12:42:07 -05:00
|
|
|
enddo
|
2019-01-30 12:22:41 -05:00
|
|
|
nsync=is1+is2+is3+is4 !Number of hard sync errors, 0-16
|
2019-01-30 13:47:01 -05:00
|
|
|
if(smax .lt. 0.9 .or. nsync .lt. 9) cycle
|
2019-01-30 15:49:52 -05:00
|
|
|
|
|
|
|
do nseq=1,3 !Try coherent sequences of 1, 2, and 4 symbols
|
2019-01-26 12:42:07 -05:00
|
|
|
if(nseq.eq.1) nsym=1
|
|
|
|
if(nseq.eq.2) nsym=2
|
|
|
|
if(nseq.eq.3) nsym=4
|
|
|
|
nt=2**(2*nsym)
|
2019-01-27 00:03:54 -05:00
|
|
|
do ks=1,NN-nsym+1,nsym !87+16=103 symbols.
|
2019-01-26 12:42:07 -05:00
|
|
|
amax=-1.0
|
|
|
|
do i=0,nt-1
|
|
|
|
i1=i/64
|
|
|
|
i2=iand(i,63)/16
|
|
|
|
i3=iand(i,15)/4
|
|
|
|
i4=iand(i,3)
|
|
|
|
if(nsym.eq.1) then
|
|
|
|
s2(i)=abs(cs(graymap(i4),ks))
|
|
|
|
elseif(nsym.eq.2) then
|
|
|
|
s2(i)=abs(cs(graymap(i3),ks)+cs(graymap(i4),ks+1))
|
|
|
|
elseif(nsym.eq.4) then
|
|
|
|
s2(i)=abs(cs(graymap(i1),ks ) + &
|
|
|
|
cs(graymap(i2),ks+1) + &
|
|
|
|
cs(graymap(i3),ks+2) + &
|
|
|
|
cs(graymap(i4),ks+3) &
|
|
|
|
)
|
|
|
|
else
|
|
|
|
print*,"Error - nsym must be 1, 2, or 4."
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
ipt=1+(ks-1)*2
|
|
|
|
if(nsym.eq.1) ibmax=1
|
|
|
|
if(nsym.eq.2) ibmax=3
|
|
|
|
if(nsym.eq.4) ibmax=7
|
|
|
|
do ib=0,ibmax
|
|
|
|
bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - &
|
|
|
|
maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))
|
2019-01-27 00:03:54 -05:00
|
|
|
if(ipt+ib.gt.2*NN) cycle
|
2019-01-26 12:42:07 -05:00
|
|
|
if(nsym.eq.1) then
|
|
|
|
bmeta(ipt+ib)=bm
|
|
|
|
elseif(nsym.eq.2) then
|
|
|
|
bmetb(ipt+ib)=bm
|
|
|
|
elseif(nsym.eq.4) then
|
|
|
|
bmetc(ipt+ib)=bm
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
|
2019-01-27 00:03:54 -05:00
|
|
|
call normalizebmet(bmeta,2*NN)
|
|
|
|
call normalizebmet(bmetb,2*NN)
|
|
|
|
call normalizebmet(bmetc,2*NN)
|
2019-01-26 12:42:07 -05:00
|
|
|
|
|
|
|
hbits=0
|
|
|
|
where(bmeta.ge.0) hbits=1
|
|
|
|
ns1=count(hbits( 1: 8).eq.(/0,0,0,1,1,0,1,1/))
|
2019-01-27 00:03:54 -05:00
|
|
|
ns2=count(hbits( 67: 74).eq.(/0,0,0,1,1,0,1,1/))
|
|
|
|
ns3=count(hbits(133:140).eq.(/0,0,0,1,1,0,1,1/))
|
|
|
|
ns4=count(hbits(199:206).eq.(/0,0,0,1,1,0,1,1/))
|
|
|
|
nsync_qual=ns1+ns2+ns3+ns4
|
2019-01-26 12:42:07 -05:00
|
|
|
|
2019-01-30 13:47:01 -05:00
|
|
|
if(nsync_qual.lt. 20) cycle
|
2019-01-27 20:19:47 -05:00
|
|
|
|
2019-01-27 00:03:54 -05:00
|
|
|
scalefac=2.83
|
|
|
|
llra( 1: 58)=bmeta( 9: 66)
|
|
|
|
llra( 59:116)=bmeta( 75:132)
|
|
|
|
llra(117:174)=bmeta(141:198)
|
|
|
|
llra=scalefac*llra
|
|
|
|
llrb( 1: 58)=bmetb( 9: 66)
|
|
|
|
llrb( 59:116)=bmetb( 75:132)
|
|
|
|
llrb(117:174)=bmetb(141:198)
|
|
|
|
llrb=scalefac*llrb
|
|
|
|
llrc( 1: 58)=bmetc( 9: 66)
|
|
|
|
llrc( 59:116)=bmetc( 75:132)
|
|
|
|
llrc(117:174)=bmetc(141:198)
|
|
|
|
llrc=scalefac*llrc
|
2019-01-26 12:42:07 -05:00
|
|
|
|
|
|
|
do isd=1,3
|
|
|
|
if(isd.eq.1) llr=llra
|
|
|
|
if(isd.eq.2) llr=llrb
|
|
|
|
if(isd.eq.3) llr=llrc
|
|
|
|
apmask=0
|
|
|
|
max_iterations=40
|
|
|
|
do ibias=0,0
|
|
|
|
llr2=llr
|
|
|
|
if(ibias.eq.1) llr2=llr+0.4
|
|
|
|
if(ibias.eq.2) llr2=llr-0.4
|
2019-01-30 12:22:41 -05:00
|
|
|
call bpdecode174_91(llr2,apmask,max_iterations,message77, &
|
|
|
|
cw,nharderror,niterations)
|
2019-01-26 12:42:07 -05:00
|
|
|
if(nharderror.ge.0) exit
|
|
|
|
enddo
|
|
|
|
if(sum(message77).eq.0) cycle
|
|
|
|
if( nharderror.ge.0 ) then
|
|
|
|
write(c77,'(77i1)') message77(1:77)
|
|
|
|
call unpack77(c77,1,message,unpk77_success)
|
|
|
|
idupe=0
|
|
|
|
do i=1,ndecodes
|
|
|
|
if(decodes(i).eq.message) idupe=1
|
|
|
|
enddo
|
|
|
|
if(idupe.eq.1) exit
|
|
|
|
ndecodes=ndecodes+1
|
|
|
|
decodes(ndecodes)=message
|
2019-01-27 00:03:54 -05:00
|
|
|
nsnr=nint(xsnr)
|
2019-01-26 12:42:07 -05:00
|
|
|
freq=f0
|
|
|
|
|
|
|
|
write(line,1000) hhmmss,nsnr,ibest/750.0,nint(freq),message
|
|
|
|
1000 format(a6,i4,f5.2,i5,' + ',1x,a37)
|
2019-01-27 00:03:54 -05:00
|
|
|
open(24,file='all_ft4.txt',status='unknown',position='append')
|
2019-01-26 12:42:07 -05:00
|
|
|
write(24,1002) cdatetime0,nsnr,ibest/750.0,nint(freq),message, &
|
|
|
|
nharderror,nsync_qual,isd,niterations
|
|
|
|
if(hhmmss.eq.' ') write(*,1002) cdatetime0,nsnr, &
|
2019-01-30 12:22:41 -05:00
|
|
|
ibest/750.0,nint(freq),message,nharderror,nsync_qual,isd, &
|
|
|
|
niterations
|
2019-01-26 12:42:07 -05:00
|
|
|
1002 format(a17,i4,f6.2,i5,' Rx ',a37,4i5)
|
|
|
|
close(24)
|
|
|
|
|
2019-01-30 12:22:41 -05:00
|
|
|
!### Temporary: assume most recent decoded message conveys "hiscall". ###
|
2019-01-26 12:42:07 -05:00
|
|
|
i0=index(message,' ')
|
|
|
|
if(i0.ge.3 .and. i0.le.7) then
|
|
|
|
hiscall=message(i0+1:i0+6)
|
|
|
|
i1=index(hiscall,' ')
|
|
|
|
if(i1.gt.0) hiscall=hiscall(1:i1)
|
|
|
|
endif
|
|
|
|
nrx=-1
|
|
|
|
if(index(message,'CQ ').eq.1) nrx=1
|
|
|
|
if((index(message,trim(mycall)//' ').eq.1) .and. &
|
|
|
|
(index(message,' '//trim(hiscall)//' ').ge.4)) then
|
|
|
|
if(index(message,' 559 ').gt.8) nrx=2
|
|
|
|
if(index(message,' R 559 ').gt.8) nrx=3
|
|
|
|
if(index(message,' RR73 ').gt.8) nrx=4
|
|
|
|
endif
|
|
|
|
!###
|
|
|
|
exit
|
|
|
|
|
|
|
|
endif
|
2019-01-30 12:22:41 -05:00
|
|
|
enddo !Sequence estimation
|
|
|
|
enddo !Candidate list
|
2019-01-26 12:42:07 -05:00
|
|
|
|
|
|
|
return
|
|
|
|
end subroutine ft4_decode
|
|
|
|
|
|
|
|
subroutine ft4_downsample(iwave,f0,c)
|
|
|
|
|
|
|
|
! Input: i*2 data in iwave() at sample rate 12000 Hz
|
|
|
|
! Output: Complex data in c(), sampled at 1200 Hz
|
|
|
|
|
|
|
|
include 'ft4_params.f90'
|
|
|
|
parameter (NFFT2=NMAX/16)
|
|
|
|
integer*2 iwave(NMAX)
|
2019-01-27 00:03:54 -05:00
|
|
|
complex c(0:NMAX/NDOWN-1)
|
2019-01-26 12:42:07 -05:00
|
|
|
complex c1(0:NFFT2-1)
|
|
|
|
complex cx(0:NMAX/2)
|
2019-01-30 13:47:01 -05:00
|
|
|
real x(NMAX), window(0:NFFT2-1)
|
2019-01-26 12:42:07 -05:00
|
|
|
equivalence (x,cx)
|
2019-01-30 13:47:01 -05:00
|
|
|
logical first
|
|
|
|
data first/.true./
|
|
|
|
save first,window
|
2019-01-26 12:42:07 -05:00
|
|
|
|
|
|
|
df=12000.0/NMAX
|
2019-01-30 13:47:01 -05:00
|
|
|
baud=12000.0/NSPS
|
|
|
|
if(first) then
|
|
|
|
bw_transition = 0.5*baud
|
|
|
|
bw_flat = 4*baud
|
|
|
|
iwt = bw_transition / df
|
|
|
|
iwf = bw_flat / df
|
|
|
|
pi=4.0*atan(1.0)
|
|
|
|
window(0:iwt-1) = 0.5*(1+cos(pi*(/(i,i=iwt-1,0,-1)/)/iwt))
|
|
|
|
window(iwt:iwt+iwf-1)=1.0
|
|
|
|
window(iwt+iwf:2*iwt+iwf-1) = 0.5*(1+cos(pi*(/(i,i=0,iwt)/)/iwt))
|
|
|
|
window(2*iwt+iwf:)=0.0
|
|
|
|
iws = baud / df
|
|
|
|
window=cshift(window,iws)
|
|
|
|
first=.false.
|
|
|
|
endif
|
|
|
|
|
2019-01-26 12:42:07 -05:00
|
|
|
x=iwave
|
|
|
|
call four2a(x,NMAX,1,-1,0) !r2c FFT to freq domain
|
|
|
|
i0=nint(f0/df)
|
|
|
|
c1=0.
|
|
|
|
c1(0)=cx(i0)
|
|
|
|
do i=1,NFFT2/2
|
2019-01-30 13:47:01 -05:00
|
|
|
if(i0+i.le.NMAX/2) c1(i)=cx(i0+i)
|
|
|
|
if(i0-i.ge.0) c1(NFFT2-i)=cx(i0-i)
|
2019-01-26 12:42:07 -05:00
|
|
|
enddo
|
2019-01-30 13:47:01 -05:00
|
|
|
c1=c1*window/NFFT2
|
2019-01-26 12:42:07 -05:00
|
|
|
call four2a(c1,NFFT2,1,1,1) !c2c FFT back to time domain
|
2019-01-27 00:03:54 -05:00
|
|
|
c=c1(0:NMAX/NDOWN-1)
|
2019-01-30 12:22:41 -05:00
|
|
|
|
2019-01-26 12:42:07 -05:00
|
|
|
return
|
|
|
|
end subroutine ft4_downsample
|
|
|
|
|