summaryrefslogtreecommitdiff
path: root/lib/qra/q65
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2021-09-09 22:49:00 +0200
committerChristoph Berg <myon@debian.org>2021-09-09 22:49:00 +0200
commit85895feeaf88bcde26bbfc71e8f6b2047c0f5f41 (patch)
tree79807e00771e4af4ce279e368262f2222806102f /lib/qra/q65
parent2f095a04ed69d9aa14b47dc4acde6b3225b2d65e (diff)
New upstream version 2.5.0~rc6+repackupstream/2.5.0_rc6+repack
Diffstat (limited to 'lib/qra/q65')
-rw-r--r--lib/qra/q65/q65.c21
-rw-r--r--lib/qra/q65/q65.f90140
-rw-r--r--lib/qra/q65/q65_encoding_modules.f90223
-rw-r--r--lib/qra/q65/q65_loops.f9032
-rw-r--r--lib/qra/q65/q65code.f9029
-rw-r--r--lib/qra/q65/qra15_65_64_irr_e23.c3
6 files changed, 378 insertions, 70 deletions
diff --git a/lib/qra/q65/q65.c b/lib/qra/q65/q65.c
index f7701792..10d756d8 100644
--- a/lib/qra/q65/q65.c
+++ b/lib/qra/q65/q65.c
@@ -434,11 +434,14 @@ int q65_intrinsics_fastfading(q65_codec_ds *pCodec,
// exponentiate and accumulate the normalization constant
sumix = 0.0f;
- for (k=0;k<nM;k++) {
- fTemp = expf(pCurIx[k]-maxlogp);
- pCurIx[k]=fTemp;
- sumix +=fTemp;
- }
+ for (k=0;k<nM;k++) {
+ float x=pCurIx[k]-maxlogp;
+ if(x < -85.0) x=-85.0;
+ if(x > 85.0) x= 85.0;
+ fTemp = expf(x);
+ pCurIx[k]=fTemp;
+ sumix +=fTemp;
+ }
// scale to a probability distribution
sumix = 1.0f/sumix;
@@ -663,9 +666,11 @@ int q65_check_llh(float *llh, const int* ydec, const int nN, const int nM, const
float t = 0;
for (k=0;k<nN;k++) {
- t+=logf(pIntrin[ydec[k]]);
- pIntrin+=nM;
- }
+ float x=pIntrin[ydec[k]];
+ if(x < 1.0e-36) x = 1.0e-36;
+ t+=logf(x);
+ pIntrin+=nM;
+ }
if (llh!=NULL)
*llh = t;
diff --git a/lib/qra/q65/q65.f90 b/lib/qra/q65/q65.f90
index a85c3271..86cd15d5 100644
--- a/lib/qra/q65/q65.f90
+++ b/lib/qra/q65/q65.f90
@@ -10,8 +10,8 @@ module q65
integer,dimension(22) :: isync = (/1,9,12,13,15,22,23,26,27,33,35, &
38,46,50,55,60,62,66,69,74,76,85/)
integer codewords(63,206)
- integer ibwa,ibwb,ncw,nsps,mode_q65,nfa,nfb
- integer idfbest,idtbest,ibw,ndistbest,maxiters
+ integer ibwa,ibwb,ncw,nsps,mode_q65,nfa,nfb,nqd
+ integer idfbest,idtbest,ibw,ndistbest,maxiters,max_drift
integer istep,nsmo,lag1,lag2,npasses,nused,iseq,ncand,nrc
integer i0,j0
integer navg(0:1)
@@ -23,7 +23,7 @@ module q65
real, allocatable,save :: ccf2(:) !Max CCF(freq) at any lag, single seq
real, allocatable,save :: ccf2_avg(:) !Like ccf2, but for accumulated average
real sync(85) !sync vector
- real df,dtstep,dtdec,f0dec,ftol,plog
+ real df,dtstep,dtdec,f0dec,ftol,plog,drift
contains
@@ -69,6 +69,7 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, &
data first/.true./
save first
+ NN=63
if(nutc+ndepth.eq.-999) stop !Silence compiler warnings
! Set some parameters and allocate storage for large arrays
@@ -123,7 +124,7 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, &
dtstep=nsps/(NSTEP*12000.0) !Step size in seconds
lag1=-1.0/dtstep
lag2=1.0/dtstep + 0.9999
- if(nsps.ge.3600 .and. emedelay.gt.0) lag2=4.0/dtstep + 0.9999 !Include EME
+ if(nsps.ge.3600 .and. emedelay.gt.0) lag2=5.5/dtstep + 0.9999 !Include EME
j0=0.5/dtstep
if(nsps.ge.7200) j0=1.0/dtstep !Nominal start-signal index
@@ -138,16 +139,17 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, &
endif
i0=nint(nfqso/df) !Target QSO frequency
- if(i0-64.lt.1 .or. i0-65+LL.gt.iz) go to 900 !Frequency out of range
- call pctile(s1(i0-64:i0-65+LL,1:jz),LL*jz,45,base)
+ ii1=max(1,i0-64)
+ ii2=i0-65+LL
+ call pctile(s1(ii1:ii2,1:jz),ii2-ii1+1*jz,45,base)
s1=s1/base
s1raw=s1
! Apply fast AGC to the symbol spectra
s1max=20.0 !Empirical choice
do j=1,jz !### Maybe wrong way? ###
- smax=maxval(s1(i0-64:i0-65+LL,j))
- if(smax.gt.s1max) s1(i0-64:i0-65+LL,j)=s1(i0-64:i0-65+LL,j)*s1max/smax
+ smax=maxval(s1(ii1:ii2,j))
+ if(smax.gt.s1max) s1(ii1:ii2,j)=s1(ii1:ii2,j)*s1max/smax
enddo
dat4=0
@@ -155,21 +157,34 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, &
! Try list decoding via "Deep Likelihood".
call timer('ccf_85 ',0)
! Try to synchronize using all 85 symbols
- call q65_ccf_85(s1,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best,ccf1)
+ call q65_ccf_85(s1,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best, &
+ better,ccf1)
call timer('ccf_85 ',1)
- call timer('list_dec',0)
- call q65_dec_q3(s1,iz,jz,s3,LL,ipk,jpk,snr2,dat4,idec,decoded)
- call timer('list_dec',1)
+ if(better.ge.1.10 .or. mode_q65.ge.8) then
+ call timer('list_dec',0)
+ call q65_dec_q3(s1,iz,jz,s3,LL,ipk,jpk,snr2,dat4,idec,decoded)
+ call timer('list_dec',1)
+! if(idec.ge.0) write(70,3070) idec,mode_q65,better,trim(decoded)
+!3070 format(i3,i5,f8.2,2x,a)
+ endif
+! If idec=3 we have a q3 decode. Continue to compute sync curve for plotting.
endif
+! Get 2d CCF and ccf2 using sync symbols only
if(iavg.eq.0) then
- call q65_ccf_22(s1,iz,jz,nfqso,ipk,jpk,f0a,xdta,ccf2)
+ call timer('ccf_22a ',0)
+ call q65_ccf_22(s1,iz,jz,nfqso,ntol,ndepth,ntrperiod,iavg,ipk,jpk, &
+ f0a,xdta,ccf2)
+ call timer('ccf_22a ',1)
endif
-! Get 2d CCF and ccf2 using sync symbols only
+! Get 2d CCF and ccf2_avg using sync symbols only
if(iavg.ge.1) then
- call q65_ccf_22(s1,iz,jz,nfqso,ipk,jpk,f0a,xdta,ccf2_avg)
+ call timer('ccf_22b ',0)
+ call q65_ccf_22(s1,iz,jz,nfqso,ntol,ndepth,ntrperiod,iavg,ipk,jpk, &
+ f0a,xdta,ccf2_avg)
+ call timer('ccf_22b ',1)
endif
if(idec.lt.0) then
f0=f0a
@@ -190,7 +205,7 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, &
smax=maxval(ccf1)
-! Estimate frequenct spread
+! Estimate frequency spread
i1=-9999
i2=-9999
do i=-ia,ia
@@ -200,11 +215,10 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, &
width=df*(i2-i1)
if(ncw.eq.0) ccf1=0.
-! write(*,3001) nutc,iavg,navg(0),sum(ccf2_avg),sum(ccf2)
-!3001 format(i4.4,2i4,2f8.2)
+
call q65_write_red(iz,xdt,ccf2_avg,ccf2)
- if(iavg.eq.2) then
+ if(idec.lt.0 .and. (iavg.eq.0 .or. iavg.eq.2)) then
call q65_dec_q012(s3,LL,snr2,dat4,idec,decoded)
endif
@@ -350,18 +364,21 @@ subroutine q65_dec_q012(s3,LL,snr2,dat4,idec,decoded)
100 return
end subroutine q65_dec_q012
-subroutine q65_ccf_85(s1,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best,ccf1)
+subroutine q65_ccf_85(s1,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best, &
+ better,ccf1)
! Attempt synchronization using all 85 symbols, in advance of an
! attempt at q3 decoding. Return ccf1 for the "red sync curve".
real s1(iz,jz)
real, allocatable :: ccf(:,:) !CCF(freq,lag)
+ real, allocatable :: best(:) !best(imsg) -- for checking 2nd best
real ccf1(-ia2:ia2)
integer ijpk(2)
integer itone(85)
allocate(ccf(-ia2:ia2,-53:214))
+ allocate(best(ncw))
ipk=0
jpk=0
ccf_best=0.
@@ -406,13 +423,21 @@ subroutine q65_ccf_85(s1,iz,jz,nfqso,ia,ia2,ipk,jpk,f0,xdt,imsg_best,ccf1)
imsg_best=imsg
ccf1=ccf(:,jpk)
endif
+ best(imsg)=ccfmax
enddo ! imsg
+
deallocate(ccf)
+ better=0.
+ if(imsg_best.gt.0) then
+ best(imsg_best)=0.
+ better=ccf_best/maxval(best)
+ endif
return
end subroutine q65_ccf_85
-subroutine q65_ccf_22(s1,iz,jz,nfqso,ipk,jpk,f0,xdt,ccf2)
+subroutine q65_ccf_22(s1,iz,jz,nfqso,ntol,ndepth,ntrperiod,iavg,ipk,jpk, &
+ f0,xdt,ccf2)
! Attempt synchronization using only the 22 sync symbols. Return ccf2
! for the "orange sync curve".
@@ -420,57 +445,81 @@ subroutine q65_ccf_22(s1,iz,jz,nfqso,ipk,jpk,f0,xdt,ccf2)
real s1(iz,jz)
real ccf2(iz) !Orange sync curve
real, allocatable :: xdt2(:)
+ real, allocatable :: s1avg(:)
integer, allocatable :: indx(:)
allocate(xdt2(iz))
+ allocate(s1avg(iz))
allocate(indx(iz))
+ ia=max(nfa,100)/df
+ ib=min(nfb,4900)/df
+ if(nqd.ne.1 .or. iavg.ne.0) max_drift=0
+ if(max_drift.ne.0) then
+ ia=max(nint(100/df),nint((nfqso-ntol)/df))
+ ib=min(nint(4900/df),nint((nfqso+ntol)/df))
+ endif
+
+ do i=ia,ib
+ s1avg(i)=sum(s1(i,1:jz))
+ enddo
+
ccfbest=0.
ibest=0
lagpk=0
lagbest=0
- do i=1,iz
+ idrift_best=0
+ do i=ia,ib
ccfmax=0.
do lag=lag1,lag2
- ccft=0.
- do k=1,85
- n=NSTEP*(k-1) + 1
- j=n+lag+j0
- if(j.ge.1 .and. j.le.jz) then
- ccft=ccft + sync(k)*s1(i,j)
+ do idrift=-max_drift,max_drift
+ ccft=0.
+ do kk=1,22
+ k=isync(kk)
+ ii=i + nint(idrift*(k-43)/85.0)
+ if(ii.lt.1 .or. ii.gt.iz) cycle
+ n=NSTEP*(k-1) + 1
+ j=n+lag+j0
+ if(j.ge.1 .and. j.le.jz) ccft=ccft + s1(ii,j)
+ enddo ! kk
+ ccft=ccft - (22.0/jz)*s1avg(i)
+ if(ccft.gt.ccfmax) then
+ ccfmax=ccft
+ lagpk=lag
+ idrift_max=idrift
endif
- enddo
- if(ccft.gt.ccfmax) then
- ccfmax=ccft
- lagpk=lag
- endif
- enddo
+ enddo ! idrift
+ enddo ! lag
ccf2(i)=ccfmax
xdt2(i)=lagpk*dtstep
if(ccfmax.gt.ccfbest .and. abs(i*df-nfqso).le.ftol) then
ccfbest=ccfmax
ibest=i
lagbest=lagpk
+ idrift_best=idrift_max
endif
- enddo
+ enddo ! i
! Parameters for the top candidate:
ipk=ibest - i0
jpk=lagbest
f0=nfqso + ipk*df
xdt=jpk*dtstep
+ drift=df*idrift_best
+ ccf2(:ia)=0.
+ ccf2(ib:)=0.
! Save parameters for best candidates
- i1=max(nfa,100)/df
- i2=min(nfb,4900)/df
- jzz=i2-i1+1
- call pctile(ccf2(i1:i2),jzz,40,base)
+ jzz=ib-ia+1
+ call pctile(ccf2(ia:ib),jzz,40,base)
ccf2=ccf2/base
- call indexx(ccf2(i1:i2),jzz,indx)
+ call indexx(ccf2(ia:ib),jzz,indx)
ncand=0
maxcand=20
do j=1,20
- i=indx(jzz-j+1)+i1-1
+ k=jzz-j+1
+ if(k.lt.1 .or. k.gt.iz) cycle
+ i=indx(k)+ia-1
if(ccf2(i).lt.3.3) exit !Candidate limit
f=i*df
if(f.ge.(nfqso-ftol) .and. f.le.(nfqso+ftol)) cycle !Looked here already
@@ -692,12 +741,6 @@ subroutine q65_snr(dat4,dtdec,f0dec,mode_q65,nused,snr2)
if(nused.eq.3) snr2=snr2 - 2.9
if(nused.ge.4) snr2=snr2 - 3.5
-! do i=ia,ib
-! write(71,3071) i*df,spec(i),db(spec(i))
-!3071 format(3f10.3)
-! enddo
-! flush(71)
-
return
end subroutine q65_snr
@@ -736,7 +779,8 @@ subroutine q65_hist(if0,msg0,dxcall,dxgrid)
msg(nhist)=msg0
go to 900
-100 dxcall=' ' !This is a lookup request
+100 if(dxcall(1:3).ne.' ') go to 900
+ dxcall=' ' !This is a lookup request
dxgrid=' '
! Look for a decode close to if0, starting with most recent ones
do i=nhist,1,-1
diff --git a/lib/qra/q65/q65_encoding_modules.f90 b/lib/qra/q65/q65_encoding_modules.f90
new file mode 100644
index 00000000..b55c7f27
--- /dev/null
+++ b/lib/qra/q65/q65_encoding_modules.f90
@@ -0,0 +1,223 @@
+module gf64math
+! add and subtract in GF(2^6) based on primitive polynomial x^6+x+1
+
+ implicit none
+ integer, private :: gf64log(0:63)
+ integer, private :: gf64antilog(0:62)
+
+! table of the logarithms of the elements of GF(M) (log(0) never used)
+ data gf64log/ &
+ -1, 0, 1, 6, 2, 12, 7, 26, 3, 32, &
+ 13, 35, 8, 48, 27, 18, 4, 24, 33, 16, &
+ 14, 52, 36, 54, 9, 45, 49, 38, 28, 41, &
+ 19, 56, 5, 62, 25, 11, 34, 31, 17, 47, &
+ 15, 23, 53, 51, 37, 44, 55, 40, 10, 61, &
+ 46, 30, 50, 22, 39, 43, 29, 60, 42, 21, &
+ 20, 59, 57, 58/
+
+! table of GF(M) elements given their logarithm
+ data gf64antilog/ &
+ 1, 2, 4, 8, 16, 32, 3, 6, 12, 24, &
+ 48, 35, 5, 10, 20, 40, 19, 38, 15, 30, &
+ 60, 59, 53, 41, 17, 34, 7, 14, 28, 56, &
+ 51, 37, 9, 18, 36, 11, 22, 44, 27, 54, &
+ 47, 29, 58, 55, 45, 25, 50, 39, 13, 26, &
+ 52, 43, 21, 42, 23, 46, 31, 62, 63, 61, &
+ 57, 49, 33/
+
+contains
+
+ integer function gf64_add(i1,i2)
+ implicit none
+ integer::i1
+ integer::i2
+ gf64_add=iand(ieor(i1,i2),63)
+ end function gf64_add
+
+ integer function gf64_mult(i1,i2)
+ implicit none
+ integer::i1
+ integer::i2
+ integer::j
+
+ if(i1.eq.0 .or. i2.eq.0) then
+ gf64_mult=0
+ elseif(i1.eq.1) then
+ gf64_mult=i2
+ elseif(i2.eq.1) then
+ gf64_mult=i1
+ else
+ j=mod(gf64log(i1)+gf64log(i2),63)
+ gf64_mult=gf64antilog(j)
+ endif
+ end function gf64_mult
+
+end module gf64math
+
+module q65_generator
+
+ integer generator(15,50)
+ data generator/ &
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, &
+ 0,20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, &
+ 0,20, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, &
+ 0,20, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, &
+ 0,20, 0, 1, 1, 0, 0, 0,10, 0, 0, 0, 0, 1, 0, &
+ 0,20, 0, 1, 1, 0, 0, 0,10, 0, 0, 0,44, 1, 0, &
+ 0,20, 0, 1, 1, 0, 0, 0,10, 1, 0, 0,44, 1, 0, &
+ 0,20, 0, 1, 1, 0, 0, 0,10, 1, 0, 0,44, 1,14, &
+ 0,20, 0, 1, 1, 0, 0, 0,10, 1,31, 0,44, 1,14, &
+ 0,20, 0, 1, 1,33, 0, 0,10, 1,31, 0,44, 1,14, &
+ 56,20, 0, 1, 1,33, 0, 0,10, 1,31, 0,44, 1,14, &
+ 56,20, 0, 1, 1,33, 0, 1,10, 1,31, 0,44, 1,14, &
+ 56, 1, 0, 1, 1,33, 0, 1,10, 1,31, 0,44, 1,14, &
+ 56, 1, 0, 1, 1,33, 0, 1,10, 1,31,36,44, 1,14, &
+ 56, 1, 0, 1, 1,33, 0, 1,43, 1,31,36,44, 1,14, &
+ 56, 1, 0, 1, 1,33, 0, 1,43,17,31,36,44, 1,14, &
+ 56, 1, 0, 1, 1,33, 0, 1,43,17,31,36,36, 1,14, &
+ 56, 1, 0, 1, 1,33,53, 1,43,17,31,36,36, 1,14, &
+ 56, 1, 0,35, 1,33,53, 1,43,17,31,36,36, 1,14, &
+ 56, 1, 0,35, 1,33,53, 1,43,17,30,36,36, 1,14, &
+ 56, 1, 0,35, 1,33,53,52,43,17,30,36,36, 1,14, &
+ 56, 1, 0,35, 1,32,53,52,43,17,30,36,36, 1,14, &
+ 56, 1,60,35, 1,32,53,52,43,17,30,36,36, 1,14, &
+ 56, 1,60,35, 1,32,53,52,43,17,30,36,36,49,14, &
+ 56, 1,60,35, 1,32,53,52,43,17,30,36,37,49,14, &
+ 56, 1,60,35,54,32,53,52,43,17,30,36,37,49,14, &
+ 56, 1,60,35,54,32,53,52, 1,17,30,36,37,49,14, &
+ 1, 1,60,35,54,32,53,52, 1,17,30,36,37,49,14, &
+ 1, 0,60,35,54,32,53,52, 1,17,30,36,37,49,14, &
+ 1, 0,60,35,54,32,53,52, 1,17,30,37,37,49,14, &
+ 1, 0,61,35,54,32,53,52, 1,17,30,37,37,49,14, &
+ 1, 0,61,35,54,32,53,52, 1,48,30,37,37,49,14, &
+ 1, 0,61,35,54,32,53,52, 1,48,30,37,37,49,15, &
+ 1, 0,61,35,54, 0,53,52, 1,48,30,37,37,49,15, &
+ 1, 0,61,35,54, 0,52,52, 1,48,30,37,37,49,15, &
+ 1, 0,61,35,54, 0,52,52, 1,48,30,37,37, 0,15, &
+ 1, 0,61,35,54, 0,52,34, 1,48,30,37,37, 0,15, &
+ 1, 0,61,35,54, 0,52,34, 1,48,30,37, 0, 0,15, &
+ 1, 0,61,35,54, 0,52,34, 1,48,30,20, 0, 0,15, &
+ 1, 0, 0,35,54, 0,52,34, 1,48,30,20, 0, 0,15, &
+ 1, 0, 0,35,54, 0,52,34, 1, 0,30,20, 0, 0,15, &
+ 0, 0, 0,35,54, 0,52,34, 1, 0,30,20, 0, 0,15, &
+ 0, 0, 0,35,54, 0,52,34, 1, 0,38,20, 0, 0,15, &
+ 0, 0, 0,35, 0, 0,52,34, 1, 0,38,20, 0, 0,15, &
+ 0, 0, 0,35, 0, 0,52, 0, 1, 0,38,20, 0, 0,15, &
+ 0, 0, 0,35, 0, 0,52, 0, 1, 0,38,20, 0, 0, 0, &
+ 0, 0, 0,35, 0, 0,52, 0, 0, 0,38,20, 0, 0, 0, &
+ 0, 0, 0,35, 0, 0,52, 0, 0, 0,38, 0, 0, 0, 0, &
+ 0, 0, 0, 0, 0, 0,52, 0, 0, 0,38, 0, 0, 0, 0, &
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,38, 0, 0, 0, 0/
+
+end module q65_generator
+
+module q65_encoding
+
+contains
+
+subroutine q65_encode(message,codeword)
+ use gf64math
+ use q65_generator
+ integer message(15)
+ integer codeword(65)
+ integer i,j
+
+ codeword=0
+ codeword(1:15)=message
+ do i=1,15
+ do j=16,65
+ codeword(j)=gf64_add(codeword(j),gf64_mult(message(i),generator(i,j-15)))
+ enddo
+ enddo
+
+ return
+end
+
+subroutine get_q65crc12(mc2,ncrc1,ncrc2)
+!
+ character c12*12,c6*6
+ integer*1 mc(90),mc2(90),tmp(6)
+ integer*1 r(13),p(13)
+ integer ncrc
+! polynomial for 12-bit CRC 0xF01
+ data p/1,1,0,0,0,0,0,0,0,1,1,1,1/
+
+! flip bit order of each 6-bit symbol for consistency with Nico's calculation
+ do i=0,14
+ tmp=mc2(i*6+1:i*6+6)
+ mc(i*6+1:i*6+6)=tmp(6:1:-1)
+ enddo
+
+! divide by polynomial
+ r=mc(1:13)
+ do i=0,77
+ r(13)=mc(i+13)
+ r=mod(r+r(1)*p,2)
+ r=cshift(r,1)
+ enddo
+
+ write(c6,'(6b1)') r(6:1:-1)
+ read(c6,'(b6.6)') ncrc1
+ read(c6,'(6b1)') mc2(79:84)
+ write(c6,'(6b1)') r(12:7:-1)
+ read(c6,'(b6.6)') ncrc2
+ read(c6,'(6b1)') mc2(85:90)
+
+end subroutine get_q65crc12
+
+subroutine get_q65_tones(msg37,codeword,itone)
+ use packjt77
+ implicit none
+ character*37 msg37
+ character*77 c77
+ character*12 c12
+ character*6 c6
+ integer codeword(65)
+ integer sync(22)
+ integer message(15)
+ integer shortcodeword(63)
+ integer itone(85)
+ integer i,j,k
+ integer*1 mbits(90)
+ integer i3,n3,ncrc1,ncrc2
+ data sync/1,9,12,13,15,22,23,26,27,33,35,38,46,50,55,60,62,66,69,74,76,85/
+
+ i3=-1
+ n3=-1
+ call pack77(msg37,i3,n3,c77)
+ mbits=0
+ read(c77,'(77i1)') mbits(1:77)
+
+! Message is 77 bits long. Add a 0 bit to create a 78-bit message and pad with
+! 12 zeros to create 90-bit mbit array for CRC calculation.
+ call get_q65crc12(mbits,ncrc1,ncrc2)
+
+! Now have message in bits 1:78 and CRC in bits 79:90.
+! Group message bits into 15 6-bit symbols:
+ do i=0,14
+ write(c6,'(6i1)') mbits( (i*6+1):(i*6+6) )
+ read(c6,'(b6.6)') message(i+1)
+ enddo
+
+! Encode to create a 65-symbol codeword
+ call q65_encode(message,codeword)
+
+!Shorten the codeword by omitting the CRC symbols (symbols 14 and 15)
+ shortcodeword(1:13)=codeword(1:13)
+ shortcodeword(14:63)=codeword(16:65)
+
+!Insert sync symbols to create array of channel symbols
+ j=1
+ k=0
+ do i=1,85
+ if(i.eq.sync(j)) then
+ j=j+1
+ itone(i)=0
+ else
+ k=k+1
+ itone(i)=shortcodeword(k)+1
+ endif
+ enddo
+end subroutine get_q65_tones
+
+end module q65_encoding
diff --git a/lib/qra/q65/q65_loops.f90 b/lib/qra/q65/q65_loops.f90
index 827e7f4c..ec93adb0 100644
--- a/lib/qra/q65/q65_loops.f90
+++ b/lib/qra/q65/q65_loops.f90
@@ -11,30 +11,35 @@ subroutine q65_loops(c00,npts2,nsps2,nsubmode,ndepth,jpk0, &
complex ,allocatable :: c0(:) !Ditto, with freq shift
character decoded*37
real a(3) !twkfreq params f,f1,f2
- real s3(LN) !Symbol spectra
+ real,allocatable :: s3(:) !Symbol spectra
integer dat4(13) !Decoded message (as 13 six-bit integers)
integer nap(0:11) !AP return codes
data nap/0,2,3,2,3,4,2,3,6,4,6,6/
+ LL=64*(mode_q65+2)
+ allocate(s3(LL*NN))
+ allocate(c0(0:npts2-1))
idec=-1
ircbest=9999
- allocate(c0(0:npts2-1))
irc=-99
s3lim=20.
baud=6000.0/nsps2
- idfmax=3
- idtmax=3
+ idfmax=1
+ idtmax=1
+ maxdist=4
ibw0=(ibwa+ibwb)/2
- maxdist=5
- if(iand(ndepth,3).ge.2) then
+ if(iand(ndepth,3).eq.2) then
+ idfmax=3
+ idtmax=3
+ maxdist=5
+ endif
+ if(iand(ndepth,3).eq.3) then
idfmax=5
idtmax=5
- maxdist=10
+ maxdist=15
endif
- if(iand(ndepth,3).eq.3) maxdist=15
- LL=64*(mode_q65+2)
napmin=99
xdt1=xdt0
f1=f0
@@ -47,15 +52,16 @@ subroutine q65_loops(c00,npts2,nsps2,nsubmode,ndepth,jpk0, &
if(mod(idf,2).eq.0) ndf=-ndf
a=0.
a(1)=-(f0+0.5*baud*ndf)
+! Variable 'drift' is frequency increase over full TxT. Therefore we want:
+ a(2)=-0.5*drift
call twkfreq(c00,c0,npts2,6000.0,a)
do idt=1,idtmax
ndt=idt/2
if(mod(idt,2).eq.0) ndt=-ndt
jpk=jpk0 + nsps2*ndt/16 !tsym/16
- if(jpk.lt.0) jpk=0
- call timer('spec64 ',0)
- call spec64(c0,nsps2,mode_q65,jpk,s3,LL,NN)
- call timer('spec64 ',1)
+ jpk=max(0,jpk)
+ jpk=min(29000,jpk)
+ call spec64(c0,npts2,nsps2,mode_q65,jpk,s3,LL,NN)
call pctile(s3,LL*NN,40,base)
s3=s3/base
where(s3(1:LL*NN)>s3lim) s3(1:LL*NN)=s3lim
diff --git a/lib/qra/q65/q65code.f90 b/lib/qra/q65/q65code.f90
new file mode 100644
index 00000000..d61cba91
--- /dev/null
+++ b/lib/qra/q65/q65code.f90
@@ -0,0 +1,29 @@
+program q65code
+ use q65_encoding
+
+ implicit none
+ character*37 msg37
+ integer nargs
+ integer codeword(65),tones(85)
+
+ nargs=iargc()
+ if(nargs .ne. 1) then
+ print*,'Usage: q65code "msg"'
+ goto 999
+ endif
+ call getarg(1,msg37)
+
+ call get_q65_tones(msg37,codeword,tones)
+
+ write(*,*) 'Generated message plus CRC (90 bits)'
+ write(*,'(a8,15i4)') '6 bit : ',codeword(1:15)
+ write(*,'(a8,15b6.6)') 'binary: ',codeword(1:15)
+ write(*,*) ' '
+ write(*,*) 'Codeword with CRC symbols (65 symbols)'
+ write(*,'(20i3)') codeword
+
+ write(*,*) ' '
+ write(*,*) 'Channel symbols (85 total)'
+ write(*,'(20i3)') tones
+
+999 end program q65code
diff --git a/lib/qra/q65/qra15_65_64_irr_e23.c b/lib/qra/q65/qra15_65_64_irr_e23.c
index d56e057f..88667169 100644
--- a/lib/qra/q65/qra15_65_64_irr_e23.c
+++ b/lib/qra/q65/qra15_65_64_irr_e23.c
@@ -494,7 +494,7 @@ static const int qra_pmat[qra_M*qra_M] = {
3, 1, 7, 5, 11, 9, 15, 13, 19, 17, 23, 21, 27, 25, 31, 29,
35, 33, 39, 37, 43, 41, 47, 45, 51, 49, 55, 53, 59, 57, 63, 61
};
-
+/*
// SO array
static const int SO[qra_N-qra_K+1] = {
14, 2, 4, 5, 9, 13, 10, 15, 11, 6, 1, 8, 2, 12, 9, 10,
@@ -515,6 +515,7 @@ static const int LOGWO[qra_N-qra_K+1] = {
static const int repfact[qra_K] = {
3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 3
};
+*/
const qracode qra15_65_64_irr_e23 = {
qra_K,