2016-09-01 17:50:52 -04:00
|
|
|
subroutine detectmsk144(cbig,n,lines,nmessages,nutc,ntol,t00)
|
2016-06-11 22:42:51 -04:00
|
|
|
use timer_module, only: timer
|
|
|
|
|
2016-07-17 16:05:27 -04:00
|
|
|
parameter (NSPM=864, NPTS=3*NSPM, MAXSTEPS=1700, NFFT=NSPM, MAXCAND=16)
|
2016-06-11 22:42:51 -04:00
|
|
|
character*22 msgreceived,allmessages(20)
|
|
|
|
character*80 lines(100)
|
|
|
|
complex cbig(n)
|
|
|
|
complex cdat(NPTS) !Analytic signal
|
|
|
|
complex cdat2(NPTS)
|
|
|
|
complex c(NSPM)
|
2016-06-21 22:29:37 -04:00
|
|
|
complex ctmp(NFFT)
|
2016-06-11 22:42:51 -04:00
|
|
|
complex cb(42) !Complex waveform for sync word
|
2016-07-05 17:06:04 -04:00
|
|
|
complex cbr(42) !Complex waveform for reversed sync word
|
2016-06-11 22:42:51 -04:00
|
|
|
complex cfac,cca,ccb
|
|
|
|
complex cc(NPTS)
|
2016-07-05 17:06:04 -04:00
|
|
|
complex ccr(NPTS)
|
2016-06-11 22:42:51 -04:00
|
|
|
complex cc1(NPTS)
|
|
|
|
complex cc2(NPTS)
|
2016-07-05 17:06:04 -04:00
|
|
|
complex ccr1(NPTS)
|
|
|
|
complex ccr2(NPTS)
|
2016-06-11 22:42:51 -04:00
|
|
|
complex bb(6)
|
2016-07-05 17:06:04 -04:00
|
|
|
integer s8(8),s8r(8),hardbits(144)
|
2016-06-11 22:42:51 -04:00
|
|
|
integer, dimension(1) :: iloc
|
|
|
|
integer*1 decoded(80)
|
2016-06-16 19:18:22 -04:00
|
|
|
integer indices(MAXSTEPS)
|
2016-06-11 22:42:51 -04:00
|
|
|
integer ipeaks(10)
|
2016-06-21 22:29:37 -04:00
|
|
|
logical ismask(NFFT)
|
2016-06-11 22:42:51 -04:00
|
|
|
real cbi(42),cbq(42)
|
2016-06-16 19:18:22 -04:00
|
|
|
real detmet(-2:MAXSTEPS+3)
|
2016-08-11 20:51:56 -04:00
|
|
|
real detmet2(-2:MAXSTEPS+3)
|
2016-06-16 19:18:22 -04:00
|
|
|
real detfer(MAXSTEPS)
|
2016-06-11 22:42:51 -04:00
|
|
|
real rcw(12)
|
|
|
|
real dd(NPTS)
|
2016-08-31 20:42:32 -04:00
|
|
|
! real ddr(NPTS)
|
2016-06-25 14:47:55 -04:00
|
|
|
real ferrs(MAXCAND)
|
2016-06-11 22:42:51 -04:00
|
|
|
real pp(12) !Half-sine pulse shape
|
2016-06-25 14:47:55 -04:00
|
|
|
real snrs(MAXCAND)
|
|
|
|
real times(MAXCAND)
|
2016-06-21 22:29:37 -04:00
|
|
|
real tonespec(NFFT)
|
2016-06-11 22:42:51 -04:00
|
|
|
real*8 dt, df, fs, pi, twopi
|
|
|
|
real softbits(144)
|
2016-07-12 14:29:46 -04:00
|
|
|
real*8 lratio(128)
|
2016-08-31 20:42:32 -04:00
|
|
|
real llr(128)
|
2016-06-11 22:42:51 -04:00
|
|
|
logical first
|
|
|
|
data first/.true./
|
|
|
|
data s8/0,1,1,1,0,0,1,0/
|
2016-07-05 17:06:04 -04:00
|
|
|
data s8r/1,0,1,1,0,0,0,1/
|
2016-07-08 20:07:07 -04:00
|
|
|
save df,first,cb,fs,pi,twopi,dt,s8,rcw,pp,nmatchedfilter
|
2016-06-11 22:42:51 -04:00
|
|
|
|
|
|
|
if(first) then
|
2016-06-16 19:18:22 -04:00
|
|
|
nmatchedfilter=1
|
2016-06-11 22:42:51 -04:00
|
|
|
! define half-sine pulse and raised-cosine edge window
|
|
|
|
pi=4d0*datan(1d0)
|
|
|
|
twopi=8d0*datan(1d0)
|
|
|
|
fs=12000.0
|
|
|
|
dt=1.0/fs
|
2016-06-21 22:29:37 -04:00
|
|
|
df=fs/NFFT
|
2016-06-11 22:42:51 -04:00
|
|
|
|
|
|
|
do i=1,12
|
|
|
|
angle=(i-1)*pi/12.0
|
|
|
|
pp(i)=sin(angle)
|
|
|
|
rcw(i)=(1-cos(angle))/2
|
|
|
|
enddo
|
|
|
|
|
2016-07-05 17:06:04 -04:00
|
|
|
! define the sync word waveforms
|
2016-06-11 22:42:51 -04:00
|
|
|
s8=2*s8-1
|
|
|
|
cbq(1:6)=pp(7:12)*s8(1)
|
|
|
|
cbq(7:18)=pp*s8(3)
|
|
|
|
cbq(19:30)=pp*s8(5)
|
|
|
|
cbq(31:42)=pp*s8(7)
|
|
|
|
cbi(1:12)=pp*s8(2)
|
|
|
|
cbi(13:24)=pp*s8(4)
|
|
|
|
cbi(25:36)=pp*s8(6)
|
|
|
|
cbi(37:42)=pp(1:6)*s8(8)
|
|
|
|
cb=cmplx(cbi,cbq)
|
2016-07-05 17:06:04 -04:00
|
|
|
s8r=2*s8r-1
|
|
|
|
cbq(1:6)=pp(7:12)*s8r(1)
|
|
|
|
cbq(7:18)=pp*s8r(3)
|
|
|
|
cbq(19:30)=pp*s8r(5)
|
|
|
|
cbq(31:42)=pp*s8r(7)
|
|
|
|
cbi(1:12)=pp*s8r(2)
|
|
|
|
cbi(13:24)=pp*s8r(4)
|
|
|
|
cbi(25:36)=pp*s8r(6)
|
|
|
|
cbi(37:42)=pp(1:6)*s8r(8)
|
|
|
|
cbr=cmplx(cbi,cbq)
|
2016-06-11 22:42:51 -04:00
|
|
|
|
|
|
|
first=.false.
|
|
|
|
endif
|
|
|
|
|
2016-06-12 16:49:02 -04:00
|
|
|
! fill the detmet, detferr arrays
|
2016-06-21 22:29:37 -04:00
|
|
|
nstep=(n-NPTS)/216 ! 72ms/4=18ms steps
|
2016-06-12 16:49:02 -04:00
|
|
|
detmet=0
|
2016-08-11 20:51:56 -04:00
|
|
|
detmet2=0
|
2016-06-21 22:29:37 -04:00
|
|
|
detfer=-999.99
|
2016-06-11 22:42:51 -04:00
|
|
|
do istp=1,nstep
|
2016-06-21 22:29:37 -04:00
|
|
|
ns=1+216*(istp-1)
|
|
|
|
ne=ns+NSPM-1
|
2016-06-11 22:55:43 -04:00
|
|
|
if( ne .gt. n ) exit
|
2016-06-21 22:29:37 -04:00
|
|
|
ctmp=cmplx(0.0,0.0)
|
|
|
|
ctmp(1:NSPM)=cbig(ns:ne)
|
2016-06-11 22:42:51 -04:00
|
|
|
|
|
|
|
! Coarse carrier frequency sync - seek tones at 2000 Hz and 4000 Hz in
|
|
|
|
! squared signal spectrum.
|
|
|
|
! search range for coarse frequency error is +/- 100 Hz
|
|
|
|
|
2016-06-21 22:29:37 -04:00
|
|
|
ctmp=ctmp**2
|
2016-06-11 22:42:51 -04:00
|
|
|
ctmp(1:12)=ctmp(1:12)*rcw
|
2016-06-21 22:29:37 -04:00
|
|
|
ctmp(NSPM-11:NSPM)=ctmp(NSPM-11:NSPM)*rcw(12:1:-1)
|
|
|
|
call four2a(ctmp,NFFT,1,-1,1)
|
2016-06-11 22:42:51 -04:00
|
|
|
tonespec=abs(ctmp)**2
|
|
|
|
|
2016-07-08 20:07:07 -04:00
|
|
|
ihlo=(4000-2*ntol)/df+1
|
|
|
|
ihhi=(4000+2*ntol)/df+1
|
2016-06-11 22:42:51 -04:00
|
|
|
ismask=.false.
|
2016-07-08 20:07:07 -04:00
|
|
|
ismask(ihlo:ihhi)=.true. ! high tone search window
|
2016-06-11 22:42:51 -04:00
|
|
|
iloc=maxloc(tonespec,ismask)
|
|
|
|
ihpk=iloc(1)
|
2016-06-21 22:29:37 -04:00
|
|
|
deltah=-real( (ctmp(ihpk-1)-ctmp(ihpk+1)) / (2*ctmp(ihpk)-ctmp(ihpk-1)-ctmp(ihpk+1)) )
|
2016-06-11 22:42:51 -04:00
|
|
|
ah=tonespec(ihpk)
|
2016-08-11 20:51:56 -04:00
|
|
|
ahavp=(sum(tonespec,ismask)-ah)/count(ismask)
|
|
|
|
trath=ah/(ahavp+0.01)
|
2016-07-08 20:07:07 -04:00
|
|
|
illo=(2000-2*ntol)/df+1
|
|
|
|
ilhi=(2000+2*ntol)/df+1
|
2016-06-11 22:42:51 -04:00
|
|
|
ismask=.false.
|
2016-07-08 20:07:07 -04:00
|
|
|
ismask(illo:ilhi)=.true. ! window for low tone
|
2016-06-11 22:42:51 -04:00
|
|
|
iloc=maxloc(tonespec,ismask)
|
|
|
|
ilpk=iloc(1)
|
2016-06-21 22:29:37 -04:00
|
|
|
deltal=-real( (ctmp(ilpk-1)-ctmp(ilpk+1)) / (2*ctmp(ilpk)-ctmp(ilpk-1)-ctmp(ilpk+1)) )
|
2016-06-11 22:42:51 -04:00
|
|
|
al=tonespec(ilpk)
|
2016-08-11 20:51:56 -04:00
|
|
|
alavp=(sum(tonespec,ismask)-al)/count(ismask)
|
|
|
|
tratl=al/(alavp+0.01)
|
2016-06-21 22:29:37 -04:00
|
|
|
fdiff=(ihpk+deltah-ilpk-deltal)*df
|
|
|
|
i2000=2000/df+1
|
|
|
|
i4000=4000/df+1
|
|
|
|
ferrh=(ihpk+deltah-i4000)*df/2.0
|
|
|
|
ferrl=(ilpk+deltal-i2000)*df/2.0
|
2016-06-25 14:47:55 -04:00
|
|
|
if( ah .ge. al ) then
|
|
|
|
ferr=ferrh
|
|
|
|
else
|
|
|
|
ferr=ferrl
|
|
|
|
endif
|
2016-06-21 22:29:37 -04:00
|
|
|
detmet(istp)=max(ah,al)
|
2016-08-11 20:51:56 -04:00
|
|
|
detmet2(istp)=max(trath,tratl)
|
2016-06-11 22:42:51 -04:00
|
|
|
detfer(istp)=ferr
|
2016-06-16 19:18:22 -04:00
|
|
|
enddo ! end of detection-metric and frequency error estimation loop
|
2016-06-11 22:42:51 -04:00
|
|
|
|
2016-06-12 16:49:02 -04:00
|
|
|
call indexx(detmet(1:nstep),nstep,indices) !find median of detection metric vector
|
2016-06-22 22:43:40 -04:00
|
|
|
xmed=detmet(indices(nstep/4))
|
2016-06-11 22:42:51 -04:00
|
|
|
detmet=detmet/xmed ! noise floor of detection metric is 1.0
|
|
|
|
ndet=0
|
2016-06-12 11:02:50 -04:00
|
|
|
|
2016-07-08 20:07:07 -04:00
|
|
|
do ip=1,MAXCAND ! Find candidates
|
2016-06-12 16:49:02 -04:00
|
|
|
iloc=maxloc(detmet(1:nstep))
|
2016-06-11 22:42:51 -04:00
|
|
|
il=iloc(1)
|
2016-07-17 16:05:27 -04:00
|
|
|
if( (detmet(il) .lt. 4.0) ) exit
|
2016-07-08 20:07:07 -04:00
|
|
|
if( abs(detfer(il)) .le. ntol ) then
|
2016-06-25 14:47:55 -04:00
|
|
|
ndet=ndet+1
|
|
|
|
times(ndet)=((il-1)*216+NSPM/2)*dt
|
|
|
|
ferrs(ndet)=detfer(il)
|
|
|
|
snrs(ndet)=12.0*log10(detmet(il))/2-9.0
|
|
|
|
endif
|
2016-07-17 16:05:27 -04:00
|
|
|
! detmet(max(1,il-1):min(nstep,il+1))=0.0
|
2016-06-25 14:47:55 -04:00
|
|
|
detmet(il)=0.0
|
2016-06-11 22:42:51 -04:00
|
|
|
enddo
|
|
|
|
|
2016-08-11 20:51:56 -04:00
|
|
|
if( ndet .lt. 3 ) then
|
|
|
|
do ip=1,MAXCAND-ndet ! Find candidates
|
|
|
|
iloc=maxloc(detmet2(1:nstep))
|
|
|
|
il=iloc(1)
|
|
|
|
if( (detmet2(il) .lt. 12.0) ) exit
|
|
|
|
if( abs(detfer(il)) .le. ntol ) then
|
|
|
|
ndet=ndet+1
|
|
|
|
times(ndet)=((il-1)*216+NSPM/2)*dt
|
|
|
|
ferrs(ndet)=detfer(il)
|
|
|
|
snrs(ndet)=12.0*log10(detmet2(il))/2-9.0
|
|
|
|
endif
|
|
|
|
! detmet2(max(1,il-1):min(nstep,il+1))=0.0
|
|
|
|
detmet2(il)=0.0
|
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
|
2016-06-11 22:42:51 -04:00
|
|
|
nmessages=0
|
2016-06-12 11:02:50 -04:00
|
|
|
allmessages=char(0)
|
|
|
|
lines=char(0)
|
2016-08-31 20:42:32 -04:00
|
|
|
nshort=0
|
2016-06-12 11:02:50 -04:00
|
|
|
|
2016-07-08 20:07:07 -04:00
|
|
|
do ip=1,ndet ! Try to sync/demod/decode each candidate.
|
2016-06-11 22:42:51 -04:00
|
|
|
imid=times(ip)*fs
|
2016-06-22 17:18:08 -04:00
|
|
|
if( imid .lt. NPTS/2 ) imid=NPTS/2
|
|
|
|
if( imid .gt. n-NPTS/2 ) imid=n-NPTS/2
|
2016-07-14 13:06:52 -04:00
|
|
|
t0=times(ip) + t00
|
2016-06-11 22:42:51 -04:00
|
|
|
cdat=cbig(imid-NPTS/2+1:imid+NPTS/2)
|
|
|
|
ferr=ferrs(ip)
|
2016-07-13 16:29:18 -04:00
|
|
|
nsnr=2*nint(snrs(ip)/2.0)
|
|
|
|
if( nsnr .lt. -4 ) nsnr=-4
|
|
|
|
if( nsnr .gt. 24 ) nsnr=24
|
2016-06-11 22:42:51 -04:00
|
|
|
|
|
|
|
! remove coarse freq error - should now be within a few Hz
|
|
|
|
call tweak1(cdat,NPTS,-(1500+ferr),cdat)
|
2016-08-31 20:42:32 -04:00
|
|
|
|
2016-06-11 22:42:51 -04:00
|
|
|
! attempt frame synchronization
|
|
|
|
! correlate with sync word waveforms
|
|
|
|
cc=0
|
2016-07-05 17:06:04 -04:00
|
|
|
ccr=0
|
2016-06-11 22:42:51 -04:00
|
|
|
cc1=0
|
|
|
|
cc2=0
|
2016-07-05 17:06:04 -04:00
|
|
|
ccr1=0
|
|
|
|
ccr2=0
|
2016-06-11 22:42:51 -04:00
|
|
|
do i=1,NPTS-(56*6+41)
|
|
|
|
cc1(i)=sum(cdat(i:i+41)*conjg(cb))
|
|
|
|
cc2(i)=sum(cdat(i+56*6:i+56*6+41)*conjg(cb))
|
|
|
|
enddo
|
|
|
|
cc=cc1+cc2
|
|
|
|
dd=abs(cc1)*abs(cc2)
|
2016-08-31 20:42:32 -04:00
|
|
|
! do i=1,NPTS-(40*6+41)
|
|
|
|
! ccr1(i)=sum(cdat(i:i+41)*conjg(cbr))
|
|
|
|
! ccr2(i)=sum(cdat(i+40*6:i+40*6+41)*conjg(cbr))
|
|
|
|
! enddo
|
|
|
|
! ccr=ccr1+ccr2
|
|
|
|
! ddr=abs(ccr1)*abs(ccr2)
|
2016-07-05 17:06:04 -04:00
|
|
|
cmax=maxval(abs(cc))
|
2016-08-31 20:42:32 -04:00
|
|
|
! crmax=maxval(abs(ccr))
|
|
|
|
! if( crmax .gt. cmax ) then
|
|
|
|
! nshort=nshort+1
|
|
|
|
! endif
|
2016-07-29 20:44:37 -04:00
|
|
|
|
2016-06-25 14:47:55 -04:00
|
|
|
! Find 6 largest peaks
|
2016-07-07 18:41:35 -04:00
|
|
|
do ipk=1, 6
|
2016-06-11 22:42:51 -04:00
|
|
|
iloc=maxloc(abs(cc))
|
|
|
|
ic1=iloc(1)
|
|
|
|
iloc=maxloc(dd)
|
|
|
|
ic2=iloc(1)
|
2016-07-08 20:07:07 -04:00
|
|
|
ipeaks(ipk)=ic2
|
|
|
|
dd(max(1,ic2-7):min(NPTS-56*6-41,ic2+7))=0.0
|
|
|
|
! ipeaks(ipk)=ic1
|
|
|
|
! cc(max(1,ic1-7):min(NPTS-56*6-41,ic1+7))=0.0
|
|
|
|
!write(*,*) ipk,ic2
|
2016-06-11 22:42:51 -04:00
|
|
|
enddo
|
|
|
|
|
2016-06-25 14:47:55 -04:00
|
|
|
do ipk=1,6
|
2016-06-11 22:42:51 -04:00
|
|
|
|
|
|
|
! we want ic to be the index of the first sample of the frame
|
|
|
|
ic0=ipeaks(ipk)
|
|
|
|
|
|
|
|
! fine adjustment of sync index
|
|
|
|
do i=1,6
|
|
|
|
if( ic0+11+NSPM .le. NPTS ) then
|
2016-06-21 22:29:37 -04:00
|
|
|
bb(i) = sum( ( cdat(ic0+i-1+6:ic0+i-1+6+NSPM:6) * conjg( cdat(ic0+i-1:ic0+i-1+NSPM:6) ) )**2 )
|
2016-06-11 22:42:51 -04:00
|
|
|
else
|
2016-06-21 22:29:37 -04:00
|
|
|
bb(i) = sum( ( cdat(ic0+i-1+6:NPTS:6) * conjg( cdat(ic0+i-1:NPTS-6:6) ) )**2 )
|
2016-06-11 22:42:51 -04:00
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
iloc=maxloc(abs(bb))
|
|
|
|
ibb=iloc(1)
|
|
|
|
bba=abs(bb(ibb))
|
2016-06-21 22:29:37 -04:00
|
|
|
bbp=atan2(-imag(bb(ibb)),-real(bb(ibb)))/(2*twopi*6*dt)
|
2016-06-11 22:42:51 -04:00
|
|
|
if( ibb .le. 3 ) ibb=ibb-1
|
|
|
|
if( ibb .gt. 3 ) ibb=ibb-7
|
2016-06-16 19:18:22 -04:00
|
|
|
|
2016-07-08 20:07:07 -04:00
|
|
|
do id=1,3 ! Slicer dither.
|
2016-06-11 22:42:51 -04:00
|
|
|
if( id .eq. 1 ) is=0
|
|
|
|
if( id .eq. 2 ) is=-1
|
|
|
|
if( id .eq. 3 ) is=1
|
|
|
|
|
|
|
|
! Adjust frame index to place peak of bb at desired lag
|
|
|
|
ic=ic0+ibb+is
|
|
|
|
if( ic .lt. 1 ) ic=ic+864
|
|
|
|
|
|
|
|
! Estimate fine frequency error.
|
|
|
|
! Should a larger separation be used when frames are averaged?
|
|
|
|
cca=sum(cdat(ic:ic+41)*conjg(cb))
|
|
|
|
if( ic+56*6+41 .le. NPTS ) then
|
|
|
|
ccb=sum(cdat(ic+56*6:ic+56*6+41)*conjg(cb))
|
|
|
|
cfac=ccb*conjg(cca)
|
|
|
|
ferr2=atan2(imag(cfac),real(cfac))/(twopi*56*6*dt)
|
|
|
|
else
|
|
|
|
ccb=sum(cdat(ic-88*6:ic-88*6+41)*conjg(cb))
|
|
|
|
cfac=cca*conjg(ccb)
|
|
|
|
ferr2=atan2(imag(cfac),real(cfac))/(twopi*88*6*dt)
|
|
|
|
endif
|
|
|
|
|
|
|
|
! Final estimate of the carrier frequency - returned to the calling program
|
2016-06-16 19:18:22 -04:00
|
|
|
fest=1500+ferr+ferr2
|
|
|
|
|
2016-07-17 16:05:27 -04:00
|
|
|
do idf=0,4 ! frequency jitter
|
2016-06-16 19:18:22 -04:00
|
|
|
if( idf .eq. 0 ) then
|
|
|
|
deltaf=0.0
|
|
|
|
elseif( mod(idf,2) .eq. 0 ) then
|
2016-07-08 20:07:07 -04:00
|
|
|
deltaf=idf
|
2016-06-16 19:18:22 -04:00
|
|
|
else
|
2016-07-08 20:07:07 -04:00
|
|
|
deltaf=-(idf+1)
|
2016-06-16 19:18:22 -04:00
|
|
|
endif
|
2016-06-11 22:42:51 -04:00
|
|
|
|
|
|
|
! Remove fine frequency error
|
2016-06-16 19:18:22 -04:00
|
|
|
call tweak1(cdat,NPTS,-(ferr2+deltaf),cdat2)
|
2016-06-11 22:42:51 -04:00
|
|
|
|
|
|
|
! place the beginning of frame at index NSPM+1
|
2016-06-16 19:18:22 -04:00
|
|
|
cdat2=cshift(cdat2,ic-(NSPM+1))
|
|
|
|
|
|
|
|
do iav=1,8 ! Hopefully we can eliminate some of these after looking at more examples
|
|
|
|
if( iav .eq. 1 ) then
|
|
|
|
c=cdat2(NSPM+1:2*NSPM)
|
|
|
|
elseif( iav .eq. 2 ) then
|
|
|
|
c=cdat2(NSPM-431:NSPM+432)
|
|
|
|
c=cshift(c,-432)
|
|
|
|
elseif( iav .eq. 3 ) then
|
|
|
|
c=cdat2(2*NSPM-431:2*NSPM+432)
|
|
|
|
c=cshift(c,-432)
|
|
|
|
elseif( iav .eq. 4 ) then
|
|
|
|
c=cdat2(1:NSPM)
|
|
|
|
elseif( iav .eq. 5 ) then
|
|
|
|
c=cdat2(2*NSPM+1:NPTS)
|
|
|
|
elseif( iav .eq. 6 ) then
|
|
|
|
c=cdat2(1:NSPM)+cdat2(NSPM+1:2*NSPM)
|
|
|
|
elseif( iav .eq. 7 ) then
|
|
|
|
c=cdat2(NSPM+1:2*NSPM)+cdat2(2*NSPM+1:NPTS)
|
|
|
|
elseif( iav .eq. 8 ) then
|
|
|
|
c=cdat2(1:NSPM)+cdat2(NSPM+1:2*NSPM)+cdat2(2*NSPM+1:NPTS)
|
|
|
|
endif
|
2016-06-11 22:42:51 -04:00
|
|
|
|
|
|
|
! Estimate final frequency error and carrier phase.
|
2016-06-16 19:18:22 -04:00
|
|
|
cca=sum(c(1:1+41)*conjg(cb))
|
|
|
|
ccb=sum(c(1+56*6:1+56*6+41)*conjg(cb))
|
|
|
|
cfac=ccb*conjg(cca)
|
|
|
|
ffin=atan2(imag(cfac),real(cfac))/(twopi*56*6*dt)
|
|
|
|
phase0=atan2(imag(cca+ccb),real(cca+ccb))
|
2016-06-21 22:29:37 -04:00
|
|
|
|
2016-07-08 20:07:07 -04:00
|
|
|
do ipha=1,1
|
|
|
|
if( ipha.eq.2 ) phase0=phase0+30*pi/180.0
|
|
|
|
if( ipha.eq.3 ) phase0=phase0-30*pi/180.0
|
2016-07-07 18:41:35 -04:00
|
|
|
|
2016-06-16 19:18:22 -04:00
|
|
|
! Remove phase error - want constellation rotated so that sample points lie on I/Q axes
|
2016-07-07 18:41:35 -04:00
|
|
|
cfac=cmplx(cos(phase0),sin(phase0))
|
|
|
|
c=c*conjg(cfac)
|
2016-06-16 19:18:22 -04:00
|
|
|
|
2016-07-07 18:41:35 -04:00
|
|
|
if( nmatchedfilter .eq. 0 ) then
|
2016-06-11 22:42:51 -04:00
|
|
|
! sample to get softsamples
|
2016-07-07 18:41:35 -04:00
|
|
|
do i=1,72
|
|
|
|
softbits(2*i-1)=imag(c(1+(i-1)*12))
|
|
|
|
softbits(2*i)=real(c(7+(i-1)*12))
|
|
|
|
enddo
|
|
|
|
else
|
2016-06-16 19:18:22 -04:00
|
|
|
! matched filter -
|
|
|
|
! how much mismatch does the RX/TX/analytic filter cause?, how rig (pair) dependent is this loss?
|
2016-07-07 18:41:35 -04:00
|
|
|
softbits(1)=sum(imag(c(1:6))*pp(7:12))+sum(imag(c(864-5:864))*pp(1:6))
|
|
|
|
softbits(2)=sum(real(c(1:12))*pp)
|
|
|
|
do i=2,72
|
|
|
|
softbits(2*i-1)=sum(imag(c(1+(i-1)*12-6:1+(i-1)*12+5))*pp)
|
|
|
|
softbits(2*i)=sum(real(c(7+(i-1)*12-6:7+(i-1)*12+5))*pp)
|
|
|
|
enddo
|
|
|
|
endif
|
2016-06-16 19:18:22 -04:00
|
|
|
|
|
|
|
! sync word hard error weight is a good discriminator for
|
|
|
|
! frames that have reasonable probability of decoding
|
2016-07-07 18:41:35 -04:00
|
|
|
hardbits=0
|
|
|
|
do i=1,144
|
|
|
|
if( softbits(i) .ge. 0.0 ) then
|
|
|
|
hardbits(i)=1
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
nbadsync1=(8-sum( (2*hardbits(1:8)-1)*s8 ) )/2
|
|
|
|
nbadsync2=(8-sum( (2*hardbits(1+56:8+56)-1)*s8 ) )/2
|
|
|
|
nbadsync=nbadsync1+nbadsync2
|
|
|
|
if( nbadsync .gt. 4 ) cycle
|
2016-06-11 22:42:51 -04:00
|
|
|
|
|
|
|
! normalize the softsymbols before submitting to decoder
|
2016-07-07 18:41:35 -04:00
|
|
|
sav=sum(softbits)/144
|
|
|
|
s2av=sum(softbits*softbits)/144
|
|
|
|
ssig=sqrt(s2av-sav*sav)
|
|
|
|
softbits=softbits/ssig
|
|
|
|
|
|
|
|
sigma=0.75
|
|
|
|
lratio(1:48)=softbits(9:9+47)
|
|
|
|
lratio(49:128)=softbits(65:65+80-1)
|
2016-08-31 20:42:32 -04:00
|
|
|
llr=2.0*lratio/(sigma*sigma)
|
2016-07-07 18:41:35 -04:00
|
|
|
lratio=exp(2.0*lratio/(sigma*sigma))
|
2016-06-11 22:42:51 -04:00
|
|
|
|
2016-07-07 18:41:35 -04:00
|
|
|
max_iterations=10
|
|
|
|
max_dither=1
|
2016-09-01 17:50:52 -04:00
|
|
|
call timer('bpdec144 ',0)
|
2016-08-31 20:42:32 -04:00
|
|
|
call bpdecode144(llr,max_iterations,decoded,niterations)
|
2016-09-01 17:50:52 -04:00
|
|
|
call timer('bpdec144 ',1)
|
2016-06-11 22:42:51 -04:00
|
|
|
|
2016-07-07 18:41:35 -04:00
|
|
|
if( niterations .ge. 0.0 ) then
|
|
|
|
call extractmessage144(decoded,msgreceived,nhashflag)
|
|
|
|
if( nhashflag .gt. 0 ) then ! CRCs match, so print it
|
|
|
|
ndupe=0
|
|
|
|
do im=1,nmessages
|
|
|
|
if( allmessages(im) .eq. msgreceived ) ndupe=1
|
|
|
|
enddo
|
|
|
|
if( ndupe .eq. 0 ) then
|
|
|
|
nmessages=nmessages+1
|
|
|
|
allmessages(nmessages)=msgreceived
|
|
|
|
write(lines(nmessages),1020) nutc,nsnr,t0,nint(fest),msgreceived
|
|
|
|
1020 format(i6.6,i4,f5.1,i5,' & ',a22)
|
|
|
|
endif
|
|
|
|
goto 999
|
|
|
|
else
|
|
|
|
msgreceived=' '
|
|
|
|
ndither=-99 ! -99 is bad hash flag
|
2016-07-08 20:07:07 -04:00
|
|
|
! write(78,1001) nutc,t0,nsnr,ip,ipk,is,idf,iav,ipha,deltaf,fest,ferr,ferr2, &
|
2016-07-07 18:41:35 -04:00
|
|
|
! ffin,bba,bbp,nbadsync1,nbadsync2, &
|
|
|
|
! phase0,niterations,ndither,msgreceived
|
2016-06-16 19:18:22 -04:00
|
|
|
endif
|
|
|
|
endif
|
2016-07-07 18:41:35 -04:00
|
|
|
enddo ! phase dither
|
2016-06-16 19:18:22 -04:00
|
|
|
enddo ! frame averaging loop
|
|
|
|
enddo ! frequency dithering loop
|
2016-06-11 22:42:51 -04:00
|
|
|
enddo ! sample-time dither loop
|
2016-06-16 19:18:22 -04:00
|
|
|
enddo ! peak loop - could be made more efficient by working harder to find good peaks
|
2016-06-11 22:42:51 -04:00
|
|
|
|
|
|
|
msgreceived=' '
|
2016-06-16 19:18:22 -04:00
|
|
|
ndither=-98
|
2016-06-11 22:42:51 -04:00
|
|
|
999 continue
|
2016-06-21 22:29:37 -04:00
|
|
|
if( nmessages .ge. 1 ) then
|
2016-08-03 09:23:51 -04:00
|
|
|
! write(78,1001) nutc,t0,nsnr,ip,ipk,is,idf,iav,ipha,deltaf,fest,ferr,ferr2, &
|
|
|
|
! ffin,bba,bbp,nbadsync1,nbadsync2, &
|
|
|
|
! phase0,niterations,ndither,msgreceived
|
|
|
|
! call flush(78)
|
|
|
|
!1001 format(i6.6,f8.2,i5,i5,i5,i5,i5,i5,i5,f6.2,f8.2,f8.2,f8.2,f8.2,f11.1,f8.2,i5,i5,f8.2,i5,i5,2x,a22)
|
2016-06-21 22:29:37 -04:00
|
|
|
exit
|
|
|
|
endif
|
2016-06-11 22:42:51 -04:00
|
|
|
enddo
|
|
|
|
return
|
|
|
|
end subroutine detectmsk144
|