summaryrefslogtreecommitdiff
path: root/lib/ft8
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2018-12-19 23:01:50 +0100
committerChristoph Berg <myon@debian.org>2018-12-19 23:01:50 +0100
commit5c60c77adff9a54fd5f94f9915b22ccd8c4c5a3b (patch)
tree410fa358a5f73260a579b4d669730f319a4d2609 /lib/ft8
parent6c82050de806dcdafaed0077400a6c3396a4a159 (diff)
parente0737c56c1e384e05064a0c6e1ac46979371041b (diff)
Update upstream source from tag 'upstream/2.0.0+repack'
Update to upstream version '2.0.0+repack' with Debian dir 55dbb3a6a7eb189e187dd79f732623ca0b56116d
Diffstat (limited to 'lib/ft8')
-rw-r--r--lib/ft8/DXpedQuickStart.txt126
-rw-r--r--lib/ft8/baseline.f9048
-rw-r--r--lib/ft8/bpdecode174_91.f90115
-rw-r--r--lib/ft8/chkcrc13a.f9024
-rw-r--r--lib/ft8/chkcrc14a.f9024
-rw-r--r--lib/ft8/compress.f9037
-rw-r--r--lib/ft8/encode174.f9050
-rw-r--r--lib/ft8/encode174_91.f9058
-rw-r--r--lib/ft8/extractmessage174.f9040
-rw-r--r--lib/ft8/extractmessage174_91.f9040
-rw-r--r--lib/ft8/filt8.f9052
-rw-r--r--lib/ft8/foxfilt.f9036
-rw-r--r--lib/ft8/foxgen.f9095
-rw-r--r--lib/ft8/foxgen_wrap.f9025
-rw-r--r--lib/ft8/ft8_downsample.f9052
-rw-r--r--lib/ft8/ft8_params.f9012
-rw-r--r--lib/ft8/ft8_testmsg.f9051
-rw-r--r--lib/ft8/ft8apset.f9043
-rw-r--r--lib/ft8/ft8b.f90468
-rw-r--r--lib/ft8/ft8code.f9083
-rw-r--r--lib/ft8/ft8d.f9063
-rw-r--r--lib/ft8/ft8sim.f90141
-rw-r--r--lib/ft8/genft8.f9046
-rw-r--r--lib/ft8/genft8refsig.f9023
-rw-r--r--lib/ft8/h1.f9017
-rw-r--r--lib/ft8/ldpc_174_87_params.f90102
-rw-r--r--lib/ft8/ldpc_174_91_c_colorder.f9011
-rw-r--r--lib/ft8/ldpc_174_91_c_generator.f9086
-rw-r--r--lib/ft8/ldpc_174_91_c_parity.f90269
-rw-r--r--lib/ft8/ldpc_174_91_c_reordered_parity.f90270
-rw-r--r--lib/ft8/osd174_91.f90372
-rw-r--r--lib/ft8/subtractft8.f9061
-rw-r--r--lib/ft8/sync8.f90142
-rw-r--r--lib/ft8/sync8d.f9054
-rw-r--r--lib/ft8/twkfreq1.f9026
-rw-r--r--lib/ft8/watterson.f9065
36 files changed, 3227 insertions, 0 deletions
diff --git a/lib/ft8/DXpedQuickStart.txt b/lib/ft8/DXpedQuickStart.txt
new file mode 100644
index 00000000..1d6ac3e0
--- /dev/null
+++ b/lib/ft8/DXpedQuickStart.txt
@@ -0,0 +1,126 @@
+ Quick Start for DXpedition Mode
+ -------------------------------
+
+These notes are intended for operators already familiar with WSJT-X
+and FT8 mode. QSOs between the Dxpedition ("Fox") and other stations
+("Hounds") are completed with as little as one transmission per Hound,
+as in the following examples:
+
+----------------------------------------------------------------------------
+ Fox (300-600 Hz) Hounds
+----------------------------------------------------------------------------
+1. CQ KH1DX AJ10
+2. KH1DX K1ABC FN42, KH1DX W9XYZ EN37, ...
+3. K1ABC KH1DX -13
+4. KH1DX K1ABC R-11
+5. K1ABC RR73; W9XYZ <KH1DX> -17
+6. KH1DX W9XYZ R-16
+7. W9XYZ RR73; G4AAA <KH1DX> -09
+8. ...
+----------------------------------------------------------------------------
+
+Everybody sets dial frequency to an agreed number and uses CAT control
+with Split Operation (either *Rig* or *Fake It*). Fox transmits up to
+5 signals simultaneously, at audio frequencies 300, 360, ... 540
+Hz. Hounds make initial calls (e.g., line 2 above) anywhere in the
+range 1000 - 4000 Hz. They send "R+rpt" 350 Hz above the frequency
+where Fox called them.
+
+
+INSTRUCTIONS FOR FOX
+--------------------
+
+1. Start WSJT-X in FT8 mode. Select *Fox* on the *Settings ->
+Advanced tab*. On the main window, check *Tx even/1st*, *Auto Seq*,
+and *Hold Tx Freq*; uncheck *Call 1st*. Set *Tx 300 Hz* and select
+Tab 3.
+
+2. In Fox mode the left window (called "Band Activity" in normal FT8
+mode) is labeled "Stations calling DXpedition <MyCall>". It will be
+filled with a sorted list of calling Hounds. You can sort by Call,
+Grid, S/N, Distance, or Random order by using the comboBox at top
+right of Tab 3. You can limit the displayed Hound callsigns to those
+no stronger than *Max dB*. Fox might use this feature to discourage
+Hounds from engaging in a QRO arms race.
+
+3. *N Slots* sets the number of simultaneous Fox signals to be used.
+Fox carries out as many as *N Slots* QSOs simultaneously.
+
+4. *Repeats* sets the maximum number of repeat transmissions of the
+same message. A QSO is aborted when this number would be exceeded.
+
+5. The *CQ* comboBox on Tab 3 offers a selection of directed CQ
+messages. *Reset* clears the QSO queue.
+
+6. The Fox operator's main task is to select Hounds to be called and
+worked. The text box on Tab 3 holds the "QSO queue": a list of Hound
+calls to be worked. Hit Enter to select the top callsign from the
+sorted list of callers (left window), or double-click on any
+particular call. Either actiion moves that Hound into the "QSO
+queue".
+
+7. The right window displays decodes of signals below 1000 Hz.
+Normally these should include only Hound messages containing "R+rpt"
+and Fox's own transmissions.
+
+8. To get things started, toggle *Enable Tx* to red. If a Hound call
+is available in the QSO queue, that station will be called. If the
+QSO queue is empty, Fox calls CQ.
+
+9. If you're using Nslots = 2 or higher, your signal no longer has
+a constant envelope. To avoid producing intermod sidebands you need
+to ensure linearity in your Tx system. One way to get things about right
+is to use the WSJT-X *Tune* button to generate a pure tone. Reduce the
+Tx audio level until your power output decreases by 10% or so. Use this
+level for your Fox transmissions.
+
+NOTE: If you are generating Nslots signals, the average power in each one
+will be 1/Nslots^2 of its normal value for single-signal transmissions.
+
+Nslots Relative dB
+-------------------
+ 1 0
+ 2 -6
+ 3 -9.5
+ 4 -12
+ 5 -14
+
+
+The following features are not yet implemented for Fox:
+
+1. Enforce all required settings
+2. Tx message timeout
+3. Manual abort of selected QSO
+4. All Tx and Rx messages to all.txt
+5. Additional sort criteria for Hound calls
+6. Selectable timeout for keeping Hounds in the sorted list
+7. Display number of active callers
+8. Display QSO rate
+
+
+INSTRUCTIONS FOR HOUND
+----------------------
+
+1. Start WSJT-X in FT8 mode. Select *Hound* On the *Settings ->
+Advanced* tab. On the main window check *Auto Seq* and uncheck *Tx
+even/1st*, *Call 1st*, and *Hold Tx Freq*. Set *Tx nnnn Hz* to some
+frequency between 1000 and 4000 Hz, and select *Tab 1*. Enter Fox's
+callsign and locator in DX Call and DX Grid, select Tx1, and start
+*Monitor*.
+
+2. When you have copied Fox, hit *Enable Tx* to call him. You may
+keep calling until he answers. You may wish to move your TxFreq
+around, hoping to find a clear calling frequency.
+
+3. When you are called by Fox with a signal report, your next
+transmission will automatically be sent as Tx3 ("R+rpt"). When Fox
+receives that message he responds with "RR73", and your QSO is
+complete!
+
+
+The following features are not yet implemented for Hound:
+
+1. Force all required settings
+2. React properly to directed CQs from Fox
+3. Disable Tx2, 4, 5, 6
+4. For Tx1, enforce TxFreq >= 1000 Hz
diff --git a/lib/ft8/baseline.f90 b/lib/ft8/baseline.f90
new file mode 100644
index 00000000..035f9ab4
--- /dev/null
+++ b/lib/ft8/baseline.f90
@@ -0,0 +1,48 @@
+subroutine baseline(s,nfa,nfb,sbase)
+
+! Fit baseline to spectrum (for FT8)
+! Input: s(npts) Linear scale in power
+! Output: sbase(npts) Baseline
+
+ implicit real*8 (a-h,o-z)
+ real*4 s(1920)
+ real*4 sbase(1920)
+ real*4 base
+ real*8 x(1000),y(1000),a(5)
+ data nseg/10/,npct/10/
+
+ df=12000.0/3840.0 !3.125 Hz
+ ia=max(1,nint(nfa/df))
+ ib=nint(nfb/df)
+ do i=ia,ib
+ s(i)=10.0*log10(s(i)) !Convert to dB scale
+ enddo
+
+ nterms=5
+ nlen=(ib-ia+1)/nseg !Length of test segment
+ i0=(ib-ia+1)/2 !Midpoint
+ k=0
+ do n=1,nseg !Loop over all segments
+ ja=ia + (n-1)*nlen
+ jb=ja+nlen-1
+ call pctile(s(ja),nlen,npct,base) !Find lowest npct of points
+ do i=ja,jb
+ if(s(i).le.base) then
+ if (k.lt.1000) k=k+1 !Save all "lower envelope" points
+ x(k)=i-i0
+ y(k)=s(i)
+ endif
+ enddo
+ enddo
+ kz=k
+ a=0.
+ call polyfit(x,y,y,kz,nterms,0,a,chisqr) !Fit a low-order polynomial
+ do i=ia,ib
+ t=i-i0
+ sbase(i)=a(1)+t*(a(2)+t*(a(3)+t*(a(4)+t*(a(5))))) + 0.65
+! write(51,3051) i*df,s(i),sbase(i)
+!3051 format(3f12.3)
+ enddo
+
+ return
+end subroutine baseline
diff --git a/lib/ft8/bpdecode174_91.f90 b/lib/ft8/bpdecode174_91.f90
new file mode 100644
index 00000000..78809f19
--- /dev/null
+++ b/lib/ft8/bpdecode174_91.f90
@@ -0,0 +1,115 @@
+subroutine bpdecode174_91(llr,apmask,maxiterations,message77,cw,nharderror,iter)
+!
+! A log-domain belief propagation decoder for the (174,91) code.
+!
+use iso_c_binding, only: c_loc,c_size_t
+use crc
+integer, parameter:: N=174, K=91, M=N-K
+integer*1 cw(N),apmask(N)
+integer*1 decoded(K)
+integer*1 message77(77)
+integer nrw(M),ncw
+integer Nm(7,M)
+integer Mn(3,N) ! 3 checks per bit
+integer synd(M)
+real tov(3,N)
+real toc(7,M)
+real tanhtoc(7,M)
+real zn(N)
+real llr(N)
+real Tmn
+
+include "ldpc_174_91_c_reordered_parity.f90"
+
+decoded=0
+toc=0
+tov=0
+tanhtoc=0
+! initialize messages to checks
+do j=1,M
+ do i=1,nrw(j)
+ toc(i,j)=llr((Nm(i,j)))
+ enddo
+enddo
+
+ncnt=0
+
+do iter=0,maxiterations
+
+! Update bit log likelihood ratios (tov=0 in iteration 0).
+ do i=1,N
+ if( apmask(i) .ne. 1 ) then
+ zn(i)=llr(i)+sum(tov(1:ncw,i))
+ else
+ zn(i)=llr(i)
+ endif
+ enddo
+
+! Check to see if we have a codeword (check before we do any iteration).
+ cw=0
+ where( zn .gt. 0. ) cw=1
+ ncheck=0
+ do i=1,M
+ synd(i)=sum(cw(Nm(1:nrw(i),i)))
+ if( mod(synd(i),2) .ne. 0 ) ncheck=ncheck+1
+! if( mod(synd(i),2) .ne. 0 ) write(*,*) 'check ',i,' unsatisfied'
+ enddo
+! write(*,*) 'number of unsatisfied parity checks ',ncheck
+ if( ncheck .eq. 0 ) then ! we have a codeword - if crc is good, return it
+ decoded=cw(1:K)
+ call chkcrc14a(decoded,nbadcrc)
+ nharderror=count( (2*cw-1)*llr .lt. 0.0 )
+ if(nbadcrc.eq.0) then
+ message77=decoded(1:77)
+ return
+ endif
+ endif
+
+ if( iter.gt.0 ) then ! this code block implements an early stopping criterion
+! if( iter.gt.10000 ) then ! this code block implements an early stopping criterion
+ nd=ncheck-nclast
+ if( nd .lt. 0 ) then ! # of unsatisfied parity checks decreased
+ ncnt=0 ! reset counter
+ else
+ ncnt=ncnt+1
+ endif
+! write(*,*) iter,ncheck,nd,ncnt
+ if( ncnt .ge. 5 .and. iter .ge. 10 .and. ncheck .gt. 15) then
+ nharderror=-1
+ return
+ endif
+ endif
+ nclast=ncheck
+
+! Send messages from bits to check nodes
+ do j=1,M
+ do i=1,nrw(j)
+ ibj=Nm(i,j)
+ toc(i,j)=zn(ibj)
+ do kk=1,ncw ! subtract off what the bit had received from the check
+ if( Mn(kk,ibj) .eq. j ) then
+ toc(i,j)=toc(i,j)-tov(kk,ibj)
+ endif
+ enddo
+ enddo
+ enddo
+
+! send messages from check nodes to variable nodes
+ do i=1,M
+ tanhtoc(1:7,i)=tanh(-toc(1:7,i)/2)
+ enddo
+
+ do j=1,N
+ do i=1,ncw
+ ichk=Mn(i,j) ! Mn(:,j) are the checks that include bit j
+ Tmn=product(tanhtoc(1:nrw(ichk),ichk),mask=Nm(1:nrw(ichk),ichk).ne.j)
+ call platanh(-Tmn,y)
+! y=atanh(-Tmn)
+ tov(i,j)=2*y
+ enddo
+ enddo
+
+enddo
+nharderror=-1
+return
+end subroutine bpdecode174_91
diff --git a/lib/ft8/chkcrc13a.f90 b/lib/ft8/chkcrc13a.f90
new file mode 100644
index 00000000..74259cfc
--- /dev/null
+++ b/lib/ft8/chkcrc13a.f90
@@ -0,0 +1,24 @@
+subroutine chkcrc13a(decoded,nbadcrc)
+
+ use crc
+ integer*1 decoded(90)
+ integer*1, target:: i1Dec8BitBytes(12)
+ character*90 cbits
+
+! Write decoded bits into cbits: 77-bit message plus 13-bit CRC
+ write(cbits,1000) decoded
+1000 format(90i1)
+ read(cbits,1001) i1Dec8BitBytes
+1001 format(12b8)
+ read(cbits,1002) ncrc13 !Received CRC13
+1002 format(77x,b13)
+
+ i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),128+64+32+16+8)
+ i1Dec8BitBytes(11:12)=0
+ icrc13=crc13(c_loc(i1Dec8BitBytes),12) !CRC13 computed from 77 msg bits
+
+ nbadcrc=1
+ if(ncrc13.eq.icrc13) nbadcrc=0
+
+ return
+end subroutine chkcrc13a
diff --git a/lib/ft8/chkcrc14a.f90 b/lib/ft8/chkcrc14a.f90
new file mode 100644
index 00000000..d9d3d7a4
--- /dev/null
+++ b/lib/ft8/chkcrc14a.f90
@@ -0,0 +1,24 @@
+subroutine chkcrc14a(decoded,nbadcrc)
+
+ use crc
+ integer*1 decoded(91)
+ integer*1, target:: i1Dec8BitBytes(12)
+ character*91 cbits
+
+! Write decoded bits into cbits: 77-bit message plus 14-bit CRC
+ write(cbits,1000) decoded
+1000 format(91i1)
+ read(cbits,1001) i1Dec8BitBytes
+1001 format(12b8)
+ read(cbits,1002) ncrc14 !Received CRC14
+1002 format(77x,b14)
+
+ i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),128+64+32+16+8)
+ i1Dec8BitBytes(11:12)=0
+ icrc14=crc14(c_loc(i1Dec8BitBytes),12) !CRC14 computed from 77 msg bits
+
+ nbadcrc=1
+ if(ncrc14.eq.icrc14) nbadcrc=0
+
+ return
+end subroutine chkcrc14a
diff --git a/lib/ft8/compress.f90 b/lib/ft8/compress.f90
new file mode 100644
index 00000000..506e2383
--- /dev/null
+++ b/lib/ft8/compress.f90
@@ -0,0 +1,37 @@
+subroutine compress(c)
+
+ parameter (NMAX=15*12000) !Samples in iwave (180,000)
+ complex c(0:NMAX-1)
+ real xr(0:NMAX-1),xi(0:NMAX-1)
+
+ xr=real(c)
+ call wavestats(xr,NMAX,rms,pk,pwr_pk,pwr_ave)
+ xr=xr/rms
+ xi=aimag(c)/rms
+
+ do i=0,NMAX-1
+ c(i)=rms*cmplx(h1(xr(i)),h1(xi(i)))
+ enddo
+
+! par=pwr_pk/pwr_ave
+! write(*,1010) 5,rms,pk,pwr_pk,pwr_ave,par
+!1010 format(i3,2f10.3,3f10.2)
+! call wavestats(xi,NMAX,rms,pk,pwr_pk,pwr_ave)
+! par=pwr_pk/pwr_ave
+! write(*,1010) 5,rms,pk,pwr_pk,pwr_ave,par
+
+ return
+end subroutine compress
+
+subroutine wavestats(x,kz,rms,pk,pwr_pk,pwr_ave)
+
+ real x(kz)
+
+ sumsq=dot_product(x,x)
+ rms=sqrt(sumsq/kz)
+ pk=max(maxval(x),-minval(x))
+ pwr_pk=pk*pk
+ pwr_ave=sumsq/kz
+
+ return
+end subroutine wavestats
diff --git a/lib/ft8/encode174.f90 b/lib/ft8/encode174.f90
new file mode 100644
index 00000000..599f1064
--- /dev/null
+++ b/lib/ft8/encode174.f90
@@ -0,0 +1,50 @@
+subroutine encode174(message,codeword)
+! Encode an 87-bit message and return a 174-bit codeword.
+! The generator matrix has dimensions (87,87).
+! The code is a (174,87) regular ldpc code with column weight 3.
+! The code was generated using the PEG algorithm.
+! After creating the codeword, the columns are re-ordered according to
+! "colorder" to make the codeword compatible with the parity-check matrix
+!
+
+include "ldpc_174_87_params.f90"
+
+integer*1 codeword(N)
+integer*1 gen(M,K)
+integer*1 itmp(N)
+integer*1 message(K)
+integer*1 pchecks(M)
+logical first
+data first/.true./
+
+save first,gen
+
+if( first ) then ! fill the generator matrix
+ gen=0
+ do i=1,M
+ do j=1,11
+ read(g(i)( (j-1)*2+1:(j-1)*2+2 ),"(Z2)") istr
+ do jj=1, 8
+ icol=(j-1)*8+jj
+ if( icol .le. 87 ) then
+ if( btest(istr,8-jj) ) gen(i,icol)=1
+ endif
+ enddo
+ enddo
+ enddo
+first=.false.
+endif
+
+do i=1,M
+ nsum=0
+ do j=1,K
+ nsum=nsum+message(j)*gen(i,j)
+ enddo
+ pchecks(i)=mod(nsum,2)
+enddo
+itmp(1:M)=pchecks
+itmp(M+1:N)=message(1:K)
+codeword(colorder+1)=itmp(1:N)
+
+return
+end subroutine encode174
diff --git a/lib/ft8/encode174_91.f90 b/lib/ft8/encode174_91.f90
new file mode 100644
index 00000000..0ffa4841
--- /dev/null
+++ b/lib/ft8/encode174_91.f90
@@ -0,0 +1,58 @@
+subroutine encode174_91(message77,codeword)
+!
+! Add a 14-bit CRC to a 77-bit message and return a 174-bit codeword
+!
+use, intrinsic :: iso_c_binding
+use iso_c_binding, only: c_loc,c_size_t
+use crc
+
+integer, parameter:: N=174, K=91, M=N-K
+character*91 tmpchar
+integer*1 codeword(N)
+integer*1 gen(M,K)
+integer*1 message77(77),message(K)
+integer*1 pchecks(M)
+integer*1, target :: i1MsgBytes(12)
+include "ldpc_174_91_c_generator.f90"
+logical first
+data first/.true./
+save first,gen
+
+if( first ) then ! fill the generator matrix
+ gen=0
+ do i=1,M
+ do j=1,23
+ read(g(i)(j:j),"(Z1)") istr
+ ibmax=4
+ if(j.eq.23) ibmax=3
+ do jj=1, ibmax
+ icol=(j-1)*4+jj
+ if( btest(istr,4-jj) ) gen(i,icol)=1
+ enddo
+ enddo
+ enddo
+first=.false.
+endif
+
+! Add 14-bit CRC to form 91-bit message+CRC14
+write(tmpchar,'(77i1)') message77
+tmpchar(78:80)='000'
+i1MsgBytes=0
+read(tmpchar,'(10b8)') i1MsgBytes(1:10)
+ncrc14 = crc14 (c_loc (i1MsgBytes), 12)
+write(tmpchar(78:91),'(b14)') ncrc14
+read(tmpchar,'(91i1)') message
+
+do i=1,M
+ nsum=0
+ do j=1,K
+ nsum=nsum+message(j)*gen(i,j)
+ enddo
+ pchecks(i)=mod(nsum,2)
+enddo
+
+codeword(1:K)=message
+codeword(K+1:N)=pchecks
+
+return
+end subroutine encode174_91
diff --git a/lib/ft8/extractmessage174.f90 b/lib/ft8/extractmessage174.f90
new file mode 100644
index 00000000..4bac6694
--- /dev/null
+++ b/lib/ft8/extractmessage174.f90
@@ -0,0 +1,40 @@
+subroutine extractmessage174(decoded,msgreceived,ncrcflag)
+ use iso_c_binding, only: c_loc,c_size_t
+ use crc
+ use packjt
+
+ character*22 msgreceived
+ character*87 cbits
+ integer*1 decoded(87)
+ integer*1, target:: i1Dec8BitBytes(11)
+ integer*4 i4Dec6BitWords(12)
+
+! Write decoded bits into cbits: 75-bit message plus 12-bit CRC
+ write(cbits,1000) decoded
+1000 format(87i1)
+ read(cbits,1001) i1Dec8BitBytes
+1001 format(11b8)
+ read(cbits,1002) ncrc12 !Received CRC12
+1002 format(75x,b12)
+
+ i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),128+64+32)
+ i1Dec8BitBytes(11)=0
+ icrc12=crc12(c_loc(i1Dec8BitBytes),11) !CRC12 computed from 75 msg bits
+
+ if(ncrc12.eq.icrc12 .or. sum(decoded(57:87)).eq.0) then !### Kludge ###
+! CRC12 checks out --- unpack 72-bit message
+ do ibyte=1,12
+ itmp=0
+ do ibit=1,6
+ itmp=ishft(itmp,1)+iand(1,decoded((ibyte-1)*6+ibit))
+ enddo
+ i4Dec6BitWords(ibyte)=itmp
+ enddo
+ call unpackmsg(i4Dec6BitWords,msgreceived)
+ ncrcflag=1
+ else
+ msgreceived=' '
+ ncrcflag=-1
+ endif
+ return
+ end subroutine extractmessage174
diff --git a/lib/ft8/extractmessage174_91.f90 b/lib/ft8/extractmessage174_91.f90
new file mode 100644
index 00000000..d2d3019e
--- /dev/null
+++ b/lib/ft8/extractmessage174_91.f90
@@ -0,0 +1,40 @@
+subroutine extractmessage174_91(decoded,msgreceived,ncrcflag)
+ use iso_c_binding, only: c_loc,c_size_t
+ use crc
+ use packjt
+
+ character*22 msgreceived
+ character*91 cbits
+ integer*1 decoded(91)
+ integer*1, target:: i1Dec8BitBytes(12)
+ integer*4 i4Dec6BitWords(12)
+
+! Write decoded bits into cbits: 77-bit message plus 14-bit CRC
+ write(cbits,1000) decoded
+1000 format(91i1)
+ read(cbits,1001) i1Dec8BitBytes
+1001 format(12b8)
+ read(cbits,1002) ncrc14 !Received CRC12
+1002 format(77x,b14)
+
+ i1Dec8BitBytes(10)=iand(i1Dec8BitBytes(10),128+64+32+16+8)
+ i1Dec8BitBytes(11:12)=0
+ icrc14=crc14(c_loc(i1Dec8BitBytes),12) !CRC12 computed from 75 msg bits
+
+ if(ncrc14.eq.icrc14 .or. sum(decoded(57:87)).eq.0) then !### Kludge ###
+! CRC14 checks out --- unpack 72-bit message
+ do ibyte=1,12
+ itmp=0
+ do ibit=1,6
+ itmp=ishft(itmp,1)+iand(1,decoded((ibyte-1)*6+ibit))
+ enddo
+ i4Dec6BitWords(ibyte)=itmp
+ enddo
+ call unpackmsg(i4Dec6BitWords,msgreceived)
+ ncrcflag=1
+ else
+ msgreceived=' '
+ ncrcflag=-1
+ endif
+ return
+ end subroutine extractmessage174_91
diff --git a/lib/ft8/filt8.f90 b/lib/ft8/filt8.f90
new file mode 100644
index 00000000..aeacf2a7
--- /dev/null
+++ b/lib/ft8/filt8.f90
@@ -0,0 +1,52 @@
+subroutine filt8(f0,nslots,width,wave)
+
+ parameter (NFFT=180000,NH=NFFT/2)
+ real wave(NFFT)
+ real x(NFFT)
+ real s1(0:NH)
+ real s2(0:NH)
+ complex cx(0:NH)
+ equivalence (x,cx)
+
+ x=wave
+ call four2a(x,NFFT,1,-1,0) !r2c
+ df=12000.0/NFFT
+ fa=f0 - 0.5*6.25
+ fb=f0 + 7.5*6.25 + (nslots-1)*60.0
+ ia2=nint(fa/df)
+ ib1=nint(fb/df)
+ ia1=nint(ia2-width/df)
+ ib2=nint(ib1+width/df)
+ pi=4.0*atan(1.0)
+ do i=ia1,ia2
+ fil=(1.0 + cos(pi*df*(i-ia2)/width))/2.0
+ cx(i)=fil*cx(i)
+ enddo
+ do i=ib1,ib2
+ fil=(1.0 + cos(pi*df*(i-ib1)/width))/2.0
+ cx(i)=fil*cx(i)
+ enddo
+ cx(0:ia1-1)=0.
+ cx(ib2+1:)=0.
+
+ call four2a(cx,nfft,1,1,-1) !c2r
+ wave=x/nfft
+
+!###
+ if(nslots.ne.99) return
+ x=wave
+ call four2a(x,NFFT,1,-1,0) !r2c
+ do i=0,NH
+ s1(i)=real(cx(i))**2 + aimag(cx(i))**2
+ enddo
+ nadd=20
+ call smo(s1,NH+1,s2,nadd)
+ do i=0,NH
+ freq=i*df
+ write(29,3101) freq,db(s2(i)) - 72.0
+3101 format(2f12.3)
+ enddo
+!###
+
+ return
+end subroutine filt8
diff --git a/lib/ft8/foxfilt.f90 b/lib/ft8/foxfilt.f90
new file mode 100644
index 00000000..d97923a8
--- /dev/null
+++ b/lib/ft8/foxfilt.f90
@@ -0,0 +1,36 @@
+subroutine foxfilt(nslots,nfreq,width,wave)
+
+ parameter (NN=79,ND=58,KK=87,NSPS=4*1920)
+ parameter (NWAVE=NN*NSPS,NFFT=614400,NH=NFFT/2)
+ real wave(NWAVE)
+ real x(NFFT)
+ complex cx(0:NH)
+ equivalence (x,cx)
+
+ x(1:NWAVE)=wave
+ x(NWAVE+1:)=0.
+ call four2a(x,NFFT,1,-1,0) !r2c
+ df=48000.0/NFFT
+ fa=nfreq - 0.5*6.25
+ fb=nfreq + 7.5*6.25 + (nslots-1)*60.0
+ ia2=nint(fa/df)
+ ib1=nint(fb/df)
+ ia1=nint(ia2-width/df)
+ ib2=nint(ib1+width/df)
+ pi=4.0*atan(1.0)
+ do i=ia1,ia2
+ fil=(1.0 + cos(pi*df*(i-ia2)/width))/2.0
+ cx(i)=fil*cx(i)
+ enddo
+ do i=ib1,ib2
+ fil=(1.0 + cos(pi*df*(i-ib1)/width))/2.0
+ cx(i)=fil*cx(i)
+ enddo
+ cx(0:ia1-1)=0.
+ cx(ib2+1:)=0.
+
+ call four2a(cx,nfft,1,1,-1) !c2r
+ wave=x(1:NWAVE)/nfft
+
+ return
+end subroutine foxfilt
diff --git a/lib/ft8/foxgen.f90 b/lib/ft8/foxgen.f90
new file mode 100644
index 00000000..7492a6f7
--- /dev/null
+++ b/lib/ft8/foxgen.f90
@@ -0,0 +1,95 @@
+subroutine foxgen()
+
+ ! Called from MainWindow::foxTxSequencer() to generate the Tx waveform in
+ ! FT8 Fox mode. The Tx message can contain up to 5 "slots", each carrying
+ ! its own FT8 signal.
+
+ ! Encoded messages can be of the form "HoundCall FoxCall rpt" (a standard FT8
+ ! message with i3bit=0) or "HoundCall_1 RR73; HoundCall_2 <FoxCall> rpt",
+ ! a new message type with i3bit=1. The waveform is generated with
+ ! fsample=48000 Hz; it is compressed to reduce the PEP-to-average power ratio,
+ ! with (currently disabled) filtering afterware to reduce spectral growth.
+
+ ! Input message information is provided in character array cmsg(5), in
+ ! common/foxcom/. The generated wave(NWAVE) is passed back in the same
+ ! common block.
+
+ parameter (NN=79,ND=58,NSPS=4*1920)
+ parameter (NWAVE=NN*NSPS,NFFT=614400,NH=NFFT/2)
+ character*40 cmsg
+ character*37 msg,msgsent
+ integer itone(79)
+ integer*1 msgbits(77),msgbits2
+ integer*1, target:: mycall
+ real x(NFFT)
+ real*8 dt,twopi,f0,fstep,dfreq,phi,dphi
+ complex cx(0:NH)
+ common/foxcom/wave(NWAVE),nslots,nfreq,i3bit(5),cmsg(5),mycall(12)
+ common/foxcom2/itone2(NN),msgbits2(77)
+ equivalence (x,cx),(y,cy)
+
+ fstep=60.d0
+ dfreq=6.25d0
+ dt=1.d0/48000.d0
+ twopi=8.d0*atan(1.d0)
+ irpt=0
+ nplot=0
+ wave=0.
+
+ do n=1,nslots
+ msg=cmsg(n)(1:37)
+ call genft8(msg,i3,n3,msgsent,msgbits,itone)
+! Make copies of itone() and msgbits() for ft8sim
+ itone2=itone
+ msgbits2=msgbits
+ f0=nfreq + fstep*(n-1)
+ phi=0.d0
+ k=0
+ do j=1,NN
+ f=f0 + dfreq*itone(j)
+ dphi=twopi*f*dt
+ do ii=1,NSPS
+ k=k+1
+ phi=phi+dphi
+ xphi=phi
+ wave(k)=wave(k)+sin(xphi)
+ enddo
+ enddo
+ enddo
+ kz=k
+
+ peak1=maxval(abs(wave))
+ wave=wave/peak1
+! call plotspec(1,wave) !Plot the spectrum
+
+! Apply compression
+! rms=sqrt(dot_product(wave,wave)/kz)
+! wave=wave/rms
+! do i=1,NWAVE
+! wave(i)=h1(wave(i))
+! enddo
+! peak2=maxval(abs(wave))
+! wave=wave/peak2
+
+! call plotspec(2,wave) !Plot the spectrum
+
+ width=50.0
+ call foxfilt(nslots,nfreq,width,wave)
+ peak3=maxval(abs(wave))
+ wave=wave/peak3
+
+! nadd=1000
+! j=0
+! do i=1,NWAVE,nadd
+! sx=dot_product(wave(i:i+nadd-1),wave(i:i+nadd-1))
+! j=j+1
+! write(30,3001) j,sx/nadd
+!3001 format(i8,f12.6)
+! enddo
+
+! call plotspec(3,wave) !Plot the spectrum
+
+ return
+end subroutine foxgen
+
+! include 'plotspec.f90'
diff --git a/lib/ft8/foxgen_wrap.f90 b/lib/ft8/foxgen_wrap.f90
new file mode 100644
index 00000000..bc8c430f
--- /dev/null
+++ b/lib/ft8/foxgen_wrap.f90
@@ -0,0 +1,25 @@
+subroutine foxgen_wrap(msg40,msgbits,itone)
+
+ parameter (NN=79,ND=58,KK=77,NSPS=4*1920)
+ parameter (NWAVE=NN*NSPS)
+
+ character*40 msg40,cmsg
+ character*12 mycall12
+ integer*1 msgbits(KK),msgbits2
+ integer itone(NN)
+ common/foxcom/wave(NWAVE),nslots,nfreq,i3bit(5),cmsg(5),mycall12
+ common/foxcom2/itone2(NN),msgbits2(KK)
+
+ nslots=1
+ nfreq=300
+ i1=index(msg40,'<')
+ i2=index(msg40,'>')
+ mycall12=msg40(i1+1:i2-1)//' '
+ cmsg(1)=msg40
+ i3bit(1)=1
+ call foxgen()
+ msgbits=msgbits2
+ itone=itone2
+
+ return
+end subroutine foxgen_wrap
diff --git a/lib/ft8/ft8_downsample.f90 b/lib/ft8/ft8_downsample.f90
new file mode 100644
index 00000000..f3552258
--- /dev/null
+++ b/lib/ft8/ft8_downsample.f90
@@ -0,0 +1,52 @@
+subroutine ft8_downsample(dd,newdat,f0,c1)
+
+! Downconvert to complex data sampled at 200 Hz ==> 32 samples/symbol
+
+ parameter (NMAX=15*12000,NSPS=1920)
+ parameter (NFFT1=192000,NFFT2=3200) !192000/60 = 3200
+
+ logical newdat,first
+ complex c1(0:NFFT2-1)
+ complex cx(0:NFFT1/2)
+ real dd(NMAX),x(NFFT1),taper(0:100)
+ equivalence (x,cx)
+ data first/.true./
+ save cx,first,taper
+
+ if(first) then
+ pi=4.0*atan(1.0)
+ do i=0,100
+ taper(i)=0.5*(1.0+cos(i*pi/100))
+ enddo
+ first=.false.
+ endif
+ if(newdat) then
+! Data in dd have changed, recompute the long FFT
+ x(1:NMAX)=dd
+ x(NMAX+1:NFFT1)=0. !Zero-pad the x array
+ call four2a(cx,NFFT1,1,-1,0) !r2c FFT to freq domain
+ newdat=.false.
+ endif
+
+ df=12000.0/NFFT1
+ baud=12000.0/NSPS
+ i0=nint(f0/df)
+ ft=f0+8.5*baud
+ it=min(nint(ft/df),NFFT1/2)
+ fb=f0-1.5*baud
+ ib=max(1,nint(fb/df))
+ k=0
+ c1=0.
+ do i=ib,it
+ c1(k)=cx(i)
+ k=k+1
+ enddo
+ c1(0:100)=c1(0:100)*taper(100:0:-1)
+ c1(k-1-100:k-1)=c1(k-1-100:k-1)*taper
+ c1=cshift(c1,i0-ib)
+ call four2a(c1,NFFT2,1,1,1) !c2c FFT back to time domain
+ fac=1.0/sqrt(float(NFFT1)*NFFT2)
+ c1=fac*c1
+
+ return
+end subroutine ft8_downsample
diff --git a/lib/ft8/ft8_params.f90 b/lib/ft8/ft8_params.f90
new file mode 100644
index 00000000..bd228bde
--- /dev/null
+++ b/lib/ft8/ft8_params.f90
@@ -0,0 +1,12 @@
+! LDPC (174,91) code
+parameter (KK=91) !Information bits (77 + CRC14)
+parameter (ND=58) !Data symbols
+parameter (NS=21) !Sync symbols (3 @ Costas 7x7)
+parameter (NN=NS+ND) !Total channel symbols (79)
+parameter (NSPS=1920) !Samples per symbol at 12000 S/s
+parameter (NZ=NSPS*NN) !Samples in full 15 s waveform (151,680)
+parameter (NMAX=15*12000) !Samples in iwave (180,000)
+parameter (NFFT1=2*NSPS, NH1=NFFT1/2) !Length of FFTs for symbol spectra
+parameter (NSTEP=NSPS/4) !Rough time-sync step size
+parameter (NHSYM=NMAX/NSTEP-3) !Number of symbol spectra (1/4-sym steps)
+parameter (NDOWN=60) !Downsample factor
diff --git a/lib/ft8/ft8_testmsg.f90 b/lib/ft8/ft8_testmsg.f90
new file mode 100644
index 00000000..2a1bf8f9
--- /dev/null
+++ b/lib/ft8/ft8_testmsg.f90
@@ -0,0 +1,51 @@
+ parameter (MAXTEST=75,NTEST=48)
+ character*37 testmsg(MAXTEST)
+ data testmsg(1:NTEST)/ &
+ "CQ K1ABC FN42", &
+ "K1ABC W9XYZ EN37", &
+ "W9XYZ K1ABC -11", &
+ "K1ABC W9XYZ R-09", &
+ "W9XYZ K1ABC RRR", &
+ "K1ABC W9XYZ 73", &
+ "K1ABC W9XYZ RR73", &
+ "CQ KH1/KH7Z", &
+ "K1ABC RR73; W9XYZ <KH1/KH7Z> -08", &
+ "CQ FD K1ABC FN42", &
+ "K1ABC W9XYZ 6A WI", &
+ "W9XYZ K1ABC R 2B EMA", &
+ "CQ TEST K1ABC/R FN42", &
+ "K1ABC/R W9XYZ EN37", &
+ "W9XYZ K1ABC/R R FN42", &
+ "K1ABC/R W9XYZ RR73", &
+ "CQ TEST K1ABC FN42", &
+ "K1ABC W9XYZ 579 WI", &
+ "W9XYZ K1ABC R 589 MA", &
+ "K1ABC KA0DEF 559 MO", &
+ "TU; KA0DEF K1ABC R 569 MA", &
+ "KA1ABC G3AAA 529 0013", &
+ "TU; G3AAA K1ABC R 559 MA", &
+ "CQ G4ABC/P IO91", &
+ "G4ABC/P PA9XYZ JO22", &
+ "PA9XYZ 590003 IO91NP", &
+ "G4ABC/P R 570007 JO22DB", &
+ "PA9XYZ G4ABC/P RR73", &
+ "CQ PJ4/K1ABC", &
+ "PJ4/K1ABC <W9XYZ>", &
+ "W9XYZ <PJ4/K1ABC> -11", &
+ "<PJ4/K1ABC> W9XYZ R-09", &
+ "<W9XYZ> PJ4/K1ABC RRR", &
+ "PJ4/K1ABC <W9XYZ> 73", &
+ "CQ W9XYZ EN37", &
+ "<W9XYZ> YW18FIFA", &
+ "<YW18FIFA> W9XYZ -11", &
+ "W9XYZ <YW18FIFA> R-09", &
+ "YW18FIFA <W9XYZ> RRR", &
+ "<W9XYZ> YW18FIFA 73", &
+ "TNX BOB 73 GL", &
+ "CQ YW18FIFA", &
+ "<YW18FIFA> KA1ABC", &
+ "KA1ABC <YW18FIFA> -11", &
+ "<YW18FIFA> KA1ABC R-17", &
+ "<KA1ABC> YW18FIFA RR73", &
+ "<YW18FIFA> KA1ABC 73", &
+ "123456789ABCDEF012"/
diff --git a/lib/ft8/ft8apset.f90 b/lib/ft8/ft8apset.f90
new file mode 100644
index 00000000..15eddd05
--- /dev/null
+++ b/lib/ft8/ft8apset.f90
@@ -0,0 +1,43 @@
+subroutine ft8apset(mycall12,hiscall12,apsym)
+ use packjt77
+ character*77 c77
+ character*37 msg
+ character*12 mycall12,hiscall12,hiscall
+ integer apsym(58)
+ logical nohiscall
+
+ if(len(trim(mycall12)).eq.0) then
+ apsym=0
+ apsym(1)=99
+ apsym(30)=99
+ return
+ endif
+
+ nohiscall=.false.
+ hiscall=hiscall12
+ if(len(trim(hiscall)).eq.0) then
+ hiscall="K9ABC"
+ nohiscall=.true.
+ endif
+
+! Encode a dummy standard message: i3=1, 28 1 28 1 1 15
+!
+ msg=trim(mycall12)//' '//trim(hiscall)//' RRR'
+ call pack77(msg,i3,n3,c77)
+ if(i3.ne.1) then
+ apsym=0
+ apsym(1)=99
+ apsym(30)=99
+ return
+ endif
+
+ read(c77,'(58i1)',err=1) apsym(1:58)
+ apsym=2*apsym-1
+ if(nohiscall) apsym(30)=99
+ return
+
+1 apsym=0
+ apsym(1)=99
+ apsym(30)=99
+ return
+end subroutine ft8apset
diff --git a/lib/ft8/ft8b.f90 b/lib/ft8/ft8b.f90
new file mode 100644
index 00000000..5db48341
--- /dev/null
+++ b/lib/ft8/ft8b.f90
@@ -0,0 +1,468 @@
+subroutine ft8b(dd0,newdat,nQSOProgress,nfqso,nftx,ndepth,lapon,lapcqonly, &
+ napwid,lsubtract,nagain,ncontest,iaptype,mycall12,hiscall12, &
+ sync0,f1,xdt,xbase,apsym,nharderrors,dmin,nbadcrc,ipass,iera,msg37,xsnr)
+
+ use crc
+ use timer_module, only: timer
+ use packjt77
+ include 'ft8_params.f90'
+ parameter(NP2=2812)
+ character*37 msg37
+ character*12 mycall12,hiscall12,hiscall12_0
+ character*77 c77
+ character*13 c13
+ real a(5)
+ real s8(0:7,NN)
+ real s2(0:511),s2l(0:511)
+ real bmeta(174),bmetb(174),bmetc(174)
+ real llra(174),llrb(174),llrc(174),llrd(174) !Soft symbols
+ real dd0(15*12000)
+ integer*1 message77(77),apmask(174),cw(174)
+ integer apsym(58)
+ integer mcq(29),mcqru(29),mcqfd(29),mcqtest(29)
+ integer mrrr(19),m73(19),mrr73(19)
+ integer itone(NN)
+ integer icos7(0:6),ip(1)
+ integer nappasses(0:5) !Number of decoding passes to use for each QSO state
+ integer naptypes(0:5,4) ! (nQSOProgress, decoding pass) maximum of 4 passes for now
+ integer ncontest,ncontest0
+ logical one(0:511,0:8)
+ integer graymap(0:7)
+ complex cd0(0:3199)
+ complex ctwk(32)
+ complex csymb(32)
+ complex cs(0:7,NN)
+ logical first,newdat,lsubtract,lapon,lapcqonly,nagain,unpk77_success
+ data icos7/3,1,4,0,6,5,2/ ! Flipped w.r.t. original FT8 sync array
+ data mcq/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0/
+ data mcqru/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,1,1,0,0/
+ data mcqfd/0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,1,0/
+ data mcqtest/0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,0,1,0,1,1,1,1,1,1,0,0,1,0/
+ data mrrr/0,1,1,1,1,1,1,0,1,0,0,1,0,0,1,0,0,0,1/
+ data m73/0,1,1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1/
+ data mrr73/0,1,1,1,1,1,1,0,0,1,1,1,0,1,0,1,0,0,1/
+ data first/.true./
+ data graymap/0,1,3,2,5,6,4,7/
+ save nappasses,naptypes,ncontest0,one,hiscall12_0
+
+
+ if(first.or.(ncontest.ne.ncontest0)) then
+ mcq=2*mcq-1
+ mcqfd=2*mcqfd-1
+ mcqru=2*mcqru-1
+ mcqtest=2*mcqtest-1
+ mrrr=2*mrrr-1
+ m73=2*m73-1
+ mrr73=2*mrr73-1
+ nappasses(0)=2
+ nappasses(1)=2
+ nappasses(2)=2
+ nappasses(3)=4
+ nappasses(4)=4
+ nappasses(5)=3
+
+! iaptype
+!------------------------
+! 1 CQ ??? ??? (29+3=32 ap bits)
+! 2 MyCall ??? ??? (29+3=32 ap bits)
+! 3 MyCall DxCall ??? (58+3=61 ap bits)
+! 4 MyCall DxCall RRR (77 ap bits)
+! 5 MyCall DxCall 73 (77 ap bits)
+! 6 MyCall DxCall RR73 (77 ap bits)
+
+ naptypes(0,1:4)=(/1,2,0,0/) ! Tx6 selected (CQ)
+ naptypes(1,1:4)=(/2,3,0,0/) ! Tx1
+ naptypes(2,1:4)=(/2,3,0,0/) ! Tx2
+ naptypes(3,1:4)=(/3,4,5,6/) ! Tx3
+ naptypes(4,1:4)=(/3,4,5,6/) ! Tx4
+ naptypes(5,1:4)=(/3,1,2,0/) ! Tx5
+
+ one=.false.
+ do i=0,511
+ do j=0,8
+ if(iand(i,2**j).ne.0) one(i,j)=.true.
+ enddo
+ enddo
+ first=.false.
+ ncontest0=ncontest
+ endif
+
+ if(hiscall12.ne.hiscall12_0) then
+ c13=hiscall12//' '
+ call save_hash_call(c13,n10,n12,n22)
+ hiscall12_0=hiscall12
+ endif
+
+ max_iterations=30
+ nharderrors=-1
+ nbadcrc=1 ! this is used upstream to flag good decodes.
+ fs2=12000.0/NDOWN
+ dt2=1.0/fs2
+ twopi=8.0*atan(1.0)
+ delfbest=0.
+ ibest=0
+
+ call timer('ft8_down',0)
+ call ft8_downsample(dd0,newdat,f1,cd0) !Mix f1 to baseband and downsample
+ call timer('ft8_down',1)
+
+ i0=nint((xdt+0.5)*fs2) !Initial guess for start of signal
+ smax=0.0
+ do idt=i0-8,i0+8 !Search over +/- one quarter symbol
+ call sync8d(cd0,idt,ctwk,0,sync)
+ if(sync.gt.smax) then
+ smax=sync
+ ibest=idt
+ endif
+ enddo
+ xdt2=ibest*dt2 !Improved estimate for DT
+
+! Now peak up in frequency
+ i0=nint(xdt2*fs2)
+ smax=0.0
+ do ifr=-5,5 !Search over +/- 2.5 Hz
+ delf=ifr*0.5
+ dphi=twopi*delf*dt2
+ phi=0.0
+ do i=1,32
+ ctwk(i)=cmplx(cos(phi),sin(phi))
+ phi=mod(phi+dphi,twopi)
+ enddo
+ call sync8d(cd0,i0,ctwk,1,sync)
+ if( sync .gt. smax ) then
+ smax=sync
+ delfbest=delf
+ endif
+ enddo
+ a=0.0
+ a(1)=-delfbest
+ call twkfreq1(cd0,NP2,fs2,a,cd0)
+ xdt=xdt2
+ f1=f1+delfbest !Improved estimate of DF
+ call sync8d(cd0,i0,ctwk,0,sync)
+
+ do k=1,NN
+ i1=ibest+(k-1)*32
+ csymb=cmplx(0.0,0.0)
+ if( i1.ge.0 .and. i1+31 .le. NP2-1 ) csymb=cd0(i1:i1+31)
+ call four2a(csymb,32,1,-1,1)
+ cs(0:7,k)=csymb(1:8)/1e3
+ s8(0:7,k)=abs(csymb(1:8))
+ enddo
+
+! sync quality check
+ is1=0
+ is2=0
+ is3=0
+ do k=1,7
+ ip=maxloc(s8(:,k))
+ if(icos7(k-1).eq.(ip(1)-1)) is1=is1+1
+ ip=maxloc(s8(:,k+36))
+ if(icos7(k-1).eq.(ip(1)-1)) is2=is2+1
+ ip=maxloc(s8(:,k+72))
+ if(icos7(k-1).eq.(ip(1)-1)) is3=is3+1
+ enddo
+! hard sync sum - max is 21
+ nsync=is1+is2+is3
+ if(nsync .le. 6) then ! bail out
+ nbadcrc=1
+ return
+ endif
+
+ do nsym=1,3
+ nt=2**(3*nsym)
+ do ihalf=1,2
+ do k=1,29,nsym
+ if(ihalf.eq.1) ks=k+7
+ if(ihalf.eq.2) ks=k+43
+ amax=-1.0
+ do i=0,nt-1
+ i1=i/64
+ i2=iand(i,63)/8
+ i3=iand(i,7)
+ if(nsym.eq.1) then
+ s2(i)=abs(cs(graymap(i3),ks))
+ elseif(nsym.eq.2) then
+ s2(i)=abs(cs(graymap(i2),ks)+cs(graymap(i3),ks+1))
+ elseif(nsym.eq.3) then
+ s2(i)=abs(cs(graymap(i1),ks)+cs(graymap(i2),ks+1)+cs(graymap(i3),ks+2))
+ else
+ print*,"Error - nsym must be 1, 2, or 3."
+ endif
+ enddo
+ s2l(0:nt-1)=log(s2(0:nt-1)+1e-32)
+ i32=1+(k-1)*3+(ihalf-1)*87
+ if(nsym.eq.1) ibmax=2
+ if(nsym.eq.2) ibmax=5
+ if(nsym.eq.3) ibmax=8
+ do ib=0,ibmax
+ bm=maxval(s2(0:nt-1),one(0:nt-1,ibmax-ib)) - &
+ maxval(s2(0:nt-1),.not.one(0:nt-1,ibmax-ib))
+ if(i32+ib .gt.174) cycle
+ if(nsym.eq.1) then
+ bmeta(i32+ib)=bm
+ elseif(nsym.eq.2) then
+ bmetb(i32+ib)=bm
+ elseif(nsym.eq.3) then
+ bmetc(i32+ib)=bm
+ endif
+ enddo
+ enddo
+ enddo
+ enddo
+ call normalizebmet(bmeta,174)
+ call normalizebmet(bmetb,174)
+ call normalizebmet(bmetc,174)
+
+ scalefac=2.83
+ llra=scalefac*bmeta
+ llrb=scalefac*bmetb
+ llrc=scalefac*bmetc
+
+ apmag=maxval(abs(llra))*1.01
+
+! pass #
+!------------------------------
+! 1 regular decoding, nsym=1
+! 2 regular decoding, nsym=2
+! 3 regular decoding, nsym=3
+! 4 ap pass 1, nsym=1 (for now?)
+! 5 ap pass 2
+! 6 ap pass 3
+! 7 ap pass 4
+
+ if(lapon.or.ncontest.eq.6) then !Hounds always use AP
+ if(.not.lapcqonly) then
+ npasses=3+nappasses(nQSOProgress)
+ else
+ npasses=4
+ endif
+ else
+ npasses=3
+ endif
+
+ do ipass=1,npasses
+ llrd=llra
+ if(ipass.eq.2) llrd=llrb
+ if(ipass.eq.3) llrd=llrc
+ if(ipass.le.3) then
+ apmask=0
+ iaptype=0
+ endif
+
+ if(ipass .gt. 3) then
+ llrd=llra
+ if(.not.lapcqonly) then
+ iaptype=naptypes(nQSOProgress,ipass-3)
+ else
+ iaptype=1
+ endif
+
+! ncontest=0 : NONE
+! 1 : NA_VHF
+! 2 : EU_VHF
+! 3 : FIELD DAY
+! 4 : RTTY
+! 5 : FOX
+! 6 : HOUND
+!
+! Conditions that cause us to bail out of AP decoding
+ if(ncontest.le.4 .and. iaptype.ge.3 .and. (abs(f1-nfqso).gt.napwid .and. abs(f1-nftx).gt.napwid) ) cycle
+ if(ncontest.eq.5) cycle ! No AP for Foxes
+ if(ncontest.eq.6.and.f1.gt.950.0) cycle ! Hounds use AP only for signals below 950 Hz
+ if(iaptype.ge.2 .and. apsym(1).gt.1) cycle ! No, or nonstandard, mycall
+ if(iaptype.ge.3 .and. apsym(30).gt.1) cycle ! No, or nonstandard, dxcall
+
+ if(iaptype.eq.1) then ! CQ or CQ RU or CQ TEST or CQ FD
+ apmask=0
+ apmask(1:29)=1
+ if(ncontest.eq.0) llrd(1:29)=apmag*mcq(1:29)
+ if(ncontest.eq.1) llrd(1:29)=apmag*mcqtest(1:29)
+ if(ncontest.eq.2) llrd(1:29)=apmag*mcqtest(1:29)
+ if(ncontest.eq.3) llrd(1:29)=apmag*mcqfd(1:29)
+ if(ncontest.eq.4) llrd(1:29)=apmag*mcqru(1:29)
+ if(ncontest.eq.6) llrd(1:29)=apmag*mcq(1:29)
+ apmask(75:77)=1
+ llrd(75:76)=apmag*(-1)
+ llrd(77)=apmag*(+1)
+ endif
+
+ if(iaptype.eq.2) then ! MyCall,???,???
+ apmask=0
+ if(ncontest.eq.0.or.ncontest.eq.1) then
+ apmask(1:29)=1
+ llrd(1:29)=apmag*apsym(1:29)
+ apmask(75:77)=1
+ llrd(75:76)=apmag*(-1)
+ llrd(77)=apmag*(+1)
+ else if(ncontest.eq.2) then
+ apmask(1:28)=1
+ llrd(1:28)=apmag*apsym(1:28)
+ apmask(72:74)=1
+ llrd(72)=apmag*(-1)
+ llrd(73)=apmag*(+1)
+ llrd(74)=apmag*(-1)
+ apmask(75:77)=1
+ llrd(75:77)=apmag*(-1)
+ else if(ncontest.eq.3) then
+ apmask(1:28)=1
+ llrd(1:28)=apmag*apsym(1:28)
+ apmask(75:77)=1
+ llrd(75:77)=apmag*(-1)
+ else if(ncontest.eq.4) then
+ apmask(2:29)=1
+ llrd(2:29)=apmag*apsym(1:28)
+ apmask(75:77)=1
+ llrd(75)=apmag*(-1)
+ llrd(76:77)=apmag*(+1)
+ else if(ncontest.eq.6) then ! ??? RR73; MyCall <???> ???
+ apmask(29:56)=1
+ llrd(29:56)=apmag*apsym(1:28)
+ apmask(72:77)=1
+ llrd(72:73)=apmag*(-1)
+ llrd(74)=apmag*(+1)
+ llrd(75:77)=apmag*(-1)
+ endif
+ endif
+
+ if(iaptype.eq.3) then ! MyCall,DxCall,???
+ apmask=0
+ if(ncontest.eq.0.or.ncontest.eq.1.or.ncontest.eq.2.or.ncontest.eq.6) then
+ apmask(1:58)=1
+ llrd(1:58)=apmag*apsym
+ apmask(75:77)=1
+ llrd(75:76)=apmag*(-1)
+ llrd(77)=apmag*(+1)
+ else if(ncontest.eq.3) then ! Field Day
+ apmask(1:56)=1
+ llrd(1:28)=apmag*apsym(1:28)
+ llrd(29:56)=apmag*apsym(30:57)
+ apmask(72:74)=1
+ apmask(75:77)=1
+ llrd(75:77)=apmag*(-1)
+ else if(ncontest.eq.4) then ! RTTY RU
+ apmask(2:57)=1
+ llrd(2:29)=apmag*apsym(1:28)
+ llrd(30:57)=apmag*apsym(30:57)
+ apmask(75:77)=1
+ llrd(75)=apmag*(-1)
+ llrd(76:77)=apmag*(+1)
+ endif
+ endif
+
+ if(iaptype.eq.5.and.ncontest.eq.6) cycle !Hound
+ if(iaptype.eq.4 .or. iaptype.eq.5 .or. iaptype.eq.6) then
+ apmask=0
+ if(ncontest.le.4 .or. (ncontest.eq.6.and.iaptype.eq.6)) then
+ apmask(1:77)=1 ! mycall, hiscall, RRR|73|RR73
+ llrd(1:58)=apmag*apsym
+ if(iaptype.eq.4) llrd(59:77)=apmag*mrrr
+ if(iaptype.eq.5) llrd(59:77)=apmag*m73
+ if(iaptype.eq.6) llrd(59:77)=apmag*mrr73
+ else if(ncontest.eq.6.and.iaptype.eq.4) then ! Hound listens for MyCall RR73;...
+ apmask(1:28)=1
+ llrd(1:28)=apmag*apsym(1:28)
+ apmask(72:77)=1
+ llrd(72:73)=apmag*(-1)
+ llrd(74)=apmag*(1)
+ llrd(75:77)=apmag*(-1)
+ endif
+ endif
+ endif
+
+ cw=0
+ call timer('bpd174_91 ',0)
+ call bpdecode174_91(llrd,apmask,max_iterations,message77,cw,nharderrors, &
+ niterations)
+ call timer('bpd174_91 ',1)
+ dmin=0.0
+ if(ndepth.eq.3 .and. nharderrors.lt.0) then
+ ndeep=3
+ if(abs(nfqso-f1).le.napwid .or. abs(nftx-f1).le.napwid) then
+ ndeep=4
+ endif
+ if(nagain) ndeep=5
+ call timer('osd174_91 ',0)
+ call osd174_91(llrd,apmask,ndeep,message77,cw,nharderrors,dmin)
+ call timer('osd174_91 ',1)
+ endif
+
+ msg37=' '
+ if(nharderrors.lt.0 .or. nharderrors.gt.36) cycle
+ if(count(cw.eq.0).eq.174) cycle !Reject the all-zero codeword
+ write(c77,'(77i1)') message77
+ read(c77(72:74),'(b3)') n3
+ read(c77(75:77),'(b3)') i3
+ if(i3.gt.4 .or. (i3.eq.0.and.n3.gt.5)) then
+ cycle
+ endif
+ call unpack77(c77,msg37,unpk77_success)
+ if(.not.unpk77_success) then
+ cycle
+ endif
+ nbadcrc=0 ! If we get this far: valid codeword, valid (i3,n3), nonquirky message.
+ call get_tones_from_77bits(message77,itone)
+ if(lsubtract) call subtractft8(dd0,itone,f1,xdt)
+ xsig=0.0
+ xnoi=0.0
+ do i=1,79
+ xsig=xsig+s8(itone(i),i)**2
+ ios=mod(itone(i)+4,7)
+ xnoi=xnoi+s8(ios,i)**2
+ enddo
+ xsnr=0.001
+ xsnr2=0.001
+ arg=xsig/xnoi-1.0
+ if(arg.gt.0.1) xsnr=arg
+ arg=xsig/xbase/2.6e6-1.0
+ if(arg.gt.0.1) xsnr2=arg
+ xsnr=10.0*log10(xsnr)-27.0
+ xsnr2=10.0*log10(xsnr2)-27.0
+ if(.not.nagain) then
+ xsnr=xsnr2
+ endif
+ if(xsnr .lt. -24.0) xsnr=-24.0
+
+ return
+ enddo
+ return
+end subroutine ft8b
+
+subroutine normalizebmet(bmet,n)
+ real bmet(n)
+
+ bmetav=sum(bmet)/real(n)
+ bmet2av=sum(bmet*bmet)/real(n)
+ var=bmet2av-bmetav*bmetav
+ if( var .gt. 0.0 ) then
+ bmetsig=sqrt(var)
+ else
+ bmetsig=sqrt(bmet2av)
+ endif
+ bmet=bmet/bmetsig
+ return
+end subroutine normalizebmet
+
+
+function bessi0(x)
+! From Numerical Recipes
+ real bessi0,x
+ double precision p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9,y
+ save p1,p2,p3,p4,p5,p6,p7,q1,q2,q3,q4,q5,q6,q7,q8,q9
+ data p1,p2,p3,p4,p5,p6,p7/1.0d0,3.5156229d0,3.0899424d0,1.2067492d0, &
+ 0.2659732d0,0.360768d-1,0.45813d-2/
+ data q1,q2,q3,q4,q5,q6,q7,q8,q9/0.39894228d0,0.1328592d-1, &
+ 0.225319d-2,-0.157565d-2,0.916281d-2,-0.2057706d-1, &
+ 0.2635537d-1,-0.1647633d-1,0.392377d-2/
+
+ if (abs(x).lt.3.75) then
+ y=(x/3.75)**2
+ bessi0=p1+y*(p2+y*(p3+y*(p4+y*(p5+y*(p6+y*p7)))))
+ else
+ ax=abs(x)
+ y=3.75/ax
+ bessi0=(exp(ax)/sqrt(ax))*(q1+y*(q2+y*(q3+y*(q4 &
+ +y*(q5+y*(q6+y*(q7+y*(q8+y*q9))))))))
+ endif
+ return
+end function bessi0
diff --git a/lib/ft8/ft8code.f90 b/lib/ft8/ft8code.f90
new file mode 100644
index 00000000..cbafd34b
--- /dev/null
+++ b/lib/ft8/ft8code.f90
@@ -0,0 +1,83 @@
+program ft8code
+
+! Provides examples of message packing, LDPC(174,91) encoding, bit and
+! symbol ordering, and other details of the FT8 protocol.
+
+ use packjt77
+ include 'ft8_params.f90' !Set various constants
+ include 'ft8_testmsg.f90'
+ parameter (NWAVE=NN*NSPS)
+
+ character*37 msg,msgsent
+ character*9 comment
+ character bad*1,msgtype*18
+ integer itone(NN)
+ integer*1 msgbits(77)
+
+! Get command-line argument(s)
+ nargs=iargc()
+ if(nargs.ne.1 .and. nargs.ne.3) then
+ print*
+ print*,'Program ft8code: Provides examples of message packing, ', &
+ 'LDPC(174,91) encoding,'
+ print*,'bit and symbol ordering, and other details of the FT8 protocol.'
+ print*
+ print*,'Usage: ft8code [-c grid] "message" # Results for specified message'
+ print*,' ft8code -t # Examples of all message types'
+ go to 999
+ endif
+
+ call getarg(1,msg) !Message to be transmitted
+ if(len(trim(msg)).eq.2 .and. msg(1:2).eq.'-t') then
+ nmsg=NTEST
+ else
+ call fmtmsg(msg,iz) !To upper case; collapse multiple blanks
+ nmsg=1
+ endif
+
+ write(*,1010)
+1010 format(4x,'Message',31x,'Decoded',29x,'Err i3.n3'/100('-'))
+
+ do imsg=1,nmsg
+ if(nmsg.gt.1) msg=testmsg(imsg)
+
+! Generate msgsent, msgbits, and itone
+ i3=-1
+ n3=-1
+ call genft8(msg,i3,n3,msgsent,msgbits,itone)
+ msgtype=""
+ if(i3.eq.0) then
+ if(n3.eq.0) msgtype="Free text"
+ if(n3.eq.1) msgtype="DXpedition mode"
+ if(n3.eq.2) msgtype="EU VHF Contest"
+ if(n3.eq.3) msgtype="ARRL Field Day"
+ if(n3.eq.4) msgtype="ARRL Field Day"
+ if(n3.eq.5) msgtype="Telemetry"
+ if(n3.ge.6) msgtype="Undefined type"
+ endif
+ if(i3.eq.1) msgtype="Standard msg"
+ 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.ge.1) n3=-1
+ bad=" "
+ comment=' '
+ if(msg.ne.msgsent) bad="*"
+ if(n3.ge.0) then
+ write(*,1020) imsg,msg,msgsent,bad,i3,n3,msgtype,comment
+1020 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',i1,1x,a18,1x,a9)
+ else
+ write(*,1022) imsg,msg,msgsent,bad,i3,msgtype,comment
+1022 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',1x,1x,a18,1x,a9)
+ endif
+ enddo
+
+ if(nmsg.eq.1) then
+ write(*,1030) msgbits
+1030 format(/'Message bits: ',/77i1)
+ write(*,1034) itone
+1034 format(/'Channel symbols (tones):'/79i1)
+ endif
+
+999 end program ft8code
diff --git a/lib/ft8/ft8d.f90 b/lib/ft8/ft8d.f90
new file mode 100644
index 00000000..daee7b2b
--- /dev/null
+++ b/lib/ft8/ft8d.f90
@@ -0,0 +1,63 @@
+program ft8d
+
+! Decode FT8 data read from *.wav files.
+
+ include 'ft8_params.f90'
+ character*12 arg
+ character infile*80,datetime*13,message*22
+ real s(NH1,NHSYM)
+ real candidate(3,100)
+ integer ihdr(11)
+ integer*2 iwave(NMAX) !Generated full-length waveform
+ real dd(NMAX)
+
+ nargs=iargc()
+ if(nargs.lt.3) then
+ print*,'Usage: ft8d MaxIt Norder file1 [file2 ...]'
+ print*,'Example ft8d 40 2 *.wav'
+ go to 999
+ endif
+ call getarg(1,arg)
+ read(arg,*) max_iterations
+ call getarg(2,arg)
+ read(arg,*) norder
+ nfiles=nargs-2
+
+ twopi=8.0*atan(1.0)
+ fs=12000.0 !Sample rate
+ dt=1.0/fs !Sample interval (s)
+ tt=NSPS*dt !Duration of "itone" symbols (s)
+ ts=2*NSPS*dt !Duration of OQPSK symbols (s)
+ baud=1.0/tt !Keying rate (baud)
+ txt=NZ*dt !Transmission length (s)
+ nfa=100.0
+ nfb=3000.0
+ nfqso=1500.0
+
+ do ifile=1,nfiles
+ call getarg(ifile+2,infile)
+ open(10,file=infile,status='old',access='stream')
+ read(10,end=999) ihdr,iwave
+ close(10)
+ j2=index(infile,'.wav')
+ read(infile(j2-6:j2-1),*) nutc
+ datetime=infile(j2-13:j2-1)
+ call sync8(iwave,nfa,nfb,nfqso,s,candidate,ncand)
+ syncmin=2.0
+ dd=iwave
+ do icand=1,ncand
+ sync=candidate(3,icand)
+ if( sync.lt.syncmin) cycle
+ f1=candidate(1,icand)
+ xdt=candidate(2,icand)
+ nsnr=min(99,nint(10.0*log10(sync)-25.5))
+ call ft8b(dd,nfqso,f1,xdt,nharderrors,dmin,nbadcrc,message,xsnr)
+ nsnr=xsnr
+ xdt=xdt-0.6
+ write(*,1110) datetime,0,nsnr,xdt,f1,message,nharderrors,dmin
+1110 format(a13,2i4,f6.2,f7.1,' ~ ',a22,i6,f7.1)
+ enddo
+ enddo ! ifile loop
+
+999 end program ft8d
+
diff --git a/lib/ft8/ft8sim.f90 b/lib/ft8/ft8sim.f90
new file mode 100644
index 00000000..bbec600d
--- /dev/null
+++ b/lib/ft8/ft8sim.f90
@@ -0,0 +1,141 @@
+program ft8sim
+
+! Generate simulated "type 2" ft8 files
+! Output is saved to a *.wav file.
+
+ use wavhdr
+ use packjt77
+ include 'ft8_params.f90' !Set various constants
+ parameter (NWAVE=NN*NSPS)
+ type(hdr) h !Header for .wav file
+ character arg*12,fname*17
+ character msg37*37,msgsent37*37
+ character c77*77
+ complex c0(0:NMAX-1)
+ complex c(0:NMAX-1)
+ real wave(NMAX)
+ integer itone(NN)
+ integer*1 msgbits(77)
+ integer*2 iwave(NMAX) !Generated full-length waveform
+
+! Get command-line argument(s)
+ nargs=iargc()
+ if(nargs.ne.8) then
+ print*,'Usage: ft8sim "message" f0 DT fdop del width nfiles snr'
+ print*,'Examples: ft8sim "K1ABC W9XYZ EN37" 1500.0 0.0 0.1 1.0 0 10 -18'
+ print*,' ft8sim "WA9XYZ/R KA1ABC/R FN42" 1500.0 0.0 0.1 1.0 0 10 -18'
+ print*,' ft8sim "K1ABC RR73; W9XYZ <KH1/KH7Z> -11" 300 0 0 0 25 1 -10'
+ go to 999
+ endif
+ call getarg(1,msg37) !Message to be transmitted
+ call getarg(2,arg)
+ read(arg,*) f0 !Frequency (only used for single-signal)
+ call getarg(3,arg)
+ read(arg,*) xdt !Time offset from nominal (s)
+ call getarg(4,arg)
+ read(arg,*) fspread !Watterson frequency spread (Hz)
+ call getarg(5,arg)
+ read(arg,*) delay !Watterson delay (ms)
+ call getarg(6,arg)
+ read(arg,*) width !Filter transition width (Hz)
+ call getarg(7,arg)
+ read(arg,*) nfiles !Number of files
+ call getarg(8,arg)
+ read(arg,*) snrdb !SNR_2500
+
+ nsig=1
+ if(f0.lt.100.0) then
+ nsig=f0
+ f0=1500
+ endif
+
+ nfiles=abs(nfiles)
+ twopi=8.0*atan(1.0)
+ fs=12000.0 !Sample rate (Hz)
+ dt=1.0/fs !Sample interval (s)
+ tt=NSPS*dt !Duration of symbols (s)
+ baud=1.0/tt !Keying rate (baud)
+ bw=8*baud !Occupied bandwidth (Hz)
+ txt=NZ*dt !Transmission length (s)
+ bandwidth_ratio=2500.0/(fs/2.0)
+ sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb)
+ if(snrdb.gt.90.0) sig=1.0
+ txt=NN*NSPS/12000.0
+
+ ! Source-encode, then get itone()
+ i3=-1
+ n3=-1
+ call pack77(msg37,i3,n3,c77)
+ call genft8(msg37,i3,n3,msgsent37,msgbits,itone)
+
+ write(*,*)
+ write(*,'(a23,a37,3x,a7,i1,a1,i1)') 'New Style FT8 Message: ',msgsent37,'i3.n3: ',i3,'.',n3
+ write(*,1000) f0,xdt,txt,snrdb,bw
+1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1, &
+ ' BW:',f4.1)
+ write(*,*)
+ if(i3.eq.1) then
+ write(*,*) ' mycall hiscall hisgrid'
+ write(*,'(28i1,1x,i1,1x,28i1,1x,i1,1x,i1,1x,15i1,1x,3i1)') msgbits(1:77)
+ else
+ write(*,'(a14)') 'Message bits: '
+ write(*,'(77i1)') msgbits
+ endif
+ write(*,*)
+ write(*,'(a17)') 'Channel symbols: '
+ write(*,'(79i1)') itone
+ write(*,*)
+
+ call sgran()
+
+ msg0=msg
+ do ifile=1,nfiles
+ k=nint((xdt+0.5)/dt)
+ ia=k
+ phi=0.0
+ c0=0.0
+ do j=1,NN !Generate complex waveform
+ dphi=twopi*(f0*dt+itone(j)/real(NSPS))
+ do i=1,NSPS
+ if(k.ge.0 .and. k.lt.NMAX) c0(k)=cmplx(cos(phi),sin(phi))
+ k=k+1
+ phi=mod(phi+dphi,twopi)
+ enddo
+ enddo
+ if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c0,NMAX,NWAVE,fs,delay,fspread)
+ c=sig*c0
+
+ ib=k
+ wave=real(c)
+ peak=maxval(abs(wave(ia:ib)))
+ nslots=1
+ if(width.gt.0.0) call filt8(f0,nslots,width,wave)
+
+ if(snrdb.lt.90) then
+ do i=1,NMAX !Add gaussian noise at specified SNR
+ xnoise=gran()
+ wave(i)=wave(i) + xnoise
+ enddo
+ endif
+
+ gain=100.0
+ if(snrdb.lt.90.0) then
+ wave=gain*wave
+ else
+ datpk=maxval(abs(wave))
+ fac=32766.9/datpk
+ wave=fac*wave
+ endif
+ if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped."
+ iwave=nint(wave)
+
+ h=default_header(12000,NMAX)
+ write(fname,1102) ifile
+1102 format('000000_',i6.6,'.wav')
+ open(10,file=fname,status='unknown',access='stream')
+ write(10) h,iwave !Save to *.wav file
+ close(10)
+ write(*,1110) ifile,xdt,f0,snrdb,fname
+1110 format(i4,f7.2,f8.2,f7.1,2x,a17)
+ enddo
+999 end program ft8sim
diff --git a/lib/ft8/genft8.f90 b/lib/ft8/genft8.f90
new file mode 100644
index 00000000..bf3116b8
--- /dev/null
+++ b/lib/ft8/genft8.f90
@@ -0,0 +1,46 @@
+subroutine genft8(msg,i3,n3,msgsent,msgbits,itone)
+
+! Encode an FT8 message, producing array itone().
+
+ use packjt77
+ include 'ft8_params.f90'
+ character msg*37,msgsent*37
+ character*77 c77
+ integer*1 msgbits(77),codeword(174)
+ integer itone(79)
+ integer icos7(0:6)
+ integer graymap(0:7)
+ logical unpk77_success
+ data icos7/3,1,4,0,6,5,2/ !Costas 7x7 tone pattern
+ data graymap/0,1,3,2,5,6,4,7/
+
+ i3=-1
+ n3=-1
+ call pack77(msg,i3,n3,c77)
+ call unpack77(c77,msgsent,unpk77_success)
+ read(c77,'(77i1)',err=1) msgbits
+ if(unpk77_success) go to 2
+1 msgbits=0
+ itone=0
+ msgsent='*** bad message *** '
+ go to 900
+
+entry get_tones_from_77bits(msgbits,itone)
+
+2 call encode174_91(msgbits,codeword) !Encode the test message
+
+! Message structure: S7 D29 S7 D29 S7
+ itone(1:7)=icos7
+ itone(36+1:36+7)=icos7
+ itone(NN-6:NN)=icos7
+ k=7
+ do j=1,ND
+ i=3*j -2
+ k=k+1
+ if(j.eq.30) k=k+7
+ indx=codeword(i)*4 + codeword(i+1)*2 + codeword(i+2)
+ itone(k)=graymap(indx)
+ enddo
+
+900 return
+end subroutine genft8
diff --git a/lib/ft8/genft8refsig.f90 b/lib/ft8/genft8refsig.f90
new file mode 100644
index 00000000..cd1468c1
--- /dev/null
+++ b/lib/ft8/genft8refsig.f90
@@ -0,0 +1,23 @@
+subroutine genft8refsig(itone,cref,f0)
+ complex cref(79*1920)
+ integer itone(79)
+! real*8 twopi,phi,dphi,dt,xnsps
+ real twopi,phi,dphi,dt,xnsps
+ data twopi/0.d0/
+ save twopi
+ if( twopi .lt. 0.1 ) twopi=8.d0*atan(1.d0)
+
+ xnsps=1920.d0
+ dt=1.d0/12000.d0
+ phi=0.d0
+ k=1
+ do i=1,79
+ dphi=twopi*(f0*dt+itone(i)/xnsps)
+ do is=1,1920
+ cref(k)=cmplx(cos(phi),sin(phi))
+ phi=mod(phi+dphi,twopi)
+ k=k+1
+ enddo
+ enddo
+ return
+end subroutine genft8refsig
diff --git a/lib/ft8/h1.f90 b/lib/ft8/h1.f90
new file mode 100644
index 00000000..aeed3f46
--- /dev/null
+++ b/lib/ft8/h1.f90
@@ -0,0 +1,17 @@
+real function h1(x)
+
+! sigma=1.0/sqrt(2.0)
+ sigma=1.0
+ xlim=sigma/sqrt(6.0)
+ ax=abs(x)
+ sgnx=1.0
+ if(x.lt.0) sgnx=-1.0
+ if(ax.le.xlim) then
+ h1=x
+ else
+ z=exp(1.0/6.0 - (ax/sigma)**2)
+ h1=sgnx*sqrt(6.0)*sigma*(2.0/3.0 - 0.5*z)
+ endif
+
+ return
+end function h1
diff --git a/lib/ft8/ldpc_174_87_params.f90 b/lib/ft8/ldpc_174_87_params.f90
new file mode 100644
index 00000000..35af9b81
--- /dev/null
+++ b/lib/ft8/ldpc_174_87_params.f90
@@ -0,0 +1,102 @@
+integer, parameter:: N=174, K=87, M=N-K
+character*22 g(87)
+integer colorder(N)
+data g/ & !parity generator matrix for (174,87) code
+"23bba830e23b6b6f50982e", &
+"1f8e55da218c5df3309052", &
+"ca7b3217cd92bd59a5ae20", &
+"56f78313537d0f4382964e", &
+"29c29dba9c545e267762fe", &
+"6be396b5e2e819e373340c", &
+"293548a138858328af4210", &
+"cb6c6afcdc28bb3f7c6e86", &
+"3f2a86f5c5bd225c961150", &
+"849dd2d63673481860f62c", &
+"56cdaec6e7ae14b43feeee", &
+"04ef5cfa3766ba778f45a4", &
+"c525ae4bd4f627320a3974", &
+"fe37802941d66dde02b99c", &
+"41fd9520b2e4abeb2f989c", &
+"40907b01280f03c0323946", &
+"7fb36c24085a34d8c1dbc4", &
+"40fc3e44bb7d2bb2756e44", &
+"d38ab0a1d2e52a8ec3bc76", &
+"3d0f929ef3949bd84d4734", &
+"45d3814f504064f80549ae", &
+"f14dbf263825d0bd04b05e", &
+"f08a91fb2e1f78290619a8", &
+"7a8dec79a51e8ac5388022", &
+"ca4186dd44c3121565cf5c", &
+"db714f8f64e8ac7af1a76e", &
+"8d0274de71e7c1a8055eb0", &
+"51f81573dd4049b082de14", &
+"d037db825175d851f3af00", &
+"d8f937f31822e57c562370", &
+"1bf1490607c54032660ede", &
+"1616d78018d0b4745ca0f2", &
+"a9fa8e50bcb032c85e3304", &
+"83f640f1a48a8ebc0443ea", &
+"eca9afa0f6b01d92305edc", &
+"3776af54ccfbae916afde6", &
+"6abb212d9739dfc02580f2", &
+"05209a0abb530b9e7e34b0", &
+"612f63acc025b6ab476f7c", &
+"0af7723161ec223080be86", &
+"a8fc906976c35669e79ce0", &
+"45b7ab6242b77474d9f11a", &
+"b274db8abd3c6f396ea356", &
+"9059dfa2bb20ef7ef73ad4", &
+"3d188ea477f6fa41317a4e", &
+"8d9071b7e7a6a2eed6965e", &
+"a377253773ea678367c3f6", &
+"ecbd7c73b9cd34c3720c8a", &
+"b6537f417e61d1a7085336", &
+"6c280d2a0523d9c4bc5946", &
+"d36d662a69ae24b74dcbd8", &
+"d747bfc5fd65ef70fbd9bc", &
+"a9fa2eefa6f8796a355772", &
+"cc9da55fe046d0cb3a770c", &
+"f6ad4824b87c80ebfce466", &
+"cc6de59755420925f90ed2", &
+"164cc861bdd803c547f2ac", &
+"c0fc3ec4fb7d2bb2756644", &
+"0dbd816fba1543f721dc72", &
+"a0c0033a52ab6299802fd2", &
+"bf4f56e073271f6ab4bf80", &
+"57da6d13cb96a7689b2790", &
+"81cfc6f18c35b1e1f17114", &
+"481a2a0df8a23583f82d6c", &
+"1ac4672b549cd6dba79bcc", &
+"c87af9a5d5206abca532a8", &
+"97d4169cb33e7435718d90", &
+"a6573f3dc8b16c9d19f746", &
+"2c4142bf42b01e71076acc", &
+"081c29a10d468ccdbcecb6", &
+"5b0f7742bca86b8012609a", &
+"012dee2198eba82b19a1da", &
+"f1627701a2d692fd9449e6", &
+"35ad3fb0faeb5f1b0c30dc", &
+"b1ca4ea2e3d173bad4379c", &
+"37d8e0af9258b9e8c5f9b2", &
+"cd921fdf59e882683763f6", &
+"6114e08483043fd3f38a8a", &
+"2e547dd7a05f6597aac516", &
+"95e45ecd0135aca9d6e6ae", &
+"b33ec97be83ce413f9acc8", &
+"c8b5dffc335095dcdcaf2a", &
+"3dd01a59d86310743ec752", &
+"14cd0f642fc0c5fe3a65ca", &
+"3a0a1dfd7eee29c2e827e0", &
+"8abdb889efbe39a510a118", &
+"3f231f212055371cf3e2a2"/
+data colorder/ &
+ 0, 1, 2, 3, 30, 4, 5, 6, 7, 8, 9, 10, 11, 32, 12, 40, 13, 14, 15, 16,&
+ 17, 18, 37, 45, 29, 19, 20, 21, 41, 22, 42, 31, 33, 34, 44, 35, 47, 51, 50, 43,&
+ 36, 52, 63, 46, 25, 55, 27, 24, 23, 53, 39, 49, 59, 38, 48, 61, 60, 57, 28, 62,&
+ 56, 58, 65, 66, 26, 70, 64, 69, 68, 67, 74, 71, 54, 76, 72, 75, 78, 77, 80, 79,&
+ 73, 83, 84, 81, 82, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,&
+ 100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,&
+ 120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,&
+ 140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,&
+ 160,161,162,163,164,165,166,167,168,169,170,171,172,173/
+
diff --git a/lib/ft8/ldpc_174_91_c_colorder.f90 b/lib/ft8/ldpc_174_91_c_colorder.f90
new file mode 100644
index 00000000..a83de09d
--- /dev/null
+++ b/lib/ft8/ldpc_174_91_c_colorder.f90
@@ -0,0 +1,11 @@
+data colorder/ &
+ 0, 1, 2, 3, 28, 4, 5, 6, 7, 8, 9, 10, 11, 34, 12, 32, 13, 14, 15, 16, &
+ 17, 18, 36, 29, 43, 19, 20, 42, 21, 40, 30, 37, 22, 47, 61, 45, 44, 23, 41, 39, &
+ 49, 24, 46, 50, 48, 26, 31, 33, 51, 38, 52, 59, 55, 66, 57, 27, 60, 35, 54, 58, &
+ 25, 56, 62, 64, 67, 69, 63, 68, 70, 72, 65, 73, 75, 74, 71, 77, 78, 76, 79, 80, &
+ 53, 81, 83, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, &
+100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119, &
+120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139, &
+140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159, &
+160,161,162,163,164,165,166,167,168,169,170,171,172,173/
+
diff --git a/lib/ft8/ldpc_174_91_c_generator.f90 b/lib/ft8/ldpc_174_91_c_generator.f90
new file mode 100644
index 00000000..675bae57
--- /dev/null
+++ b/lib/ft8/ldpc_174_91_c_generator.f90
@@ -0,0 +1,86 @@
+character*23 g(83)
+
+data g/ &
+ "8329ce11bf31eaf509f27fc", &
+ "761c264e25c259335493132", &
+ "dc265902fb277c6410a1bdc", &
+ "1b3f417858cd2dd33ec7f62", &
+ "09fda4fee04195fd034783a", &
+ "077cccc11b8873ed5c3d48a", &
+ "29b62afe3ca036f4fe1a9da", &
+ "6054faf5f35d96d3b0c8c3e", &
+ "e20798e4310eed27884ae90", &
+ "775c9c08e80e26ddae56318", &
+ "b0b811028c2bf997213487c", &
+ "18a0c9231fc60adf5c5ea32", &
+ "76471e8302a0721e01b12b8", &
+ "ffbccb80ca8341fafb47b2e", &
+ "66a72a158f9325a2bf67170", &
+ "c4243689fe85b1c51363a18", &
+ "0dff739414d1a1b34b1c270", &
+ "15b48830636c8b99894972e", &
+ "29a89c0d3de81d665489b0e", &
+ "4f126f37fa51cbe61bd6b94", &
+ "99c47239d0d97d3c84e0940", &
+ "1919b75119765621bb4f1e8", &
+ "09db12d731faee0b86df6b8", &
+ "488fc33df43fbdeea4eafb4", &
+ "827423ee40b675f756eb5fe", &
+ "abe197c484cb74757144a9a", &
+ "2b500e4bc0ec5a6d2bdbdd0", &
+ "c474aa53d70218761669360", &
+ "8eba1a13db3390bd6718cec", &
+ "753844673a27782cc42012e", &
+ "06ff83a145c37035a5c1268", &
+ "3b37417858cc2dd33ec3f62", &
+ "9a4a5a28ee17ca9c324842c", &
+ "bc29f465309c977e89610a4", &
+ "2663ae6ddf8b5ce2bb29488", &
+ "46f231efe457034c1814418", &
+ "3fb2ce85abe9b0c72e06fbe", &
+ "de87481f282c153971a0a2e", &
+ "fcd7ccf23c69fa99bba1412", &
+ "f0261447e9490ca8e474cec", &
+ "4410115818196f95cdd7012", &
+ "088fc31df4bfbde2a4eafb4", &
+ "b8fef1b6307729fb0a078c0", &
+ "5afea7acccb77bbc9d99a90", &
+ "49a7016ac653f65ecdc9076", &
+ "1944d085be4e7da8d6cc7d0", &
+ "251f62adc4032f0ee714002", &
+ "56471f8702a0721e00b12b8", &
+ "2b8e4923f2dd51e2d537fa0", &
+ "6b550a40a66f4755de95c26", &
+ "a18ad28d4e27fe92a4f6c84", &
+ "10c2e586388cb82a3d80758", &
+ "ef34a41817ee02133db2eb0", &
+ "7e9c0c54325a9c15836e000", &
+ "3693e572d1fde4cdf079e86", &
+ "bfb2cec5abe1b0c72e07fbe", &
+ "7ee18230c583cccc57d4b08", &
+ "a066cb2fedafc9f52664126", &
+ "bb23725abc47cc5f4cc4cd2", &
+ "ded9dba3bee40c59b5609b4", &
+ "d9a7016ac653e6decdc9036", &
+ "9ad46aed5f707f280ab5fc4", &
+ "e5921c77822587316d7d3c2", &
+ "4f14da8242a8b86dca73352", &
+ "8b8b507ad467d4441df770e", &
+ "22831c9cf1169467ad04b68", &
+ "213b838fe2ae54c38ee7180", &
+ "5d926b6dd71f085181a4e12", &
+ "66ab79d4b29ee6e69509e56", &
+ "958148682d748a38dd68baa", &
+ "b8ce020cf069c32a723ab14", &
+ "f4331d6d461607e95752746", &
+ "6da23ba424b9596133cf9c8", &
+ "a636bcbc7b30c5fbeae67fe", &
+ "5cb0d86a07df654a9089a20", &
+ "f11f106848780fc9ecdd80a", &
+ "1fbb5364fb8d2c9d730d5ba", &
+ "fcb86bc70a50c9d02a5d034", &
+ "a534433029eac15f322e34c", &
+ "c989d9c7c3d3b8c55d75130", &
+ "7bb38b2f0186d46643ae962", &
+ "2644ebadeb44b9467d1f42c", &
+ "608cc857594bfbb55d69600"/
diff --git a/lib/ft8/ldpc_174_91_c_parity.f90 b/lib/ft8/ldpc_174_91_c_parity.f90
new file mode 100644
index 00000000..6210ee26
--- /dev/null
+++ b/lib/ft8/ldpc_174_91_c_parity.f90
@@ -0,0 +1,269 @@
+data Mn/ &
+ 1, 24, 66, &
+ 2, 5, 70, &
+ 3, 31, 65, &
+ 4, 49, 58, &
+ 6, 60, 67, &
+ 7, 32, 75, &
+ 8, 48, 82, &
+ 9, 35, 41, &
+ 10, 39, 62, &
+ 11, 14, 61, &
+ 12, 71, 74, &
+ 13, 23, 78, &
+ 15, 16, 79, &
+ 17, 54, 63, &
+ 18, 50, 57, &
+ 19, 30, 47, &
+ 20, 64, 80, &
+ 21, 28, 69, &
+ 22, 25, 43, &
+ 26, 34, 72, &
+ 27, 36, 37, &
+ 29, 40, 44, &
+ 33, 52, 53, &
+ 38, 55, 83, &
+ 42, 51, 59, &
+ 45, 76, 81, &
+ 46, 68, 77, &
+ 56, 67, 73, &
+ 1, 4, 5, &
+ 2, 47, 51, &
+ 3, 46, 82, &
+ 6, 24, 76, &
+ 7, 9, 16, &
+ 8, 10, 78, &
+ 11, 35, 55, &
+ 12, 38, 64, &
+ 13, 22, 37, &
+ 14, 15, 58, &
+ 17, 50, 53, &
+ 18, 29, 56, &
+ 19, 26, 57, &
+ 20, 39, 77, &
+ 21, 36, 63, &
+ 23, 54, 74, &
+ 25, 69, 73, &
+ 27, 33, 65, &
+ 28, 44, 79, &
+ 30, 43, 52, &
+ 31, 45, 61, &
+ 32, 48, 71, &
+ 34, 60, 62, &
+ 40, 41, 70, &
+ 42, 66, 68, &
+ 49, 75, 83, &
+ 59, 72, 80, &
+ 36, 64, 81, &
+ 1, 65, 74, &
+ 2, 8, 81, &
+ 3, 26, 79, &
+ 4, 22, 72, &
+ 5, 38, 50, &
+ 6, 9, 52, &
+ 7, 18, 77, &
+ 10, 28, 55, &
+ 11, 56, 59, &
+ 12, 67, 68, &
+ 13, 29, 47, &
+ 14, 39, 54, &
+ 15, 60, 70, &
+ 16, 37, 66, &
+ 17, 25, 82, &
+ 19, 21, 71, &
+ 20, 30, 31, &
+ 23, 75, 80, &
+ 24, 69, 75, &
+ 27, 32, 62, &
+ 33, 59, 76, &
+ 34, 53, 61, &
+ 35, 46, 47, &
+ 40, 43, 83, &
+ 41, 42, 63, &
+ 20, 44, 48, &
+ 16, 45, 73, &
+ 42, 49, 57, &
+ 25, 51, 62, &
+ 33, 58, 78, &
+ 1, 44, 45, &
+ 2, 7, 61, &
+ 3, 6, 54, &
+ 4, 35, 48, &
+ 5, 13, 21, &
+ 8, 56, 79, &
+ 9, 64, 69, &
+ 10, 19, 66, &
+ 11, 36, 60, &
+ 12, 37, 58, &
+ 14, 32, 43, &
+ 15, 63, 80, &
+ 17, 28, 77, &
+ 18, 74, 83, &
+ 22, 53, 81, &
+ 23, 30, 34, &
+ 24, 31, 40, &
+ 26, 41, 76, &
+ 27, 57, 70, &
+ 29, 49, 65, &
+ 3, 38, 78, &
+ 5, 39, 82, &
+ 46, 50, 73, &
+ 51, 52, 74, &
+ 55, 71, 72, &
+ 44, 67, 72, &
+ 43, 68, 78, &
+ 1, 32, 59, &
+ 2, 6, 71, &
+ 4, 16, 54, &
+ 7, 65, 67, &
+ 8, 30, 42, &
+ 9, 22, 31, &
+ 10, 18, 76, &
+ 11, 23, 82, &
+ 12, 28, 61, &
+ 13, 52, 79, &
+ 14, 50, 51, &
+ 15, 81, 83, &
+ 17, 29, 60, &
+ 19, 33, 64, &
+ 20, 26, 73, &
+ 21, 34, 40, &
+ 24, 27, 77, &
+ 25, 55, 58, &
+ 35, 53, 66, &
+ 36, 48, 68, &
+ 37, 46, 75, &
+ 38, 45, 47, &
+ 39, 57, 69, &
+ 41, 56, 62, &
+ 20, 49, 53, &
+ 46, 52, 63, &
+ 45, 70, 75, &
+ 27, 35, 80, &
+ 1, 15, 30, &
+ 2, 68, 80, &
+ 3, 36, 51, &
+ 4, 28, 51, &
+ 5, 31, 56, &
+ 6, 20, 37, &
+ 7, 40, 82, &
+ 8, 60, 69, &
+ 9, 10, 49, &
+ 11, 44, 57, &
+ 12, 39, 59, &
+ 13, 24, 55, &
+ 14, 21, 65, &
+ 16, 71, 78, &
+ 17, 30, 76, &
+ 18, 25, 80, &
+ 19, 61, 83, &
+ 22, 38, 77, &
+ 23, 41, 50, &
+ 7, 26, 58, &
+ 29, 32, 81, &
+ 33, 40, 73, &
+ 18, 34, 48, &
+ 13, 42, 64, &
+ 5, 26, 43, &
+ 47, 69, 72, &
+ 54, 55, 70, &
+ 45, 62, 68, &
+ 10, 63, 67, &
+ 14, 66, 72, &
+ 22, 60, 74, &
+ 35, 39, 79, &
+ 1, 46, 64/
+
+data Nm/ &
+ 1, 29, 57, 87, 114, 142, 174, &
+ 2, 30, 58, 88, 115, 143, 0, &
+ 3, 31, 59, 89, 107, 144, 0, &
+ 4, 29, 60, 90, 116, 145, 0, &
+ 2, 29, 61, 91, 108, 146, 166, &
+ 5, 32, 62, 89, 115, 147, 0, &
+ 6, 33, 63, 88, 117, 148, 161, &
+ 7, 34, 58, 92, 118, 149, 0, &
+ 8, 33, 62, 93, 119, 150, 0, &
+ 9, 34, 64, 94, 120, 150, 170, &
+ 10, 35, 65, 95, 121, 151, 0, &
+ 11, 36, 66, 96, 122, 152, 0, &
+ 12, 37, 67, 91, 123, 153, 165, &
+ 10, 38, 68, 97, 124, 154, 171, &
+ 13, 38, 69, 98, 125, 142, 0, &
+ 13, 33, 70, 83, 116, 155, 0, &
+ 14, 39, 71, 99, 126, 156, 0, &
+ 15, 40, 63, 100, 120, 157, 164, &
+ 16, 41, 72, 94, 127, 158, 0, &
+ 17, 42, 73, 82, 128, 138, 147, &
+ 18, 43, 72, 91, 129, 154, 0, &
+ 19, 37, 60, 101, 119, 159, 172, &
+ 12, 44, 74, 102, 121, 160, 0, &
+ 1, 32, 75, 103, 130, 153, 0, &
+ 19, 45, 71, 85, 131, 157, 0, &
+ 20, 41, 59, 104, 128, 161, 166, &
+ 21, 46, 76, 105, 130, 141, 0, &
+ 18, 47, 64, 99, 122, 145, 0, &
+ 22, 40, 67, 106, 126, 162, 0, &
+ 16, 48, 73, 102, 118, 142, 156, &
+ 3, 49, 73, 103, 119, 146, 0, &
+ 6, 50, 76, 97, 114, 162, 0, &
+ 23, 46, 77, 86, 127, 163, 0, &
+ 20, 51, 78, 102, 129, 164, 0, &
+ 8, 35, 79, 90, 132, 141, 173, &
+ 21, 43, 56, 95, 133, 144, 0, &
+ 21, 37, 70, 96, 134, 147, 0, &
+ 24, 36, 61, 107, 135, 159, 0, &
+ 9, 42, 68, 108, 136, 152, 173, &
+ 22, 52, 80, 103, 129, 148, 163, &
+ 8, 52, 81, 104, 137, 160, 0, &
+ 25, 53, 81, 84, 118, 165, 0, &
+ 19, 48, 80, 97, 113, 166, 0, &
+ 22, 47, 82, 87, 112, 151, 0, &
+ 26, 49, 83, 87, 135, 140, 169, &
+ 27, 31, 79, 109, 134, 139, 174, &
+ 16, 30, 67, 79, 135, 167, 0, &
+ 7, 50, 82, 90, 133, 164, 0, &
+ 4, 54, 84, 106, 138, 150, 0, &
+ 15, 39, 61, 109, 124, 160, 0, &
+ 25, 30, 85, 110, 124, 144, 145, &
+ 23, 48, 62, 110, 123, 139, 0, &
+ 23, 39, 78, 101, 132, 138, 0, &
+ 14, 44, 68, 89, 116, 168, 0, &
+ 24, 35, 64, 111, 131, 153, 168, &
+ 28, 40, 65, 92, 137, 146, 0, &
+ 15, 41, 84, 105, 136, 151, 0, &
+ 4, 38, 86, 96, 131, 161, 0, &
+ 25, 55, 65, 77, 114, 152, 0, &
+ 5, 51, 69, 95, 126, 149, 172, &
+ 10, 49, 78, 88, 122, 158, 0, &
+ 9, 51, 76, 85, 137, 169, 0, &
+ 14, 43, 81, 98, 139, 170, 0, &
+ 17, 36, 56, 93, 127, 165, 174, &
+ 3, 46, 57, 106, 117, 154, 0, &
+ 1, 53, 70, 94, 132, 171, 0, &
+ 5, 28, 66, 112, 117, 170, 0, &
+ 27, 53, 66, 113, 133, 143, 169, &
+ 18, 45, 75, 93, 136, 149, 167, &
+ 2, 52, 69, 105, 140, 168, 0, &
+ 11, 50, 72, 111, 115, 155, 0, &
+ 20, 55, 60, 111, 112, 167, 171, &
+ 28, 45, 83, 109, 128, 163, 0, &
+ 11, 44, 57, 100, 110, 172, 0, &
+ 6, 54, 74, 75, 134, 140, 0, &
+ 26, 32, 77, 104, 120, 156, 0, &
+ 27, 42, 63, 99, 130, 159, 0, &
+ 12, 34, 86, 107, 113, 155, 0, &
+ 13, 47, 59, 92, 123, 173, 0, &
+ 17, 55, 74, 98, 141, 143, 157, &
+ 26, 56, 58, 101, 125, 162, 0, &
+ 7, 31, 71, 108, 121, 148, 0, &
+ 24, 54, 80, 100, 125, 158, 0/
+
+data nrw/ &
+7,6,6,6,7,6,7,6,6,7,6,6,7,7,6,6,6, &
+7,6,7,6,7,6,6,6,7,6,6,6,7,6,6,6,6, &
+7,6,6,6,7,7,6,6,6,6,7,7,6,6,6,6,7, &
+6,6,6,7,6,6,6,6,7,6,6,6,7,6,6,6,7, &
+7,6,6,7,6,6,6,6,6,6,6,7,6,6,6/
+
+ncw=3
diff --git a/lib/ft8/ldpc_174_91_c_reordered_parity.f90 b/lib/ft8/ldpc_174_91_c_reordered_parity.f90
new file mode 100644
index 00000000..2309ad8e
--- /dev/null
+++ b/lib/ft8/ldpc_174_91_c_reordered_parity.f90
@@ -0,0 +1,270 @@
+data Mn/ &
+ 16, 45, 73, &
+ 25, 51, 62, &
+ 33, 58, 78, &
+ 1, 44, 45, &
+ 2, 7, 61, &
+ 3, 6, 54, &
+ 4, 35, 48, &
+ 5, 13, 21, &
+ 8, 56, 79, &
+ 9, 64, 69, &
+ 10, 19, 66, &
+ 11, 36, 60, &
+ 12, 37, 58, &
+ 14, 32, 43, &
+ 15, 63, 80, &
+ 17, 28, 77, &
+ 18, 74, 83, &
+ 22, 53, 81, &
+ 23, 30, 34, &
+ 24, 31, 40, &
+ 26, 41, 76, &
+ 27, 57, 70, &
+ 29, 49, 65, &
+ 3, 38, 78, &
+ 5, 39, 82, &
+ 46, 50, 73, &
+ 51, 52, 74, &
+ 55, 71, 72, &
+ 44, 67, 72, &
+ 43, 68, 78, &
+ 1, 32, 59, &
+ 2, 6, 71, &
+ 4, 16, 54, &
+ 7, 65, 67, &
+ 8, 30, 42, &
+ 9, 22, 31, &
+ 10, 18, 76, &
+ 11, 23, 82, &
+ 12, 28, 61, &
+ 13, 52, 79, &
+ 14, 50, 51, &
+ 15, 81, 83, &
+ 17, 29, 60, &
+ 19, 33, 64, &
+ 20, 26, 73, &
+ 21, 34, 40, &
+ 24, 27, 77, &
+ 25, 55, 58, &
+ 35, 53, 66, &
+ 36, 48, 68, &
+ 37, 46, 75, &
+ 38, 45, 47, &
+ 39, 57, 69, &
+ 41, 56, 62, &
+ 20, 49, 53, &
+ 46, 52, 63, &
+ 45, 70, 75, &
+ 27, 35, 80, &
+ 1, 15, 30, &
+ 2, 68, 80, &
+ 3, 36, 51, &
+ 4, 28, 51, &
+ 5, 31, 56, &
+ 6, 20, 37, &
+ 7, 40, 82, &
+ 8, 60, 69, &
+ 9, 10, 49, &
+ 11, 44, 57, &
+ 12, 39, 59, &
+ 13, 24, 55, &
+ 14, 21, 65, &
+ 16, 71, 78, &
+ 17, 30, 76, &
+ 18, 25, 80, &
+ 19, 61, 83, &
+ 22, 38, 77, &
+ 23, 41, 50, &
+ 7, 26, 58, &
+ 29, 32, 81, &
+ 33, 40, 73, &
+ 18, 34, 48, &
+ 13, 42, 64, &
+ 5, 26, 43, &
+ 47, 69, 72, &
+ 54, 55, 70, &
+ 45, 62, 68, &
+ 10, 63, 67, &
+ 14, 66, 72, &
+ 22, 60, 74, &
+ 35, 39, 79, &
+ 1, 46, 64, &
+ 1, 24, 66, &
+ 2, 5, 70, &
+ 3, 31, 65, &
+ 4, 49, 58, &
+ 1, 4, 5, &
+ 6, 60, 67, &
+ 7, 32, 75, &
+ 8, 48, 82, &
+ 9, 35, 41, &
+ 10, 39, 62, &
+ 11, 14, 61, &
+ 12, 71, 74, &
+ 13, 23, 78, &
+ 11, 35, 55, &
+ 15, 16, 79, &
+ 7, 9, 16, &
+ 17, 54, 63, &
+ 18, 50, 57, &
+ 19, 30, 47, &
+ 20, 64, 80, &
+ 21, 28, 69, &
+ 22, 25, 43, &
+ 13, 22, 37, &
+ 2, 47, 51, &
+ 23, 54, 74, &
+ 26, 34, 72, &
+ 27, 36, 37, &
+ 21, 36, 63, &
+ 29, 40, 44, &
+ 19, 26, 57, &
+ 3, 46, 82, &
+ 14, 15, 58, &
+ 33, 52, 53, &
+ 30, 43, 52, &
+ 6, 9, 52, &
+ 27, 33, 65, &
+ 25, 69, 73, &
+ 38, 55, 83, &
+ 20, 39, 77, &
+ 18, 29, 56, &
+ 32, 48, 71, &
+ 42, 51, 59, &
+ 28, 44, 79, &
+ 34, 60, 62, &
+ 31, 45, 61, &
+ 46, 68, 77, &
+ 6, 24, 76, &
+ 8, 10, 78, &
+ 40, 41, 70, &
+ 17, 50, 53, &
+ 42, 66, 68, &
+ 4, 22, 72, &
+ 36, 64, 81, &
+ 13, 29, 47, &
+ 2, 8, 81, &
+ 56, 67, 73, &
+ 5, 38, 50, &
+ 12, 38, 64, &
+ 59, 72, 80, &
+ 3, 26, 79, &
+ 45, 76, 81, &
+ 1, 65, 74, &
+ 7, 18, 77, &
+ 11, 56, 59, &
+ 14, 39, 54, &
+ 16, 37, 66, &
+ 10, 28, 55, &
+ 15, 60, 70, &
+ 17, 25, 82, &
+ 20, 30, 31, &
+ 12, 67, 68, &
+ 23, 75, 80, &
+ 27, 32, 62, &
+ 24, 69, 75, &
+ 19, 21, 71, &
+ 34, 53, 61, &
+ 35, 46, 47, &
+ 33, 59, 76, &
+ 40, 43, 83, &
+ 41, 42, 63, &
+ 49, 75, 83, &
+ 20, 44, 48, &
+ 42, 49, 57/
+
+data Nm/ &
+ 4, 31, 59, 91, 92, 96, 153, &
+ 5, 32, 60, 93, 115, 146, 0, &
+ 6, 24, 61, 94, 122, 151, 0, &
+ 7, 33, 62, 95, 96, 143, 0, &
+ 8, 25, 63, 83, 93, 96, 148, &
+ 6, 32, 64, 97, 126, 138, 0, &
+ 5, 34, 65, 78, 98, 107, 154, &
+ 9, 35, 66, 99, 139, 146, 0, &
+ 10, 36, 67, 100, 107, 126, 0, &
+ 11, 37, 67, 87, 101, 139, 158, &
+ 12, 38, 68, 102, 105, 155, 0, &
+ 13, 39, 69, 103, 149, 162, 0, &
+ 8, 40, 70, 82, 104, 114, 145, &
+ 14, 41, 71, 88, 102, 123, 156, &
+ 15, 42, 59, 106, 123, 159, 0, &
+ 1, 33, 72, 106, 107, 157, 0, &
+ 16, 43, 73, 108, 141, 160, 0, &
+ 17, 37, 74, 81, 109, 131, 154, &
+ 11, 44, 75, 110, 121, 166, 0, &
+ 45, 55, 64, 111, 130, 161, 173, &
+ 8, 46, 71, 112, 119, 166, 0, &
+ 18, 36, 76, 89, 113, 114, 143, &
+ 19, 38, 77, 104, 116, 163, 0, &
+ 20, 47, 70, 92, 138, 165, 0, &
+ 2, 48, 74, 113, 128, 160, 0, &
+ 21, 45, 78, 83, 117, 121, 151, &
+ 22, 47, 58, 118, 127, 164, 0, &
+ 16, 39, 62, 112, 134, 158, 0, &
+ 23, 43, 79, 120, 131, 145, 0, &
+ 19, 35, 59, 73, 110, 125, 161, &
+ 20, 36, 63, 94, 136, 161, 0, &
+ 14, 31, 79, 98, 132, 164, 0, &
+ 3, 44, 80, 124, 127, 169, 0, &
+ 19, 46, 81, 117, 135, 167, 0, &
+ 7, 49, 58, 90, 100, 105, 168, &
+ 12, 50, 61, 118, 119, 144, 0, &
+ 13, 51, 64, 114, 118, 157, 0, &
+ 24, 52, 76, 129, 148, 149, 0, &
+ 25, 53, 69, 90, 101, 130, 156, &
+ 20, 46, 65, 80, 120, 140, 170, &
+ 21, 54, 77, 100, 140, 171, 0, &
+ 35, 82, 133, 142, 171, 174, 0, &
+ 14, 30, 83, 113, 125, 170, 0, &
+ 4, 29, 68, 120, 134, 173, 0, &
+ 1, 4, 52, 57, 86, 136, 152, &
+ 26, 51, 56, 91, 122, 137, 168, &
+ 52, 84, 110, 115, 145, 168, 0, &
+ 7, 50, 81, 99, 132, 173, 0, &
+ 23, 55, 67, 95, 172, 174, 0, &
+ 26, 41, 77, 109, 141, 148, 0, &
+ 2, 27, 41, 61, 62, 115, 133, &
+ 27, 40, 56, 124, 125, 126, 0, &
+ 18, 49, 55, 124, 141, 167, 0, &
+ 6, 33, 85, 108, 116, 156, 0, &
+ 28, 48, 70, 85, 105, 129, 158, &
+ 9, 54, 63, 131, 147, 155, 0, &
+ 22, 53, 68, 109, 121, 174, 0, &
+ 3, 13, 48, 78, 95, 123, 0, &
+ 31, 69, 133, 150, 155, 169, 0, &
+ 12, 43, 66, 89, 97, 135, 159, &
+ 5, 39, 75, 102, 136, 167, 0, &
+ 2, 54, 86, 101, 135, 164, 0, &
+ 15, 56, 87, 108, 119, 171, 0, &
+ 10, 44, 82, 91, 111, 144, 149, &
+ 23, 34, 71, 94, 127, 153, 0, &
+ 11, 49, 88, 92, 142, 157, 0, &
+ 29, 34, 87, 97, 147, 162, 0, &
+ 30, 50, 60, 86, 137, 142, 162, &
+ 10, 53, 66, 84, 112, 128, 165, &
+ 22, 57, 85, 93, 140, 159, 0, &
+ 28, 32, 72, 103, 132, 166, 0, &
+ 28, 29, 84, 88, 117, 143, 150, &
+ 1, 26, 45, 80, 128, 147, 0, &
+ 17, 27, 89, 103, 116, 153, 0, &
+ 51, 57, 98, 163, 165, 172, 0, &
+ 21, 37, 73, 138, 152, 169, 0, &
+ 16, 47, 76, 130, 137, 154, 0, &
+ 3, 24, 30, 72, 104, 139, 0, &
+ 9, 40, 90, 106, 134, 151, 0, &
+ 15, 58, 60, 74, 111, 150, 163, &
+ 18, 42, 79, 144, 146, 152, 0, &
+ 25, 38, 65, 99, 122, 160, 0, &
+ 17, 42, 75, 129, 170, 172, 0/
+
+data nrw/ &
+7,6,6,6,7,6,7,6,6,7,6,6,7,7,6,6, &
+6,7,6,7,6,7,6,6,6,7,6,6,6,7,6,6, &
+6,6,7,6,6,6,7,7,6,6,6,6,7,7,6,6, &
+6,6,7,6,6,6,7,6,6,6,6,7,6,6,6,7, &
+6,6,6,7,7,6,6,7,6,6,6,6,6,6,6,7, &
+6,6,6/
+
+ncw=3
diff --git a/lib/ft8/osd174_91.f90 b/lib/ft8/osd174_91.f90
new file mode 100644
index 00000000..958b0c9f
--- /dev/null
+++ b/lib/ft8/osd174_91.f90
@@ -0,0 +1,372 @@
+subroutine osd174_91(llr,apmask,ndeep,message77,cw,nhardmin,dmin)
+!
+! An ordered-statistics decoder for the (174,91) code.
+!
+integer, parameter:: N=174, K=91, M=N-K
+integer*1 apmask(N),apmaskr(N)
+integer*1 gen(K,N)
+integer*1 genmrb(K,N),g2(N,K)
+integer*1 temp(K),m0(K),me(K),mi(K),misub(K),e2sub(N-K),e2(N-K),ui(N-K)
+integer*1 r2pat(N-K)
+integer indices(N),nxor(N)
+integer*1 cw(N),ce(N),c0(N),hdec(N)
+integer*1 decoded(K)
+integer*1 message77(77)
+integer indx(N)
+real llr(N),rx(N),absrx(N)
+
+include "ldpc_174_91_c_generator.f90"
+
+logical first,reset
+data first/.true./
+save first,gen
+
+if( first ) then ! fill the generator matrix
+ gen=0
+ do i=1,M
+ do j=1,23
+ read(g(i)(j:j),"(Z1)") istr
+ ibmax=4
+ if(j.eq.23) ibmax=3
+ do jj=1, ibmax
+ irow=(j-1)*4+jj
+ if( btest(istr,4-jj) ) gen(irow,K+i)=1
+ enddo
+ enddo
+ enddo
+ do irow=1,K
+ gen(irow,irow)=1
+ enddo
+first=.false.
+endif
+
+rx=llr
+apmaskr=apmask
+
+! Hard decisions on the received word.
+hdec=0
+where(rx .ge. 0) hdec=1
+
+! Use magnitude of received symbols as a measure of reliability.
+absrx=abs(rx)
+call indexx(absrx,N,indx)
+
+! Re-order the columns of the generator matrix in order of decreasing reliability.
+do i=1,N
+ genmrb(1:K,i)=gen(1:K,indx(N+1-i))
+ indices(i)=indx(N+1-i)
+enddo
+
+! Do gaussian elimination to create a generator matrix with the most reliable
+! received bits in positions 1:K in order of decreasing reliability (more or less).
+do id=1,K ! diagonal element indices
+ do icol=id,K+20 ! The 20 is ad hoc - beware
+ iflag=0
+ if( genmrb(id,icol) .eq. 1 ) then
+ iflag=1
+ if( icol .ne. id ) then ! reorder column
+ temp(1:K)=genmrb(1:K,id)
+ genmrb(1:K,id)=genmrb(1:K,icol)
+ genmrb(1:K,icol)=temp(1:K)
+ itmp=indices(id)
+ indices(id)=indices(icol)
+ indices(icol)=itmp
+ endif
+ do ii=1,K
+ if( ii .ne. id .and. genmrb(ii,id) .eq. 1 ) then
+ genmrb(ii,1:N)=ieor(genmrb(ii,1:N),genmrb(id,1:N))
+ endif
+ enddo
+ exit
+ endif
+ enddo
+enddo
+
+g2=transpose(genmrb)
+
+! The hard decisions for the K MRB bits define the order 0 message, m0.
+! Encode m0 using the modified generator matrix to find the "order 0" codeword.
+! Flip various combinations of bits in m0 and re-encode to generate a list of
+! codewords. Return the member of the list that has the smallest Euclidean
+! distance to the received word.
+
+hdec=hdec(indices) ! hard decisions from received symbols
+m0=hdec(1:K) ! zero'th order message
+absrx=absrx(indices)
+rx=rx(indices)
+apmaskr=apmaskr(indices)
+
+call mrbencode91(m0,c0,g2,N,K)
+nxor=ieor(c0,hdec)
+nhardmin=sum(nxor)
+dmin=sum(nxor*absrx)
+
+cw=c0
+ntotal=0
+nrejected=0
+
+if(ndeep.eq.0) goto 998 ! norder=0
+if(ndeep.gt.5) ndeep=5
+if( ndeep.eq. 1) then
+ nord=1
+ npre1=0
+ npre2=0
+ nt=40
+ ntheta=12
+elseif(ndeep.eq.2) then
+ nord=1
+ npre1=1
+ npre2=0
+ nt=40
+ ntheta=12
+elseif(ndeep.eq.3) then
+ nord=1
+ npre1=1
+ npre2=1
+ nt=40
+ ntheta=12
+ ntau=14
+elseif(ndeep.eq.4) then
+ nord=2
+ npre1=1
+ npre2=0
+ nt=40
+ ntheta=12
+ ntau=19
+elseif(ndeep.eq.5) then
+ nord=2
+ npre1=1
+ npre2=1
+ nt=40
+ ntheta=12
+ ntau=19
+endif
+
+do iorder=1,nord
+ misub(1:K-iorder)=0
+ misub(K-iorder+1:K)=1
+ iflag=K-iorder+1
+ do while(iflag .ge.0)
+ if(iorder.eq.nord .and. npre1.eq.0) then
+ iend=iflag
+ else
+ iend=1
+ endif
+ do n1=iflag,iend,-1
+ mi=misub
+ mi(n1)=1
+ if(any(iand(apmaskr(1:K),mi).eq.1)) cycle
+ ntotal=ntotal+1
+ me=ieor(m0,mi)
+ if(n1.eq.iflag) then
+ call mrbencode91(me,ce,g2,N,K)
+ e2sub=ieor(ce(K+1:N),hdec(K+1:N))
+ e2=e2sub
+ nd1Kpt=sum(e2sub(1:nt))+1
+ d1=sum(ieor(me(1:K),hdec(1:K))*absrx(1:K))
+ else
+ e2=ieor(e2sub,g2(K+1:N,n1))
+ nd1Kpt=sum(e2(1:nt))+2
+ endif
+ if(nd1Kpt .le. ntheta) then
+ call mrbencode91(me,ce,g2,N,K)
+ nxor=ieor(ce,hdec)
+ if(n1.eq.iflag) then
+ dd=d1+sum(e2sub*absrx(K+1:N))
+ else
+ dd=d1+ieor(ce(n1),hdec(n1))*absrx(n1)+sum(e2*absrx(K+1:N))
+ endif
+ if( dd .lt. dmin ) then
+ dmin=dd
+ cw=ce
+ nhardmin=sum(nxor)
+ nd1Kptbest=nd1Kpt
+ endif
+ else
+ nrejected=nrejected+1
+ endif
+ enddo
+! Get the next test error pattern, iflag will go negative
+! when the last pattern with weight iorder has been generated.
+ call nextpat91(misub,k,iorder,iflag)
+ enddo
+enddo
+
+if(npre2.eq.1) then
+ reset=.true.
+ ntotal=0
+ do i1=K,1,-1
+ do i2=i1-1,1,-1
+ ntotal=ntotal+1
+ mi(1:ntau)=ieor(g2(K+1:K+ntau,i1),g2(K+1:K+ntau,i2))
+ call boxit91(reset,mi(1:ntau),ntau,ntotal,i1,i2)
+ enddo
+ enddo
+
+ ncount2=0
+ ntotal2=0
+ reset=.true.
+! Now run through again and do the second pre-processing rule
+ misub(1:K-nord)=0
+ misub(K-nord+1:K)=1
+ iflag=K-nord+1
+ do while(iflag .ge.0)
+ me=ieor(m0,misub)
+ call mrbencode91(me,ce,g2,N,K)
+ e2sub=ieor(ce(K+1:N),hdec(K+1:N))
+ do i2=0,ntau
+ ntotal2=ntotal2+1
+ ui=0
+ if(i2.gt.0) ui(i2)=1
+ r2pat=ieor(e2sub,ui)
+778 continue
+ call fetchit91(reset,r2pat(1:ntau),ntau,in1,in2)
+ if(in1.gt.0.and.in2.gt.0) then
+ ncount2=ncount2+1
+ mi=misub
+ mi(in1)=1
+ mi(in2)=1
+ if(sum(mi).lt.nord+npre1+npre2.or.any(iand(apmaskr(1:K),mi).eq.1)) cycle
+ me=ieor(m0,mi)
+ call mrbencode91(me,ce,g2,N,K)
+ nxor=ieor(ce,hdec)
+ dd=sum(nxor*absrx)
+ if( dd .lt. dmin ) then
+ dmin=dd
+ cw=ce
+ nhardmin=sum(nxor)
+ endif
+ goto 778
+ endif
+ enddo
+ call nextpat91(misub,K,nord,iflag)
+ enddo
+endif
+
+998 continue
+! Re-order the codeword to [message bits][parity bits] format.
+cw(indices)=cw
+hdec(indices)=hdec
+decoded=cw(1:K)
+call chkcrc14a(decoded,nbadcrc)
+message77=decoded(1:77)
+if(nbadcrc.eq.1) nhardmin=-nhardmin
+
+return
+end subroutine osd174_91
+
+subroutine mrbencode91(me,codeword,g2,N,K)
+integer*1 me(K),codeword(N),g2(N,K)
+! fast encoding for low-weight test patterns
+ codeword=0
+ do i=1,K
+ if( me(i) .eq. 1 ) then
+ codeword=ieor(codeword,g2(1:N,i))
+ endif
+ enddo
+return
+end subroutine mrbencode91
+
+subroutine nextpat91(mi,k,iorder,iflag)
+ integer*1 mi(k),ms(k)
+! generate the next test error pattern
+ ind=-1
+ do i=1,k-1
+ if( mi(i).eq.0 .and. mi(i+1).eq.1) ind=i
+ enddo
+ if( ind .lt. 0 ) then ! no more patterns of this order
+ iflag=ind
+ return
+ endif
+ ms=0
+ ms(1:ind-1)=mi(1:ind-1)
+ ms(ind)=1
+ ms(ind+1)=0
+ if( ind+1 .lt. k ) then
+ nz=iorder-sum(ms)
+ ms(k-nz+1:k)=1
+ endif
+ mi=ms
+ do i=1,k ! iflag will point to the lowest-index 1 in mi
+ if(mi(i).eq.1) then
+ iflag=i
+ exit
+ endif
+ enddo
+ return
+end subroutine nextpat91
+
+subroutine boxit91(reset,e2,ntau,npindex,i1,i2)
+ integer*1 e2(1:ntau)
+ integer indexes(5000,2),fp(0:525000),np(5000)
+ logical reset
+ common/boxes/indexes,fp,np
+
+ if(reset) then
+ patterns=-1
+ fp=-1
+ np=-1
+ sc=-1
+ indexes=-1
+ reset=.false.
+ endif
+
+ indexes(npindex,1)=i1
+ indexes(npindex,2)=i2
+ ipat=0
+ do i=1,ntau
+ if(e2(i).eq.1) then
+ ipat=ipat+ishft(1,ntau-i)
+ endif
+ enddo
+
+ ip=fp(ipat) ! see what's currently stored in fp(ipat)
+ if(ip.eq.-1) then
+ fp(ipat)=npindex
+ else
+ do while (np(ip).ne.-1)
+ ip=np(ip)
+ enddo
+ np(ip)=npindex
+ endif
+ return
+end subroutine boxit91
+
+subroutine fetchit91(reset,e2,ntau,i1,i2)
+ integer indexes(5000,2),fp(0:525000),np(5000)
+ integer lastpat
+ integer*1 e2(ntau)
+ logical reset
+ common/boxes/indexes,fp,np
+ save lastpat,inext
+
+ if(reset) then
+ lastpat=-1
+ reset=.false.
+ endif
+
+ ipat=0
+ do i=1,ntau
+ if(e2(i).eq.1) then
+ ipat=ipat+ishft(1,ntau-i)
+ endif
+ enddo
+ index=fp(ipat)
+
+ if(lastpat.ne.ipat .and. index.gt.0) then ! return first set of indices
+ i1=indexes(index,1)
+ i2=indexes(index,2)
+ inext=np(index)
+ elseif(lastpat.eq.ipat .and. inext.gt.0) then
+ i1=indexes(inext,1)
+ i2=indexes(inext,2)
+ inext=np(inext)
+ else
+ i1=-1
+ i2=-1
+ inext=-1
+ endif
+ lastpat=ipat
+ return
+end subroutine fetchit91
+
diff --git a/lib/ft8/subtractft8.f90 b/lib/ft8/subtractft8.f90
new file mode 100644
index 00000000..1031cf2b
--- /dev/null
+++ b/lib/ft8/subtractft8.f90
@@ -0,0 +1,61 @@
+subroutine subtractft8(dd,itone,f0,dt)
+
+! Subtract an ft8 signal
+!
+! Measured signal : dd(t) = a(t)cos(2*pi*f0*t+theta(t))
+! Reference signal : cref(t) = exp( j*(2*pi*f0*t+phi(t)) )
+! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ]
+! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt}
+
+ use timer_module, only: timer
+
+ parameter (NMAX=15*12000,NFRAME=1920*79)
+ parameter (NFFT=NMAX,NFILT=1400)
+ real*4 dd(NMAX), window(-NFILT/2:NFILT/2)
+ complex cref,camp,cfilt,cw
+ integer itone(79)
+ logical first
+ data first/.true./
+ common/heap8/cref(NFRAME),camp(NMAX),cfilt(NMAX),cw(NMAX)
+ save first
+
+ nstart=dt*12000+1
+ call genft8refsig(itone,cref,f0)
+ camp=0.
+ do i=1,nframe
+ id=nstart-1+i
+ if(id.ge.1.and.id.le.NMAX) camp(i)=dd(id)*conjg(cref(i))
+ enddo
+
+ if(first) then
+! Create and normalize the filter
+ pi=4.0*atan(1.0)
+ fac=1.0/float(nfft)
+ sum=0.0
+ do j=-NFILT/2,NFILT/2
+ window(j)=cos(pi*j/NFILT)**2
+ sum=sum+window(j)
+ enddo
+ cw=0.
+ cw(1:NFILT+1)=window/sum
+ cw=cshift(cw,NFILT/2+1)
+ call four2a(cw,nfft,1,-1,1)
+ cw=cw*fac
+ first=.false.
+ endif
+
+ cfilt=0.0
+ cfilt(1:nframe)=camp(1:nframe)
+ call four2a(cfilt,nfft,1,-1,1)
+ cfilt(1:nfft)=cfilt(1:nfft)*cw(1:nfft)
+ call four2a(cfilt,nfft,1,1,1)
+
+! Subtract the reconstructed signal
+ do i=1,nframe
+ j=nstart+i-1
+ if(j.ge.1 .and. j.le.NMAX) dd(j)=dd(j)-2*REAL(cfilt(i)*cref(i))
+ enddo
+
+ return
+end subroutine subtractft8
+
diff --git a/lib/ft8/sync8.f90 b/lib/ft8/sync8.f90
new file mode 100644
index 00000000..3924f1ba
--- /dev/null
+++ b/lib/ft8/sync8.f90
@@ -0,0 +1,142 @@
+subroutine sync8(dd,nfa,nfb,syncmin,nfqso,maxcand,s,candidate, &
+ ncand,sbase)
+
+ include 'ft8_params.f90'
+! Search over +/- 2.5s relative to 0.5s TX start time.
+ parameter (JZ=62)
+ complex cx(0:NH1)
+ real s(NH1,NHSYM)
+ real savg(NH1)
+ real sbase(NH1)
+ real x(NFFT1)
+ real sync2d(NH1,-JZ:JZ)
+ real red(NH1)
+ real candidate0(3,maxcand)
+ real candidate(3,maxcand)
+ real dd(NMAX)
+ integer jpeak(NH1)
+ integer indx(NH1)
+ integer ii(1)
+ integer icos7(0:6)
+ data icos7/3,1,4,0,6,5,2/ !Costas 7x7 tone pattern
+ equivalence (x,cx)
+
+! Compute symbol spectra, stepping by NSTEP steps.
+ savg=0.
+ tstep=NSTEP/12000.0
+ df=12000.0/NFFT1 !3.125 Hz
+ fac=1.0/300.0
+ do j=1,NHSYM
+ ia=(j-1)*NSTEP + 1
+ ib=ia+NSPS-1
+ x(1:NSPS)=fac*dd(ia:ib)
+ x(NSPS+1:)=0.
+ call four2a(x,NFFT1,1,-1,0) !r2c FFT
+ do i=1,NH1
+ s(i,j)=real(cx(i))**2 + aimag(cx(i))**2
+ enddo
+ savg=savg + s(1:NH1,j) !Average spectrum
+ enddo
+ call baseline(savg,nfa,nfb,sbase)
+
+ ia=max(1,nint(nfa/df))
+ ib=nint(nfb/df)
+ nssy=NSPS/NSTEP ! # steps per symbol
+ nfos=NFFT1/NSPS ! # frequency bin oversampling factor
+ jstrt=0.5/tstep
+ candidate0=0.
+ k=0
+
+ do i=ia,ib
+ do j=-JZ,+JZ
+ ta=0.
+ tb=0.
+ tc=0.
+ t0a=0.
+ t0b=0.
+ t0c=0.
+ do n=0,6
+ m=j+jstrt+nssy*n
+ if(m.ge.1.and.m.le.NHSYM) then
+ ta=ta + s(i+nfos*icos7(n),m)
+ t0a=t0a + sum(s(i:i+nfos*6:nfos,m))
+ endif
+ tb=tb + s(i+nfos*icos7(n),m+nssy*36)
+ t0b=t0b + sum(s(i:i+nfos*6:nfos,m+nssy*36))
+ if(m+nssy*72.le.NHSYM) then
+ tc=tc + s(i+nfos*icos7(n),m+nssy*72)
+ t0c=t0c + sum(s(i:i+nfos*6:nfos,m+nssy*72))
+ endif
+ enddo
+ t=ta+tb+tc
+ t0=t0a+t0b+t0c
+ t0=(t0-t)/6.0
+ sync_abc=t/t0
+ t=tb+tc
+ t0=t0b+t0c
+ t0=(t0-t)/6.0
+ sync_bc=t/t0
+ sync2d(i,j)=max(sync_abc,sync_bc)
+ enddo
+ enddo
+
+ red=0.
+ do i=ia,ib
+ ii=maxloc(sync2d(i,-JZ:JZ)) - 1 - JZ
+ j0=ii(1)
+ jpeak(i)=j0
+ red(i)=sync2d(i,j0)
+ enddo
+ iz=ib-ia+1
+ call indexx(red(ia:ib),iz,indx)
+ ibase=indx(nint(0.40*iz)) - 1 + ia
+ if(ibase.lt.1) ibase=1
+ if(ibase.gt.nh1) ibase=nh1
+ base=red(ibase)
+ red=red/base
+
+ do i=1,min(maxcand,iz)
+ n=ia + indx(iz+1-i) - 1
+ if(red(n).lt.syncmin.or.isnan(red(n)).or.k.eq.maxcand) exit
+ k=k+1
+ candidate0(1,k)=n*df
+ candidate0(2,k)=(jpeak(n)-1)*tstep
+ candidate0(3,k)=red(n)
+ enddo
+ ncand=k
+
+! Put nfqso at top of list, and save only the best of near-dupe freqs.
+ do i=1,ncand
+ if(abs(candidate0(1,i)-nfqso).lt.10.0) candidate0(1,i)=-candidate0(1,i)
+ if(i.ge.2) then
+ do j=1,i-1
+ fdiff=abs(candidate0(1,i))-abs(candidate0(1,j))
+ if(abs(fdiff).lt.4.0) then
+ if(candidate0(3,i).ge.candidate0(3,j)) candidate0(3,j)=0.
+ if(candidate0(3,i).lt.candidate0(3,j)) candidate0(3,i)=0.
+ endif
+ enddo
+ endif
+ enddo
+
+ fac=20.0/maxval(s)
+ s=fac*s
+
+! Sort by sync
+! call indexx(candidate0(3,1:ncand),ncand,indx)
+! Sort by frequency
+ call indexx(candidate0(1,1:ncand),ncand,indx)
+ k=1
+! do i=ncand,1,-1
+ do i=1,ncand
+ j=indx(i)
+! if( candidate0(3,j) .ge. syncmin .and. candidate0(2,j).ge.-1.5 ) then
+ if( candidate0(3,j) .ge. syncmin ) then
+ candidate(2:3,k)=candidate0(2:3,j)
+ candidate(1,k)=abs(candidate0(1,j))
+ k=k+1
+ endif
+ enddo
+ ncand=k-1
+ return
+end subroutine sync8
diff --git a/lib/ft8/sync8d.f90 b/lib/ft8/sync8d.f90
new file mode 100644
index 00000000..798f2831
--- /dev/null
+++ b/lib/ft8/sync8d.f90
@@ -0,0 +1,54 @@
+subroutine sync8d(cd0,i0,ctwk,itwk,sync)
+
+! Compute sync power for a complex, downsampled FT8 signal.
+
+ parameter(NP2=2812,NDOWN=60)
+ complex cd0(0:3199)
+ complex csync(0:6,32)
+ complex csync2(32)
+ complex ctwk(32)
+ complex z1,z2,z3
+ logical first
+ integer icos7(0:6)
+ data icos7/3,1,4,0,6,5,2/
+ data first/.true./
+ save first,twopi,fs2,dt2,taus,baud,csync
+
+ p(z1)=real(z1)**2 + aimag(z1)**2 !Statement function for power
+
+! Set some constants and compute the csync array.
+ if( first ) then
+ twopi=8.0*atan(1.0)
+ fs2=12000.0/NDOWN !Sample rate after downsampling
+ dt2=1/fs2 !Corresponding sample interval
+ taus=32*dt2 !Symbol duration
+ baud=1.0/taus !Keying rate
+ do i=0,6
+ phi=0.0
+ dphi=twopi*icos7(i)*baud*dt2
+ do j=1,32
+ csync(i,j)=cmplx(cos(phi),sin(phi)) !Waveform for 7x7 Costas array
+ phi=mod(phi+dphi,twopi)
+ enddo
+ enddo
+ first=.false.
+ endif
+
+ sync=0
+ do i=0,6 !Sum over 7 Costas frequencies and
+ i1=i0+i*32 !three Costas arrays
+ i2=i1+36*32
+ i3=i1+72*32
+ csync2=csync(i,1:32)
+ if(itwk.eq.1) csync2=ctwk*csync2 !Tweak the frequency
+ z1=0.
+ z2=0.
+ z3=0.
+ if(i1.ge.0 .and. i1+31.le.NP2-1) z1=sum(cd0(i1:i1+31)*conjg(csync2))
+ if(i2.ge.0 .and. i2+31.le.NP2-1) z2=sum(cd0(i2:i2+31)*conjg(csync2))
+ if(i3.ge.0 .and. i3+31.le.NP2-1) z3=sum(cd0(i3:i3+31)*conjg(csync2))
+ sync = sync + p(z1) + p(z2) + p(z3)
+ enddo
+
+ return
+end subroutine sync8d
diff --git a/lib/ft8/twkfreq1.f90 b/lib/ft8/twkfreq1.f90
new file mode 100644
index 00000000..e6aa8f8b
--- /dev/null
+++ b/lib/ft8/twkfreq1.f90
@@ -0,0 +1,26 @@
+subroutine twkfreq1(ca,npts,fsample,a,cb)
+
+ complex ca(npts)
+ complex cb(npts)
+ complex w,wstep
+ real a(5)
+ data twopi/6.283185307/
+
+! Mix the complex signal
+ w=1.0
+ wstep=1.0
+ x0=0.5*(npts+1)
+ s=2.0/npts
+ do i=1,npts
+ x=s*(i-x0)
+ p2=1.5*x*x - 0.5
+ p3=2.5*(x**3) - 1.5*x
+ p4=4.375*(x**4) - 3.75*(x**2) + 0.375
+ dphi=(a(1) + x*a(2) + p2*a(3) + p3*a(4) + p4*a(5)) * (twopi/fsample)
+ wstep=cmplx(cos(dphi),sin(dphi))
+ w=w*wstep
+ cb(i)=w*ca(i)
+ enddo
+
+ return
+end subroutine twkfreq1
diff --git a/lib/ft8/watterson.f90 b/lib/ft8/watterson.f90
new file mode 100644
index 00000000..a1131d7b
--- /dev/null
+++ b/lib/ft8/watterson.f90
@@ -0,0 +1,65 @@
+subroutine watterson(c,npts,nsig,fs,delay,fspread)
+!
+! npts is the total length of the simulated data vector
+! nsig is the number of points that are occupied by signal
+!
+ complex c(0:npts-1)
+ complex c2(0:npts-1)
+ complex cs1(0:npts-1)
+ complex cs2(0:npts-1)
+
+ nonzero=0
+ df=fs/npts
+ if(fspread.gt.0.0) then
+ do i=0,npts-1
+ xx=gran()
+ yy=gran()
+ cs1(i)=0.707*cmplx(xx,yy)
+ xx=gran()
+ yy=gran()
+ cs2(i)=0.707*cmplx(xx,yy)
+ enddo
+ call four2a(cs1,npts,1,-1,1) !To freq domain
+ call four2a(cs2,npts,1,-1,1)
+ do i=0,npts-1
+ f=i*df
+ if(i.gt.npts/2) f=(i-npts)*df
+ x=(f/(0.5*fspread))**2
+ a=0.
+ if(x.le.50.0) then
+ a=exp(-x)
+ endif
+ cs1(i)=a*cs1(i)
+ cs2(i)=a*cs2(i)
+ if(abs(f).lt.10.0) then
+ p1=real(cs1(i))**2 + aimag(cs1(i))**2
+ p2=real(cs2(i))**2 + aimag(cs2(i))**2
+ if(p1.gt.0.0) nonzero=nonzero+1
+! write(62,3101) f,p1,p2,db(p1+1.e-12)-60,db(p2+1.e-12)-60
+!3101 format(f10.3,2f12.3,2f10.3)
+ endif
+ enddo
+ call four2a(cs1,npts,1,1,1) !Back to time domain
+ call four2a(cs2,npts,1,1,1)
+ cs1(0:npts-1)=cs1(0:npts-1)/npts
+ cs2(0:npts-1)=cs2(0:npts-1)/npts
+ endif
+
+ nshift=nint(0.001*delay*fs)
+ c2(0:npts-1)=cshift(c(0:npts-1),nshift)
+ sq=0.
+ do i=0,npts-1
+ if(nonzero.gt.1) then
+ c(i)=0.5*(cs1(i)*c(i) + cs2(i)*c2(i))
+ else
+ c(i)=0.5*(c(i) + c2(i))
+ endif
+ sq=sq + real(c(i))**2 + aimag(c(i))**2
+! write(61,3001) i/12000.0,c(i)
+!3001 format(3f12.6)
+ enddo
+ rms=sqrt(sq/nsig)
+ c=c/rms
+
+ return
+end subroutine watterson