From 5c88480ddc5c5dab1f3444a8b8de9303fd6140da Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Sat, 27 Mar 2021 10:23:34 +0100 Subject: New upstream version 2.4.0~rc4+repack --- lib/77bit/packjt77.f90 | 4 +- lib/allsim.f90 | 51 +- lib/decoder.f90 | 7 +- lib/fast_decode.f90 | 7 - lib/fst4_decode.f90 | 2 +- lib/ft4/ft4code.f90 | 3 +- lib/ft8/ft8code.f90 | 3 +- lib/geniscat.f90 | 55 -- lib/iscat.f90 | 206 -------- lib/jt9.f90 | 6 + lib/morse.f90 | 1 + lib/msk144code.f90 | 3 +- lib/msk144decodeframe.f90 | 2 +- lib/q65_decode.f90 | 72 +-- lib/qra/q65/q65.c | 6 +- lib/qra/q65/q65.f90 | 241 +++++++-- lib/qra/q65/q65.h | 11 +- lib/qra/q65/q65_loops.f90 | 12 +- lib/qra/q65/q65_subs.c | 5 +- lib/qra/q65/q65sim.f90 | 33 +- lib/qra/qra64/Makefile.Win | 30 -- lib/qra/qra64/fadengauss.c | 302 ----------- lib/qra/qra64/fadenlorentz.c | 304 ----------- lib/qra/qra64/main.c | 746 -------------------------- lib/qra/qra64/qra64.c | 1121 ---------------------------------------- lib/qra/qra64/qra64.h | 269 ---------- lib/qra/qra64/qra64_all.c | 1050 ------------------------------------- lib/qra/qra64/qra64_subs.c | 65 --- lib/qra/qra64/qra64example.txt | 88 ---- lib/qra/qra64/qra64sim.f90 | 201 ------- lib/qra_loops.f90 | 137 ----- lib/symspec.f90 | 28 +- lib/sync4.f90 | 4 +- lib/sync64.f90 | 164 ------ lib/synciscat.f90 | 185 ------- lib/test_q65.f90 | 2 +- 36 files changed, 355 insertions(+), 5071 deletions(-) delete mode 100644 lib/geniscat.f90 delete mode 100644 lib/iscat.f90 delete mode 100644 lib/qra/qra64/Makefile.Win delete mode 100644 lib/qra/qra64/fadengauss.c delete mode 100644 lib/qra/qra64/fadenlorentz.c delete mode 100644 lib/qra/qra64/main.c delete mode 100644 lib/qra/qra64/qra64.c delete mode 100644 lib/qra/qra64/qra64.h delete mode 100644 lib/qra/qra64/qra64_all.c delete mode 100644 lib/qra/qra64/qra64_subs.c delete mode 100644 lib/qra/qra64/qra64example.txt delete mode 100644 lib/qra/qra64/qra64sim.f90 delete mode 100644 lib/qra_loops.f90 delete mode 100644 lib/sync64.f90 delete mode 100644 lib/synciscat.f90 (limited to 'lib') diff --git a/lib/77bit/packjt77.f90 b/lib/77bit/packjt77.f90 index 83d848f1..aec73c68 100644 --- a/lib/77bit/packjt77.f90 +++ b/lib/77bit/packjt77.f90 @@ -816,8 +816,8 @@ subroutine split77(msg,nwords,nw,w) endif j=j+1 !Index in msg n=n+1 !Index in word + if(c.ge.'a' .and. c.le.'z') c=char(ichar(c)-32) !Force upper case msg(j:j)=c - if(c.ge.'a' .and. c.le.'z') msg(j:j)=char(ichar(c)-32) !Force upper case if(n.le.13) w(k)(n:n)=c !Copy character c into word c0=c enddo @@ -830,7 +830,7 @@ subroutine split77(msg,nwords,nw,w) call chkcall(w(3),bcall_1,ok1) if(ok1 .and. w(1)(1:3).eq.'CQ ') then w(1)='CQ_'//w(2)(1:10) !Make "CQ " into "CQ_" - w(2:12)=w(3:13) !Move all remeining words down by one + w(2:12)=w(3:13) !Move all remaining words down by one nwords=nwords-1 endif diff --git a/lib/allsim.f90 b/lib/allsim.f90 index 3735a449..4b255d21 100644 --- a/lib/allsim.f90 +++ b/lib/allsim.f90 @@ -10,7 +10,7 @@ program allsim integer*2 iwave(NMAX) !Generated waveform (no noise) integer itone(206) !Channel symbols (values 0-8) integer icw(250) !Encoded CW message bits - integer*1 msgbits(77) !Encoded message bits for FT8, FT4 + integer*1 msgbits(101) !Encoded message bits for FST4 FT8 FT4 real dat(NMAX) !Audio waveform complex cwave(NMAX) real wave(NMAX) @@ -22,8 +22,8 @@ program allsim print*,'Usage: allsim snr [isig]' print*,'Examples: allsim -10 #Include all signal types' print*,' allsim -10 6 #Include FT8 only' - print*,'isig order: 1 2 3 4 5 6 7 8 9' - print*,' Carrier CW WSPR JT9 JT4 FT8 FT4 QRA64 JT65' + print*,'isig order: 1 2 3 4 5 6 7 8 9 10' + print*,' Carrier CW WSPR FST4 JT9 JT4 FT8 FT4 Q65 JT65' go to 999 endif @@ -52,42 +52,50 @@ program allsim itone=0 if(isig.eq.0 .or. isig.eq.1) then - call addit(itone,12000,85,6912,400,sig,dat) !Unmodulated carrier + call addit(itone,12000,85,6912,400,sig,dat) !1 Unmodulated carrier endif if(isig.eq.0 .or. isig.eq.2) then call morse('CQ CQ DE KA2ABC KA2ABC',icw,ncw) - call addcw(icw,ncw,600,sig,dat) !CW + call addcw(icw,ncw,600,sig,dat) !2 CW at 20 WPM endif if(isig.eq.0 .or. isig.eq.3) then call genwspr(message,msgsent,itone) - call addit(itone,12000,86,8192,800,sig,dat) !WSPR (only 59 s of data) + call addit(itone,12000,86,8192,800,sig,dat) !3 WSPR (only 59 s of data) endif - if(isig.eq.0 .or. isig.eq.4) then - call gen9(message,0,msgsent,itone,itype) - call addit(itone,12000,85,6912,1000,sig,dat) !JT9 + if(isig.eq.0 .or. isig.eq.4) then !4 FST4-60 + iwspr=0 + call genfst4(msg37,0,msgsent37,msgbits,itone,iwspr) + nwave=162*3888 + call gen_fst4wave(itone,160,3888,nwave,12000.0,1,1000.0,0,cwave,wave) + dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave) endif if(isig.eq.0 .or. isig.eq.5) then - call gen4(message,0,msgsent,itone,itype) - call addit(itone,11025,206,2520,1200,sig,dat) !JT4 + call gen9(message,0,msgsent,itone,itype) + call addit(itone,12000,85,6912,1200,sig,dat) !4 JT9 endif if(isig.eq.0 .or. isig.eq.6) then - call genft8(msg37,i3,n3,msgsent37,msgbits,itone) !FT8 + call gen4(message,0,msgsent,itone,itype) + call addit(itone,11025,206,2520,1400,sig,dat) !6 JT4 + endif + + if(isig.eq.0 .or. isig.eq.7) then + call genft8(msg37,i3,n3,msgsent37,msgbits,itone) !7 FT8 nwave=79*1920 - call gen_ft8wave(itone,79,1920,2.0,12000.0,1400.0,cwave,wave,0,nwave) + call gen_ft8wave(itone,79,1920,2.0,12000.0,1600.0,cwave,wave,0,nwave) dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave) k=30*12000 dat(6001+k:6000+nwave+k)=dat(6001+k:6000+nwave+k) + sig*wave(1:nwave) endif - if(isig.eq.0 .or. isig.eq.7) then - call genft4(msg37,0,msgsent37,msgbits,itone) !FT4 + if(isig.eq.0 .or. isig.eq.8) then + call genft4(msg37,0,msgsent37,msgbits,itone) !8 FT4 nwave=105*576 - call gen_ft4wave(itone,103,576,12000.0,1600.0,cwave,wave,0,nwave) + call gen_ft4wave(itone,103,576,12000.0,1800.0,cwave,wave,0,nwave) dat(6001:6000+nwave)=dat(6001:6000+nwave) + sig*wave(1:nwave) k=15*12000 dat(6001+k:6000+nwave+k)=dat(6001+k:6000+nwave+k) + sig*wave(1:nwave) @@ -95,17 +103,16 @@ program allsim dat(6001+k:6000+nwave+k)=dat(6001+k:6000+nwave+k) + sig*wave(1:nwave) k=45*12000 dat(6001+k:6000+nwave+k)=dat(6001+k:6000+nwave+k) + sig*wave(1:nwave) - endif - if(isig.eq.0 .or. isig.eq.8) then - call genqra64(message,0,msgsent,itone,itype) - call addit(itone,12000,84,6912,1800,sig,dat) !QRA64 + if(isig.eq.0 .or. isig.eq.9) then + call genq65(msg37,0,msgsent37,itone,i3,n3) + call addit(itone,12000,85,7200,2000,sig,dat) !9 Q65 endif - if(isig.eq.0 .or. isig.eq.9) then + if(isig.eq.0 .or. isig.eq.10) then call gen65(message,0,msgsent,itone,itype) - call addit(itone,11025,126,4096,2000,sig,dat) !JT65 + call addit(itone,11025,126,4096,2200,sig,dat) !10 JT65A endif iwave=nint(rms*dat) diff --git a/lib/decoder.f90 b/lib/decoder.f90 index 5a254a56..d1a53009 100644 --- a/lib/decoder.f90 +++ b/lib/decoder.f90 @@ -269,8 +269,6 @@ subroutine multimode_decoder(ss,id2,params,nfsample) if(params%nmode.eq.4 .or. params%nmode.eq.65) open(14,file=trim(temp_dir)// & '/avemsg.txt',status='unknown') - if(params%nmode.eq.164) open(17,file=trim(temp_dir)//'/red.dat', & - status='unknown') if(params%nmode.eq.4) then jz=52*nfsample @@ -289,7 +287,6 @@ subroutine multimode_decoder(ss,id2,params,nfsample) endif npts65=52*12000 - if(params%nmode.eq.164) npts65=54*12000 if(baddata(id2,npts65)) then nsynced=0 ndecoded=0 @@ -368,7 +365,7 @@ subroutine multimode_decoder(ss,id2,params,nfsample) endif if(params%nmode.ne.8 .or. params%nzhsym.eq.50 .or. & .not.params%ndiskdat) then - + write(*,1010) nsynced,ndecoded,navg0 1010 format('',2i4,i9) call flush(6) @@ -806,7 +803,7 @@ contains select type(this) type is (counting_q65_decoder) - if(idec.gt.0) this%decoded = this%decoded + 1 + if(idec.ge.0) this%decoded = this%decoded + 1 end select return diff --git a/lib/fast_decode.f90 b/lib/fast_decode.f90 index d32314b9..30384b0a 100644 --- a/lib/fast_decode.f90 +++ b/lib/fast_decode.f90 @@ -86,13 +86,6 @@ subroutine fast_decode(id2,narg,trperiod,line,mycall_12, & endif jz=ib-ia+1 line(1:100)(1:1)=char(0) - if(npick.eq.2) then - call iscat(cdat2(ia),jz,3,40,t2,pick,cfile6,minsync,ntol, & - mousebutton,mode4,nafc,ndebug,psavg,nmax,nlines,line) - else - call iscat(cdat(ia),jz,3,40,t2,pick,cfile6,minsync,ntol, & - mousebutton,mode4,nafc,ndebug,psavg,maxlines,nlines,line) - endif 900 return end subroutine fast_decode diff --git a/lib/fst4_decode.f90 b/lib/fst4_decode.f90 index b58b270e..64fc207d 100644 --- a/lib/fst4_decode.f90 +++ b/lib/fst4_decode.f90 @@ -614,7 +614,7 @@ contains endif call this%callback(nutc,smax1,nsnr,xdt,fsig,msg, & iaptype,qual,ntrperiod,lwspr,fmid,w50) - if(iwspr.eq.0 .and. nb.lt.0) go to 900 +! if(iwspr.eq.0 .and. nb.lt.0) go to 900 goto 800 endif enddo ! metrics diff --git a/lib/ft4/ft4code.f90 b/lib/ft4/ft4code.f90 index a7b2ccdd..dae55245 100644 --- a/lib/ft4/ft4code.f90 +++ b/lib/ft4/ft4code.f90 @@ -65,7 +65,8 @@ program ft4code if(i3.eq.2) msgtype="EU VHF Contest" if(i3.eq.3) msgtype="ARRL RTTY Roundup" if(i3.eq.4) msgtype="Nonstandard calls" - if(i3.ge.5) msgtype="Undefined msg type" + if(i3.eq.5) msgtype="EU VHF Contest" + if(i3.ge.6) msgtype="Undefined msg type" if(i3.ge.1) n3=-1 bad=" " comment=' ' diff --git a/lib/ft8/ft8code.f90 b/lib/ft8/ft8code.f90 index 8d5b5279..219fd2e3 100644 --- a/lib/ft8/ft8code.f90 +++ b/lib/ft8/ft8code.f90 @@ -64,7 +64,8 @@ program ft8code if(i3.eq.2) msgtype="EU VHF Contest" if(i3.eq.3) msgtype="ARRL RTTY Roundup" if(i3.eq.4) msgtype="Nonstandard call" - if(i3.ge.5) msgtype="Undefined type" + if(i3.eq.5) msgtype="EU VHF Contest" + if(i3.ge.6) msgtype="Undefined type" if(i3.ge.1) n3=-1 bad=" " comment=' ' diff --git a/lib/geniscat.f90 b/lib/geniscat.f90 deleted file mode 100644 index 6df6ed98..00000000 --- a/lib/geniscat.f90 +++ /dev/null @@ -1,55 +0,0 @@ -subroutine geniscat(msg,msgsent,itone) - -! Generate an ISCAT waveform. - - parameter (NSZ=1291) - character msg*28,msgsent*28 !Message to be transmitted - integer imsg(30) - integer itone(NSZ) - real*8 sps - character c*42 - integer icos(4) !Costas array - data icos/0,1,3,2/ - data nsync/4/,nlen/2/,ndat/18/ - data c/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ /.?@-'/ - - sps=256.d0*12000.d0/11025.d0 - nsym=int(30*12000.d0/sps) - nblk=nsync+nlen+ndat - - do i=22,1,-1 - if(msg(i:i).ne.' ' .and. msg(i:i).ne.char(0)) exit - enddo - nmsg=i - msglen=nmsg+1 - k=0 - kk=1 - imsg(1)=40 !Always start with BOM char: '@' - do i=1,nmsg !Define the tone sequence - imsg(i+1)=36 !Illegal char set to blank - do j=1,42 - if(msg(i:i).eq.c(j:j)) imsg(i+1)=j-1 - enddo - enddo - - do i=1,nsym !Total symbols in 30 s - j=mod(i-1,nblk)+1 - if(j.le.nsync) then - itone(i)=icos(j) !Insert 4x4 Costas array - else if(j.gt.nsync .and. j.le.nsync+nlen) then - itone(i)=msglen !Insert message-length indicator - if(j.ge.nsync+2) then - n=msglen + 5*(j-nsync-1) - if(n.gt.41) n=n-42 - itone(i)=n - endif - else - k=k+1 - kk=mod(k-1,msglen)+1 - itone(i)=imsg(kk) - endif - enddo - msgsent=msg - - return -end subroutine geniscat diff --git a/lib/iscat.f90 b/lib/iscat.f90 deleted file mode 100644 index 17d1454f..00000000 --- a/lib/iscat.f90 +++ /dev/null @@ -1,206 +0,0 @@ -subroutine iscat(cdat0,npts0,nh,npct,t2,pick,cfile6,minsync,ntol, & - mousebutton,mode4,nafc,nmore,psavg,maxlines,nlines,line) - -! Decode an ISCAT signal - - parameter (NMAX=30*3101) - parameter (NSZ=4*1400) - character cfile6*6 !File time - character c42*42 - character msg*29,msg1*29,msgbig*29 - character*80 line(100) - character csync*1 - complex cdat0(NMAX) - complex cdat(NMAX) - real s0(288,NSZ) - real fs1(0:41,30) - real psavg(72) !Average spectrum of whole file - integer nsum(30) - integer ntol - integer icos(4) - logical pick,last - data icos/0,1,3,2/ - data nsync/4/,nlen/2/,ndat/18/ - data c42/'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ /.?@-'/ - save cdat,s0 - - nlines = 0 - fsample=3100.78125 !Sample rate after 9/32 downsampling - nsps=144/mode4 - - bigworst=-1.e30 !Silence compiler warnings ... - bigxsync=0. - bigsig=-1.e30 - msglenbig=0 - ndf0big=0 - nfdotbig=0 - bigt2=0. - bigavg=0. - bigtana=0. - if(nmore.eq.-999) bigsig=-1 !... to here - - last=.false. - do inf=1,6 !Loop over data-segment sizes - nframes=2**inf - if(nframes*24*nsps.gt.npts0) then - nframes=npts0/(24*nsps) - last=.true. - endif - npts=nframes*24*nsps - - do ia=1,npts0-npts,nsps*24 !Loop over start times stepped by 1 frame - ib=ia+npts-1 - cdat(1:npts)=cdat0(ia:ib) - t3=(ia + 0.5*npts)/fsample + 0.9 - if(pick) t3=t2+t3 - -! Compute symbol spectra and establish sync: - call synciscat(cdat,npts,nh,npct,s0,jsym,df,ntol, & - mousebutton,mode4,nafc,psavg,xsync,sig,ndf0,msglen, & - ipk,jpk,idf,df1) - nfdot=nint(idf*df1) - - isync=xsync - if(msglen.eq.0 .or. isync.lt.max(minsync,0)) then - msglen=0 - worst=1. - avg=1. - ndf0=0 - cycle - endif - - ipk3=0 !Silence compiler warning - nblk=nsync+nlen+ndat - fs1=0. - nsum=0 - nfold=jsym/96 - jb=96*nfold - k=0 - n=0 - do j=jpk,jsym,4 !Fold information symbols into fs1 - k=k+1 - km=mod(k-1,nblk)+1 - if(km.gt.6) then - n=n+1 - m=mod(n-1,msglen)+1 - ii=nint(idf*float(j-jb/2)/float(jb)) - do i=0,41 - iii=ii+ipk+2*i - if(iii.ge.1 .and. iii.le.288) fs1(i,m)=fs1(i,m) + s0(iii,j) - enddo - nsum(m)=nsum(m)+1 - endif - enddo - - do m=1,msglen - fs1(0:41,m)=fs1(0:41,m)/nsum(m) - enddo - -! Read out the message contents: - msg= ' ' - msg1=' ' - mpk=0 - worst=9999. - sum=0. - do m=1,msglen - smax=0. - smax2=0. - do i=0,41 - if(fs1(i,m).gt.smax) then - smax=fs1(i,m) - ipk3=i - endif - enddo - do i=0,41 - if(fs1(i,m).gt.smax2 .and. i.ne.ipk3) smax2=fs1(i,m) - enddo - rr=0. - if(smax2.gt.0.0) rr=smax/smax2 - sum=sum + rr - if(rr.lt.worst) worst=rr - if(ipk3.eq.40) mpk=m - msg1(m:m)=c42(ipk3+1:ipk3+1) - enddo - - avg=sum/msglen - if(mpk.eq.1) then - msg=msg1(2:) - else if(mpk.lt.msglen) then - msg=msg1(mpk+1:msglen)//msg1(1:mpk-1) - else - msg=msg1(1:msglen-1) - endif - - ttot=npts/3100.78125 - - if(worst.gt.bigworst) then - bigworst=worst - bigavg=avg - bigxsync=xsync - bigsig=sig - ndf0big=ndf0 - nfdotbig=nfdot - msgbig=msg - msglenbig=msglen - bigt2=t3 - bigtana=nframes*24*nsps/fsample - endif - - isync = xsync - if(avg.gt.2.5 .and. xsync.ge.max(float(minsync),1.5) .and. & - maxlines.ge.2) then - nsig=nint(sig) - nworst=10.0*(worst-1.0) - navg=10.0*(avg-1.0) - if(nworst.gt.10) nworst=10 - if(navg.gt.10) navg=10 - tana=nframes*24*nsps/fsample - csync=' ' - if(isync.ge.1) csync='*' - if(nlines.le.maxlines-1) nlines = nlines + 1 - write(line(nlines),1020) cfile6,isync,nsig,t2,ndf0,nfdot,csync, & - msg(1:28),msglen,navg,nworst,tana,char(0) - endif - enddo - if(last) exit - enddo - - worst=bigworst - avg=bigavg - xsync=bigxsync - sig=bigsig - ndf0=ndf0big - nfdot=nfdotbig - msg=msgbig - msglen=msglenbig - t2=bigt2 - tana=bigtana - - isync=xsync - nworst=10.0*(worst-1.0) - navg=10.0*(avg-1.0) - if(nworst.gt.10) nworst=10 - if(navg.gt.10) navg=10 - - if(navg.le.0 .or. isync.lt.max(minsync,0)) then - msg=' ' - nworst=0 - navg=0 - ndf0=0 - nfdot=0 - sig=-20 - msglen=0 - tana=0. - t2=0. - endif - csync=' ' - if(isync.ge.1) csync='*' - nsig=nint(sig) - - if(nlines.le.maxlines-1) nlines = nlines + 1 - write(line(nlines),1020) cfile6,isync,nsig,t2,ndf0,nfdot,csync,msg(1:28), & - msglen,navg,nworst,tana,char(0) -1020 format(a6,2i4,f5.1,i5,i4,1x,a1,2x,a28,i4,i3,2x,i1,f5.1,a1) - - return -end subroutine iscat diff --git a/lib/jt9.f90 b/lib/jt9.f90 index 9a150dad..e07fd742 100644 --- a/lib/jt9.f90 +++ b/lib/jt9.f90 @@ -206,6 +206,12 @@ program jt9 go to 999 endif + if(mycall.eq.'b') mycall=' ' + if(hiscall.eq.'b') then + hiscall=' ' + hisgrid=' ' + endif + if (mode .eq. 241) then ntol = min (ntol, 100) else if (mode .eq. 65 + 9 .and. .not. have_ntol) then diff --git a/lib/morse.f90 b/lib/morse.f90 index de5f7a1b..7b428958 100644 --- a/lib/morse.f90 +++ b/lib/morse.f90 @@ -64,6 +64,7 @@ subroutine morse(msg,idat,n) ! Insert this character nmax=ic(21,j) + if (n + nmax + 4 .gt. size (idat)) exit do i=1,nmax n=n+1 idat(n)=ic(i,j) diff --git a/lib/msk144code.f90 b/lib/msk144code.f90 index e75ebf3d..2cb4d6a4 100644 --- a/lib/msk144code.f90 +++ b/lib/msk144code.f90 @@ -51,7 +51,8 @@ program msk144code if(i3.eq.2) msgtype="EU VHF Contest" if(i3.eq.3) msgtype="ARRL RTTY Roundup" if(i3.eq.4) msgtype="Nonstandard calls" - if(i3.ge.5) msgtype="Undefined msg type" + if(i3.eq.5) msgtype="EU VHF Contest" + if(i3.ge.6) msgtype="Undefined msg type" if(i3.ge.1) n3=-1 if(i4tone(41).lt.0) then msgtype="Sh msg" diff --git a/lib/msk144decodeframe.f90 b/lib/msk144decodeframe.f90 index 24119b9b..b8bdba28 100644 --- a/lib/msk144decodeframe.f90 +++ b/lib/msk144decodeframe.f90 @@ -100,7 +100,7 @@ subroutine msk144decodeframe(c,softbits,msgreceived,nsuccess) nsuccess=1 write(c77,'(77i1)') decoded77 read(c77(72:77),'(2b3)') n3,i3 - if( (i3.eq.0.and.(n3.eq.1 .or. n3.eq.3 .or. n3.eq.4 .or. n3.gt.5)) .or. i3.eq.3 .or. i3.gt.4 ) then + if( (i3.eq.0.and.(n3.eq.1 .or. n3.eq.3 .or. n3.eq.4 .or. n3.gt.5)) .or. i3.eq.3 .or. i3.gt.5 ) then nsuccess=0 else call unpack77(c77,1,msgreceived,unpk77_success) diff --git a/lib/q65_decode.f90 b/lib/q65_decode.f90 index 0bea7d8e..7869527d 100644 --- a/lib/q65_decode.f90 +++ b/lib/q65_decode.f90 @@ -67,10 +67,10 @@ contains integer dat4(13) !Decoded message as 12 6-bit integers integer dgen(13) logical lclearave,lnewdat0,lapcqonly,unpk77_success - logical single_decode,lagain + logical single_decode,lagain,ex complex, allocatable :: c00(:) !Analytic signal, 6000 Sa/s complex, allocatable :: c0(:) !Analytic signal, 6000 Sa/s - + ! Start by setting some parameters and allocating storage for large arrays call sec0(0,tdecode) nfa=nfa0 @@ -79,7 +79,7 @@ contains idec=-1 idf=0 idt=0 - irc=0 + nrc=-2 mode_q65=2**nsubmode npts=ntrperiod*12000 nfft1=ntrperiod*12000 @@ -87,7 +87,7 @@ contains ! Determine the T/R sequence: iseq=0 (even), or iseq=1 (odd) n=nutc - if(ntrperiod.ge.60) n=100*n + if(ntrperiod.ge.60 .and. nutc.le.2359) n=100*n write(cutc,'(i6.6)') n read(cutc,'(3i2)') ih,im,is nsec=3600*ih + 60*im + is @@ -98,9 +98,12 @@ contains allocate (c00(0:nfft1-1)) allocate (c0(0:nfft1-1)) - if(ntrperiod.eq.15) then - nsps=1800 - else if(ntrperiod.eq.30) then + if(lagain) then + call q65_hist(nfqso,dxcall=hiscall,dxgrid=hisgrid) + endif + + nsps=1800 + if(ntrperiod.eq.30) then nsps=3600 else if(ntrperiod.eq.60) then nsps=7200 @@ -108,23 +111,26 @@ contains nsps=16000 else if(ntrperiod.eq.300) then nsps=41472 - else - stop 'Invalid TR period' endif baud=12000.0/nsps this%callback => callback nFadingModel=1 + + inquire(file='ndepth.dat',exist=ex) + if(.not.ex) ndepth=iand(ndepth,not(3)) + 1 !Treat any ndepth as "Fast" + maxiters=67 ibwa=max(1,int(1.8*log(baud*mode_q65)) + 1) - ibwb=min(10,ibwa+3) + ibwb=min(10,ibwa+4) if(iand(ndepth,3).ge.2) then - ibwa=max(1,int(1.8*log(baud*mode_q65)) + 2) + ibwa=max(1,int(1.8*log(baud*mode_q65)) + 1) ibwb=min(10,ibwa+5) else if(iand(ndepth,3).eq.3) then ibwa=max(1,ibwa-1) ibwb=min(10,ibwb+1) + maxiters=100 endif - + ! Generate codewords for full-AP list decoding call q65_set_list(mycall,hiscall,hisgrid,codewords,ncw) dgen=0 @@ -175,7 +181,6 @@ contains call timer('q65loops',0) call q65_loops(c00,npts/2,nsps/2,nsubmode,ndepth,jpk0, & xdt,f0,iaptype,xdt1,f1,snr2,dat4,idec) -! idec=-1 !### TEMPORARY ### call timer('q65loops',1) if(idec.ge.0) then dtdec=xdt1 @@ -185,8 +190,9 @@ contains enddo ! ipass if(iand(ndepth,16).eq.0 .or. navg(iseq).lt.2) go to 100 + ! There was no single-transmission decode. Try for an average 'q3n' decode. - call timer('list_avg',0) +50 call timer('list_avg',0) ! Call top-level routine in q65 module: establish sync and try for a q3 ! decode, this time using the cumulative 's1a' symbol spectra. iavg=1 @@ -229,10 +235,13 @@ contains write(c77,1000) dat4(1:12),dat4(13)/2 1000 format(12b6.6,b5.5) call unpack77(c77,0,decoded,unpk77_success) !Unpack to get msgsent + call q65_snr(dat4,dtdec,f0dec,mode_q65,nused,snr2) nsnr=nint(snr2) call this%callback(nutc,snr1,nsnr,dtdec,f0dec,decoded, & idec,nused,ntrperiod) - if(iand(ndepth,128).ne.0) call q65_clravg !AutoClrAvg after decode + call q65_hist(nint(f0dec),msg0=decoded) + if(iand(ndepth,128).ne.0 .and. .not.lagain .and. & + int(abs(f0dec-nfqso)).le.ntol ) call q65_clravg !AutoClrAvg call sec0(1,tdecode) open(22,file=trim(data_dir)//'/q65_decodes.dat',status='unknown', & position='append',iostat=ios) @@ -244,21 +253,15 @@ contains if(c6.eq.' ') c6=' ' c4=hisgrid(1:4) if(c4.eq.' ') c4=' ' - fmt='(i6.4,1x,a4,5i2,3i3,f6.2,f7.1,f7.2,f6.1,f6.2,'// & + fmt='(i6.4,1x,a4,4i2,6i3,i4,f6.2,f7.1,f6.1,f7.1,f6.2,'// & '1x,a6,1x,a6,1x,a4,1x,a)' if(ntrperiod.le.30) fmt(5:5)='6' - write(22,fmt) nutc,cmode,nQSOprogress,idec,idf,idt,ibw,nused, & - icand,ncand,xdt,f0,snr1,snr2,tdecode,mycall(1:6),c6,c4, & - trim(decoded) + if(idec.eq.3) nrc=0 + write(22,fmt) nutc,cmode,nQSOprogress,idec,idfbest,idtbest,ibw, & + ndistbest,nused,icand,ncand,nrc,ndepth,xdt,f0,snr2,plog, & + tdecode,mycall(1:6),c6,c4,trim(decoded) close(22) endif - else -! Report snr1, even if no decode. - nsnr=db(snr1) - 35.0 - if(nsnr.lt.-35) nsnr=-35 - idec=-1 - call this%callback(nutc,snr1,nsnr,xdt,f0,decoded, & - idec,0,ntrperiod) endif navg0=1000*navg(0) + navg(1) if(single_decode .or. lagain) go to 900 @@ -309,10 +312,13 @@ contains ! Unpack decoded message for display to user write(c77,1000) dat4(1:12),dat4(13)/2 call unpack77(c77,0,decoded,unpk77_success) !Unpack to get msgsent + call q65_snr(dat4,dtdec,f0dec,mode_q65,nused,snr2) nsnr=nint(snr2) call this%callback(nutc,snr1,nsnr,dtdec,f0dec,decoded, & idec,nused,ntrperiod) - if(iand(ndepth,128).ne.0) call q65_clravg !AutoClrAvg after decode + call q65_hist(nint(f0dec),msg0=decoded) + if(iand(ndepth,128).ne.0 .and. .not.lagain .and. & + int(abs(f0dec-nfqso)).le.ntol ) call q65_clravg !AutoClrAvg call sec0(1,tdecode) open(22,file=trim(data_dir)//'/q65_decodes.dat',status='unknown', & position='append',iostat=ios) @@ -324,16 +330,18 @@ contains if(c6.eq.' ') c6=' ' c4=hisgrid(1:4) if(c4.eq.' ') c4=' ' - fmt='(i6.4,1x,a4,5i2,3i3,f6.2,f7.1,f7.2,f6.1,f6.2,'// & + fmt='(i6.4,1x,a4,4i2,6i3,i4,f6.2,f7.1,f6.1,f7.1,f6.2,'// & '1x,a6,1x,a6,1x,a4,1x,a)' if(ntrperiod.le.30) fmt(5:5)='6' - write(22,fmt) nutc,cmode,nQSOprogress,idec,idf,idt,ibw,nused, & - icand,ncand,xdt,f0,snr1,snr2,tdecode,mycall(1:6),c6,c4, & - trim(decoded) + if(idec.eq.3) nrc=0 + write(22,fmt) nutc,cmode,nQSOprogress,idec,idfbest,idtbest,ibw, & + ndistbest,nused,icand,ncand,nrc,ndepth,xdt,f0,snr2,plog, & + tdecode,mycall(1:6),c6,c4,trim(decoded) close(22) endif endif - enddo + enddo ! icand + if(iavg.eq.0 .and.navg(iseq).ge.2) go to 50 900 return end subroutine decode diff --git a/lib/qra/q65/q65.c b/lib/qra/q65/q65.c index f47f25fa..f7701792 100644 --- a/lib/qra/q65/q65.c +++ b/lib/qra/q65/q65.c @@ -522,7 +522,9 @@ int q65_esnodb_fastfading( } -int q65_decode(q65_codec_ds *pCodec, int* pDecodedCodeword, int *pDecodedMsg, const float *pIntrinsics, const int *pAPMask, const int *pAPSymbols) +int q65_decode(q65_codec_ds *pCodec, int* pDecodedCodeword, int *pDecodedMsg, + const float *pIntrinsics, const int *pAPMask, + const int *pAPSymbols, const int maxiters) { const qracode *pQraCode; float *ix, *ex; @@ -579,7 +581,7 @@ int q65_decode(q65_codec_ds *pCodec, int* pDecodedCodeword, int *pDecodedMsg, co rc = qra_extrinsic( pQraCode, ex, ix, - 100, + maxiters, pCodec->qra_v2cmsg, pCodec->qra_c2vmsg); diff --git a/lib/qra/q65/q65.f90 b/lib/qra/q65/q65.f90 index 106df8a3..a85c3271 100644 --- a/lib/qra/q65/q65.f90 +++ b/lib/qra/q65/q65.f90 @@ -11,15 +11,19 @@ module q65 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 idf,idt,ibw - integer istep,nsmo,lag1,lag2,npasses,nused,iseq,ncand + integer idfbest,idtbest,ibw,ndistbest,maxiters + integer istep,nsmo,lag1,lag2,npasses,nused,iseq,ncand,nrc integer i0,j0 integer navg(0:1) logical lnewdat - real candidates(20,3) !snr, xdt, and f0 of top candidates - real,allocatable,save :: s1a(:,:,:) !Cumulative symbol spectra - real sync(85) !sync vector - real df,dtstep,dtdec,f0dec,ftol + real candidates(20,3) !snr, xdt, and f0 of top candidates + real, allocatable :: s1raw(:,:) !Symbol spectra, 1/8-symbol steps + real, allocatable :: s1(:,:) !Symbol spectra w/suppressed peaks + real, allocatable,save :: s1a(:,:,:) !Cumulative symbol spectra + 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 contains @@ -45,7 +49,7 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & ! width Estimated Doppler spread ! dat4(13) Decoded message as 13 six-bit integers ! snr2 Estimated SNR of decoded signal -! idec Flag for decing results +! idec Flag for decoding results ! -1 No decode ! 0 No AP ! 1 "CQ ? ?" @@ -60,10 +64,8 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & integer dat4(13) character*37 decoded logical first,lclearave - real, allocatable :: s1(:,:) !Symbol spectra, 1/8-symbol steps real, allocatable :: s3(:,:) !Data-symbol energies s3(LL,63) real, allocatable :: ccf1(:) !CCF(freq) at fixed lag (red) - real, allocatable :: ccf2(:) !Max CCF(freq) at any lag (orange) data first/.true./ save first @@ -71,6 +73,7 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & ! Set some parameters and allocate storage for large arrays irc=-2 + nrc=-2 idec=-1 snr1=0. dat4=0 @@ -94,13 +97,20 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & enddo endif - allocate(s1(iz,jz)) allocate(s3(-64:LL-65,63)) allocate(ccf1(-ia2:ia2)) - allocate(ccf2(iz)) if(LL.ne.LL0 .or. iz.ne.iz0 .or. jz.ne.jz0 .or. lclearave) then + if(allocated(s1raw)) deallocate(s1raw) + allocate(s1raw(iz,jz)) + if(allocated(s1)) deallocate(s1) + allocate(s1(iz,jz)) if(allocated(s1a)) deallocate(s1a) allocate(s1a(iz,jz,0:1)) + if(allocated(ccf2)) deallocate(ccf2) + allocate(ccf2(iz)) + if(allocated(ccf2_avg)) deallocate(ccf2_avg) + allocate(ccf2_avg(iz)) + s1=0. s1a=0. navg=0 LL0=LL @@ -108,6 +118,8 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & jz0=jz lclearave=.false. endif + ccf1=0. + if(iavg.eq.0) ccf2_avg=0. dtstep=nsps/(NSTEP*12000.0) !Step size in seconds lag1=-1.0/dtstep lag2=1.0/dtstep + 0.9999 @@ -127,8 +139,9 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & 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,40,base) + call pctile(s1(i0-64:i0-65+LL,1:jz),LL*jz,45,base) s1=s1/base + s1raw=s1 ! Apply fast AGC to the symbol spectra s1max=20.0 !Empirical choice @@ -138,7 +151,7 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & enddo dat4=0 - if(ncw.gt.0 .and. iavg.lt.2) then + if(ncw.gt.0 .and. iavg.le.1) then ! Try list decoding via "Deep Likelihood". call timer('ccf_85 ',0) ! Try to synchronize using all 85 symbols @@ -150,8 +163,14 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & call timer('list_dec',1) endif + if(iavg.eq.0) then + call q65_ccf_22(s1,iz,jz,nfqso,ipk,jpk,f0a,xdta,ccf2) + endif + ! Get 2d CCF and ccf2 using sync symbols only - call q65_ccf_22(s1,iz,jz,nfqso,ipk,jpk,f0a,xdta,ccf2) + if(iavg.ge.1) then + call q65_ccf_22(s1,iz,jz,nfqso,ipk,jpk,f0a,xdta,ccf2_avg) + endif if(idec.lt.0) then f0=f0a xdt=xdta @@ -181,7 +200,9 @@ subroutine q65_dec0(iavg,nutc,iwave,ntrperiod,nfqso,ntol,ndepth,lclearave, & width=df*(i2-i1) if(ncw.eq.0) ccf1=0. - call q65_write_red(iz,ia2,xdt,ccf1,ccf2) +! 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 call q65_dec_q012(s3,LL,snr2,dat4,idec,decoded) @@ -233,9 +254,11 @@ subroutine q65_symspec(iwave,nmax,iz,jz,s1) enddo enddo if(lnewdat) then - s1a(:,:,iseq)=s1a(:,:,iseq) + s1 navg(iseq)=navg(iseq) + 1 - endif + ntc=min(navg(iseq),4) !Averaging time constant in sequences + u=1.0/ntc + s1a(:,:,iseq)=u*s1 + (1.0-u)*s1a(:,:,iseq) + endif return end subroutine q65_symspec @@ -263,6 +286,7 @@ subroutine q65_dec_q3(s1,iz,jz,s3,LL,ipk,jpk,snr2,dat4,idec,decoded) b90=1.72**ibw b90ts=b90/baud call q65_dec1(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) + nrc=irc if(irc.ge.0) then snr2=esnodb - db(2500.0/baud) + 3.0 !Empirical adjustment idec=3 @@ -314,6 +338,7 @@ subroutine q65_dec_q012(s3,LL,snr2,dat4,idec,decoded) b90=1.72**ibw b90ts=b90/baud call q65_dec2(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) + nrc=irc if(irc.ge.0) then snr2=esnodb - db(2500.0/baud) + 3.0 !Empirical adjustment idec=iaptype @@ -446,11 +471,11 @@ subroutine q65_ccf_22(s1,iz,jz,nfqso,ipk,jpk,f0,xdt,ccf2) maxcand=20 do j=1,20 i=indx(jzz-j+1)+i1-1 - if(ccf2(i).lt.3.4) exit !Candidate limit + if(ccf2(i).lt.3.3) exit !Candidate limit f=i*df - if(f.ge.(nfqso-ftol) .and. f.le.(nfqso+ftol)) cycle - i3=max(1,i-67*mode_q65) - i4=min(iz,i+3*mode_q65) + if(f.ge.(nfqso-ftol) .and. f.le.(nfqso+ftol)) cycle !Looked here already + i3=max(1, i-mode_q65) + i4=min(iz,i+mode_q65) biggest=maxval(ccf2(i3:i4)) if(ccf2(i).ne.biggest) cycle ncand=ncand+1 @@ -486,6 +511,7 @@ subroutine q65_dec1(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) else irc=-1 endif + nrc=irc return end subroutine q65_dec1 @@ -504,8 +530,9 @@ subroutine q65_dec2(s3,nsubmode,b90ts,esnodb,irc,dat4,decoded) nFadingModel=1 decoded=' ' call q65_intrinsics_ff(s3,nsubmode,b90ts,nFadingModel,s3prob) - call q65_dec(s3,s3prob,APmask,APsymbols,esnodb,dat4,irc) + call q65_dec(s3,s3prob,APmask,APsymbols,maxiters,esnodb,dat4,irc) if(sum(dat4).le.0) irc=-2 + nrc=irc if(irc.ge.0) then write(c77,1000) dat4(1:12),dat4(13)/2 1000 format(12b6.6,b5.5) @@ -537,32 +564,33 @@ subroutine q65_s1_to_s3(s1,iz,jz,ipk,jpk,LL,mode_q65,sync,s3) if(j.ge.1 .and. j.le.jz) s3(-64:LL-65,n)=s1(i1:i2,j) enddo endif - + call q65_bzap(s3,LL) !Zap birdies + return end subroutine q65_s1_to_s3 -subroutine q65_write_red(iz,ia2,xdt,ccf1,ccf2) +subroutine q65_write_red(iz,xdt,ccf2_avg,ccf2) ! Write data for the red and orange sync curves to LU 17. - real ccf1(-ia2:ia2) + real ccf2_avg(iz) real ccf2(iz) - call q65_sync_curve(ccf1,-ia2,ia2,rms1) + call q65_sync_curve(ccf2_avg,1,iz,rms1) call q65_sync_curve(ccf2,1,iz,rms2) rewind 17 - write(17,1000) xdt - do i=1,iz + write(17,1000) xdt,minval(ccf2_avg),maxval(ccf2_avg) + do i=max(1,nint(nfa/df)),min(iz,int(nfb/df)) freq=i*df - ii=i-i0 - if(freq.ge.float(nfa) .and. freq.le.float(nfb)) then - ccf1a=-99.0 - if(ii.ge.-ia2 .and. ii.le.ia2) ccf1a=ccf1(ii) - write(17,1000) freq,ccf1a,ccf2(i) -1000 format(3f10.3) - endif + y1=ccf2_avg(i) + if(y1.gt.10.0) y1=10.0 + 2.0*log10(y1/10.0) + y2=ccf2(i) + if(y2.gt.10.0) y2=10.0 + 2.0*log10(y2/10.0) + write(17,1000) freq,y1,y2 +1000 format(3f10.3) enddo + flush(17) return end subroutine q65_write_red @@ -582,11 +610,148 @@ subroutine q65_sync_curve(ccf1,ia,ib,rms1) dot_product(ccf1(ib-ic:ib),ccf1(ib-ic:ib)) rms1=0. if(nsum.gt.0) rms1=sqrt(sq/nsum) - if(rms1.gt.0.0) ccf1=2.0*ccf1/rms1 - smax1=maxval(ccf1) - if(smax1.gt.10.0) ccf1=10.0*ccf1/smax1 + if(rms1.gt.0.0) ccf1=ccf1/rms1 +! smax1=maxval(ccf1) +! if(smax1.gt.10.0) ccf1=10.0*ccf1/smax1 return end subroutine q65_sync_curve +subroutine q65_bzap(s3,LL) + + parameter (NBZAP=15) + real s3(-64:LL-65,63) + integer ipk1(1) + integer, allocatable :: hist(:) + + allocate(hist(-64:LL-65)) + hist=0 + do j=1,63 + ipk1=maxloc(s3(:,j)) + i=ipk1(1) - 65 + hist(i)=hist(i)+1 + enddo + if(maxval(hist).gt.NBZAP) then + do i=-64,LL-65 + if(hist(i).gt.NBZAP) s3(i,1:63)=1.0 + enddo + endif + + return +end subroutine q65_bzap + +subroutine q65_snr(dat4,dtdec,f0dec,mode_q65,nused,snr2) + +! Estimate SNR of a decoded transmission by aligning the spectra of +! all 85 symbols. + + integer dat4(13) + integer codeword(63) + integer itone(85) + real, allocatable :: spec(:) + + allocate(spec(iz0)) + call q65_enc(dat4,codeword) + i=1 + k=0 + do j=1,85 + if(j.eq.isync(i)) then + i=i+1 + itone(j)=0 + else + k=k+1 + itone(j)=codeword(k) + 1 + endif + enddo + + spec=0. + lagpk=nint(dtdec/dtstep) + do k=1,85 + j=j0 + NSTEP*(k-1) + 1 + lagpk + if(j.ge.1 .and. j.le.jz0) then + do i=1,iz0 + ii=i+mode_q65*itone(k) + if(ii.ge.1 .and. ii.le.iz0) spec(i)=spec(i) + s1raw(ii,j) + enddo + endif + enddo + + i0=nint(f0dec/df) + nsum=max(10*mode_q65,nint(50.0/df)) + ia=max(1,i0-2*nsum) + ib=min(iz0,i0+2*nsum) + sum1=sum(spec(ia:ia+nsum-1)) + sum2=sum(spec(ib-nsum+1:ib)) + avg=(sum1+sum2)/(2.0*nsum) + spec=spec/avg !Baseline level is now 1.0 + smax=maxval(spec(ia:ib)) + sig_area=sum(spec(ia+nsum:ib-nsum)-1.0) + w_equiv=sig_area/(smax-1.0) + snr2=db(max(1.0,sig_area)) - db(2500.0/df) + if(nused.eq.2) snr2=snr2 - 2.0 + 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 + +subroutine q65_hist(if0,msg0,dxcall,dxgrid) + +! Save the MAXHIST most receent decodes, and their f0 values; or, if +! dxcall is present, look up the most recent dxcall and dxgrid at the +! specified f0. + + parameter (MAXHIST=100) + integer,intent(in) :: if0 !Audio freq of decode + character(len=37),intent(in),optional :: msg0 !Decoded message + character(len=12),intent(out),optional :: dxcall !Second callsign in message + character(len=6),intent(out),optional :: dxgrid !Third word in msg, if grid + + character*6 g1 + character*37 msg(MAXHIST) !Saved messages + integer nf0(MAXHIST) !Saved frequencies + logical isgrid !Statement function + data nhist/0/ + save nhist,nf0,msg + + isgrid(g1)=g1(1:1).ge.'A' .and. g1(1:1).le.'R' .and. g1(2:2).ge.'A' .and. & + g1(2:2).le.'R' .and. g1(3:3).ge.'0' .and. g1(3:3).le.'9' .and. & + g1(4:4).ge.'0' .and. g1(4:4).le.'9' .and. g1(1:4).ne.'RR73' + + if(present(dxcall)) go to 100 !This is a lookup request + + if(nhist.eq.MAXHIST) then + nf0(1:MAXHIST-1)=nf0(2:MAXHIST) !List is full, must make room + msg(1:MAXHIST-1)=msg(2:MAXHIST) + nhist=MAXHIST-1 + endif + nhist=nhist+1 !Insert msg0 at end of list + nf0(nhist)=if0 + msg(nhist)=msg0 + go to 900 + +100 dxcall=' ' !This is a lookup request + dxgrid=' ' +! Look for a decode close to if0, starting with most recent ones + do i=nhist,1,-1 + if(abs(nf0(i)-if0).gt.10) cycle + i1=index(msg(i),' ') + if(i1.ge.4 .and. i1.le.13) then + i2=index(msg(i)(i1+1:),' ') + i1 + dxcall=msg(i)(i1+1:i2-1) !Extract dxcall + g1=msg(i)(i2+1:i2+4) + if(isgrid(g1)) dxgrid=g1(1:4) !Extract dxgrid + exit + endif + enddo + +900 return +end subroutine q65_hist + end module q65 diff --git a/lib/qra/q65/q65.h b/lib/qra/q65/q65.h index 9e3d79ad..d0a04d4e 100644 --- a/lib/qra/q65/q65.h +++ b/lib/qra/q65/q65.h @@ -75,11 +75,12 @@ int q65_intrinsics_fastfading(q65_codec_ds *pCodec, int q65_decode(q65_codec_ds *pCodec, - int* pDecodedCodeword, - int *pDecodedMsg, - const float *pIntrinsics, - const int *pAPMask, - const int *pAPSymbols); + int* pDecodedCodeword, + int *pDecodedMsg, + const float *pIntrinsics, + const int *pAPMask, + const int *pAPSymbols, + const int maxiters); int q65_decode_fullaplist(q65_codec_ds *codec, int *ydec, diff --git a/lib/qra/q65/q65_loops.f90 b/lib/qra/q65/q65_loops.f90 index 092997e6..827e7f4c 100644 --- a/lib/qra/q65/q65_loops.f90 +++ b/lib/qra/q65/q65_loops.f90 @@ -38,6 +38,9 @@ subroutine q65_loops(c00,npts2,nsps2,nsubmode,ndepth,jpk0, & napmin=99 xdt1=xdt0 f1=f0 + idfbest=0 + idtbest=0 + ndistbest=0 do idf=1,idfmax ndf=idf/2 @@ -56,6 +59,7 @@ subroutine q65_loops(c00,npts2,nsps2,nsubmode,ndepth,jpk0, & call pctile(s3,LL*NN,40,base) s3=s3/base where(s3(1:LL*NN)>s3lim) s3(1:LL*NN)=s3lim + call q65_bzap(s3,LL) !Zap birdies do ibw=ibwa,ibwb ndist=ndf**2 + ndt**2 + (ibw-ibw0)**2 if(ndist.gt.maxdist) cycle @@ -69,7 +73,13 @@ subroutine q65_loops(c00,npts2,nsps2,nsubmode,ndepth,jpk0, & ! -1 = invalid params ! -2 = decode failed ! -3 = CRC mismatch - if(irc.ge.0) go to 100 + if(irc.ge.0) then + idfbest=idf + idtbest=idt + ndistbest=ndist + nrc=irc + go to 100 + endif enddo ! ibw (b90 loop) enddo ! idt (DT loop) enddo ! idf (f0 loop) diff --git a/lib/qra/q65/q65_subs.c b/lib/qra/q65/q65_subs.c index e55fe927..4311ba39 100644 --- a/lib/qra/q65/q65_subs.c +++ b/lib/qra/q65/q65_subs.c @@ -77,7 +77,7 @@ void q65_intrinsics_ff_(float s3[], int* submode, float* B90Ts, } void q65_dec_(float s3[], float s3prob[], int APmask[], int APsymbols[], - float* esnodb0, int xdec[], int* rc0) + int* maxiters0, float* esnodb0, int xdec[], int* rc0) { /* Input: s3[LL,NN] Symbol spectra @@ -93,8 +93,9 @@ void q65_dec_(float s3[], float s3prob[], int APmask[], int APsymbols[], int rc; int ydec[63]; float esnodb; + int maxiters=*maxiters0; - rc = q65_decode(&codec,ydec,xdec,s3prob,APmask,APsymbols); + rc = q65_decode(&codec,ydec,xdec,s3prob,APmask,APsymbols,maxiters); *rc0=rc; // rc = -1: Invalid params // rc = -2: Decode failed diff --git a/lib/qra/q65/q65sim.f90 b/lib/qra/q65/q65sim.f90 index 5c7efb1a..f3db7b9d 100644 --- a/lib/qra/q65/q65sim.f90 +++ b/lib/qra/q65/q65sim.f90 @@ -9,10 +9,13 @@ program q65sim integer*2 iwave(NMAX) !Generated waveform integer itone(85) !Channel symbols (values 0-65) integer y(63) !Codeword + integer istart !averaging compatible start seconds + integer imins !minutes for 15s period timestamp + integer isecs !seconds for 15s period timestamp real*4 xnoise(NMAX) !Generated random noise real*4 dat(NMAX) !Generated real data complex cdat(NMAX) !Generated complex waveform - complex cspread(0:NMAX-1) !Complex amplitude for Rayleigh fading + complex cspread(0:NMAX-1) !Complex amplitude for Rayleigh fading complex z real*8 f0,dt,twopi,phi,dphi,baud,fsample,freq character msg*37,fname*17,csubmode*1,arg*12 @@ -22,10 +25,13 @@ program q65sim if(nargs.ne.10) then print*,'Usage: q65sim "msg" A-E freq fDop DT f1 Stp TRp Nfile SNR' print*,'Example: q65sim "K1ABC W9XYZ EN37" A 1500 0.0 0.0 0.0 1 60 1 -26' + print*,'Example: q65sim "ST" A 1500 0.0 0.0 0.0 1 60 1 -26' print*,' fDop = Doppler spread' print*,' f1 = Drift or Doppler rate (Hz/min)' print*,' Stp = Step size (Hz)' print*,' Stp = 0 implies no Doppler tracking' + print*,' Creates filenames which increment to permit averaging in first period' + print*,' If msg = ST program produces a single tone at freq' go to 999 endif call getarg(1,msg) @@ -94,14 +100,17 @@ program q65sim h=default_header(12000,npts) write(*,1004) -1004 format('File TR Freq Mode S/N Dop DT f1 Stp Message'/70('-')) - - do ifile=1,nfiles !Loop over requested number of files - if(ntrperiod.lt.60) then - write(fname,1005) ifile !Output filename -1005 format('000000_',i6.6,'.wav') +1004 format('File TR Freq Mode S/N Dop DT f1 Stp Message'/70('-')) + + do ifile=1,nfiles !Loop over requested number of files + istart = (ifile*ntrperiod*2) - (ntrperiod*2) + if(ntrperiod.lt.30) then !wdg was 60 + imins=istart/60 + isecs=istart-(60*imins) + write(fname,1005) imins,isecs !Construction of output filename for 15s periods with averaging +1005 format('000000_',i4.4, i2.2,'.wav') else - write(fname,1106) ifile + write(fname,1106) istart/60 !Output filename to be compatible with averaging 30-300s periods 1106 format('000000_',i4.4,'.wav') endif @@ -118,7 +127,7 @@ program q65sim sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb) if(snrdb.gt.90.0) sig=1.0 write(*,1020) ifile,ntrperiod,f0,csubmode,snrdb,fspread,xdt,f1,nstp,trim(msgsent) -1020 format(i4,i6,f7.1,2x,a1,2x,f5.1,f6.2,2f6.1,i4,2x,a) +1020 format(i4,i6,f7.1,2x,a1,2x,f5.1,1x,f6.2,2f6.1,i4,2x,a) phi=0.d0 dphi=0.d0 k=(xdt+0.5)*12000 !Start audio at t=xdt+0.5 s (TR=15 and 30 s) @@ -130,7 +139,11 @@ program q65sim if(isym.ne.isym0) then freq_drift=f1*i*dt/60.0 if(nstp.ne.0) freq_drift=freq_drift - nstp*nint(freq_drift/nstp) - freq = f0 + freq_drift + itone(isym)*baud*mode65 + if (msg(1:2).eq.'ST') then + freq = f0 + freq_drift + else + freq = f0 + freq_drift + itone(isym)*baud*mode65 + endif dphi=twopi*freq*dt isym0=isym endif diff --git a/lib/qra/qra64/Makefile.Win b/lib/qra/qra64/Makefile.Win deleted file mode 100644 index 7bd10c2d..00000000 --- a/lib/qra/qra64/Makefile.Win +++ /dev/null @@ -1,30 +0,0 @@ -FC = gfortran -CC = gcc -CFLAGS = -O2 -Wall -I. -D_WIN32 - -# Default rules -%.o: %.c - ${CC} ${CFLAGS} -c $< -%.o: %.f - ${FC} ${FFLAGS} -c $< -%.o: %.F - ${FC} ${FFLAGS} -c $< -%.o: %.f90 - ${FC} ${FFLAGS} -c $< -%.o: %.F90 - ${FC} ${FFLAGS} -c $< - -all: qra64.exe - -OBJS1 = main.o qra64.o -qra64.exe: $(OBJS1) - ${CC} -o qra64.exe $(OBJS1) ../qracodes/libqra64.a -lm - -OBJS2 = qra64sim.o options.o wavhdr.o -qra64sim.exe: $(OBJS2) - ${FC} -o qra64sim.exe $(OBJS2) ../qracodes/libqra64.a -lm - -.PHONY : clean - -clean: - $(RM) *.o qra64.exe qra64sim.exe diff --git a/lib/qra/qra64/fadengauss.c b/lib/qra/qra64/fadengauss.c deleted file mode 100644 index c229626f..00000000 --- a/lib/qra/qra64/fadengauss.c +++ /dev/null @@ -1,302 +0,0 @@ -// Gaussian energy fading tables for QRA64 -static const int glen_tab_gauss[64] = { - 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, - 3, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 5, 5, 5, 6, - 6, 6, 7, 7, 8, 8, 9, 10, - 10, 11, 12, 13, 14, 15, 17, 18, - 19, 21, 23, 25, 27, 29, 32, 34, - 37, 41, 44, 48, 52, 57, 62, 65 -}; -static const float ggauss1[2] = { -0.0296f, 0.9101f -}; -static const float ggauss2[2] = { -0.0350f, 0.8954f -}; -static const float ggauss3[2] = { -0.0411f, 0.8787f -}; -static const float ggauss4[2] = { -0.0483f, 0.8598f -}; -static const float ggauss5[2] = { -0.0566f, 0.8387f -}; -static const float ggauss6[2] = { -0.0660f, 0.8154f -}; -static const float ggauss7[2] = { -0.0767f, 0.7898f -}; -static const float ggauss8[2] = { -0.0886f, 0.7621f -}; -static const float ggauss9[2] = { -0.1017f, 0.7325f -}; -static const float ggauss10[2] = { -0.1159f, 0.7012f -}; -static const float ggauss11[2] = { -0.1310f, 0.6687f -}; -static const float ggauss12[2] = { -0.1465f, 0.6352f -}; -static const float ggauss13[2] = { -0.1621f, 0.6013f -}; -static const float ggauss14[2] = { -0.1771f, 0.5674f -}; -static const float ggauss15[2] = { -0.1911f, 0.5339f -}; -static const float ggauss16[2] = { -0.2034f, 0.5010f -}; -static const float ggauss17[3] = { -0.0299f, 0.2135f, 0.4690f -}; -static const float ggauss18[3] = { -0.0369f, 0.2212f, 0.4383f -}; -static const float ggauss19[3] = { -0.0454f, 0.2263f, 0.4088f -}; -static const float ggauss20[3] = { -0.0552f, 0.2286f, 0.3806f -}; -static const float ggauss21[3] = { -0.0658f, 0.2284f, 0.3539f -}; -static const float ggauss22[3] = { -0.0766f, 0.2258f, 0.3287f -}; -static const float ggauss23[3] = { -0.0869f, 0.2212f, 0.3049f -}; -static const float ggauss24[3] = { -0.0962f, 0.2148f, 0.2826f -}; -static const float ggauss25[4] = { -0.0351f, 0.1041f, 0.2071f, 0.2616f -}; -static const float ggauss26[4] = { -0.0429f, 0.1102f, 0.1984f, 0.2420f -}; -static const float ggauss27[4] = { -0.0508f, 0.1145f, 0.1890f, 0.2237f -}; -static const float ggauss28[4] = { -0.0582f, 0.1169f, 0.1791f, 0.2067f -}; -static const float ggauss29[5] = { -0.0289f, 0.0648f, 0.1176f, 0.1689f, 0.1908f -}; -static const float ggauss30[5] = { -0.0351f, 0.0703f, 0.1168f, 0.1588f, 0.1760f -}; -static const float ggauss31[5] = { -0.0411f, 0.0745f, 0.1146f, 0.1488f, 0.1623f -}; -static const float ggauss32[6] = { -0.0246f, 0.0466f, 0.0773f, 0.1115f, 0.1390f, 0.1497f -}; -static const float ggauss33[6] = { -0.0297f, 0.0512f, 0.0788f, 0.1075f, 0.1295f, 0.1379f -}; -static const float ggauss34[6] = { -0.0345f, 0.0549f, 0.0791f, 0.1029f, 0.1205f, 0.1270f -}; -static const float ggauss35[7] = { -0.0240f, 0.0387f, 0.0575f, 0.0784f, 0.0979f, 0.1118f, 0.1169f -}; -static const float ggauss36[7] = { -0.0281f, 0.0422f, 0.0590f, 0.0767f, 0.0926f, 0.1037f, 0.1076f -}; -static const float ggauss37[8] = { -0.0212f, 0.0318f, 0.0449f, 0.0596f, 0.0744f, 0.0872f, 0.0960f, 0.0991f -}; -static const float ggauss38[8] = { -0.0247f, 0.0348f, 0.0467f, 0.0593f, 0.0716f, 0.0819f, 0.0887f, 0.0911f -}; -static const float ggauss39[9] = { -0.0199f, 0.0278f, 0.0372f, 0.0476f, 0.0584f, 0.0684f, 0.0766f, 0.0819f, -0.0838f -}; -static const float ggauss40[10] = { -0.0166f, 0.0228f, 0.0303f, 0.0388f, 0.0478f, 0.0568f, 0.0649f, 0.0714f, -0.0756f, 0.0771f -}; -static const float ggauss41[10] = { -0.0193f, 0.0254f, 0.0322f, 0.0397f, 0.0474f, 0.0548f, 0.0613f, 0.0664f, -0.0697f, 0.0709f -}; -static const float ggauss42[11] = { -0.0168f, 0.0217f, 0.0273f, 0.0335f, 0.0399f, 0.0464f, 0.0524f, 0.0576f, -0.0617f, 0.0643f, 0.0651f -}; -static const float ggauss43[12] = { -0.0151f, 0.0191f, 0.0237f, 0.0288f, 0.0342f, 0.0396f, 0.0449f, 0.0498f, -0.0540f, 0.0572f, 0.0592f, 0.0599f -}; -static const float ggauss44[13] = { -0.0138f, 0.0171f, 0.0210f, 0.0252f, 0.0297f, 0.0343f, 0.0388f, 0.0432f, -0.0471f, 0.0504f, 0.0529f, 0.0545f, 0.0550f -}; -static const float ggauss45[14] = { -0.0128f, 0.0157f, 0.0189f, 0.0224f, 0.0261f, 0.0300f, 0.0339f, 0.0377f, -0.0412f, 0.0444f, 0.0470f, 0.0489f, 0.0501f, 0.0505f -}; -static const float ggauss46[15] = { -0.0121f, 0.0146f, 0.0173f, 0.0202f, 0.0234f, 0.0266f, 0.0299f, 0.0332f, -0.0363f, 0.0391f, 0.0416f, 0.0437f, 0.0452f, 0.0461f, 0.0464f -}; -static const float ggauss47[17] = { -0.0097f, 0.0116f, 0.0138f, 0.0161f, 0.0186f, 0.0212f, 0.0239f, 0.0267f, -0.0294f, 0.0321f, 0.0346f, 0.0369f, 0.0389f, 0.0405f, 0.0417f, 0.0424f, -0.0427f -}; -static const float ggauss48[18] = { -0.0096f, 0.0113f, 0.0131f, 0.0151f, 0.0172f, 0.0194f, 0.0217f, 0.0241f, -0.0264f, 0.0287f, 0.0308f, 0.0329f, 0.0347f, 0.0362f, 0.0375f, 0.0384f, -0.0390f, 0.0392f -}; -static const float ggauss49[19] = { -0.0095f, 0.0110f, 0.0126f, 0.0143f, 0.0161f, 0.0180f, 0.0199f, 0.0219f, -0.0239f, 0.0258f, 0.0277f, 0.0294f, 0.0310f, 0.0325f, 0.0337f, 0.0347f, -0.0354f, 0.0358f, 0.0360f -}; -static const float ggauss50[21] = { -0.0083f, 0.0095f, 0.0108f, 0.0122f, 0.0136f, 0.0152f, 0.0168f, 0.0184f, -0.0201f, 0.0217f, 0.0234f, 0.0250f, 0.0265f, 0.0279f, 0.0292f, 0.0303f, -0.0313f, 0.0320f, 0.0326f, 0.0329f, 0.0330f -}; -static const float ggauss51[23] = { -0.0074f, 0.0084f, 0.0095f, 0.0106f, 0.0118f, 0.0131f, 0.0144f, 0.0157f, -0.0171f, 0.0185f, 0.0199f, 0.0213f, 0.0227f, 0.0240f, 0.0252f, 0.0263f, -0.0273f, 0.0282f, 0.0290f, 0.0296f, 0.0300f, 0.0303f, 0.0303f -}; -static const float ggauss52[25] = { -0.0068f, 0.0076f, 0.0085f, 0.0094f, 0.0104f, 0.0115f, 0.0126f, 0.0137f, -0.0149f, 0.0160f, 0.0172f, 0.0184f, 0.0196f, 0.0207f, 0.0218f, 0.0228f, -0.0238f, 0.0247f, 0.0255f, 0.0262f, 0.0268f, 0.0273f, 0.0276f, 0.0278f, -0.0279f -}; -static const float ggauss53[27] = { -0.0063f, 0.0070f, 0.0078f, 0.0086f, 0.0094f, 0.0103f, 0.0112f, 0.0121f, -0.0131f, 0.0141f, 0.0151f, 0.0161f, 0.0170f, 0.0180f, 0.0190f, 0.0199f, -0.0208f, 0.0216f, 0.0224f, 0.0231f, 0.0237f, 0.0243f, 0.0247f, 0.0251f, -0.0254f, 0.0255f, 0.0256f -}; -static const float ggauss54[29] = { -0.0060f, 0.0066f, 0.0072f, 0.0079f, 0.0086f, 0.0093f, 0.0101f, 0.0109f, -0.0117f, 0.0125f, 0.0133f, 0.0142f, 0.0150f, 0.0159f, 0.0167f, 0.0175f, -0.0183f, 0.0190f, 0.0197f, 0.0204f, 0.0210f, 0.0216f, 0.0221f, 0.0225f, -0.0228f, 0.0231f, 0.0233f, 0.0234f, 0.0235f -}; -static const float ggauss55[32] = { -0.0053f, 0.0058f, 0.0063f, 0.0068f, 0.0074f, 0.0080f, 0.0086f, 0.0093f, -0.0099f, 0.0106f, 0.0113f, 0.0120f, 0.0127f, 0.0134f, 0.0141f, 0.0148f, -0.0155f, 0.0162f, 0.0168f, 0.0174f, 0.0180f, 0.0186f, 0.0191f, 0.0196f, -0.0201f, 0.0204f, 0.0208f, 0.0211f, 0.0213f, 0.0214f, 0.0215f, 0.0216f -}; -static const float ggauss56[34] = { -0.0052f, 0.0056f, 0.0060f, 0.0065f, 0.0070f, 0.0075f, 0.0080f, 0.0086f, -0.0091f, 0.0097f, 0.0103f, 0.0109f, 0.0115f, 0.0121f, 0.0127f, 0.0133f, -0.0138f, 0.0144f, 0.0150f, 0.0155f, 0.0161f, 0.0166f, 0.0170f, 0.0175f, -0.0179f, 0.0183f, 0.0186f, 0.0189f, 0.0192f, 0.0194f, 0.0196f, 0.0197f, -0.0198f, 0.0198f -}; -static const float ggauss57[37] = { -0.0047f, 0.0051f, 0.0055f, 0.0058f, 0.0063f, 0.0067f, 0.0071f, 0.0076f, -0.0080f, 0.0085f, 0.0090f, 0.0095f, 0.0100f, 0.0105f, 0.0110f, 0.0115f, -0.0120f, 0.0125f, 0.0130f, 0.0134f, 0.0139f, 0.0144f, 0.0148f, 0.0152f, -0.0156f, 0.0160f, 0.0164f, 0.0167f, 0.0170f, 0.0173f, 0.0175f, 0.0177f, -0.0179f, 0.0180f, 0.0181f, 0.0181f, 0.0182f -}; -static const float ggauss58[41] = { -0.0041f, 0.0044f, 0.0047f, 0.0050f, 0.0054f, 0.0057f, 0.0060f, 0.0064f, -0.0068f, 0.0072f, 0.0076f, 0.0080f, 0.0084f, 0.0088f, 0.0092f, 0.0096f, -0.0101f, 0.0105f, 0.0109f, 0.0113f, 0.0117f, 0.0121f, 0.0125f, 0.0129f, -0.0133f, 0.0137f, 0.0140f, 0.0144f, 0.0147f, 0.0150f, 0.0153f, 0.0155f, -0.0158f, 0.0160f, 0.0162f, 0.0163f, 0.0164f, 0.0165f, 0.0166f, 0.0167f, -0.0167f -}; -static const float ggauss59[44] = { -0.0039f, 0.0042f, 0.0044f, 0.0047f, 0.0050f, 0.0053f, 0.0056f, 0.0059f, -0.0062f, 0.0065f, 0.0068f, 0.0072f, 0.0075f, 0.0079f, 0.0082f, 0.0086f, -0.0089f, 0.0093f, 0.0096f, 0.0100f, 0.0104f, 0.0107f, 0.0110f, 0.0114f, -0.0117f, 0.0120f, 0.0124f, 0.0127f, 0.0130f, 0.0132f, 0.0135f, 0.0138f, -0.0140f, 0.0142f, 0.0144f, 0.0146f, 0.0148f, 0.0149f, 0.0150f, 0.0151f, -0.0152f, 0.0153f, 0.0153f, 0.0153f -}; -static const float ggauss60[48] = { -0.0036f, 0.0038f, 0.0040f, 0.0042f, 0.0044f, 0.0047f, 0.0049f, 0.0052f, -0.0055f, 0.0057f, 0.0060f, 0.0063f, 0.0066f, 0.0068f, 0.0071f, 0.0074f, -0.0077f, 0.0080f, 0.0083f, 0.0086f, 0.0089f, 0.0092f, 0.0095f, 0.0098f, -0.0101f, 0.0104f, 0.0107f, 0.0109f, 0.0112f, 0.0115f, 0.0117f, 0.0120f, -0.0122f, 0.0124f, 0.0126f, 0.0128f, 0.0130f, 0.0132f, 0.0134f, 0.0135f, -0.0136f, 0.0137f, 0.0138f, 0.0139f, 0.0140f, 0.0140f, 0.0140f, 0.0140f -}; -static const float ggauss61[52] = { -0.0033f, 0.0035f, 0.0037f, 0.0039f, 0.0041f, 0.0043f, 0.0045f, 0.0047f, -0.0049f, 0.0051f, 0.0053f, 0.0056f, 0.0058f, 0.0060f, 0.0063f, 0.0065f, -0.0068f, 0.0070f, 0.0073f, 0.0075f, 0.0078f, 0.0080f, 0.0083f, 0.0085f, -0.0088f, 0.0090f, 0.0093f, 0.0095f, 0.0098f, 0.0100f, 0.0102f, 0.0105f, -0.0107f, 0.0109f, 0.0111f, 0.0113f, 0.0115f, 0.0116f, 0.0118f, 0.0120f, -0.0121f, 0.0122f, 0.0124f, 0.0125f, 0.0126f, 0.0126f, 0.0127f, 0.0128f, -0.0128f, 0.0129f, 0.0129f, 0.0129f -}; -static const float ggauss62[57] = { -0.0030f, 0.0031f, 0.0033f, 0.0034f, 0.0036f, 0.0038f, 0.0039f, 0.0041f, -0.0043f, 0.0045f, 0.0047f, 0.0048f, 0.0050f, 0.0052f, 0.0054f, 0.0056f, -0.0058f, 0.0060f, 0.0063f, 0.0065f, 0.0067f, 0.0069f, 0.0071f, 0.0073f, -0.0075f, 0.0077f, 0.0080f, 0.0082f, 0.0084f, 0.0086f, 0.0088f, 0.0090f, -0.0092f, 0.0094f, 0.0096f, 0.0097f, 0.0099f, 0.0101f, 0.0103f, 0.0104f, -0.0106f, 0.0107f, 0.0108f, 0.0110f, 0.0111f, 0.0112f, 0.0113f, 0.0114f, -0.0115f, 0.0116f, 0.0116f, 0.0117f, 0.0117f, 0.0118f, 0.0118f, 0.0118f, -0.0118f -}; -static const float ggauss63[62] = { -0.0027f, 0.0029f, 0.0030f, 0.0031f, 0.0032f, 0.0034f, 0.0035f, 0.0037f, -0.0038f, 0.0040f, 0.0041f, 0.0043f, 0.0045f, 0.0046f, 0.0048f, 0.0049f, -0.0051f, 0.0053f, 0.0055f, 0.0056f, 0.0058f, 0.0060f, 0.0062f, 0.0063f, -0.0065f, 0.0067f, 0.0069f, 0.0071f, 0.0072f, 0.0074f, 0.0076f, 0.0078f, -0.0079f, 0.0081f, 0.0083f, 0.0084f, 0.0086f, 0.0088f, 0.0089f, 0.0091f, -0.0092f, 0.0094f, 0.0095f, 0.0096f, 0.0098f, 0.0099f, 0.0100f, 0.0101f, -0.0102f, 0.0103f, 0.0104f, 0.0105f, 0.0105f, 0.0106f, 0.0107f, 0.0107f, -0.0108f, 0.0108f, 0.0108f, 0.0108f, 0.0109f, 0.0109f -}; -static const float ggauss64[65] = { -0.0028f, 0.0029f, 0.0030f, 0.0031f, 0.0032f, 0.0034f, 0.0035f, 0.0036f, -0.0037f, 0.0039f, 0.0040f, 0.0041f, 0.0043f, 0.0044f, 0.0046f, 0.0047f, -0.0048f, 0.0050f, 0.0051f, 0.0053f, 0.0054f, 0.0056f, 0.0057f, 0.0059f, -0.0060f, 0.0062f, 0.0063f, 0.0065f, 0.0066f, 0.0068f, 0.0069f, 0.0071f, -0.0072f, 0.0074f, 0.0075f, 0.0077f, 0.0078f, 0.0079f, 0.0081f, 0.0082f, -0.0083f, 0.0084f, 0.0086f, 0.0087f, 0.0088f, 0.0089f, 0.0090f, 0.0091f, -0.0092f, 0.0093f, 0.0094f, 0.0094f, 0.0095f, 0.0096f, 0.0097f, 0.0097f, -0.0098f, 0.0098f, 0.0099f, 0.0099f, 0.0099f, 0.0099f, 0.0100f, 0.0100f, -0.0100f -}; -static const float *gptr_tab_gauss[64] = { -ggauss1, ggauss2, ggauss3, ggauss4, -ggauss5, ggauss6, ggauss7, ggauss8, -ggauss9, ggauss10, ggauss11, ggauss12, -ggauss13, ggauss14, ggauss15, ggauss16, -ggauss17, ggauss18, ggauss19, ggauss20, -ggauss21, ggauss22, ggauss23, ggauss24, -ggauss25, ggauss26, ggauss27, ggauss28, -ggauss29, ggauss30, ggauss31, ggauss32, -ggauss33, ggauss34, ggauss35, ggauss36, -ggauss37, ggauss38, ggauss39, ggauss40, -ggauss41, ggauss42, ggauss43, ggauss44, -ggauss45, ggauss46, ggauss47, ggauss48, -ggauss49, ggauss50, ggauss51, ggauss52, -ggauss53, ggauss54, ggauss55, ggauss56, -ggauss57, ggauss58, ggauss59, ggauss60, -ggauss61, ggauss62, ggauss63, ggauss64 -}; diff --git a/lib/qra/qra64/fadenlorentz.c b/lib/qra/qra64/fadenlorentz.c deleted file mode 100644 index 673a8903..00000000 --- a/lib/qra/qra64/fadenlorentz.c +++ /dev/null @@ -1,304 +0,0 @@ -// Lorentz energy fading tables for QRA64 -static const int glen_tab_lorentz[64] = { - 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 3, 3, - 3, 3, 3, 3, 3, 4, 4, 4, - 4, 4, 5, 5, 5, 5, 6, 6, - 7, 7, 7, 8, 8, 9, 10, 10, - 11, 12, 13, 14, 15, 16, 17, 19, - 20, 22, 23, 25, 27, 30, 32, 35, - 38, 41, 45, 49, 53, 57, 62, 65 -}; -static const float glorentz1[2] = { -0.0214f, 0.9107f -}; -static const float glorentz2[2] = { -0.0244f, 0.9030f -}; -static const float glorentz3[2] = { -0.0280f, 0.8950f -}; -static const float glorentz4[2] = { -0.0314f, 0.8865f -}; -static const float glorentz5[2] = { -0.0349f, 0.8773f -}; -static const float glorentz6[2] = { -0.0388f, 0.8675f -}; -static const float glorentz7[2] = { -0.0426f, 0.8571f -}; -static const float glorentz8[2] = { -0.0463f, 0.8459f -}; -static const float glorentz9[2] = { -0.0500f, 0.8339f -}; -static const float glorentz10[2] = { -0.0538f, 0.8210f -}; -static const float glorentz11[2] = { -0.0579f, 0.8074f -}; -static const float glorentz12[2] = { -0.0622f, 0.7930f -}; -static const float glorentz13[2] = { -0.0668f, 0.7777f -}; -static const float glorentz14[2] = { -0.0715f, 0.7616f -}; -static const float glorentz15[3] = { -0.0196f, 0.0765f, 0.7445f -}; -static const float glorentz16[3] = { -0.0210f, 0.0816f, 0.7267f -}; -static const float glorentz17[3] = { -0.0226f, 0.0870f, 0.7080f -}; -static const float glorentz18[3] = { -0.0242f, 0.0925f, 0.6885f -}; -static const float glorentz19[3] = { -0.0259f, 0.0981f, 0.6682f -}; -static const float glorentz20[3] = { -0.0277f, 0.1039f, 0.6472f -}; -static const float glorentz21[3] = { -0.0296f, 0.1097f, 0.6255f -}; -static const float glorentz22[4] = { -0.0143f, 0.0316f, 0.1155f, 0.6031f -}; -static const float glorentz23[4] = { -0.0153f, 0.0337f, 0.1213f, 0.5803f -}; -static const float glorentz24[4] = { -0.0163f, 0.0358f, 0.1270f, 0.5570f -}; -static const float glorentz25[4] = { -0.0174f, 0.0381f, 0.1325f, 0.5333f -}; -static const float glorentz26[4] = { -0.0186f, 0.0405f, 0.1378f, 0.5095f -}; -static const float glorentz27[5] = { -0.0113f, 0.0198f, 0.0429f, 0.1428f, 0.4855f -}; -static const float glorentz28[5] = { -0.0120f, 0.0211f, 0.0455f, 0.1473f, 0.4615f -}; -static const float glorentz29[5] = { -0.0129f, 0.0225f, 0.0481f, 0.1514f, 0.4376f -}; -static const float glorentz30[5] = { -0.0137f, 0.0239f, 0.0508f, 0.1549f, 0.4140f -}; -static const float glorentz31[6] = { -0.0095f, 0.0147f, 0.0254f, 0.0536f, 0.1578f, 0.3907f -}; -static const float glorentz32[6] = { -0.0101f, 0.0156f, 0.0270f, 0.0564f, 0.1600f, 0.3680f -}; -static const float glorentz33[7] = { -0.0076f, 0.0109f, 0.0167f, 0.0287f, 0.0592f, 0.1614f, 0.3458f -}; -static const float glorentz34[7] = { -0.0081f, 0.0116f, 0.0178f, 0.0305f, 0.0621f, 0.1620f, 0.3243f -}; -static const float glorentz35[7] = { -0.0087f, 0.0124f, 0.0190f, 0.0324f, 0.0649f, 0.1618f, 0.3035f -}; -static const float glorentz36[8] = { -0.0069f, 0.0093f, 0.0133f, 0.0203f, 0.0343f, 0.0676f, 0.1607f, 0.2836f -}; -static const float glorentz37[8] = { -0.0074f, 0.0100f, 0.0142f, 0.0216f, 0.0362f, 0.0702f, 0.1588f, 0.2645f -}; -static const float glorentz38[9] = { -0.0061f, 0.0080f, 0.0107f, 0.0152f, 0.0230f, 0.0382f, 0.0726f, 0.1561f, -0.2464f -}; -static const float glorentz39[10] = { -0.0052f, 0.0066f, 0.0086f, 0.0115f, 0.0162f, 0.0244f, 0.0402f, 0.0747f, -0.1526f, 0.2291f -}; -static const float glorentz40[10] = { -0.0056f, 0.0071f, 0.0092f, 0.0123f, 0.0173f, 0.0259f, 0.0422f, 0.0766f, -0.1484f, 0.2128f -}; -static const float glorentz41[11] = { -0.0049f, 0.0061f, 0.0076f, 0.0098f, 0.0132f, 0.0184f, 0.0274f, 0.0441f, -0.0780f, 0.1437f, 0.1975f -}; -static const float glorentz42[12] = { -0.0044f, 0.0053f, 0.0065f, 0.0082f, 0.0106f, 0.0141f, 0.0196f, 0.0290f, -0.0460f, 0.0791f, 0.1384f, 0.1831f -}; -static const float glorentz43[13] = { -0.0040f, 0.0048f, 0.0057f, 0.0070f, 0.0088f, 0.0113f, 0.0150f, 0.0209f, -0.0305f, 0.0477f, 0.0797f, 0.1327f, 0.1695f -}; -static const float glorentz44[14] = { -0.0037f, 0.0043f, 0.0051f, 0.0062f, 0.0075f, 0.0094f, 0.0121f, 0.0160f, -0.0221f, 0.0321f, 0.0493f, 0.0799f, 0.1267f, 0.1568f -}; -static const float glorentz45[15] = { -0.0035f, 0.0040f, 0.0047f, 0.0055f, 0.0066f, 0.0081f, 0.0101f, 0.0129f, -0.0171f, 0.0234f, 0.0335f, 0.0506f, 0.0795f, 0.1204f, 0.1450f -}; -static const float glorentz46[16] = { -0.0033f, 0.0037f, 0.0043f, 0.0050f, 0.0059f, 0.0071f, 0.0087f, 0.0108f, -0.0138f, 0.0181f, 0.0246f, 0.0349f, 0.0517f, 0.0786f, 0.1141f, 0.1340f -}; -static const float glorentz47[17] = { -0.0031f, 0.0035f, 0.0040f, 0.0046f, 0.0054f, 0.0064f, 0.0077f, 0.0093f, -0.0116f, 0.0147f, 0.0192f, 0.0259f, 0.0362f, 0.0525f, 0.0773f, 0.1076f, -0.1237f -}; -static const float glorentz48[19] = { -0.0027f, 0.0030f, 0.0034f, 0.0038f, 0.0043f, 0.0050f, 0.0058f, 0.0069f, -0.0082f, 0.0100f, 0.0123f, 0.0156f, 0.0203f, 0.0271f, 0.0374f, 0.0530f, -0.0755f, 0.1013f, 0.1141f -}; -static const float glorentz49[20] = { -0.0026f, 0.0029f, 0.0032f, 0.0036f, 0.0041f, 0.0047f, 0.0054f, 0.0063f, -0.0074f, 0.0088f, 0.0107f, 0.0131f, 0.0165f, 0.0213f, 0.0282f, 0.0383f, -0.0531f, 0.0734f, 0.0950f, 0.1053f -}; -static const float glorentz50[22] = { -0.0023f, 0.0025f, 0.0028f, 0.0031f, 0.0035f, 0.0039f, 0.0044f, 0.0050f, -0.0058f, 0.0067f, 0.0079f, 0.0094f, 0.0114f, 0.0139f, 0.0175f, 0.0223f, -0.0292f, 0.0391f, 0.0529f, 0.0709f, 0.0889f, 0.0971f -}; -static const float glorentz51[23] = { -0.0023f, 0.0025f, 0.0027f, 0.0030f, 0.0034f, 0.0037f, 0.0042f, 0.0048f, -0.0054f, 0.0062f, 0.0072f, 0.0085f, 0.0100f, 0.0121f, 0.0148f, 0.0184f, -0.0233f, 0.0301f, 0.0396f, 0.0524f, 0.0681f, 0.0829f, 0.0894f -}; -static const float glorentz52[25] = { -0.0021f, 0.0023f, 0.0025f, 0.0027f, 0.0030f, 0.0033f, 0.0036f, 0.0040f, -0.0045f, 0.0051f, 0.0058f, 0.0067f, 0.0077f, 0.0090f, 0.0107f, 0.0128f, -0.0156f, 0.0192f, 0.0242f, 0.0308f, 0.0398f, 0.0515f, 0.0650f, 0.0772f, -0.0824f -}; -static const float glorentz53[27] = { -0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0027f, 0.0029f, 0.0032f, 0.0035f, -0.0039f, 0.0044f, 0.0049f, 0.0055f, 0.0062f, 0.0072f, 0.0083f, 0.0096f, -0.0113f, 0.0135f, 0.0164f, 0.0201f, 0.0249f, 0.0314f, 0.0398f, 0.0502f, -0.0619f, 0.0718f, 0.0759f -}; -static const float glorentz54[30] = { -0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0026f, 0.0029f, -0.0031f, 0.0034f, 0.0038f, 0.0042f, 0.0047f, 0.0052f, 0.0059f, 0.0067f, -0.0076f, 0.0088f, 0.0102f, 0.0120f, 0.0143f, 0.0171f, 0.0208f, 0.0256f, -0.0317f, 0.0395f, 0.0488f, 0.0586f, 0.0666f, 0.0698f -}; -static const float glorentz55[32] = { -0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0024f, 0.0026f, -0.0028f, 0.0031f, 0.0034f, 0.0037f, 0.0041f, 0.0045f, 0.0050f, 0.0056f, -0.0063f, 0.0071f, 0.0081f, 0.0094f, 0.0108f, 0.0127f, 0.0149f, 0.0178f, -0.0214f, 0.0261f, 0.0318f, 0.0389f, 0.0470f, 0.0553f, 0.0618f, 0.0643f -}; -static const float glorentz56[35] = { -0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0020f, 0.0021f, 0.0023f, -0.0024f, 0.0026f, 0.0028f, 0.0031f, 0.0033f, 0.0036f, 0.0040f, 0.0044f, -0.0049f, 0.0054f, 0.0060f, 0.0067f, 0.0076f, 0.0087f, 0.0099f, 0.0114f, -0.0133f, 0.0156f, 0.0184f, 0.0220f, 0.0264f, 0.0318f, 0.0381f, 0.0451f, -0.0520f, 0.0572f, 0.0591f -}; -static const float glorentz57[38] = { -0.0013f, 0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, -0.0021f, 0.0023f, 0.0024f, 0.0026f, 0.0028f, 0.0031f, 0.0033f, 0.0036f, -0.0039f, 0.0043f, 0.0047f, 0.0052f, 0.0058f, 0.0064f, 0.0072f, 0.0081f, -0.0092f, 0.0104f, 0.0120f, 0.0139f, 0.0162f, 0.0190f, 0.0224f, 0.0265f, -0.0315f, 0.0371f, 0.0431f, 0.0487f, 0.0529f, 0.0544f -}; -static const float glorentz58[41] = { -0.0012f, 0.0013f, 0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, -0.0019f, 0.0020f, 0.0022f, 0.0023f, 0.0025f, 0.0026f, 0.0028f, 0.0030f, -0.0033f, 0.0036f, 0.0039f, 0.0042f, 0.0046f, 0.0050f, 0.0056f, 0.0061f, -0.0068f, 0.0076f, 0.0086f, 0.0097f, 0.0110f, 0.0125f, 0.0144f, 0.0167f, -0.0194f, 0.0226f, 0.0265f, 0.0309f, 0.0359f, 0.0409f, 0.0455f, 0.0488f, -0.0500f -}; -static const float glorentz59[45] = { -0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, 0.0015f, 0.0016f, -0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0021f, 0.0022f, 0.0023f, 0.0025f, -0.0026f, 0.0028f, 0.0030f, 0.0033f, 0.0035f, 0.0038f, 0.0041f, 0.0045f, -0.0049f, 0.0054f, 0.0059f, 0.0065f, 0.0072f, 0.0081f, 0.0090f, 0.0102f, -0.0115f, 0.0130f, 0.0149f, 0.0171f, 0.0197f, 0.0227f, 0.0263f, 0.0302f, -0.0345f, 0.0387f, 0.0425f, 0.0451f, 0.0460f -}; -static const float glorentz60[49] = { -0.0010f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, -0.0014f, 0.0015f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, 0.0021f, -0.0022f, 0.0024f, 0.0025f, 0.0027f, 0.0028f, 0.0030f, 0.0033f, 0.0035f, -0.0038f, 0.0041f, 0.0044f, 0.0048f, 0.0052f, 0.0057f, 0.0063f, 0.0069f, -0.0077f, 0.0085f, 0.0095f, 0.0106f, 0.0119f, 0.0135f, 0.0153f, 0.0174f, -0.0199f, 0.0227f, 0.0259f, 0.0293f, 0.0330f, 0.0365f, 0.0395f, 0.0415f, -0.0423f -}; -static const float glorentz61[53] = { -0.0009f, 0.0010f, 0.0010f, 0.0011f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, -0.0013f, 0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0016f, 0.0017f, 0.0018f, -0.0019f, 0.0020f, 0.0021f, 0.0023f, 0.0024f, 0.0025f, 0.0027f, 0.0029f, -0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0041f, 0.0044f, 0.0047f, 0.0051f, -0.0056f, 0.0061f, 0.0067f, 0.0073f, 0.0081f, 0.0089f, 0.0099f, 0.0110f, -0.0124f, 0.0139f, 0.0156f, 0.0176f, 0.0199f, 0.0225f, 0.0253f, 0.0283f, -0.0314f, 0.0343f, 0.0367f, 0.0383f, 0.0389f -}; -static const float glorentz62[57] = { -0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, 0.0011f, 0.0011f, 0.0011f, -0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, 0.0015f, 0.0015f, 0.0016f, -0.0017f, 0.0018f, 0.0019f, 0.0020f, 0.0021f, 0.0022f, 0.0023f, 0.0024f, -0.0026f, 0.0027f, 0.0029f, 0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0040f, -0.0043f, 0.0047f, 0.0050f, 0.0055f, 0.0059f, 0.0064f, 0.0070f, 0.0077f, -0.0085f, 0.0093f, 0.0103f, 0.0114f, 0.0127f, 0.0142f, 0.0158f, 0.0177f, -0.0198f, 0.0221f, 0.0246f, 0.0272f, 0.0297f, 0.0321f, 0.0340f, 0.0353f, -0.0357f -}; -static const float glorentz63[62] = { -0.0008f, 0.0008f, 0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, 0.0010f, -0.0011f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, 0.0014f, -0.0015f, 0.0015f, 0.0016f, 0.0017f, 0.0017f, 0.0018f, 0.0019f, 0.0020f, -0.0021f, 0.0022f, 0.0023f, 0.0025f, 0.0026f, 0.0028f, 0.0029f, 0.0031f, -0.0033f, 0.0035f, 0.0038f, 0.0040f, 0.0043f, 0.0046f, 0.0050f, 0.0053f, -0.0058f, 0.0062f, 0.0068f, 0.0074f, 0.0081f, 0.0088f, 0.0097f, 0.0106f, -0.0117f, 0.0130f, 0.0144f, 0.0159f, 0.0176f, 0.0195f, 0.0216f, 0.0237f, -0.0259f, 0.0280f, 0.0299f, 0.0315f, 0.0325f, 0.0328f -}; -static const float glorentz64[65] = { -0.0008f, 0.0008f, 0.0008f, 0.0009f, 0.0009f, 0.0009f, 0.0010f, 0.0010f, -0.0010f, 0.0011f, 0.0011f, 0.0012f, 0.0012f, 0.0012f, 0.0013f, 0.0013f, -0.0014f, 0.0014f, 0.0015f, 0.0016f, 0.0016f, 0.0017f, 0.0018f, 0.0019f, -0.0020f, 0.0021f, 0.0022f, 0.0023f, 0.0024f, 0.0025f, 0.0027f, 0.0028f, -0.0030f, 0.0031f, 0.0033f, 0.0035f, 0.0038f, 0.0040f, 0.0043f, 0.0046f, -0.0049f, 0.0052f, 0.0056f, 0.0061f, 0.0066f, 0.0071f, 0.0077f, 0.0084f, -0.0091f, 0.0100f, 0.0109f, 0.0120f, 0.0132f, 0.0145f, 0.0159f, 0.0175f, -0.0192f, 0.0209f, 0.0228f, 0.0246f, 0.0264f, 0.0279f, 0.0291f, 0.0299f, -0.0301f -}; -static const float *gptr_tab_lorentz[64] = { -glorentz1, glorentz2, glorentz3, glorentz4, -glorentz5, glorentz6, glorentz7, glorentz8, -glorentz9, glorentz10, glorentz11, glorentz12, -glorentz13, glorentz14, glorentz15, glorentz16, -glorentz17, glorentz18, glorentz19, glorentz20, -glorentz21, glorentz22, glorentz23, glorentz24, -glorentz25, glorentz26, glorentz27, glorentz28, -glorentz29, glorentz30, glorentz31, glorentz32, -glorentz33, glorentz34, glorentz35, glorentz36, -glorentz37, glorentz38, glorentz39, glorentz40, -glorentz41, glorentz42, glorentz43, glorentz44, -glorentz45, glorentz46, glorentz47, glorentz48, -glorentz49, glorentz50, glorentz51, glorentz52, -glorentz53, glorentz54, glorentz55, glorentz56, -glorentz57, glorentz58, glorentz59, glorentz60, -glorentz61, glorentz62, glorentz63, glorentz64 -}; diff --git a/lib/qra/qra64/main.c b/lib/qra/qra64/main.c deleted file mode 100644 index b685fd31..00000000 --- a/lib/qra/qra64/main.c +++ /dev/null @@ -1,746 +0,0 @@ -/* -main.c -QRA64 mode encode/decode tests - -(c) 2016 - Nico Palermo, IV3NWV - -Thanks to Andrea Montefusco IW0HDV for his help on adapting the sources -to OSs other than MS Windows - ------------------------------------------------------------------------------- -This file is part of the qracodes project, a Forward Error Control -encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. - -Files in this package: - main.c - this file - qra64.c/.h - qra64 mode encode/decoding functions - - ../qracodes/normrnd.{c,h} - random gaussian number generator - ../qracodes/npfwht.{c,h} - Fast Walsh-Hadamard Transforms - ../qracodes/pdmath.{c,h} - Elementary math on probability distributions - ../qracodes/qra12_63_64_irr_b.{c,h} - Tables for a QRA(12,63) irregular RA - code over GF(64) - ../qracodes/qra13_64_64_irr_e.{c,h} - Tables for a QRA(13,64) irregular RA - code over GF(64) - ../qracodes/qracodes.{c,h} - QRA codes encoding/decoding functions - -------------------------------------------------------------------------------- - - qracodes is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - qracodes is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with qracodes source distribution. - If not, see . - ------------------------------------------------------------------------------ - -The code used by the QRA64 mode is the code: QRA13_64_64_IRR_E: K=13 -N=64 Q=64 irregular QRA code (defined in qra13_64_64_irr_e.{h,c}). - -This code has been designed to include a CRC as the 13th information -symbol and improve the code UER (Undetected Error Rate). The CRC -symbol is not sent along the channel (the codes are punctured) and the -resulting code is still a (12,63) code with an effective code rate of -R = 12/63. -*/ - -// OS dependent defines and includes ------------------------------------------ - -#if _WIN32 // note the underscore: without it, it's not msdn official! -// Windows (x64 and x86) -#include // required only for GetTickCount(...) -#include // _beginthread -#endif - -#if __linux__ -#include -#include - -unsigned GetTickCount(void) { - struct timespec ts; - unsigned theTick = 0U; - clock_gettime( CLOCK_REALTIME, &ts ); - theTick = ts.tv_nsec / 1000000; - theTick += ts.tv_sec * 1000; - return theTick; -} -#endif - -#if __APPLE__ -#endif - -#include -#include -#include - -#include "qra64.h" -#include "../qracodes/normrnd.h" // gaussian numbers generator - -// ---------------------------------------------------------------------------- - -// channel types -#define CHANNEL_AWGN 0 -#define CHANNEL_RAYLEIGH 1 -#define CHANNEL_FASTFADE 2 - -#define JT65_SNR_EBNO_OFFSET 29.1f // with the synch used in JT65 -#define QRA64_SNR_EBNO_OFFSET 31.0f // with the costas array synch - -void printwordd(char *msg, int *x, int size) -{ - int k; - printf("\n%s ",msg); - for (k=0;k-15) - if (channel_type == CHANNEL_AWGN) - for (k=0;k=0) { // decoded - printf("K1JT rx: received with apcode=%d %s\n",rc, decode_type[rc]); - -// Step 2a: K1JT replies to IV3NWV (with no grid) - printf("K1JT tx: IV3NWV K1JT\n"); - encodemsg_jt65(x,CALL_IV3NWV,CALL_K1JT, GRID_BLANK); - qra64_encode(codec_k1jt, y, x); - rx = mfskchannel(y,channel_type,EbNodB); - -// Step 2b: IV3NWV attempts to decode [? ? ?], [IV3NWV ? ?] or [IV3NWV ?] - rc = qra64_decode(codec_iv3nwv, 0, xdec,rx); - if (rc>=0) { // decoded - printf("IV3NWV rx: received with apcode=%d %s\n",rc, decode_type[rc]); - -// Step 3a: IV3NWV replies to K1JT with a 73 - printf("IV3NWV tx: K1JT IV3NWV 73\n"); - encodemsg_jt65(x,CALL_K1JT,CALL_IV3NWV, GRID_73); - qra64_encode(codec_iv3nwv, y, x); - rx = mfskchannel(y,channel_type,EbNodB); - -// Step 3b: K1JT attempts to decode [? ? ?] or [K1JT IV3NWV ?] - rc = qra64_decode(codec_k1jt, 0, xdec,rx); - if (rc>=0) { // decoded - printf("K1JT rx: received with apcode=%d %s\n",rc, decode_type[rc]); - -// Step 4a: K1JT replies to IV3NWV with a 73 - printf("K1JT tx: IV3NWV K1JT 73\n"); - encodemsg_jt65(x,CALL_IV3NWV,CALL_K1JT, GRID_73); - qra64_encode(codec_k1jt, y, x); - rx = mfskchannel(y,channel_type,EbNodB); - -// Step 4b: IV3NWV attempts to decode [? ? ?], [IV3NWV ? ?], or [IV3NWV ?] - rc = qra64_decode(codec_iv3nwv, 0, xdec,rx); - if (rc>=0) { // decoded - printf("IV3NWV rx: received with apcode=%d %s\n",rc, decode_type[rc]); - return 0; - } - } - } - } - printf("no decode\n"); - return -1; -} - -int test_proc_2(int channel_type, float EbNodB, int mode) -{ -/* -Here we simulate the decoder of K1JT after K1JT has sent a msg [IV3NWV K1JT] -and IV3NWV sends him the msg [K1JT IV3NWV JN66]. - -If mode=QRA_NOAP, K1JT decoder attempts to decode only msgs of type [? ? ?]. - -If mode=QRA_AUTOP, K1JT decoder will attempt to decode also the msgs -[K1JT IV3NWV] and [K1JT IV3NWV ?]. - -In the case a decode is successful the return code of the qra64_decode function -indicates the amount of a-priori information required to decode the received -message according to this table: - - rc=0 [? ? ?] AP0 - rc=1 [CQ ? ?] AP27 - rc=2 [CQ ? ] AP42 - rc=3 [CALL ? ?] AP29 - rc=4 [CALL ? ] AP44 - rc=5 [CALL CALL ?] AP57 - rc=6 [? CALL ?] AP29 - rc=7 [? CALL ] AP44 - rc=8 [CALL CALL GRID] AP72 - rc=9 [CQ CALL ?] AP55 - rc=10 [CQ CALL ] AP70 - rc=11 [CQ CALL GRID] AP70 - -The return code is <0 when decoding is unsuccessful - -This test simulates the situation ntx times and reports how many times -a particular type decode among the above 6 cases succeded. -*/ - - int x[QRA64_K], xdec[QRA64_K]; - int y[QRA64_N]; - float *rx; - float ebnodbest, ebnodbavg=0; - int rc,k; - - int ndecok[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - int nundet = 0; - int ntx = 200,ndec=0; - - qra64codec *codec_iv3nwv = qra64_init(mode); // codec for IV3NWV - qra64codec *codec_k1jt = qra64_init(mode); // codec for K1JT - - printf("\nQRA64 Test #2 - Decoding with AP knowledge (SNR-Eb/No offset = %.1f dB)\n\n", - QRA64_SNR_EBNO_OFFSET); - -// This will enable K1JT's decoder to look for calls directed to him [K1JT ? ?/b] -// printf("K1JT decoder enabled for [K1JT ? ?/blank]\n"); -// qra64_apset(codec_k1jt, CALL_K1JT,0,0,APTYPE_MYCALL); - -// This will enable K1JT's decoder to look for IV3NWV calls directed to him [K1JT IV3NWV ?/b] -// printf("K1JT decoder enabled for [K1JT IV3NWV ?]\n"); -// qra64_apset(codec_k1jt, CALL_CQ,CALL_IV3NWV,0,APTYPE_BOTHCALLS); - -// This will enable K1JT's decoder to look for msges sent by IV3NWV [? IV3NWV ?] -// printf("K1JT decoder enabled for [? IV3NWV ?/blank]\n"); -// qra64_apset(codec_k1jt, 0,CALL_IV3NWV,GRID_BLANK,APTYPE_HISCALL); - -// This will enable K1JT's decoder to look for full-knowledge [K1JT IV3NWV JN66] msgs - printf("K1JT decoder enabled for [K1JT IV3NWV JN66]\n"); - qra64_apset(codec_k1jt, CALL_K1JT,CALL_IV3NWV,GRID_JN66,APTYPE_FULL); - -// This will enable K1JT's decoder to look for calls from IV3NWV [CQ IV3NWV ?/b] msgs - printf("K1JT decoder enabled for [CQ IV3NWV ?/b/JN66]\n"); - qra64_apset(codec_k1jt, 0,CALL_IV3NWV,GRID_JN66,APTYPE_CQHISCALL); - - - // Dx station IV3NWV calls - printf("\nIV3NWV encoder sends msg: [K1JT IV3NWV JN66]\n\n"); - encodemsg_jt65(x,CALL_CQ,CALL_IV3NWV,GRID_JN66); - -// printf("\nIV3NWV encoder sends msg: [CQ IV3NWV JN66]\n\n"); -// encodemsg_jt65(x,CALL_CQ,CALL_IV3NWV,GRID_JN66); - -// printf("\nIV3NWV encoder sends msg: [CQ IV3NWV]\n\n"); -// encodemsg_jt65(x,CALL_CQ,CALL_IV3NWV,GRID_BLANK); - qra64_encode(codec_iv3nwv, y, x); - - printf("Simulating K1JT decoder up to AP72\n"); - - for (k=0;k=0) { - ebnodbavg +=ebnodbest; - if (memcmp(xdec,x,12*sizeof(int))==0) - ndecok[rc]++; - else - nundet++; - } - } - printf("\n\n"); - - - printf("Transimtted msgs:%d\nDecoded msgs:\n\n",ntx); - for (k=0;k<12;k++) { - printf("%3d with %s\n",ndecok[k],decode_type[k]); - ndec += ndecok[k]; - } - printf("\nTotal: %d/%d (%d undetected errors)\n\n",ndec,ntx,nundet); - printf(""); - - ebnodbavg/=(ndec+nundet); - printf("Estimated SNR (average in dB) = %.2f dB\n\n",ebnodbavg-QRA64_SNR_EBNO_OFFSET); - - return 0; -} - -int test_fastfading(float EbNodB, float B90, int fadingModel, int submode, int apmode, int olddec, int channel_type, int ntx) -{ - int x[QRA64_K], xdec[QRA64_K]; - int y[QRA64_N]; - float *rx; - float ebnodbest, ebnodbavg=0; - int rc,k; - float rxolddec[QRA64_N*QRA64_M]; // holds the energies at nominal tone freqs - - int ndecok[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - int nundet = 0; - int ndec=0; - - qra64codec *codec_iv3nwv; - qra64codec *codec_k1jt; - - codec_iv3nwv=qra64_init(QRA_NOAP); - codec_k1jt =qra64_init(apmode); - - if (channel_type==2) { // fast-fading case - printf("Simulating the fast-fading channel\n"); - printf("B90=%.2f Hz - Fading Model=%s - Submode=QRA64%c\n",B90,fadingModel?"Lorentz":"Gauss",submode+'A'); - printf("Decoder metric = %s\n",olddec?"AWGN":"Matched to fast-fading signal"); - } - else { - printf("Simulating the %s channel\n",channel_type?"Rayleigh block fading":"AWGN"); - printf("Decoder metric = AWGN\n"); - } - - - printf("\nEncoding msg [K1JT IV3NWV JN66]\n"); - encodemsg_jt65(x,CALL_K1JT,CALL_IV3NWV,GRID_JN66); -// printf("["); -// for (k=0;k<11;k++) printf("%02hX ",x[k]); printf("%02hX]\n",x[11]); - - qra64_encode(codec_iv3nwv, y, x); - printf("%d transmissions will be simulated\n\n",ntx); - - if (apmode==QRA_USERAP) { - // This will enable K1JT's decoder to look for cq/qrz calls [CQ/QRZ ? ?/b] - printf("K1JT decoder enabled for [CQ ? ?/blank]\n"); - qra64_apset(codec_k1jt, CALL_K1JT,0,0,APTYPE_CQQRZ); - - // This will enable K1JT's decoder to look for calls directed to him [K1JT ? ?/b] - printf("K1JT decoder enabled for [K1JT ? ?/blank]\n"); - qra64_apset(codec_k1jt, CALL_K1JT,0,0,APTYPE_MYCALL); - - // This will enable K1JT's decoder to look for msges sent by IV3NWV [? IV3NWV ?] - printf("K1JT decoder enabled for [? IV3NWV ?/blank]\n"); - qra64_apset(codec_k1jt, 0,CALL_IV3NWV,GRID_BLANK,APTYPE_HISCALL); - - // This will enable K1JT's decoder to look for IV3NWV calls directed to him [K1JT IV3NWV ?/b] - printf("K1JT decoder enabled for [K1JT IV3NWV ?]\n"); - qra64_apset(codec_k1jt, CALL_K1JT,CALL_IV3NWV,0,APTYPE_BOTHCALLS); - - // This will enable K1JT's decoder to look for full-knowledge [K1JT IV3NWV JN66] msgs - printf("K1JT decoder enabled for [K1JT IV3NWV JN66]\n"); - qra64_apset(codec_k1jt, CALL_K1JT,CALL_IV3NWV,GRID_JN66,APTYPE_FULL); - - // This will enable K1JT's decoder to look for calls from IV3NWV [CQ IV3NWV ?/b] msgs - printf("K1JT decoder enabled for [CQ IV3NWV ?/b/JN66]\n"); - qra64_apset(codec_k1jt, 0,CALL_IV3NWV,GRID_JN66,APTYPE_CQHISCALL); - - } - - printf("\nNow decoding with K1JT's decoder...\n"); -/* - if (channel_type==2) // simulate a fast-faded signal - printf("Simulating a fast-fading channel with given B90 and spread type\n"); - else - printf("Simulating a %s channel\n",channel_type?"Rayleigh block fading":"AWGN"); -*/ - for (k=0;k=0) { - ebnodbavg +=ebnodbest; - if (memcmp(xdec,x,12*sizeof(int))==0) - ndecok[rc]++; - else { - fprintf(stderr,"\nUndetected error with rc=%d\n",rc); - nundet++; - } - } - - } - printf(" %5.1f %%\r",100.0*k/ntx); - - printf("\n\n"); - - printf("Msgs transmitted:%d\nMsg decoded:\n\n",ntx); - for (k=0;k<12;k++) { - printf("rc=%2d %3d with %s\n",k,ndecok[k],decode_type[k]); - ndec += ndecok[k]; - } - printf("\nTotal: %d/%d (%d undetected errors)\n\n",ndec,ntx,nundet); - printf(""); - - if (ndec>0) { - ebnodbavg/=(ndec+nundet); - printf("Estimated SNR (average in dB) = %.2f dB\n\n",ebnodbavg-QRA64_SNR_EBNO_OFFSET); - } - - return 0; -} - - - -void syntax(void) -{ - - printf("\nQRA64 Mode Tests\n"); - printf("2016, Nico Palermo - IV3NWV\n\n"); - printf("---------------------------\n\n"); - printf("Syntax: qra64 [-s] [-c] [-a] [-t] [-h]\n"); - printf("Options: \n"); - printf(" -s : set simulation SNR in 2500 Hz BW (default:-27.5 dB)\n"); - printf(" -c : set channel type 0=AWGN (default) 1=Rayleigh 2=Fast-fading\n"); - printf(" -a : set decode type 0=NOAP 1=AUTOAP (default) 2=USERAP\n"); - printf(" -t: 0=simulate seq of msgs between IV3NWV and K1JT (default)\n"); - printf(" 1=simulate K1JT receiving K1JT IV3NWV JN66\n"); - printf(" 2=simulate fast-fading/awgn/rayliegh decoders performance\n"); - printf(" -n : simulate the transmission of ntx codewords (default=100)\n"); - - printf("Options used only for fast-fading simulations (-c2):\n"); - printf(" -b : 90%% fading bandwidth in Hz [1..230 Hz] (default = 2.5 Hz)\n"); - printf(" -m : fading model. 0=Gauss, 1=Lorentz (default = Lorentz)\n"); - printf(" -q : qra64 submode. 0=QRA64A,... 4=QRA64E (default = QRA64A)\n"); - printf(" -d : use the old awgn decoder\n"); - printf(" -h: this help\n"); - printf("Example:\n"); - printf(" qra64 -t2 -c2 -a2 -b50 -m1 -q2 -n10000 -s-26\n"); - printf(" runs the error performance test (-t2)\n"); - printf(" with USER_AP (-a2)\n"); - printf(" simulating a fast fading channel (-c2)\n"); - printf(" with B90 = 50 Hz (-b50), Lorentz Doppler (-m1), mode QRA64C (-q2)\n"); - printf(" ntx = 10000 codewords (-n10000) and SNR = -26 dB (-s-26)\n"); - -} - -int main(int argc, char* argv[]) -{ - int k, rc, nok=0; - float SNRdB = -27.5f; - unsigned int channel = CHANNEL_AWGN; - unsigned int mode = QRA_AUTOAP; - unsigned int testtype=0; - int nqso = 100; - float EbNodB; - float B90 = 2.5; - int fadingModel = 1; - int submode = 0; - int olddec = 0; - int ntx = 100; - -// Parse the command line - while(--argc) { - argv++; - - if (strncmp(*argv,"-h",2)==0) { - syntax(); - return 0; - } - else - if (strncmp(*argv,"-n",2)==0) { - ntx = ( int)atoi((*argv)+2); - if (ntx<100 || ntx>1000000) { - printf("Invalid -n option. ntx must be in the range [100..1000000]\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-a",2)==0) { - mode = ( int)atoi((*argv)+2); - if (mode>2) { - printf("Invalid decoding mode\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-s",2)==0) { - SNRdB = (float)atof((*argv)+2); - if (SNRdB>20 || SNRdB<-50) { - printf("SNR should be in the range [-50..20]\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-t",2)==0) { - testtype = ( int)atoi((*argv)+2); - if (testtype>2) { - printf("Invalid test type\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-c",2)==0) { - channel = ( int)atoi((*argv)+2); - if (channel>CHANNEL_FASTFADE) { - printf("Invalid channel type\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-b",2)==0) { - B90 = (float)atof((*argv)+2); - if (B90<1 || B90>230) { - printf("Invalid B90\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-m",2)==0) { - fadingModel = (int)atoi((*argv)+2); - if (fadingModel<0 || fadingModel>1) { - printf("Invalid fading model\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-q",2)==0) { - submode = (int)atoi((*argv)+2); - if (submode<0 || submode>4) { - printf("Invalid submode\n"); - syntax(); - return -1; - } - } - else - if (strncmp(*argv,"-d",2)==0) { - olddec = 1; - } - else { - printf("Invalid option\n"); - syntax(); - return -1; - } - } - - if (testtype<2) // old tests - if (channel==CHANNEL_FASTFADE) { - printf("Invalid Option. Test type 0 and 1 supports only AWGN or Rayleigh Channel model\n"); - return -1; - } - - EbNodB = SNRdB+QRA64_SNR_EBNO_OFFSET; - -#if defined(__linux__) || defined(__unix__) - srand48(GetTickCount()); -#endif - - if (testtype==0) { - for (k=0;k. - ------------------------------------------------------------------------------ - -QRA code used in this sowftware release: - -QRA13_64_64_IRR_E: K=13 N=64 Q=64 irregular QRA code (defined in -qra13_64_64_irr_e.h /.c) - -Codes with K=13 are designed to include a CRC as the 13th information symbol -and improve the code UER (Undetected Error Rate). -The CRC symbol is not sent along the channel (the codes are punctured) and the -resulting code is a (12,63) code -*/ -//---------------------------------------------------------------------------- - -#include -#include - -#include "qra64.h" -#include "../qracodes/qracodes.h" -#include "../qracodes/qra13_64_64_irr_e.h" -#include "../qracodes/pdmath.h" -#include "../qracodes/normrnd.h" - -// Code parameters of the QRA64 mode -#define QRA64_CODE qra_13_64_64_irr_e -#define QRA64_NMSG 218 // Must much value indicated in QRA64_CODE.NMSG - -#define QRA64_KC (QRA64_K+1) // Information symbols (crc included) -#define QRA64_NC (QRA64_N+1) // Codeword length (as defined in the code) -#define QRA64_NITER 100 // max number of iterations per decode - -// static functions declarations ---------------------------------------------- -static int calc_crc6(const int *x, int sz); -static void ix_mask(float *dst, const float *src, const int *mask, - const int *x); -static int qra64_decode_attempts(qra64codec *pcodec, int *xdec, const float *ix); -static int qra64_do_decode(int *x, const float *pix, const int *ap_mask, - const int *ap_x); -static float qra64_fastfading_estim_noise_std( - const float *rxen, - const float esnometric, - const int submode); - -static void qra64_fastfading_intrinsics( - float *pix, - const float *rxen, - const float *hptr, - const int hlen, - const float sigma, - const float EsNoMetric, - const int submode); - -static float qra64_fastfading_msg_esno( - const int *ydec, - const float *rxen, - const float sigma, - const float EsNoMetric, - const int hlen, - const int submode); - - -// a-priori information masks for fields in JT65-like msgs -------------------- - -// when defined limits the AP masks to reduce the false decode rate -#define LIMIT_AP_MASKS - -#ifdef LIMIT_AP_MASKS -#define MASK_CQQRZ 0xFFFFFFC -#define MASK_CALL1 0xFFFFFFC -#define MASK_CALL2 0xFFFFFFC -#define MASK_GRIDFULL 0x3FFC -#define MASK_GRIDFULL12 0x3FFC -#define MASK_GRIDBIT 0x8000 -#else -#define MASK_CQQRZ 0xFFFFFFC -#define MASK_CALL1 0xFFFFFFF -#define MASK_CALL2 0xFFFFFFF -#define MASK_GRIDFULL 0xFFFF -#define MASK_GRIDFULL12 0x3FFC -#define MASK_GRIDBIT 0x8000 // b[15] is 1 for free text, 0 otherwise -#endif - -// ---------------------------------------------------------------------------- - - - - -qra64codec *qra64_init(int flags) -{ - - // Eb/No value for which we optimize the decoder metric - const float EbNodBMetric = 2.8f; - const float EbNoMetric = (float)pow(10,EbNodBMetric/10); - const float R = 1.0f*(QRA64_KC)/(QRA64_NC); - - qra64codec *pcodec = (qra64codec*)malloc(sizeof(qra64codec)); - - if (!pcodec) - return 0; // can't allocate memory - - pcodec->decEsNoMetric = 1.0f*QRA64_m*R*EbNoMetric; - pcodec->apflags = flags; - - memset(pcodec->apmsg_set,0,APTYPE_SIZE*sizeof(int)); - - if (flags==QRA_NOAP) - return pcodec; - - // for QRA_USERAP and QRA_AUTOAP modes we always enable [CQ/QRZ ? ?] mgs look-up. - // encode CQ/QRZ AP messages - // NOTE: Here we handle only CQ and QRZ msgs. - // 'CQ nnn', 'CQ DX' and 'DE' msgs will be handled by the decoder - // as messages with no a-priori knowledge - qra64_apset(pcodec, CALL_CQ, 0, GRID_BLANK, APTYPE_CQQRZ); - - // initialize masks for decoding with a-priori information - encodemsg_jt65(pcodec->apmask_cqqrz, MASK_CQQRZ, 0, MASK_GRIDBIT); - encodemsg_jt65(pcodec->apmask_cqqrz_ooo, MASK_CQQRZ, 0, MASK_GRIDFULL); - encodemsg_jt65(pcodec->apmask_call1, MASK_CALL1, 0, MASK_GRIDBIT); - encodemsg_jt65(pcodec->apmask_call1_ooo, MASK_CALL1, 0, MASK_GRIDFULL); - encodemsg_jt65(pcodec->apmask_call2, 0, MASK_CALL2, MASK_GRIDBIT); - encodemsg_jt65(pcodec->apmask_call2_ooo, 0, MASK_CALL2, MASK_GRIDFULL); - encodemsg_jt65(pcodec->apmask_call1_call2, MASK_CALL1,MASK_CALL2, MASK_GRIDBIT); - encodemsg_jt65(pcodec->apmask_call1_call2_grid,MASK_CALL1,MASK_CALL2, MASK_GRIDFULL12); - encodemsg_jt65(pcodec->apmask_cq_call2, MASK_CQQRZ, MASK_CALL2, MASK_GRIDBIT); - encodemsg_jt65(pcodec->apmask_cq_call2_ooo, MASK_CQQRZ, MASK_CALL2, MASK_GRIDFULL12); - - return pcodec; -} - -void qra64_close(qra64codec *pcodec) -{ - free(pcodec); -} - -int qra64_apset(qra64codec *pcodec, const int mycall, const int hiscall, const int grid, const int aptype) -{ -// Set decoder a-priori knowledge accordingly to the type of the message to look up for -// arguments: -// pcodec = pointer to a qra64codec data structure as returned by qra64_init -// mycall = mycall to look for -// hiscall = hiscall to look for -// grid = grid to look for -// aptype = define and masks the type of AP to be set accordingly to the following: -// APTYPE_CQQRZ set [cq/qrz ? ?/blank] -// APTYPE_MYCALL set [mycall ? ?/blank] -// APTYPE_HISCALL set [? hiscall ?/blank] -// APTYPE_BOTHCALLS set [mycall hiscall ?] -// APTYPE_FULL set [mycall hiscall grid] -// APTYPE_CQHISCALL set [cq/qrz hiscall ?/blank] and [cq/qrz hiscall grid] -// returns: -// 0 on success -// -1 when qra64_init was called with the QRA_NOAP flag -// -2 invalid apytpe - - if (pcodec->apflags==QRA_NOAP) - return -1; - - switch (aptype) { - case APTYPE_CQQRZ: - encodemsg_jt65(pcodec->apmsg_cqqrz, CALL_CQ, 0, GRID_BLANK); - break; - case APTYPE_MYCALL: - encodemsg_jt65(pcodec->apmsg_call1, mycall, 0, GRID_BLANK); - break; - case APTYPE_HISCALL: - encodemsg_jt65(pcodec->apmsg_call2, 0, hiscall, GRID_BLANK); - break; - case APTYPE_BOTHCALLS: - encodemsg_jt65(pcodec->apmsg_call1_call2, mycall, hiscall, GRID_BLANK); - break; - case APTYPE_FULL: - encodemsg_jt65(pcodec->apmsg_call1_call2_grid, mycall, hiscall, grid); - break; - case APTYPE_CQHISCALL: - encodemsg_jt65(pcodec->apmsg_cq_call2, CALL_CQ, hiscall, GRID_BLANK); - encodemsg_jt65(pcodec->apmsg_cq_call2_grid, CALL_CQ, hiscall, grid); - break; - default: - return -2; // invalid ap type - } - - pcodec->apmsg_set[aptype]=1; // signal the decoder to look-up for the specified type - - - return 0; -} -void qra64_apdisable(qra64codec *pcodec, const int aptype) -{ - if (pcodec->apflags==QRA_NOAP) - return; - - if (aptype=APTYPE_SIZE) - return; - - pcodec->apmsg_set[aptype] = 0; // signal the decoder not to look-up to the specified type -} - -void qra64_encode(qra64codec *pcodec, int *y, const int *x) -{ - int encx[QRA64_KC]; // encoder input buffer - int ency[QRA64_NC]; // encoder output buffer - - int hiscall,mycall,grid; - - memcpy(encx,x,QRA64_K*sizeof(int)); // Copy input to encoder buffer - encx[QRA64_K]=calc_crc6(encx,QRA64_K); // Compute and add crc symbol - qra_encode(&QRA64_CODE, ency, encx); // encode msg+crc using given QRA code - - // copy codeword to output puncturing the crc symbol - memcpy(y,ency,QRA64_K*sizeof(int)); // copy information symbols - memcpy(y+QRA64_K,ency+QRA64_KC,QRA64_C*sizeof(int)); // copy parity symbols - - if (pcodec->apflags!=QRA_AUTOAP) - return; - - // Here we handle the QRA_AUTOAP mode -------------------------------------------- - - // When a [hiscall mycall ?] msg is detected we instruct the decoder - // to look for [mycall hiscall ?] msgs - // otherwise when a [cq mycall ?] msg is sent we reset the APTYPE_BOTHCALLS - - // look if the msg sent is a std type message (bit15 of grid field = 0) - if ((x[9]&0x80)) - return; // no, it's a text message, nothing to do - - // It's a [hiscall mycall grid] message - - // We assume that mycall is our call (but we don't check it) - // hiscall the station we are calling or a general call (CQ/QRZ/etc..) - decodemsg_jt65(&hiscall,&mycall,&grid,x); - - - if ((hiscall>=CALL_CQ && hiscall<=CALL_CQ999) || hiscall==CALL_CQDX || - hiscall==CALL_DE) { - // tell the decoder to look for msgs directed to us - qra64_apset(pcodec,mycall,0,0,APTYPE_MYCALL); - // We are making a general call and don't know who might reply - // Reset APTYPE_BOTHCALLS so decoder won't look for [mycall hiscall ?] msgs - qra64_apdisable(pcodec,APTYPE_BOTHCALLS); - } else { - // We are replying to someone named hiscall - // Set APTYPE_BOTHCALLS so decoder will try for [mycall hiscall ?] msgs - qra64_apset(pcodec,mycall, hiscall, GRID_BLANK, APTYPE_BOTHCALLS); - } - -} - -#define EBNO_MIN -10.0f // minimum Eb/No value returned by the decoder (in dB) -// AWGN metric decoder -int qra64_decode(qra64codec *pcodec, float *ebno, int *x, const float *rxen) -{ - int k; - float *srctmp, *dsttmp; - float ix[QRA64_NC*QRA64_M]; // (depunctured) intrisic information - int xdec[QRA64_KC]; // decoded message (with crc) - int ydec[QRA64_NC]; // re-encoded message (for snr calculations) - float noisestd; // estimated noise variance - float msge; // estimated message energy - float ebnoval; // estimated Eb/No - int rc; - - if (QRA64_NMSG!=QRA64_CODE.NMSG) // sanity check - return -16; // QRA64_NMSG define is wrong - - // compute symbols intrinsic probabilities from received energy observations - noisestd = qra_mfskbesselmetric(ix, rxen, QRA64_m, QRA64_N,pcodec->decEsNoMetric); - - // de-puncture observations adding a uniform distribution for the crc symbol - - // move check symbols distributions one symbol towards the end - dsttmp = PD_ROWADDR(ix,QRA64_M, QRA64_NC-1); //Point to last symbol prob dist - srctmp = dsttmp-QRA64_M; // source is the previous pd - for (k=0;k57.004f) - ebnoval=57.004f; - ebnoval = ebnoval*57.03f/(57.03f-ebnoval); - - // compute value in dB - if (ebnoval<=0) { - ebnoval = EBNO_MIN; // assume a minimum, positive value - } - else { - ebnoval = 10.0f*(float)log10(ebnoval); - if (ebnoval4) - return -17; // invalid submode - - if (B90<1.0f || B90>238.0f) - return -18; // B90 out of range - - // compute index to most appropriate amplitude weighting function coefficients - hidx = (int)(log((float)B90)/log(1.09f) - 0.499f); - - if (hidx<0 || hidx > 64) - return -19; // index of weighting function out of range - - if (fadingModel==0) { // gaussian fading model - // point to gaussian energy weighting taps - hlen = glen_tab_gauss[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) - hptr = gptr_tab_gauss[hidx]; // pointer to the first (L+1)/2 coefficients of w fun - } - else if (fadingModel==1) { - // point to lorentzian energy weighting taps - hlen = glen_tab_lorentz[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) - hptr = gptr_tab_lorentz[hidx]; // pointer to the first (L+1)/2 coefficients of w fun - } - else - return -20; // invalid fading model index - - - // compute (euristically) the optimal decoder metric accordingly the given spread amount - // We assume that the decoder threshold is: - // Es/No(dB) = Es/No(AWGN)(dB) + 8*log(B90)/log(240)(dB) - // that's to say, at the maximum Doppler spread bandwidth (240 Hz) there's a ~8 dB Es/No degradation - // over the AWGN case - tempf = 8.0f*(float)log((float)B90)/(float)log(240.0f); - EsNoMetric = pcodec->decEsNoMetric*(float)pow(10.0f,tempf/10.0f); - - - - // Step 1 ----------------------------------------------------------------------------------- - // Evaluate the noise stdev from the received energies at nominal tone frequencies - noisestd = qra64_fastfading_estim_noise_std(rxen, EsNoMetric, submode); - - // Step 2 ----------------------------------------------------------------------------------- - // Compute message symbols probability distributions - qra64_fastfading_intrinsics(ix, rxen, hptr, hlen, noisestd, EsNoMetric, submode); - - // Step 3 --------------------------------------------------------------------------- - // De-puncture observations adding a uniform distribution for the crc symbol - // Move check symbols distributions one symbol towards the end - dsttmp = PD_ROWADDR(ix,QRA64_M, QRA64_NC-1); //Point to last symbol prob dist - srctmp = dsttmp-QRA64_M; // source is the previous pd - for (k=0;k Eb/N0 conversion - ebnoval = 1.0f/(1.0f*QRA64_K/QRA64_N*QRA64_m)*esno; - - // compute value in dB - if (ebnoval<=0) { - ebnoval = EBNO_MIN; // assume a minimum, positive value - } - else { - ebnoval = 10.0f*(float)log10(ebnoval); - if (ebnoval238.0f) - return -18; // B90 out of range - - // compute index to most appropriate energy weighting function coefficients - hidx = (int)(log((float)B90)/log(1.09f) - 0.499f); - - if (hidx<0 || hidx > 64) - return -19; // index of weighting function out of range - - if (fadingModel==0) { // gaussian fading model - // point to gaussian weighting taps - hlen = glen_tab_gauss[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) - hptr = gptr_tab_gauss[hidx]; // pointer to the first (L+1)/2 coefficients of w fun - } - else if (fadingModel==1) { - // point to lorentzian weighting taps - hlen = glen_tab_lorentz[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) - hptr = gptr_tab_lorentz[hidx]; // pointer to the first (L+1)/2 coefficients of w fun - } - else - return -20; // invalid fading model index - - - // Compute the unfaded tone amplitudes from the Eb/No value passed to the call - N0 = 1.0f; // assume unitary noise PSD - sigmanoise = (float)sqrt(N0/2); - EsN0 = (float)pow(10.0f,EbN0dB/10.0f)*QRA64_m*QRA64_K/QRA64_N; // Es/No = m*R*Eb/No - Es = EsN0*N0; - - // compute signal bin sigmas - for (n=0;n=0;j--) { - normrnd_s(iq, 2, 0 , sigmasig[j]); - *curi++ += iq[0]; - *curq++ += iq[1]; - } - - } - - // compute total bin energies (S+N) and store in first half of buffer - curi = channel_out; - curq = channel_out+bpm; - for (n=0;nmaxloglh) // keep track of the max loglikelihood - maxloglh = loglh; - curix[k]=loglh; - } - - // scale to likelihoods - sumix = 0.f; - for (k=0;k1 - if (u<1) - return 0.f; - - // check u(bps/tothlen)) - return 10000.f; - - // solve for Es/No - esno = (u-1.0f)/(1.0f/tothlen-u/bps); - - return esno; - - -} - -#ifdef LIMIT_AP_MASKS - -static int call1_match(const int *papmsg, const int *pdec) -{ - // assumes MASK_CALL1 = 0xFFFFFFC - int u = papmsg[4]^pdec[4]; - return (u&0x3C)==0; -} -static int call2_match(const int *papmsg, const int *pdec) -{ - // assumes MASK_CALL2 = 0xFFFFFFC - int u = papmsg[9]^pdec[9]; - return (u&0x30)==0; -} -static int grid_match(const int *papmsg, const int *pdec) -{ - // assumes MASK_GRIDFULL = 0x3FFC - int u = papmsg[11]^pdec[11]; - int rc = (u&0x03)==0; - - u = papmsg[9]^pdec[9]; - - return (u&0x0C)==0 && rc; -} - -#else -#define call1_match(a,b) (1) -#define call2_match(a,b) (1) -#define grid_match(a,b) (1) -#endif - - - - -// Attempt to decode given intrisic information -static int qra64_decode_attempts(qra64codec *pcodec, int *xdec, const float *ix) -{ - int rc; - - // Attempt to decode without a-priori info -------------------------------- - rc = qra64_do_decode(xdec, ix, NULL, NULL); - if (rc>=0) - return 0; // successfull decode with AP0 - else - if (pcodec->apflags==QRA_NOAP) - // nothing more to do - return rc; // rc<0 = unsuccessful decode - - // Here we handle decoding with AP knowledge - - - // Attempt to decode CQ calls - rc = qra64_do_decode(xdec,ix,pcodec->apmask_cqqrz, pcodec->apmsg_cqqrz); - if (rc>=0) - return 1; // decoded [cq/qrz ? ?] - - rc = qra64_do_decode(xdec, ix, pcodec->apmask_cqqrz_ooo, - pcodec->apmsg_cqqrz); - if (rc>=0) - // check that ooo really matches - if (grid_match(pcodec->apmsg_cqqrz,xdec)) - return 2; // decoded [cq/qrz ? ooo] - - // attempt to decode calls directed to us - if (pcodec->apmsg_set[APTYPE_MYCALL]) { - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1, - pcodec->apmsg_call1); - if (rc>=0) - // check that mycall really matches - if (call1_match(pcodec->apmsg_call1,xdec)) - return 3; // decoded [mycall ? ?] - - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_ooo, - pcodec->apmsg_call1); - if (rc>=0) - // check that mycall and ooo really match - if (call1_match(pcodec->apmsg_call1,xdec) && - grid_match(pcodec->apmsg_call1,xdec)) - return 4; // decoded [mycall ? ooo] - } - - // attempt to decode [mycall hiscall ?] msgs - if (pcodec->apmsg_set[APTYPE_BOTHCALLS]) { - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_call2, - pcodec->apmsg_call1_call2); - if (rc>=0) - // check that mycall and hiscall really match - if (call1_match(pcodec->apmsg_call1_call2,xdec) && - call2_match(pcodec->apmsg_call1_call2,xdec)) - return 5; // decoded [mycall srccall ?] - } - - // attempt to decode [? hiscall ?/b] msgs - if (pcodec->apmsg_set[APTYPE_HISCALL]) { - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call2, - pcodec->apmsg_call2); - if (rc>=0) - // check that hiscall really match - if (call2_match(pcodec->apmsg_call2,xdec)) - return 6; // decoded [? hiscall ?] - - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call2_ooo, - pcodec->apmsg_call2); - if (rc>=0) - // check that hiscall and ooo match - if (call2_match(pcodec->apmsg_call2,xdec) && - grid_match(pcodec->apmsg_call2,xdec)) - return 7; // decoded [? hiscall ooo] - } - - // attempt to decode [cq/qrz hiscall ?/b/grid] msgs - if (pcodec->apmsg_set[APTYPE_CQHISCALL]) { - - rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2, - pcodec->apmsg_cq_call2); - if (rc>=0) - // check that hiscall matches - if (call2_match(pcodec->apmsg_call2,xdec)) - return 9; // decoded [cq/qrz hiscall ?] - - rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2_ooo, - pcodec->apmsg_cq_call2_grid); - if (rc>=0) { - // Full AP mask need special handling - // To minimize false decodes we check the decoded message - // with what passed in the ap_set call - if (memcmp(pcodec->apmsg_cq_call2_grid,xdec, QRA64_K*sizeof(int))==0) - return 11; // decoded [cq/qrz hiscall grid] - } - - rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2_ooo, - pcodec->apmsg_cq_call2); - if (rc>=0) { - // Full AP mask need special handling - // To minimize false decodes we check the decoded message - // with what passed in the ap_set call - if (memcmp(pcodec->apmsg_cq_call2,xdec, QRA64_K*sizeof(int))==0) - return 10; // decoded [cq/qrz hiscall ] - } - } - - // attempt to decode [mycall hiscall grid] - if (pcodec->apmsg_set[APTYPE_FULL]) { - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_call2_grid, - pcodec->apmsg_call1_call2_grid); - if (rc>=0) { - // Full AP mask need special handling - // All the three msg fields were given. - // To minimize false decodes we check the decoded message - // with what passed in the ap_set call - if (memcmp(pcodec->apmsg_call1_call2_grid,xdec, QRA64_K*sizeof(int))==0) - return 8; // decoded [mycall hiscall grid] - } - } - - // all decoding attempts failed - return -1; -} - - - -// Decode with given a-priori information -static int qra64_do_decode(int *xdec, const float *pix, const int *ap_mask, - const int *ap_x) -{ - int rc; - const float *ixsrc; - float ix_masked[QRA64_NC*QRA64_M]; // Masked intrinsic information - float ex[QRA64_NC*QRA64_M]; // Extrinsic information from the decoder - - float v2cmsg[QRA64_NMSG*QRA64_M]; // buffers for the decoder messages - float c2vmsg[QRA64_NMSG*QRA64_M]; - - if (ap_mask==NULL) { // no a-priori information - ixsrc = pix; // intrinsic source is what passed as argument - } else { - // a-priori information provided - // mask channel observations with a-priori - ix_mask(ix_masked,pix,ap_mask,ap_x); - ixsrc = ix_masked; // intrinsic source is the masked version - } - - // run the decoding algorithm - rc = qra_extrinsic(&QRA64_CODE,ex,ixsrc,QRA64_NITER,v2cmsg,c2vmsg); - if (rc<0) - return -1; // no convergence in given iterations - - // decode - qra_mapdecode(&QRA64_CODE,xdec,ex,ixsrc); - - // verify crc - if (calc_crc6(xdec,QRA64_K)!=xdec[QRA64_K]) // crc doesn't match (detected error) - return -2; // decoding was succesfull but crc doesn't match - - return 0; -} - - -// crc functions -------------------------------------------------------------- -// crc-6 generator polynomial -// g(x) = x^6 + a5*x^5 + ... + a1*x + a0 - -// g(x) = x^6 + x + 1 -#define CRC6_GEN_POL 0x30 // MSB=a0 LSB=a5 - -// g(x) = x^6 + x^2 + x + 1 (See: https://users.ece.cmu.edu/~koopman/crc/) -// #define CRC6_GEN_POL 0x38 // MSB=a0 LSB=a5. Simulation results are similar - -static int calc_crc6(const int *x, int sz) -{ - // todo: compute it faster using a look up table - int k,j,t,sr = 0; - for (k=0;k>1) ^ CRC6_GEN_POL; - else - sr = (sr>>1); - t>>=1; - } - } - return sr; -} - -static void ix_mask(float *dst, const float *src, const int *mask, - const int *x) -{ - // mask intrinsic information (channel observations) with a priori knowledge - - int k,kk, smask; - float *row; - - memcpy(dst,src,(QRA64_NC*QRA64_M)*sizeof(float)); - - for (k=0;k>22)&0x3F; - y[1]= (call1>>16)&0x3F; - y[2]= (call1>>10)&0x3F; - y[3]= (call1>>4)&0x3F; - y[4]= (call1<<2)&0x3F; - - y[4] |= (call2>>26)&0x3F; - y[5]= (call2>>20)&0x3F; - y[6]= (call2>>14)&0x3F; - y[7]= (call2>>8)&0x3F; - y[8]= (call2>>2)&0x3F; - y[9]= (call2<<4)&0x3F; - - y[9] |= (grid>>12)&0x3F; - y[10]= (grid>>6)&0x3F; - y[11]= (grid)&0x3F; - -} -void decodemsg_jt65(int *call1, int *call2, int *grid, const int *x) -{ - int nc1, nc2, ng; - - nc1 = x[4]>>2; - nc1 |= x[3]<<4; - nc1 |= x[2]<<10; - nc1 |= x[1]<<16; - nc1 |= x[0]<<22; - - nc2 = x[9]>>4; - nc2 |= x[8]<<2; - nc2 |= x[7]<<8; - nc2 |= x[6]<<14; - nc2 |= x[5]<<20; - nc2 |= (x[4]&0x03)<<26; - - ng = x[11]; - ng |= x[10]<<6; - ng |= (x[9]&0x0F)<<12; - - *call1 = nc1; - *call2 = nc2; - *grid = ng; -} diff --git a/lib/qra/qra64/qra64.h b/lib/qra/qra64/qra64.h deleted file mode 100644 index 3b2b5bd3..00000000 --- a/lib/qra/qra64/qra64.h +++ /dev/null @@ -1,269 +0,0 @@ -// qra64.h -// Encoding/decoding functions for the QRA64 mode -// -// (c) 2016 - Nico Palermo, IV3NWV -// ------------------------------------------------------------------------------ -// This file is part of the qracodes project, a Forward Error Control -// encoding/decoding package based on Q-ary RA (Repeat and Accumulate) LDPC codes. -// -// qracodes is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// qracodes is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with qracodes source distribution. -// If not, see . - -#ifndef _qra64_h_ -#define _qra64_h_ - -// qra64_init(...) initialization flags -#define QRA_NOAP 0 // don't use a-priori knowledge -#define QRA_AUTOAP 1 // use auto a-priori knowledge -#define QRA_USERAP 2 // a-priori knowledge messages provided by the user - -// QRA code parameters -#define QRA64_K 12 // information symbols -#define QRA64_N 63 // codeword length -#define QRA64_C 51 // (number of parity checks C=(N-K)) -#define QRA64_M 64 // code alphabet size -#define QRA64_m 6 // bits per symbol - -// packed predefined callsigns and fields as defined in JT65 -#define CALL_CQ 0xFA08319 -#define CALL_QRZ 0xFA0831A -#define CALL_CQ000 0xFA0831B -#define CALL_CQ999 0xFA08702 -#define CALL_CQDX 0x5624C39 -#define CALL_DE 0xFF641D1 -#define GRID_BLANK 0x7E91 - -// Types of a-priori knowledge messages -#define APTYPE_CQQRZ 0 // [cq/qrz ? ?/blank] -#define APTYPE_MYCALL 1 // [mycall ? ?/blank] -#define APTYPE_HISCALL 2 // [? hiscall ?/blank] -#define APTYPE_BOTHCALLS 3 // [mycall hiscall ?] -#define APTYPE_FULL 4 // [mycall hiscall grid] -#define APTYPE_CQHISCALL 5 // [cq/qrz hiscall ?/blank] -#define APTYPE_SIZE (APTYPE_CQHISCALL+1) - -typedef struct { - float decEsNoMetric; - int apflags; - int apmsg_set[APTYPE_SIZE]; // indicate which ap type knowledge has - // been set by the user -// ap messages buffers - int apmsg_cqqrz[12]; // [cq/qrz ? ?/blank] - int apmsg_call1[12]; // [mycall ? ?/blank] - int apmsg_call2[12]; // [? hiscall ?/blank] - int apmsg_call1_call2[12]; // [mycall hiscall ?] - int apmsg_call1_call2_grid[12]; // [mycall hiscall grid] - int apmsg_cq_call2[12]; // [cq hiscall ?/blank] - int apmsg_cq_call2_grid[12]; // [cq hiscall grid] - -// ap messages masks - int apmask_cqqrz[12]; - int apmask_cqqrz_ooo[12]; - int apmask_call1[12]; - int apmask_call1_ooo[12]; - int apmask_call2[12]; - int apmask_call2_ooo[12]; - int apmask_call1_call2[12]; - int apmask_call1_call2_grid[12]; - int apmask_cq_call2[12]; - int apmask_cq_call2_ooo[12]; -} qra64codec; - -#ifdef __cplusplus -extern "C" { -#endif - -qra64codec *qra64_init(int flags); -// QRA64 mode initialization function -// arguments: -// flags: set the decoder mode -// QRA_NOAP use no a-priori information -// QRA_AUTOAP use any relevant previous decodes -// QRA_USERAP use a-priori information provided via qra64_apset(...) -// returns: -// Pointer to initialized qra64codec data structure -// this pointer should be passed to the encoding/decoding functions -// -// 0 if unsuccessful (can't allocate memory) -// ---------------------------------------------------------------------------- - -void qra64_encode(qra64codec *pcodec, int *y, const int *x); -// QRA64 encoder -// arguments: -// pcodec = pointer to a qra64codec data structure as returned by qra64_init -// x = pointer to the message to be encoded, int x[12] -// x must point to an array of integers (i.e. defined as int x[12]) -// y = pointer to encoded message, int y[63]= -// ---------------------------------------------------------------------------- - -int qra64_decode(qra64codec *pcodec, float *ebno, int *x, const float *r); -// QRA64 mode decoder -// arguments: -// pcodec = pointer to a qra64codec data structure as returned by qra64_init -// ebno = pointer to a float where the avg Eb/No (in dB) will be stored -// in case of successfull decoding -// (pass a null pointer if not interested) -// x = pointer to decoded message, int x[12] -// r = pointer to received symbol energies (squared amplitudes) -// r must point to an array of length QRA64_M*QRA64_N (=64*63=4032) -// The first QRA_M entries should be the energies of the first -// symbol in the codeword; the last QRA_M entries should be the -// energies of the last symbol in the codeword -// -// return code: -// -// The return code is <0 when decoding is unsuccessful -// -16 indicates that the definition of QRA64_NMSG does not match what required by the code -// If the decoding process is successfull the return code is accordingly to the following table -// rc=0 [? ? ?] AP0 (decoding with no a-priori) -// rc=1 [CQ ? ?] AP27 -// rc=2 [CQ ? ] AP44 -// rc=3 [CALL ? ?] AP29 -// rc=4 [CALL ? ] AP45 -// rc=5 [CALL CALL ?] AP57 -// rc=6 [? CALL ?] AP29 -// rc=7 [? CALL ] AP45 -// rc=8 [CALL CALL GRID] AP72 (actually a AP68 mask to reduce false decodes) -// rc=9 [CQ CALL ?] AP55 -// rc=10 [CQ CALL ] AP70 (actaully a AP68 mask to reduce false decodes) - -// return codes in the range 1-10 indicate the amount and the type of a-priori -// information was required to decode the received message. - - -// Decode a QRA64 msg using a fast-fading metric -int qra64_decode_fastfading( - qra64codec *pcodec, // ptr to the codec structure - float *ebno, // ptr to where the estimated Eb/No value will be saved - int *x, // ptr to decoded message - const float *rxen, // ptr to received symbol energies array - const int submode, // submode idx (0=QRA64A ... 4=QRA64E) - const float B90, // spread bandwidth (90% fractional energy) - const int fadingModel); // 0=Gaussian 1=Lorentzian fade model -// -// rxen: The array of the received bin energies -// Bins must be spaced by integer multiples of the symbol rate (1/Ts Hz) -// The array must be an array of total length U = L x N where: -// L: is the number of frequency bins per message symbol (see after) -// N: is the number of symbols in a QRA64 msg (63) -// -// The number of bins/symbol L depends on the selected submode accordingly to -// the following rule: -// L = (64+64*2^submode+64) = 64*(2+2^submode) -// Tone 0 is always supposed to be at offset 64 in the array. -// The m-th tone nominal frequency is located at offset 64 + m*2^submode (m=0..63) -// -// Submode A: (2^submode = 1) -// L = 64*3 = 196 bins/symbol -// Total length of the energies array: U = 192*63 = 12096 floats -// -// Submode B: (2^submode = 2) -// L = 64*4 = 256 bins/symbol -// Total length of the energies array: U = 256*63 = 16128 floats -// -// Submode C: (2^submode = 4) -// L = 64*6 = 384 bins/symbol -// Total length of the energies array: U = 384*63 = 24192 floats -// -// Submode D: (2^submode = 8) -// L = 64*10 = 640 bins/symbol -// Total length of the energies array: U = 640*63 = 40320 floats -// -// Submode E: (2^submode = 16) -// L = 64*18 = 1152 bins/symbol -// Total length of the energies array: U = 1152*63 = 72576 floats -// -// Note: The rxen array is modified and reused for internal calculations. -// -// -// B90: spread fading bandwidth in Hz (90% fractional average energy) -// -// B90 should be in the range 1 Hz ... 238 Hz -// The value passed to the call is rounded to the closest value among the -// 64 available values: -// B = 1.09^k Hz, with k=0,1,...,63 -// -// I.e. B90=27 Hz will be approximated in this way: -// k = rnd(log(27)/log(1.09)) = 38 -// B90 = 1.09^k = 1.09^38 = 26.4 Hz -// -// For any input value the maximum rounding error is not larger than +/- 5% -// -// return codes: same return codes of qra64_decode (+some additional error codes) - - -// Simulate the fast-fading channel (to be used with qra64_decode_fastfading) -int qra64_fastfading_channel( - float **rxen, - const int *xmsg, - const int submode, - const float EbN0dB, - const float B90, - const int fadingModel); -// Simulate transmission over a fading channel with given B90, fading model and submode -// and non coherent detection. -// Sets rxen to point to an array of bin energies formatted as required -// by the (fast-fading) decoding routine. -// returns 0 on success or negative values on error conditions - - -int qra64_apset(qra64codec *pcodec, const int mycall, const int hiscall, const int grid, const int aptype); -// Set decoder a-priori knowledge accordingly to the type of the message to -// look up for -// arguments: -// pcodec = pointer to a qra64codec data structure as returned by qra64_init -// mycall = mycall to look for -// hiscall = hiscall to look for -// grid = grid to look for -// aptype = define the type of AP to be set: -// APTYPE_CQQRZ set [cq/qrz ? ?/blank] -// APTYPE_MYCALL set [mycall ? ?/blank] -// APTYPE_HISCALL set [? hiscall ?/blank] -// APTYPE_BOTHCALLS set [mycall hiscall ?] -// APTYPE_FULL set [mycall hiscall grid] -// APTYPE_CQHISCALL set [cq/qrz hiscall ?/blank] - -// returns: -// 0 on success -// -1 when qra64_init was called with the QRA_NOAP flag -// -2 invalid apytpe (valid range [APTYPE_CQQRZ..APTYPE_CQHISCALL] -// (APTYPE_CQQRZ [cq/qrz ? ?] is set by default ) - -void qra64_apdisable(qra64codec *pcodec, const int aptype); -// disable specific AP type -// arguments: -// pcodec = pointer to a qra64codec data structure as returned by qra64_init -// aptype = define the type of AP to be disabled -// APTYPE_CQQRZ disable [cq/qrz ? ?/blank] -// APTYPE_MYCALL disable [mycall ? ?/blank] -// APTYPE_HISCALL disable [ ? hiscall ?/blank] -// APTYPE_BOTHCALLS disable [mycall hiscall ? ] -// APTYPE_FULL disable [mycall hiscall grid] -// APTYPE_CQHISCALL set [cq/qrz hiscall ?/blank] - -void qra64_close(qra64codec *pcodec); -// Free memory allocated by qra64_init -// arguments: -// pcodec = pointer to a qra64codec data structure as returned by qra64_init - -// ---------------------------------------------------------------------------- - -// encode/decode std msgs in 12 symbols as done in jt65 -void encodemsg_jt65(int *y, const int call1, const int call2, const int grid); -void decodemsg_jt65(int *call1, int *call2, int *grid, const int *x); - -#ifdef __cplusplus -} -#endif - -#endif // _qra64_h_ diff --git a/lib/qra/qra64/qra64_all.c b/lib/qra/qra64/qra64_all.c deleted file mode 100644 index 28f8ab92..00000000 --- a/lib/qra/qra64/qra64_all.c +++ /dev/null @@ -1,1050 +0,0 @@ -/* -qra64.c -Encoding/decoding functions for the QRA64 mode - -(c) 2016 - Nico Palermo, IV3NWV - -------------------------------------------------------------------------------- - - qracodes is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - qracodes is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with qracodes source distribution. - If not, see . - ------------------------------------------------------------------------------ - -QRA code used in this sowftware release: - -QRA13_64_64_IRR_E: K=13 N=64 Q=64 irregular QRA code (defined in -qra13_64_64_irr_e.h /.c) - -Codes with K=13 are designed to include a CRC as the 13th information symbol -and improve the code UER (Undetected Error Rate). -The CRC symbol is not sent along the channel (the codes are punctured) and the -resulting code is a (12,63) code -*/ -//---------------------------------------------------------------------------- - -#include -#include - -#include "qra64.h" -#include "../qracodes/qracodes.h" -#include "../qracodes/qra13_64_64_irr_e.h" -#include "../qracodes/pdmath.h" -#include "../qracodes/normrnd.h" - -// Code parameters of the QRA64 mode -#define QRA64_CODE qra_13_64_64_irr_e -#define QRA64_NMSG 218 // Must much value indicated in QRA64_CODE.NMSG - -#define QRA64_KC (QRA64_K+1) // Information symbols (crc included) -#define QRA64_NC (QRA64_N+1) // Codeword length (as defined in the code) -#define QRA64_NITER 100 // max number of iterations per decode - -// static functions declarations ---------------------------------------------- -static int calc_crc6(const int *x, int sz); -static void ix_mask(float *dst, const float *src, const int *mask, - const int *x); -static int qra64_decode_attempts(qra64codec *pcodec, int *xdec, const float *ix); -static int qra64_do_decode(int *x, const float *pix, const int *ap_mask, - const int *ap_x); -static float qra64_fastfading_estim_noise_std( - float *rxen, - const float esnometric, - const int submode); -static void qra64_fastfading_intrinsics( - float *pix, - const float *rxamp, - const float *hptr, - const int hlen, - const float cmetric, - const int submode); -static float qra64_fastfading_msg_esno( - const int *ydec, - const float *rxamp, - const float sigma, - const float EsNoMetric, - const int hlen, - const int submode); - - -// a-priori information masks for fields in JT65-like msgs -------------------- -#define MASK_CQQRZ 0xFFFFFFC // CQ/QRZ calls common bits -#define MASK_CALL1 0xFFFFFFF -#define MASK_CALL2 0xFFFFFFF -#define MASK_GRIDFULL 0xFFFF -#define MASK_GRIDFULL12 0x3FFC // less aggressive mask (to be used with full AP decoding) -#define MASK_GRIDBIT 0x8000 // b[15] is 1 for free text, 0 otherwise -// ---------------------------------------------------------------------------- - -qra64codec *qra64_init(int flags) -{ - - // Eb/No value for which we optimize the decoder metric - const float EbNodBMetric = 2.8f; - const float EbNoMetric = (float)pow(10,EbNodBMetric/10); - const float R = 1.0f*(QRA64_KC)/(QRA64_NC); - - qra64codec *pcodec = (qra64codec*)malloc(sizeof(qra64codec)); - - if (!pcodec) - return 0; // can't allocate memory - - pcodec->decEsNoMetric = 1.0f*QRA64_m*R*EbNoMetric; - pcodec->apflags = flags; - - memset(pcodec->apmsg_set,0,APTYPE_SIZE*sizeof(int)); - - if (flags==QRA_NOAP) - return pcodec; - - // for QRA_USERAP and QRA_AUTOAP modes we always enable [CQ/QRZ ? ?] mgs look-up. - // encode CQ/QRZ AP messages - // NOTE: Here we handle only CQ and QRZ msgs. - // 'CQ nnn', 'CQ DX' and 'DE' msgs will be handled by the decoder - // as messages with no a-priori knowledge - qra64_apset(pcodec, CALL_CQ, 0, GRID_BLANK, APTYPE_CQQRZ); - - // initialize masks for decoding with a-priori information - encodemsg_jt65(pcodec->apmask_cqqrz, MASK_CQQRZ, 0, MASK_GRIDBIT); - encodemsg_jt65(pcodec->apmask_cqqrz_ooo, MASK_CQQRZ, 0, MASK_GRIDFULL); - encodemsg_jt65(pcodec->apmask_call1, MASK_CALL1, 0, MASK_GRIDBIT); - encodemsg_jt65(pcodec->apmask_call1_ooo, MASK_CALL1, 0, MASK_GRIDFULL); - encodemsg_jt65(pcodec->apmask_call2, 0, MASK_CALL2, MASK_GRIDBIT); - encodemsg_jt65(pcodec->apmask_call2_ooo, 0, MASK_CALL2, MASK_GRIDFULL); - encodemsg_jt65(pcodec->apmask_call1_call2, MASK_CALL1,MASK_CALL2, MASK_GRIDBIT); - encodemsg_jt65(pcodec->apmask_call1_call2_grid,MASK_CALL1,MASK_CALL2, MASK_GRIDFULL12); - encodemsg_jt65(pcodec->apmask_cq_call2, MASK_CQQRZ, MASK_CALL2, MASK_GRIDBIT); - encodemsg_jt65(pcodec->apmask_cq_call2_ooo, MASK_CQQRZ, MASK_CALL2, MASK_GRIDFULL12); - - return pcodec; -} - -void qra64_close(qra64codec *pcodec) -{ - free(pcodec); -} - -int qra64_apset(qra64codec *pcodec, const int mycall, const int hiscall, const int grid, const int aptype) -{ -// Set decoder a-priori knowledge accordingly to the type of the message to look up for -// arguments: -// pcodec = pointer to a qra64codec data structure as returned by qra64_init -// mycall = mycall to look for -// hiscall = hiscall to look for -// grid = grid to look for -// aptype = define and masks the type of AP to be set accordingly to the following: -// APTYPE_CQQRZ set [cq/qrz ? ?/blank] -// APTYPE_MYCALL set [mycall ? ?/blank] -// APTYPE_HISCALL set [? hiscall ?/blank] -// APTYPE_BOTHCALLS set [mycall hiscall ?] -// APTYPE_FULL set [mycall hiscall grid] -// APTYPE_CQHISCALL set [cq/qrz hiscall ?/blank] and [cq/qrz hiscall grid] -// returns: -// 0 on success -// -1 when qra64_init was called with the QRA_NOAP flag -// -2 invalid apytpe - - if (pcodec->apflags==QRA_NOAP) - return -1; - - switch (aptype) { - case APTYPE_CQQRZ: - encodemsg_jt65(pcodec->apmsg_cqqrz, CALL_CQ, 0, GRID_BLANK); - break; - case APTYPE_MYCALL: - encodemsg_jt65(pcodec->apmsg_call1, mycall, 0, GRID_BLANK); - break; - case APTYPE_HISCALL: - encodemsg_jt65(pcodec->apmsg_call2, 0, hiscall, GRID_BLANK); - break; - case APTYPE_BOTHCALLS: - encodemsg_jt65(pcodec->apmsg_call1_call2, mycall, hiscall, GRID_BLANK); - break; - case APTYPE_FULL: - encodemsg_jt65(pcodec->apmsg_call1_call2_grid, mycall, hiscall, grid); - break; - case APTYPE_CQHISCALL: - encodemsg_jt65(pcodec->apmsg_cq_call2, CALL_CQ, hiscall, GRID_BLANK); - encodemsg_jt65(pcodec->apmsg_cq_call2_grid, CALL_CQ, hiscall, grid); - break; - default: - return -2; // invalid ap type - } - - pcodec->apmsg_set[aptype]=1; // signal the decoder to look-up for the specified type - - - return 0; -} -void qra64_apdisable(qra64codec *pcodec, const int aptype) -{ - if (pcodec->apflags==QRA_NOAP) - return; - - if (aptype=APTYPE_SIZE) - return; - - pcodec->apmsg_set[aptype] = 0; // signal the decoder not to look-up to the specified type -} - -void qra64_encode(qra64codec *pcodec, int *y, const int *x) -{ - int encx[QRA64_KC]; // encoder input buffer - int ency[QRA64_NC]; // encoder output buffer - - int hiscall,mycall,grid; - - memcpy(encx,x,QRA64_K*sizeof(int)); // Copy input to encoder buffer - encx[QRA64_K]=calc_crc6(encx,QRA64_K); // Compute and add crc symbol - qra_encode(&QRA64_CODE, ency, encx); // encode msg+crc using given QRA code - - // copy codeword to output puncturing the crc symbol - memcpy(y,ency,QRA64_K*sizeof(int)); // copy information symbols - memcpy(y+QRA64_K,ency+QRA64_KC,QRA64_C*sizeof(int)); // copy parity symbols - - if (pcodec->apflags!=QRA_AUTOAP) - return; - - // Here we handle the QRA_AUTOAP mode -------------------------------------------- - - // When a [hiscall mycall ?] msg is detected we instruct the decoder - // to look for [mycall hiscall ?] msgs - // otherwise when a [cq mycall ?] msg is sent we reset the APTYPE_BOTHCALLS - - // look if the msg sent is a std type message (bit15 of grid field = 0) - if ((x[9]&0x80)==1) - return; // no, it's a text message, nothing to do - - // It's a [hiscall mycall grid] message - - // We assume that mycall is our call (but we don't check it) - // hiscall the station we are calling or a general call (CQ/QRZ/etc..) - decodemsg_jt65(&hiscall,&mycall,&grid,x); - - - if ((hiscall>=CALL_CQ && hiscall<=CALL_CQ999) || hiscall==CALL_CQDX || - hiscall==CALL_DE) { - // tell the decoder to look for msgs directed to us - qra64_apset(pcodec,mycall,0,0,APTYPE_MYCALL); - // We are making a general call and don't know who might reply - // Reset APTYPE_BOTHCALLS so decoder won't look for [mycall hiscall ?] msgs - qra64_apdisable(pcodec,APTYPE_BOTHCALLS); - } else { - // We are replying to someone named hiscall - // Set APTYPE_BOTHCALLS so decoder will try for [mycall hiscall ?] msgs - qra64_apset(pcodec,mycall, hiscall, GRID_BLANK, APTYPE_BOTHCALLS); - } - -} - -#define EBNO_MIN -10.0f // minimum Eb/No value returned by the decoder (in dB) -int qra64_decode(qra64codec *pcodec, float *ebno, int *x, const float *rxen) -{ - int k; - float *srctmp, *dsttmp; - float ix[QRA64_NC*QRA64_M]; // (depunctured) intrisic information - int xdec[QRA64_KC]; // decoded message (with crc) - int ydec[QRA64_NC]; // re-encoded message (for snr calculations) - float noisestd; // estimated noise variance - float msge; // estimated message energy - float ebnoval; // estimated Eb/No - int rc; - - if (QRA64_NMSG!=QRA64_CODE.NMSG) // sanity check - return -16; // QRA64_NMSG define is wrong - - // compute symbols intrinsic probabilities from received energy observations - noisestd = qra_mfskbesselmetric(ix, rxen, QRA64_m, QRA64_N,pcodec->decEsNoMetric); - - // de-puncture observations adding a uniform distribution for the crc symbol - - // move check symbols distributions one symbol towards the end - dsttmp = PD_ROWADDR(ix,QRA64_M, QRA64_NC-1); //Point to last symbol prob dist - srctmp = dsttmp-QRA64_M; // source is the previous pd - for (k=0;k57.004f) - ebnoval=57.004f; - ebnoval = ebnoval*57.03f/(57.03f-ebnoval); - - // compute value in dB - if (ebnoval<=0) - ebnoval = EBNO_MIN; // assume a minimum, positive value - else - ebnoval = 10.0f*(float)log10(ebnoval); - if (ebnoval4) - return -17; // invalid submode - - if (B90<1.0f || B90>238.0f) - return -18; // B90 out of range - - // compute index to most appropriate amplitude weighting function coefficients - hidx = (int)(log((float)B90)/log(1.09f) - 0.499f); - - if (hidx<0 || hidx > 64) - return -19; // index of weighting function out of range - - if (fadingModel==0) { // gaussian fading model - // point to gaussian weighting taps - hlen = hlen_tab_gauss[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) - hptr = hptr_tab_gauss[hidx]; // pointer to the first (L+1)/2 coefficients of w fun - } - else if (fadingModel==1) { - // point to lorentzian weighting taps - hlen = hlen_tab_lorentz[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) - hptr = hptr_tab_lorentz[hidx]; // pointer to the first (L+1)/2 coefficients of w fun - } - else - return -20; // invalid fading model index - - - // compute (euristically) the optimal decoder metric accordingly the given spread amount - // We assume that the decoder threshold is: - // Es/No(dB) = Es/No(AWGN)(dB) + 8*log(B90)/log(240)(dB) - // that's to say, at the maximum Doppler spread bandwidth (240 Hz) there's a ~8 dB Es/No degradation - // over the AWGN case - tempf = 8.0f*(float)log((float)B90)/(float)log(240.0f); - EsNoMetric = pcodec->decEsNoMetric*(float)pow(10.0f,tempf/10.0f); - - // Step 1 ----------------------------------------------------------------------------------- - // Evaluate the noise stdev from the received energies at nominal tone frequencies - // and transform energies to amplitudes - tempf = hptr[hlen-1]; // amplitude weigth at nominal freq; - tempf = tempf*tempf; // fractional energy at nominal freq. bin - - noisestd = qra64_fastfading_estim_noise_std(rxen, EsNoMetric, submode); - cmetric = (float)sqrt(M_PI_2*EsNoMetric)/noisestd; - - // Step 2 ----------------------------------------------------------------------------------- - // Compute message symbols probability distributions - qra64_fastfading_intrinsics(ix, rxen, hptr, hlen, cmetric, submode); - - // Step 3 --------------------------------------------------------------------------- - // De-puncture observations adding a uniform distribution for the crc symbol - // Move check symbols distributions one symbol towards the end - dsttmp = PD_ROWADDR(ix,QRA64_M, QRA64_NC-1); //Point to last symbol prob dist - srctmp = dsttmp-QRA64_M; // source is the previous pd - for (k=0;k238.0f) - return -18; // B90 out of range - - // compute index to most appropriate amplitude weighting function coefficients - hidx = (int)(log((float)B90)/log(1.09f) - 0.499f); - - if (hidx<0 || hidx > 64) - return -19; // index of weighting function out of range - - if (fadingModel==0) { // gaussian fading model - // point to gaussian weighting taps - hlen = hlen_tab_gauss[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) - hptr = hptr_tab_gauss[hidx]; // pointer to the first (L+1)/2 coefficients of w fun - } - else if (fadingModel==1) { - // point to lorentzian weighting taps - hlen = hlen_tab_lorentz[hidx]; // hlen = (L+1)/2 (where L=(odd) number of taps of w fun) - hptr = hptr_tab_lorentz[hidx]; // pointer to the first (L+1)/2 coefficients of w fun - } - else - return -20; // invalid fading model index - - - // Compute the unfaded tone amplitudes from the Eb/No value passed to the call - N0 = 1.0f; // assume unitary noise PSD - sigmanoise = (float)sqrt(N0/2); - EsN0 = (float)pow(10.0f,EbN0dB/10.0f)*QRA64_m*QRA64_K/QRA64_N; // Es/No = m*R*Eb/No - Es = EsN0*N0; - A = (float)sqrt(Es/2.0f); // unfaded tone amplitude (i^2+q^2 = Es/2+Es/2 = Es) - - - // Generate gaussian noise iq components - normrnd_s(channel_out, bpm*2, 0 , sigmanoise); - - // Add message symbols energies - for (n=0;n=0;j--) { - sigmasig = A*hptr[j]; - normrnd_s(iq, 2, 0 , sigmasig); -// iq[0]=sigmasig*sqrt(2); iq[1]=0; debug: used to verify Eb/No - *curi++ += iq[0]; - *curq++ += iq[1]; -// tote +=iq[0]*iq[0]+iq[1]*iq[1]; // debug - } - - } - -// tote = tote/QRA64_N; // debug - - // compute total bin energies (S+N) and store in first half of buffer - curi = channel_out; - curq = channel_out+bpm; - for (n=0;n=0;j--) { - u = *curbin++ * hptr[j]*cmetric; - u = u*u/(u+(float)M_E); // log(I0(u)) approx. - loglh = loglh + u; - } - if (loglh>maxloglh) // keep track of the max loglikelihood - maxloglh = loglh; - curix[k]=loglh; - } - // scale to likelihoods - sumix = 0.f; - for (k=0;k=0;j--) { - u = *curbin++; - msgsn += u*u; - } - - } - - msgsn = msgsn/(QRA64_N*tothlen); // avg msg energy per bin (noise included) - - // as sigma is overestimated (sigmatrue = sigma*sqrt((1+EsNoMetric/bps)/(1+EsNo/bps)) - // we have: msgsn = (1+x/hlen)/(1+x/bps)*2*sigma^2*(1+EsnoMetric/bps), where x = Es/N0(true) - // - // we can then write: - // u = msgsn/2.0f/(sigma*sigma)/(1.0f+EsNoMetric/bps); - // (1+x/hlen)/(1+x/bps) = u - - u = msgsn/(2.0f*sigma*sigma)/(1.0f+EsNoMetric/bps); - - // check u>1 - if (u<1) - return 0.f; - - // check u(bps/tothlen)) - return 10000.f; - - // solve for Es/No - esno = (u-1.0f)/(1.0f/tothlen-u/bps); - - return esno; - - -} - - -// Attempt to decode given intrisic information -static int qra64_decode_attempts(qra64codec *pcodec, int *xdec, const float *ix) -{ - int rc; - - // Attempt to decode without a-priori info -------------------------------- - rc = qra64_do_decode(xdec, ix, NULL, NULL); - if (rc>=0) - return 0; // successfull decode with AP0 - else - if (pcodec->apflags==QRA_NOAP) - // nothing more to do - return rc; // rc<0 = unsuccessful decode - - // Here we handle decoding with AP knowledge - - // Attempt to decode CQ calls - rc = qra64_do_decode(xdec,ix,pcodec->apmask_cqqrz, pcodec->apmsg_cqqrz); - if (rc>=0) return 1; // decoded [cq/qrz ? ?] - - rc = qra64_do_decode(xdec, ix, pcodec->apmask_cqqrz_ooo, - pcodec->apmsg_cqqrz); - if (rc>=0) return 2; // decoded [cq ? ooo] - - // attempt to decode calls directed to us - if (pcodec->apmsg_set[APTYPE_MYCALL]) { - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1, - pcodec->apmsg_call1); - if (rc>=0) return 3; // decoded [mycall ? ?] - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_ooo, - pcodec->apmsg_call1); - if (rc>=0) return 4; // decoded [mycall ? ooo] - } - - // attempt to decode [mycall srccall ?] msgs - if (pcodec->apmsg_set[APTYPE_BOTHCALLS]) { - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_call2, - pcodec->apmsg_call1_call2); - if (rc>=0) return 5; // decoded [mycall srccall ?] - } - - // attempt to decode [? hiscall ?/b] msgs - if (pcodec->apmsg_set[APTYPE_HISCALL]) { - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call2, - pcodec->apmsg_call2); - if (rc>=0) return 6; // decoded [? hiscall ?] - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call2_ooo, - pcodec->apmsg_call2); - if (rc>=0) return 7; // decoded [? hiscall ooo] - } - - // attempt to decode [cq/qrz hiscall ?/b/grid] msgs - if (pcodec->apmsg_set[APTYPE_CQHISCALL]) { - - rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2, - pcodec->apmsg_cq_call2); - if (rc>=0) return 9; // decoded [cq/qrz hiscall ?] - - rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2_ooo, - pcodec->apmsg_cq_call2_grid); - if (rc>=0) { - // Full AP mask need special handling - // To minimize false decodes we check the decoded message - // with what passed in the ap_set call - if (memcmp(pcodec->apmsg_cq_call2_grid,xdec, QRA64_K*sizeof(int))!=0) - return -1; - else - return 11; // decoded [cq/qrz hiscall grid] - }; - - rc = qra64_do_decode(xdec, ix, pcodec->apmask_cq_call2_ooo, - pcodec->apmsg_cq_call2); - if (rc>=0) { - // Full AP mask need special handling - // To minimize false decodes we check the decoded message - // with what passed in the ap_set call - if (memcmp(pcodec->apmsg_cq_call2,xdec, QRA64_K*sizeof(int))!=0) - return -1; - else - return 10; // decoded [cq/qrz hiscall ] - } - } - - // attempt to decode [mycall hiscall grid] - if (pcodec->apmsg_set[APTYPE_FULL]) { - rc = qra64_do_decode(xdec, ix, pcodec->apmask_call1_call2_grid, - pcodec->apmsg_call1_call2_grid); - if (rc>=0) { - // Full AP mask need special handling - // All the three msg fields were given. - // To minimize false decodes we check the decoded message - // with what passed in the ap_set call - if (memcmp(pcodec->apmsg_call1_call2_grid,xdec, QRA64_K*sizeof(int))!=0) - return -1; - else - return 8; // decoded [mycall hiscall grid] - } - } - - // all decoding attempts failed - return rc; -} - - - -// Decode with given a-priori information -static int qra64_do_decode(int *xdec, const float *pix, const int *ap_mask, - const int *ap_x) -{ - int rc; - const float *ixsrc; - float ix_masked[QRA64_NC*QRA64_M]; // Masked intrinsic information - float ex[QRA64_NC*QRA64_M]; // Extrinsic information from the decoder - - float v2cmsg[QRA64_NMSG*QRA64_M]; // buffers for the decoder messages - float c2vmsg[QRA64_NMSG*QRA64_M]; - - if (ap_mask==NULL) { // no a-priori information - ixsrc = pix; // intrinsic source is what passed as argument - } else { - // a-priori information provided - // mask channel observations with a-priori - ix_mask(ix_masked,pix,ap_mask,ap_x); - ixsrc = ix_masked; // intrinsic source is the masked version - } - - // run the decoding algorithm - rc = qra_extrinsic(&QRA64_CODE,ex,ixsrc,QRA64_NITER,v2cmsg,c2vmsg); - if (rc<0) - return -1; // no convergence in given iterations - - // decode - qra_mapdecode(&QRA64_CODE,xdec,ex,ixsrc); - - // verify crc - if (calc_crc6(xdec,QRA64_K)!=xdec[QRA64_K]) // crc doesn't match (detected error) - return -2; // decoding was succesfull but crc doesn't match - - return 0; -} - - -// crc functions -------------------------------------------------------------- -// crc-6 generator polynomial -// g(x) = x^6 + a5*x^5 + ... + a1*x + a0 - -// g(x) = x^6 + x + 1 -#define CRC6_GEN_POL 0x30 // MSB=a0 LSB=a5 - -// g(x) = x^6 + x^2 + x + 1 (See: https://users.ece.cmu.edu/~koopman/crc/) -// #define CRC6_GEN_POL 0x38 // MSB=a0 LSB=a5. Simulation results are similar - -static int calc_crc6(const int *x, int sz) -{ - // todo: compute it faster using a look up table - int k,j,t,sr = 0; - for (k=0;k>1) ^ CRC6_GEN_POL; - else - sr = (sr>>1); - t>>=1; - } - } - return sr; -} - -static void ix_mask(float *dst, const float *src, const int *mask, - const int *x) -{ - // mask intrinsic information (channel observations) with a priori knowledge - - int k,kk, smask; - float *row; - - memcpy(dst,src,(QRA64_NC*QRA64_M)*sizeof(float)); - - for (k=0;k>22)&0x3F; - y[1]= (call1>>16)&0x3F; - y[2]= (call1>>10)&0x3F; - y[3]= (call1>>4)&0x3F; - y[4]= (call1<<2)&0x3F; - - y[4] |= (call2>>26)&0x3F; - y[5]= (call2>>20)&0x3F; - y[6]= (call2>>14)&0x3F; - y[7]= (call2>>8)&0x3F; - y[8]= (call2>>2)&0x3F; - y[9]= (call2<<4)&0x3F; - - y[9] |= (grid>>12)&0x3F; - y[10]= (grid>>6)&0x3F; - y[11]= (grid)&0x3F; - -} -void decodemsg_jt65(int *call1, int *call2, int *grid, const int *x) -{ - int nc1, nc2, ng; - - nc1 = x[4]>>2; - nc1 |= x[3]<<4; - nc1 |= x[2]<<10; - nc1 |= x[1]<<16; - nc1 |= x[0]<<22; - - nc2 = x[9]>>4; - nc2 |= x[8]<<2; - nc2 |= x[7]<<8; - nc2 |= x[6]<<14; - nc2 |= x[5]<<20; - nc2 |= (x[4]&0x03)<<26; - - ng = x[11]; - ng |= x[10]<<6; - ng |= (x[9]&0x0F)<<12; - - *call1 = nc1; - *call2 = nc2; - *grid = ng; -} diff --git a/lib/qra/qra64/qra64_subs.c b/lib/qra/qra64/qra64_subs.c deleted file mode 100644 index b60f9faf..00000000 --- a/lib/qra/qra64/qra64_subs.c +++ /dev/null @@ -1,65 +0,0 @@ -// qra64_subs.c -// Fortran interface routines for QRA64 - -#include "qra64.h" -#include - -static qra64codec *pqra64codec = NULL; - -void qra64_enc_(int x[], int y[]) -{ - if (pqra64codec==NULL) pqra64codec = qra64_init(QRA_USERAP); - qra64_encode(pqra64codec, y, x); -} - -void qra64_dec_(float r[], int* nc1, int* nc2, int* ng2, int* APtype, - int* iset, int* ns0, float* b0, int* nf0, - int xdec[], float* snr, int* rc) -{ -/* - APtype: AP ------------------------------------------------------------------------ - -1 0 (no AP information) - 0 [CQ/QRZ ? ? ] 25/37 - 1 [MyCall ? ? ] 25/37 - 2 [ ? HisCall ? ] 25/37 - 3 [MyCall HisCall ? ] 49/68 - 4 [MyCall HisCall grid] 68 - 5 [CQ/QRZ HisCall ? ] 49/68 - - rc Message format AP APTYPE Comments ------------------------------------------------------------------------- - -16 Failed sanity check - -2 Decoded but CRC failed - -1 No decode - 0 [ ? ? ? ] 0 -1 Decode with no AP info - 1 [CQ/QRZ ? ? ] 25 0 - 2 [CQ/QRZ ? _ ] 37 0 - 3 [MyCall ? ? ] 25 1 - 4 [MyCall ? _ ] 37 1 - 5 [MyCall HisCall ? ] 49 3 - 6 [ ? HisCall ? ] 25 2 Optional - 7 [ ? HisCall _ ] 37 2 Optional - 8 [MyCall HisCall Grid] 68 4 - 9 [CQ/QRZ HisCall ? ] 49 5 Optional (not needed?) - 10 [CQ/QRZ HisCall _ ] 68 5 Optional - 11 [CQ/QRZ HisCall Grid] 68 ? Optional -*/ - - float EbNodBEstimated; - int err=0; - int nSubmode=*ns0; - float b90=*b0; - int nFadingModel=*nf0; - - if(pqra64codec==NULL) pqra64codec = qra64_init(QRA_USERAP); - err=qra64_apset(pqra64codec,*nc1,*nc2,*ng2,*APtype); - if(err<0) printf("ERROR: qra64_apset returned %d\n",err); - - if(*iset==0) { - *rc = qra64_decode_fastfading(pqra64codec,&EbNodBEstimated,xdec,r, - nSubmode,b90,nFadingModel); - *snr = EbNodBEstimated - 31.0; - } -} - diff --git a/lib/qra/qra64/qra64example.txt b/lib/qra/qra64/qra64example.txt deleted file mode 100644 index 3add33d3..00000000 --- a/lib/qra/qra64/qra64example.txt +++ /dev/null @@ -1,88 +0,0 @@ -$ qra64_nico -h - -QRA64 Mode Tests -2016, Nico Palermo - IV3NWV - ---------------------------- - -Syntax: qra64 [-s] [-c] [-a] [-t] [-h] -Options: - -s : set simulation SNR in 2500 Hz BW (default:-27.5 dB) - -c : set channel type 0=AWGN (default) 1=Rayleigh - -a : set decode type 0=NOAP 1=AUTOAP (default) 2=USERAP - -t: 0=simulate seq of msgs between IV3NWV and K1JT (default) - 1=simulate K1JT receiving K1JT IV3NWV JN66 - 2=simulate fast-fading routines (option -c ignored) -Options used only for fast-fading simulations: - -b : 90% fading bandwidth in Hz [1..230 Hz] (default = 2.5 Hz) - -m : fading model. 0=Gauss, 1=Lorentz (default = Lorentz) - -q : qra64 submode. 0=QRA64A,... 4=QRA64E (default = QRA64A) - -h: this help - - -############################################################################# -Usage example: - -qra64 -c2 -t2 -a2 -b50 -m1 -q2 -s-26.0 -n50000 - -Simulate a fast-fading channel (-c2) -Evaluate decoder performance (-t2) with -USER_AP (-a2) -B90 = 50 Hz (-b50) -Lorentz model (-m1) -submode QRA64C (-q2) -Input SNR = -26.0 dB (-s-26.0) -Simulate 50000 transmissions (-n50000) - -(type qra64 -h for command syntax) - -Command Output: - -Input SNR = -26.0dB ap-mode=USER AP - -Simulating the fast-fading channel -B90=50.00 Hz - Fading Model=Lorentz - Submode=QRA64C -Decoder metric = Matched to fast-fading signal - -Encoding msg [K1JT IV3NWV JN66] -50000 transmissions will be simulated - -K1JT decoder enabled for [CQ ? ?/blank] -K1JT decoder enabled for [K1JT ? ?/blank] -K1JT decoder enabled for [? IV3NWV ?/blank] -K1JT decoder enabled for [K1JT IV3NWV ?] -K1JT decoder enabled for [K1JT IV3NWV JN66] -K1JT decoder enabled for [CQ IV3NWV ?/b/JN66] - -Now decoding with K1JT's decoder... - 5.5 % -Undetected error with rc=6 - 13.1 % -Undetected error with rc=7 - 70.8 % -Undetected error with rc=1 - 75.8 % -Undetected error with rc=9 - 88.9 % -Undetected error with rc=6 - 100.0 % - -Msgs transmitted:50000 -Msg decoded: - -rc= 0 0 with [? ? ?] AP0 -rc= 1 0 with [CQ ? ?] AP27 -rc= 2 0 with [CQ ? ] AP42 -rc= 3 145 with [CALL ? ?] AP29 -rc= 4 0 with [CALL ? ] AP44 -rc= 5 12085 with [CALL CALL ?] AP57 -rc= 6 0 with [? CALL ?] AP29 -rc= 7 0 with [? CALL ] AP44 -rc= 8 24307 with [CALL CALL G] AP72 -rc= 9 0 with [CQ CALL ?] AP55 -rc=10 0 with [CQ CALL ] AP70 -rc=11 0 with [CQ CALL G] AP70 - -Total: 36537/50000 (5 undetected errors) - -Estimated SNR (average in dB) = -26.26 dB diff --git a/lib/qra/qra64/qra64sim.f90 b/lib/qra/qra64/qra64sim.f90 deleted file mode 100644 index 2360ef7d..00000000 --- a/lib/qra/qra64/qra64sim.f90 +++ /dev/null @@ -1,201 +0,0 @@ -program qra64sim - -! Generate simulated QRA64 data for testing the decoder. - - use wavhdr - use packjt - parameter (NMAX=54*12000) ! = 648,000 - parameter (NFFT=10*65536,NH=NFFT/2) - type(hdr) h !Header for .wav file - integer*2 iwave(NMAX) !Generated waveform - integer*4 itone(84) !Channel symbols (values 0-63) - real*4 xnoise(NMAX) !Generated random noise - real*4 dat(NMAX) !Generated real data - complex cdat(NMAX) !Generated complex waveform - complex cspread(0:NFFT-1) !Complex amplitude for Rayleigh fading - complex z - complex c00(0:720000) !Analytic signal for dat() - real*8 f0,dt,twopi,phi,dphi,baud,fsample,freq - character msg*22,fname*11,csubmode*1,arg*12,cd*1 - character msgsent*22 - logical lsync - data lsync/.false./ - - nargs=iargc() - if(nargs.ne.8) then - print*,'Usage: qra64sim "msg" A-E Nsigs fDop DT Nfiles Sync SNR' - print*,'Example qra64sim "K1ABC W9XYZ EN37" A 10 0.2 0.0 1 T -26' - print*,'Sync = T to include sync test.' - go to 999 - endif - call getarg(1,msg) - call getarg(2,csubmode) - mode64=2**(ichar(csubmode)-ichar('A')) - call getarg(3,arg) - read(arg,*) nsigs - call getarg(4,arg) - read(arg,*) fspread - call getarg(5,arg) - read(arg,*) xdt - call getarg(6,arg) - read(arg,*) nfiles - call getarg(7,arg) - if(arg(1:1).eq.'T' .or. arg(1:1).eq.'1') lsync=.true. - call getarg(8,arg) - read(arg,*) snrdb - - if(mode64.ge.8) nsigs=1 - rms=100. - fsample=12000.d0 !Sample rate (Hz) - dt=1.d0/fsample !Sample interval (s) - twopi=8.d0*atan(1.d0) - npts=54*12000 !Total samples in .wav file - nsps=6912 - baud=12000.d0/nsps !Keying rate = 1.7361111111 - nsym=84 !Number of channel symbols - h=default_header(12000,npts) - dfsig=2000.0/nsigs !Freq spacing between sigs in file (Hz) - ichk=0 - - write(*,1000) -1000 format('File Sig Freq A-E S/N DT Dop Message'/60('-')) - - nsync=0 - do ifile=1,nfiles !Loop over requested number of files - write(fname,1002) ifile !Output filename -1002 format('000000_',i4.4) - open(10,file=fname//'.wav',access='stream',status='unknown') - xnoise=0. - cdat=0. - if(snrdb.lt.90) then - do i=1,npts - xnoise(i)=gran() !Generate gaussian noise - enddo - endif - - do isig=1,nsigs !Generate requested number of sigs - if(mod(nsigs,2).eq.0) f0=1500.0 + dfsig*(isig-0.5-nsigs/2) - if(mod(nsigs,2).eq.1) f0=1500.0 + dfsig*(isig-(nsigs+1)/2) - if(nsigs.eq.1) f0=1000.0 - xsnr=snrdb - if(snrdb.eq.0.0) xsnr=-20 - isig - - call genqra64(msg,ichk,msgsent,itone,itype) - - bandwidth_ratio=2500.0/6000.0 - sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*xsnr) - if(xsnr.gt.90.0) sig=1.0 - write(*,1020) ifile,isig,f0,csubmode,xsnr,xdt,fspread,msg -1020 format(i4,i4,f10.3,2x,a1,2x,f5.1,f6.2,f6.1,1x,a22) - - phi=0.d0 - dphi=0.d0 - k=(xdt+1.0)*12000 !Start audio at t = xdt + 1.0 s - isym0=-99 - do i=1,npts !Add this signal into cdat() - isym=i/nsps + 1 - if(isym.gt.nsym) exit - if(isym.ne.isym0) then - freq=f0 + itone(isym)*baud*mode64 - dphi=twopi*freq*dt - isym0=isym - endif - phi=phi + dphi - if(phi.gt.twopi) phi=phi-twopi - xphi=phi - z=cmplx(cos(xphi),sin(xphi)) - k=k+1 - if(k.ge.1) cdat(k)=cdat(k) + sig*z - enddo - enddo - - if(fspread.ne.0) then !Apply specified Doppler spread - df=12000.0/nfft - twopi=8*atan(1.0) - cspread(0)=1.0 - cspread(NH)=0. - b=6.0 !Use truncated Lorenzian shape for fspread - do i=1,NH - f=i*df - x=b*f/fspread - z=0. - a=0. - if(x.lt.3.0) then !Cutoff beyond x=3 - a=sqrt(1.111/(1.0+x*x)-0.1) !Lorentzian - call random_number(r1) - phi1=twopi*r1 - z=a*cmplx(cos(phi1),sin(phi1)) - endif - cspread(i)=z - z=0. - if(x.lt.50.0) then - call random_number(r2) - phi2=twopi*r2 - z=a*cmplx(cos(phi2),sin(phi2)) - endif - cspread(NFFT-i)=z - enddo - -! do i=0,NFFT-1 -! f=i*df -! if(i.gt.NH) f=(i-nfft)*df -! s=real(cspread(i))**2 + aimag(cspread(i))**2 -! write(13,3000) i,f,s,cspread(i) -!3000 format(i5,f10.3,3f12.6) -! enddo -! s=real(cspread(0))**2 + aimag(cspread(0))**2 -! write(13,3000) 1024,0.0,s,cspread(0) - - call four2a(cspread,NFFT,1,1,1) !Transform to time domain - - sum=0. - do i=0,NFFT-1 - p=real(cspread(i))**2 + aimag(cspread(i))**2 - sum=sum+p - enddo - avep=sum/NFFT - fac=sqrt(1.0/avep) - cspread=fac*cspread !Normalize to constant avg power - cdat=cspread(1:npts)*cdat !Apply Rayleigh fading - -! do i=0,NFFT-1 -! p=real(cspread(i))**2 + aimag(cspread(i))**2 -! write(14,3010) i,p,cspread(i) -!3010 format(i8,3f12.6) -! enddo - - endif - - dat=aimag(cdat) + xnoise !Add the generated noise - fac=32767.0/nsigs - if(snrdb.ge.90.0) iwave(1:npts)=nint(fac*dat(1:npts)) - if(snrdb.lt.90.0) iwave(1:npts)=nint(rms*dat(1:npts)) - write(10) h,iwave(1:npts) !Save the .wav file - close(10) - - if(lsync) then - cd=' ' - if(ifile.eq.nfiles) cd='d' - nf1=200 - nf2=3000 - nfqso=nint(f0) - ntol=100 - minsync=0 - emedelay=0.0 - call ana64(dat,npts,c00) - call sync64(c00,nf1,nf2,nfqso,ntol,minsync,mode64,emedelay,xdt2,f02, & - jpk0,sync,sync2,width) - terr=1.01/(8.0*baud) - ferr=1.01*mode64*baud - if(abs(xdt2-xdt).lt.terr .and. abs(f02-f0).lt.ferr) nsync=nsync+1 - open(40,file='sync64.out',status='unknown',position='append') - write(40,1030) ifile,64,csubmode,snrdb,fspread,xdt2-xdt,f02-f0, & - width,sync,sync2,nsync,cd -1030 format(i4,i3,1x,a1,2f7.1,f7.2,4f8.1,i5,1x,a1) - close(40) - endif - enddo - if(lsync) write(*,1040) snrdb,nfiles,nsync -1040 format('SNR:',f6.1,' nfiles:',i5,' nsynced:',i5) - -999 end program qra64sim diff --git a/lib/qra_loops.f90 b/lib/qra_loops.f90 deleted file mode 100644 index cebd7036..00000000 --- a/lib/qra_loops.f90 +++ /dev/null @@ -1,137 +0,0 @@ -subroutine qra_loops(c00,npts2,nsps,mode,mode64,nsubmode,nFadingModel, & - ndepth,nc1,nc2,ng2,naptype,jpk0,xdt,f0,width,snr2,irc,dat4) - - use packjt - use timer_module, only: timer - parameter (LN=2176*63) !LN=LL*NN; LL = 64*(mode64+2) - character*37 decoded - complex c00(0:npts2-1) !Analytic representation of dd(), 6000 Hz - complex ,allocatable :: c0(:) !Ditto, with freq shift - real a(3) !twkfreq params f,f1,f2 - real s3(LN) !Symbol spectra - real s3avg(LN) !Averaged symbol spectra - integer dat4(12),dat4x(12) !Decoded message (as 12 integers) - integer nap(0:11) !AP return codes - data nap/0,2,3,2,3,4,2,3,6,4,6,6/,nsave/0/ - save nsave,s3avg - - allocate(c0(0:npts2-1)) - irc=-99 - s3lim=20. - ibwmax=11 - if(mode64.le.4) ibwmax=9 - ibwmin=ibwmax - idtmax=3 - call qra_params(ndepth,maxaptype,idfmax,idtmax,ibwmin,ibwmax,maxdist) - LL=64*(mode64+2) - NN=63 - napmin=99 - ncall=0 - - do iavg=0,1 - if(iavg.eq.1) then - idfmax=1 - idtmax=1 - endif - do idf=1,idfmax - ndf=idf/2 - if(mod(idf,2).eq.0) ndf=-ndf - a=0. - a(1)=-(f0+0.4*ndf) - call twkfreq(c00,c0,npts2,6000.0,a) - do idt=1,idtmax - ndt=idt/2 - if(iavg.eq.0) then - if(mod(idt,2).eq.0) ndt=-ndt - jpk=jpk0 + 240*ndt !240/6000 = 0.04 s = tsym/32 - if(jpk.lt.0) jpk=0 - call timer('spec64 ',0) - call spec64(c0,nsps,mode,mode64,jpk,s3,LL,NN) - call timer('spec64 ',1) - call pctile(s3,LL*NN,40,base) - s3=s3/base - where(s3(1:LL*NN)>s3lim) s3(1:LL*NN)=s3lim - else - s3(1:LL*NN)=s3avg(1:LL*NN) - endif - do ibw=ibwmax,ibwmin,-2 - ndist=ndf**2 + ndt**2 + ((ibwmax-ibw)/2)**2 - if(ndist.gt.maxdist) cycle - b90=1.728**ibw - if(b90.gt.230.0) cycle - if(b90.lt.0.15*width) exit - ncall=ncall+1 - call timer('qra64_de',0) - call qra64_dec(s3,nc1,nc2,ng2,naptype,0,nSubmode,b90, & - nFadingModel,dat4,snr2,irc) - call timer('qra64_de',1) - if(irc.eq.0) go to 200 - if(irc.gt.0) call badmsg(irc,dat4,nc1,nc2,ng2) - iirc=max(0,min(irc,11)) - if(irc.gt.0 .and. nap(iirc).lt.napmin) then - dat4x=dat4 - b90x=b90 - snr2x=snr2 - napmin=nap(iirc) - irckeep=irc - xdtkeep=jpk/6000.0 - 1.0 - f0keep=-a(1) - idfkeep=idf - idtkeep=idt - ibwkeep=ibw - ndistx=ndist - go to 100 !### - endif - enddo ! ibw (b90 loop) - !### if(iand(ndepth,3).lt.3 .and. irc.ge.0) go to 100 - enddo ! idt (DT loop) - enddo ! idf (f0 loop) -! if(iavg.eq.0 .and. abs(jpk0-4320).le.1300) then - if(iavg.eq.0) then - a=0. - a(1)=-f0 - call twkfreq(c00,c0,npts2,6000.0,a) - jpk=3000 !### These definitions need work ### -! if(nsps.ge.3600) jpk=4080 !### - if(nsps.ge.3600) jpk=6000 !### - call spec64(c0,nsps,mode,mode64,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 - s3avg(1:LL*NN)=s3avg(1:LL*NN)+s3(1:LL*NN) - nsave=nsave+1 - endif - if(iavg.eq.0 .and. nsave.lt.2) exit - enddo ! iavg - -100 if(napmin.ne.99) then - dat4=dat4x - b90=b90x - snr2=snr2x - irc=irckeep - xdt=xdtkeep - f0=f0keep - idt=idtkeep - idf=idfkeep - ibw=ibwkeep - ndist=ndistx - endif - -200 if(mode.eq.65 .and. nsps.eq.7200/2) xdt=xdt+0.4 !### Empirical -- WHY ??? ### - - if(irc.ge.0) then - navg=nsave - if(iavg.eq.0) navg=0 - !### For tests only: - open(53,file='fort.53',status='unknown',position='append') - call unpackmsg(dat4,decoded) !Unpack the user message - write(53,3053) idf,idt,ibw,b90,xdt,f0,snr2,ndist,irc,navg,decoded(1:22) -3053 format(3i5,f7.1,f7.2,2f7.1,3i4,2x,a22) - close(53) - !### - nsave=0 - s3avg=0. - irc=irc + 100*navg - endif - return -end subroutine qra_loops diff --git a/lib/symspec.f90 b/lib/symspec.f90 index 707a6368..8f5ddd09 100644 --- a/lib/symspec.f90 +++ b/lib/symspec.f90 @@ -140,20 +140,20 @@ subroutine chk_samples(ihsym,k,nstop) call system_clock(count0,clkfreq) maxhsym=0 endif - if((mod(ihsym,100).eq.0 .or. ihsym.ge.nstop-100) .and. & - k0.ne.99999999) then - call system_clock(count1,clkfreq) - dtime=dfloat(count1-count0)/dfloat(clkfreq) - if(dtime.lt.28.0) return - if(dtime.gt.1.d-6) fsample=(k-3456)/dtime - call date_and_time(values=itime) - sec=itime(7)+0.001*itime(8) - write(ctime,3000) itime(5)-itime(4)/60,itime(6),sec -3000 format(i2.2,':',i2.2,':',f6.3) - write(33,3033) ctime,dtime,ihsym,nstop,k,fsample -3033 format(a12,f12.6,2i7,i10,f15.3) - flush(33) - endif +! if((mod(ihsym,100).eq.0 .or. ihsym.ge.nstop-100) .and. & +! k0.ne.99999999) then +! call system_clock(count1,clkfreq) +! dtime=dfloat(count1-count0)/dfloat(clkfreq) +! if(dtime.lt.28.0) return +! if(dtime.gt.1.d-6) fsample=(k-3456)/dtime +! call date_and_time(values=itime) +! sec=itime(7)+0.001*itime(8) +! write(ctime,3000) itime(5)-itime(4)/60,itime(6),sec +!3000 format(i2.2,':',i2.2,':',f6.3) +! write(33,3033) ctime,dtime,ihsym,nstop,k,fsample +!3033 format(a12,f12.6,2i7,i10,f15.3) +! flush(33) +! endif k0=k return diff --git a/lib/sync4.f90 b/lib/sync4.f90 index 9bfe6c60..00387fdb 100644 --- a/lib/sync4.f90 +++ b/lib/sync4.f90 @@ -29,7 +29,7 @@ subroutine sync4(dat,jz,ntol,nfqso,mode,mode4,minwidth,dtx,dfx,snrx, & df=0.5*11025.0/nfft ftop=nfqso + 7*mode4*df if(ftop.gt.11025.0/4.0) then - print*,'*** Rx Freq is set too high for this sybmode ***' + print*,'*** Rx Freq is set too high for this submode ***' go to 900 endif @@ -85,7 +85,7 @@ subroutine sync4(dat,jz,ntol,nfqso,mode,mode4,minwidth,dtx,dfx,snrx, & enddo if(syncbest.lt.-1.e29) go to 900 ccfred=red - call pctile(ccfred(iaa:ibb),ibb-iaa+1,45,base) + call pctile(ccfred(ia:ib),ib-ia+1,45,base) ccfred=ccfred-base dfx=ipk*df diff --git a/lib/sync64.f90 b/lib/sync64.f90 deleted file mode 100644 index e9581430..00000000 --- a/lib/sync64.f90 +++ /dev/null @@ -1,164 +0,0 @@ -subroutine sync64(c0,nf1,nf2,nfqso,ntol,minsync,mode64,emedelay,dtx,f0, & - jpk,sync,sync2,width) - - use timer_module, only: timer - - parameter (NMAX=60*12000) !Max size of raw data at 12000 Hz - parameter (NSPS=3456) !Samples per symbol at 6000 Hz - parameter (NSPC=7*NSPS) !Samples per Costas waveform - real s1(0:NSPC-1) !Power spectrum of Costas 1 - real s2(0:NSPC-1) !Power spectrum of Costas 2 - real s3(0:NSPC-1) !Power spectrum of Costas 3 - real s0(0:NSPC-1) !Sum of s1+s2+s3 - real s0a(0:NSPC-1) !Best synchromized spectrum (saved) - real s0b(0:NSPC-1) !tmp - real a(5) !Parameters of Lorentzian fit - integer icos7(0:6) !Costas 7x7 tones - integer ipk0(1) - complex cc(0:NSPC-1) !Costas waveform - complex c0(0:720000) !Complex spectrum of dd() - complex c1(0:NSPC-1) !Complex spectrum of Costas 1 - complex c2(0:NSPC-1) !Complex spectrum of Costas 2 - complex c3(0:NSPC-1) !Complex spectrum of Costas 3 - data icos7/2,5,6,0,4,1,3/ !Costas 7x7 tone pattern - data mode64z/-1/ - save - - if(mode64.ne.mode64z) then -! Submode has changed, recompute the complex Costas waveform - twopi=8.0*atan(1.0) - dfgen=mode64*12000.0/6912.0 - k=-1 - phi=0. - do j=0,6 - dphi=twopi*10.0*icos7(j)*dfgen/6000.0 - do i=1,NSPS - phi=phi + dphi - if(phi.gt.twopi) phi=phi-twopi - k=k+1 - cc(k)=cmplx(cos(phi),sin(phi)) - enddo - enddo - mode64z=mode64 - endif - - nfft3=NSPC - df3=6000.0/nfft3 - - fa=max(nf1,nfqso-ntol) - fb=min(nf2,nfqso+ntol) - iaa=max(0,nint(fa/df3)) - ibb=min(NSPC-1,nint(fb/df3)) - - maxtol=max(ntol,500) - fa=max(nf1,nfqso-maxtol) - fb=min(nf2,nfqso+maxtol) - ia=max(0,nint(fa/df3)) - ib=min(NSPC-1,nint(fb/df3)) - id=0.1*(ib-ia) - iz=ib-ia+1 - sync=-1.e30 - smaxall=0. - jpk=0 - ja=0 -! jb=(5.0+emedelay)*6000 !Bigger range than necessary? - jb=(2.0+emedelay)*6000 !Bigger range than necessary? - jstep=100 - ipk=0 - kpk=0 - nadd=10*mode64 - if(minsync.eq.-2) nadd=10 !### - if(mod(nadd,2).eq.0) nadd=nadd+1 !Make nadd odd - nskip=max(49,nadd) - - do j1=ja,jb,jstep !Loop over DT - call timer('sync64_1',0) - j2=j1 + 39*NSPS - j3=j1 + 77*NSPS - c1=1.e-4*c0(j1:j1+NSPC-1) * conjg(cc) - c2=1.e-4*c0(j2:j2+NSPC-1) * conjg(cc) - c3=1.e-4*c0(j3:j3+NSPC-1) * conjg(cc) - call four2a(c1,nfft3,1,-1,1) - call four2a(c2,nfft3,1,-1,1) - call four2a(c3,nfft3,1,-1,1) - s1=0. - s2=0. - s3=0. - s0b=0. - do i=ia,ib - freq=i*df3 - s1(i)=real(c1(i))**2 + aimag(c1(i))**2 - s2(i)=real(c2(i))**2 + aimag(c2(i))**2 - s3(i)=real(c3(i))**2 + aimag(c3(i))**2 - enddo - call timer('sync64_1',1) - - call timer('sync64_2',0) - s0(ia:ib)=s1(ia:ib) + s2(ia:ib) + s3(ia:ib) - s0(:ia-1)=0. - s0(ib+1:)=0. - if(nadd.ge.3) then !Smooth the spectrum - iiz=3 - if(minsync.eq.-2) iiz=1 - do ii=1,iiz !### Was ii=1,3 - s0b(ia:ib)=s0(ia:ib) - call smo(s0b(ia:ib),iz,s0(ia:ib),nadd) - enddo - endif - call averms(s0(ia+id:ib-id),iz-2*id,nskip,ave,rms) - s=(maxval(s0(iaa:ibb))-ave)/rms - ipk0=maxloc(s0(iaa:ibb)) - ip=ipk0(1) + iaa - 1 - if(s.gt.sync) then - jpk=j1 - s0a=(s0-ave)/rms - sync=s - dtx=jpk/6000.0 - 1.0 - ipk=ip - f0=ip*df3 - endif - call timer('sync64_2',1) - enddo ! j1 (DT loop) - - s0a=s0a+2.0 - - nskip=50 - call lorentzian(s0a(ia+nskip:ib-nskip),iz-2*nskip,a) - f0a=(a(3)+ia+49)*df3 - w1=df3*a(4) - w2=2*nadd*df3 - width=w1 - if(w1.gt.1.2*w2) width=sqrt(w1**2 - w2**2) - - sq=0. - do i=1,20 - j=ia+nskip+1 - k=ib-nskip-21+i - sq=sq + (s0a(j)-a(1))**2 + (s0a(k)-a(1))**2 - enddo - rms2=sqrt(sq/40.0) - sync2=10.0*log10(a(2)/rms2) - - slimit=6.0 - rewind 17 - write(17,1110) 0.0,0.0 - rewind 17 - do i=2,iz-2*nskip-1,3 - x=i - z=(x-a(3))/(0.5*a(4)) - yfit=a(1) - if(abs(z).lt.3.0) then - d=1.0 + z*z - yfit=a(1) + a(2)*(1.0/d - 0.1) - endif - j=i+ia+49 - freq=j*df3 - ss=(s0a(j-1)+s0a(j)+s0a(j+1))/3.0 - if(ss.gt.slimit) write(17,1110) freq,ss -1110 format(3f10.3) - enddo - flush(17) - close(17) - - return -end subroutine sync64 diff --git a/lib/synciscat.f90 b/lib/synciscat.f90 deleted file mode 100644 index 747eeca6..00000000 --- a/lib/synciscat.f90 +++ /dev/null @@ -1,185 +0,0 @@ -subroutine synciscat(cdat,npts,nh,npct,s0,jsym,df,ntol, & - mousebutton,mode4,nafc,psavg,xsync,sig,ndf0,msglen, & - ipk,jpk,idf,df1) - -! Synchronize an ISCAT signal -! cdat() is the downsampled analytic signal. -! Sample rate = fsample = BW = 11025 * (9/32) = 3100.78125 Hz -! npts, nsps, etc., are all reduced by 9/32 - - parameter (NMAX=30*3101) - parameter (NSZ=4*1400) - complex cdat(NMAX) - complex c(288) - real s0(288,NSZ) - real fs0(288,96) !108 = 96 + 3*4 - real savg(288) - real sref(288) - real psavg(72) !Average spectrum of whole file - integer icos(4) - data icos/0,1,3,2/ - data nsync/4/,nlen/2/,ndat/18/ - -! Silence compiler warnings: - sigbest=-20.0 - ndf0best=0 - msglenbest=0 - ipkbest=0 - jpkbest=0 - ipk2=0 - idfbest=mousebutton - - fsample=3100.78125 !New sample rate - nsps=144/mode4 - nsym=npts/nsps - 1 - nblk=nsync+nlen+ndat - nfft=2*nsps !FFTs at twice the symbol length, - - kstep=nsps/4 ! stepped by 1/4 symbol - df=fsample/nfft - fac=1.0/1000.0 !Somewhat arbitrary - savg=0. - s0=0. - - ia=1-kstep - do j=1,4*nsym !Compute symbol spectra - ia=ia+kstep - ib=ia+nsps-1 - if(ib.gt.npts) exit - c(1:nsps)=fac*cdat(ia:ib) - c(nsps+1:nfft)=0. - call four2a(c,nfft,1,-1,1) - do i=1,nfft - s0(i,j)=real(c(i))**2 + aimag(c(i))**2 - savg(i)=savg(i) + s0(i,j) !Accumulate avg spectrum - enddo - i0=40 - enddo - - jsym=4*nsym - savg=savg/jsym - - do i=1,71 !Compute spectrum in dB, for plot - if(mode4.eq.1) then - psavg(i)=2*db(savg(4*i)+savg(4*i-1)+savg(4*i-2)+savg(4*i-3)) + 1.0 - else - psavg(i)=2*db(savg(2*i)+savg(2*i-1)) + 7.0 - endif - enddo - - do i=nh+1,nfft-nh - call pctile(savg(i-nh),2*nh+1,npct,sref(i)) - enddo - sref(1:nh)=sref(nh+11) - sref(nfft-nh+1:nfft)=sref(nfft-nh) - - do i=1,nfft !Normalize the symbol spectra - fac=1.0/sref(i) - if(i.lt.11) fac=1.0/savg(11) - do j=1,jsym - s0(i,j)=fac*s0(i,j) - enddo - enddo - - nfold=jsym/96 - jb=96*nfold - - ttot=npts/fsample !Length of record (s) - df1=df/ttot !Step size for f1=fdot - idf1=int(-25.0/df1) - idf2=int(5.0/df1) - if(nafc.eq.0) then - idf1=0 - idf2=0 - else if(mod(-idf1,2).eq.1) then - idf1=idf1-1 - endif - - xsyncbest=0. - do idf=idf1,idf2 !Loop over fdot - fs0=0. - do j=1,jb !Fold s0 into fs0, modulo 4*nblk - k=mod(j-1,4*nblk)+1 - ii=nint(idf*float(j-jb/2)/float(jb)) - ia=max(1-ii,1) - ib=min(nfft-ii,nfft) - do i=ia,ib - fs0(i,k)=fs0(i,k) + s0(i+ii,j) - enddo - enddo - ref=nfold*4 - - i0=27 - if(mode4.eq.1) i0=95 - ia=i0-nint(ntol/df) - ib=i0+nint(ntol/df) - if(ia.lt.1) ia=1 - if(ib.gt.nfft-3) ib=nfft-3 - - smax=0. - ipk=1 - jpk=1 - do j=0,4*nblk-1 !Find sync pattern: lags 0-95 - do i=ia,ib !Search specified freq range - ss=0. - do n=1,4 !Sum over 4 sync tones - k=j+4*n-3 - if(k.gt.96) k=k-96 - ss=ss + fs0(i+2*icos(n),k) - enddo - if(ss.gt.smax) then - smax=ss - ipk=i !Frequency offset, DF - jpk=j+1 !Time offset, DT - endif - enddo - enddo - - xsync=smax/ref - 1.0 - if(nfold.lt.26) xsync=xsync * sqrt(nfold/26.0) - xsync=xsync-0.5 !Empirical - - sig=db(smax/ref - 1.0) - 15.0 - if(mode4.eq.1) sig=sig-5.0 -! if(sig.lt.-20 .or. xsync.lt.1.0) sig=-20.0 -! if(sig.lt.-20) sig=-20.0 - ndf0=nint(df*(ipk-i0)) - - smax=0. - ja=jpk+16 - if(ja.gt.4*nblk) ja=ja-4*nblk - jj=jpk+20 - if(jj.gt.4*nblk) jj=jj-4*nblk - do i=ipk,ipk+60,2 !Find User's message length - ss=fs0(i,ja) + fs0(i+10,jj) - if(ss.gt.smax) then - smax=ss - ipk2=i - endif - enddo - - msglen=(ipk2-ipk)/2 - if(msglen.lt.2 .or. msglen.gt.29) cycle - - if(xsync.ge.xsyncbest) then - xsyncbest=xsync - sigbest=sig - ndf0best=ndf0 - msglenbest=msglen - ipkbest=ipk - jpkbest=jpk - idfbest=idf - endif - enddo - - xsync=xsyncbest - sig=sigbest - ndf0=ndf0best - msglen=msglenbest - ipk=ipkbest - jpk=jpkbest - idf=idfbest - if(nafc.eq.0) idf=0 - - return -end subroutine synciscat diff --git a/lib/test_q65.f90 b/lib/test_q65.f90 index 29d3ebef..4135a290 100644 --- a/lib/test_q65.f90 +++ b/lib/test_q65.f90 @@ -103,7 +103,7 @@ program test_q65 dterr=tsym/4.0 nferr=max(1,nint(0.5*baud),nint(fdop/3.0)) ndec1z=nfiles - + do nsnr=ia,ib,-1 snr1=nsnr if(ia.eq.99) snr1=snr -- cgit v1.2.3