summaryrefslogtreecommitdiff
path: root/lib/fst4
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fst4')
-rw-r--r--lib/fst4/decode240_74.f908
-rw-r--r--lib/fst4/fastosd240_74.f90291
-rw-r--r--lib/fst4/fst4sim.f9028
-rw-r--r--lib/fst4/ldpcsim240_74.f902
-rw-r--r--lib/fst4/lorentzian_fading.f9043
5 files changed, 356 insertions, 16 deletions
diff --git a/lib/fst4/decode240_74.f90 b/lib/fst4/decode240_74.f90
index be18f6e0..f5aac2e1 100644
--- a/lib/fst4/decode240_74.f90
+++ b/lib/fst4/decode240_74.f90
@@ -25,6 +25,8 @@ subroutine decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharder
include "ldpc_240_74_parity.f90"
maxiterations=30
+ if(Keff.eq.50) maxiterations=1
+
nosd=0
if(maxosd.gt.3) maxosd=3
if(maxosd.eq.0) then ! osd with channel llrs
@@ -36,6 +38,8 @@ subroutine decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharder
nosd=0
endif
+ if(maxosd.eq.0) goto 73
+
toc=0
tov=0
tanhtoc=0
@@ -133,9 +137,11 @@ subroutine decode240_74(llr,Keff,maxosd,norder,apmask,message74,cw,ntype,nharder
enddo ! bp iterations
+73 continue
do i=1,nosd
zn=zsave(:,i)
- call osd240_74(zn,Keff,apmask,norder,message74,cw,nharderror,dminosd)
+! call osd240_74(zn,Keff,apmask,norder,message74,cw,nharderror,dminosd)
+ call fastosd240_74(zn,Keff,apmask,norder,message74,cw,nharderror,dminosd)
if(nharderror.gt.0) then
hdec=0
where(llr .ge. 0) hdec=1
diff --git a/lib/fst4/fastosd240_74.f90 b/lib/fst4/fastosd240_74.f90
new file mode 100644
index 00000000..f4bb61d6
--- /dev/null
+++ b/lib/fst4/fastosd240_74.f90
@@ -0,0 +1,291 @@
+subroutine fastosd240_74(llr,k,apmask,ndeep,message74,cw,nhardmin,dmin)
+!
+! An ordered-statistics decoder for the (240,74) code.
+! Message payload is 50 bits. Any or all of a 24-bit CRC can be
+! used for detecting incorrect codewords. The remaining CRC bits are
+! cascaded with the LDPC code for the purpose of improving the
+! distance spectrum of the code.
+!
+! If p1 (0.le.p1.le.24) is the number of CRC24 bits that are
+! to be used for bad codeword detection, then the argument k should
+! be set to 77+p1.
+!
+! Valid values for k are in the range [50,74].
+!
+ character*24 c24
+ integer, parameter:: N=240
+ integer*1 apmask(N),apmaskr(N)
+ integer*1, allocatable, save :: gen(:,:)
+ integer*1, allocatable :: genmrb(:,:),g2(:,:)
+ integer*1, allocatable :: temp(:),temprow(:),m0(:),me(:),mi(:)
+ integer indices(N),indices2(N),nxor(N)
+ integer*1 cw(N),ce(N),c0(N),hdec(N)
+ integer*1, allocatable :: decoded(:)
+ integer*1 message74(74)
+ integer*1, allocatable :: sp(:)
+ integer indx(N),ksave
+ real llr(N),rx(N),absrx(N)
+
+ logical first
+ data first/.true./,ksave/64/
+ save first,ksave
+
+ allocate( genmrb(k,N), g2(N,k) )
+ allocate( temp(k), temprow(n), m0(k), me(k), mi(k) )
+ allocate( decoded(k) )
+
+ if( first .or. k.ne.ksave) then ! fill the generator matrix
+!
+! Create generator matrix for partial CRC cascaded with LDPC code.
+!
+! Let p2=74-k and p1+p2=24.
+!
+! The last p2 bits of the CRC24 are cascaded with the LDPC code.
+!
+! The first p1=k-50 CRC24 bits will be used for error detection.
+!
+ if( allocated(gen) ) deallocate(gen)
+ allocate( gen(k,N) )
+ gen=0
+ do i=1,k
+ message74=0
+ message74(i)=1
+ if(i.le.50) then
+ call get_crc24(message74,74,ncrc24)
+ write(c24,'(b24.24)') ncrc24
+ read(c24,'(24i1)') message74(51:74)
+ message74(51:k)=0
+ endif
+ call encode240_74(message74,cw)
+ gen(i,:)=cw
+ enddo
+
+ first=.false.
+ ksave=k
+ endif
+
+! Use best k elements from the sorted list for the first basis. For the 2nd basis replace
+! the nswap lowest quality symbols with the best nswap elements from the parity symbols.
+ nswap=20
+
+ do ibasis=1,2
+ 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(llr)
+ 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
+
+ if(ibasis.eq.2) then
+ do i=k-nswap+1,k
+ temp(1:k)=genmrb(1:k,i)
+ genmrb(1:k,i)=genmrb(1:k,i+nswap)
+ genmrb(1:k,i+nswap)=temp(1:k)
+ itmp=indices(i)
+ indices(i)=indices(i+nswap)
+ indices(i+nswap)=itmp
+ enddo
+ endif
+
+! 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).
+
+ icol=1
+ indices2=0
+ nskipped=0
+ do id=1,k
+ iflag=0
+ do while(iflag.eq.0)
+ if(genmrb(id,icol).ne.1) then
+ do j=id+1,k
+ if(genmrb(j,icol).eq.1) then
+ temprow=genmrb(id,:)
+ genmrb(id,:)=genmrb(j,:)
+ genmrb(j,:)=temprow
+ iflag=1
+ endif
+ enddo
+ if(iflag.eq.0) then ! skip this column
+ nskipped=nskipped+1
+ indices2(k+nskipped)=icol ! put icol where skipped columns go
+ icol=icol+1 ! look at the next column
+ endif
+ else
+ iflag=1
+ endif
+ enddo
+ indices2(id)=icol
+ do j=1,k
+ if(id.ne.j .and. genmrb(j,icol).eq.1) then
+ genmrb(j,:)=ieor(genmrb(id,:),genmrb(j,:))
+ endif
+ enddo
+ icol=icol+1
+ enddo
+ do i=k+nskipped+1,240
+ indices2(i)=i
+ enddo
+ genmrb(1:k,:)=genmrb(1:k,indices2)
+ indices=indices(indices2)
+
+!************************************
+ 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=abs(llr)
+ absrx=absrx(indices)
+ rx=rx(indices)
+ apmaskr=apmaskr(indices)
+
+ call mrbencode74(m0,c0,g2,N,k)
+ nxor=ieor(c0,hdec)
+ nhardmin=sum(nxor)
+ dmin=sum(nxor*absrx)
+ np=32
+ if(ibasis.eq.1) allocate(sp(np))
+
+ cw=c0
+ ntotal=0
+ nrejected=0
+
+ if(ndeep.eq.0) goto 998 ! norder=0
+ if(ndeep.gt.4) ndeep=4
+ if( ndeep.eq. 1) then
+ nord=1
+ xlambda=0.0
+ nsyncmax=np
+ elseif(ndeep.eq.2) then
+ nord=2
+ xlambda=0.0
+ nsyncmax=np
+ elseif(ndeep.eq.3) then
+ nord=3
+ xlambda=4.0
+ nsyncmax=11
+ elseif(ndeep.eq.4) then
+ nord=4
+ xlambda=3.4
+ nsyndmax=12
+ endif
+
+ s1=sum(absrx(1:k))
+ s2=sum(absrx(k+1:N))
+ rho=s1/(s1+xlambda*s2)
+ rhodmin=rho*dmin
+ nerr64=-1
+ do iorder=1,nord
+!beta=0.0
+!if(iorder.ge.3) beta=0.4
+!spnc_order=sum(absrx(k-iorder+1:k))+beta*(N-k)
+!if(dmin.lt.spnc_order) cycle
+ mi(1:k-iorder)=0
+ mi(k-iorder+1:k)=1
+ iflag=k-iorder+1
+ do while(iflag .ge.0)
+ ntotal=ntotal+1
+ me=ieor(m0,mi)
+ d1=sum(mi(1:k)*absrx(1:k))
+ if(d1.gt.rhodmin) exit
+ call partial_syndrome(me,sp,np,g2,N,K)
+ nwhsp=sum(ieor(sp(1:np),hdec(k:k+np-1)))
+ if(nwhsp.le.nsyndmax) then
+ call mrbencode74(me,ce,g2,N,k)
+ nxor=ieor(ce,hdec)
+ dd=sum(nxor*absrx(1:N))
+ if( dd .lt. dmin ) then
+ dmin=dd
+ rhodmin=rho*dmin
+ cw=ce
+ nhardmin=sum(nxor)
+ nwhspmin=nwhsp
+ nerr64=sum(nxor(1:K))
+ endif
+ endif
+! Get the next test error pattern, iflag will go negative
+! when the last pattern with weight iorder has been generated.
+ call nextpat74(mi,k,iorder,iflag)
+ enddo
+ enddo
+
+998 continue
+! Re-order the codeword to [message bits][parity bits] format.
+ cw(indices)=cw
+ hdec(indices)=hdec
+ message74=cw(1:74)
+ call get_crc24(message74,74,nbadcrc)
+ if(nbadcrc.eq.0) exit
+ nhardmin=-nhardmin
+ enddo ! basis loop
+ return
+end subroutine fastosd240_74
+
+subroutine mrbencode74(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 mrbencode74
+
+subroutine partial_syndrome(me,sp,np,g2,N,K)
+ integer*1 me(K),sp(np),g2(N,K)
+! compute partial syndrome
+ sp=0
+ do i=1,K
+ if( me(i) .eq. 1 ) then
+ sp=ieor(sp,g2(K:K+np-1,i))
+ endif
+ enddo
+ return
+end subroutine partial_syndrome
+
+subroutine nextpat74(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 nextpat74
+
diff --git a/lib/fst4/fst4sim.f90 b/lib/fst4/fst4sim.f90
index 5b8f33bc..83ac5bae 100644
--- a/lib/fst4/fst4sim.f90
+++ b/lib/fst4/fst4sim.f90
@@ -19,10 +19,10 @@ program fst4sim
! Get command-line argument(s)
nargs=iargc()
- if(nargs.ne.10) then
- print*,'Need 10 arguments, got ',nargs
- print*,'Usage: fst4sim "message" TRsec f0 DT h fdop del nfiles snr W'
- print*,'Examples: fst4sim "K1JT K9AN EN50" 60 1500 0.0 1 0.1 1.0 10 -15 F'
+ if(nargs.ne.9) then
+ print*,'Need 9 arguments, got ',nargs
+ print*,'Usage: fst4sim "message" TRsec f0 DT fdop del nfiles snr W'
+ print*,'Examples: fst4sim "K1JT K9AN EN50" 60 1500 0.0 0.1 1.0 10 -15 F'
print*,'W (T or F) argument is hint to encoder to use WSPR message when there is abiguity'
go to 999
endif
@@ -34,16 +34,14 @@ program fst4sim
call getarg(4,arg)
read(arg,*) xdt !Time offset from nominal (s)
call getarg(5,arg)
- read(arg,*) hmod !Modulation index, h
- call getarg(6,arg)
read(arg,*) fspread !Watterson frequency spread (Hz)
- call getarg(7,arg)
+ call getarg(6,arg)
read(arg,*) delay !Watterson delay (ms)
- call getarg(8,arg)
+ call getarg(7,arg)
read(arg,*) nfiles !Number of files
- call getarg(9,arg)
+ call getarg(8,arg)
read(arg,*) snrdb !SNR_2500
- call getarg(10,arg)
+ call getarg(9,arg)
read(arg,*) wspr_hint !0:break ties as 77-bit 1:break ties as 50-bit
nfiles=abs(nfiles)
@@ -89,8 +87,8 @@ program fst4sim
call genfst4(msg37,0,msgsent37,msgbits,itone,iwspr)
write(*,*)
write(*,'(a9,a37,a3,L2,a7,i2)') 'Message: ',msgsent37,'W:',wspr_hint,' iwspr:',iwspr
- write(*,1000) f00,xdt,hmod,txt,snrdb
-1000 format('f0:',f9.3,' DT:',f6.2,' hmod:',i6,' TxT:',f6.1,' SNR:',f6.1)
+ write(*,1000) f00,xdt,txt,snrdb
+1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1)
write(*,*)
if(i3.eq.1) then
write(*,*) ' mycall hiscall hisgrid'
@@ -106,7 +104,8 @@ program fst4sim
! call sgran()
- fsample=12000.0
+ fsample=12000.0
+ hmod=1
icmplx=1
f0=f00+1.5*hmod*baud
call gen_fst4wave(itone,NN,nsps,nwave,fsample,hmod,f0,icmplx,c0,wave)
@@ -118,7 +117,8 @@ program fst4sim
do ifile=1,nfiles
c=c0
- if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c,nwave,NZ,fs,delay,fspread)
+ if(fspread.gt.0.0 .or. delay.ne.0.0) call watterson(c,nwave,NZ,fs,delay,fspread)
+ if(fspread.lt.0.0) call lorentzian_fading(c,nwave,fs,-fspread)
c=sig*c
wave=real(c)
if(snrdb.lt.90) then
diff --git a/lib/fst4/ldpcsim240_74.f90 b/lib/fst4/ldpcsim240_74.f90
index b488aa6b..78e8e6b5 100644
--- a/lib/fst4/ldpcsim240_74.f90
+++ b/lib/fst4/ldpcsim240_74.f90
@@ -101,7 +101,7 @@ write(*,'(24i1)') msgbits(51:74)
llr=2.0*rxdata/(ss*ss)
apmask=0
dmin=0.0
- maxosd=0
+ maxosd=2
call decode240_74(llr, Keff, maxosd, norder, apmask, message74, cw, ntype, nharderror, dmin)
if(nharderror.ge.0) then
n2err=0
diff --git a/lib/fst4/lorentzian_fading.f90 b/lib/fst4/lorentzian_fading.f90
new file mode 100644
index 00000000..c1bd5c32
--- /dev/null
+++ b/lib/fst4/lorentzian_fading.f90
@@ -0,0 +1,43 @@
+subroutine lorentzian_fading(c,npts,fs,fspread)
+!
+! npts is the total length of the simulated data vector
+!
+ complex c(0:npts-1)
+ complex cspread(0:npts-1)
+ complex z
+
+ twopi=8.0*atan(1.0)
+ df=fs/npts
+ nh=npts/2
+ cspread(0)=1.0
+ cspread(nh)=0.
+ b=6.0
+ do i=1,nh
+ f=i*df
+ x=b*f/fspread
+ z=0.
+ a=0.
+ if(x.lt.3.0) then
+ a=sqrt(1.111/(1.0+x*x)-0.1)
+ phi1=twopi*rran()
+ z=a*cmplx(cos(phi1),sin(phi1))
+ endif
+ cspread(i)=z
+ z=0.
+ if(x.lt.3.0) then
+ phi2=twopi*rran()
+ z=a*cmplx(cos(phi2),sin(phi2))
+ endif
+ cspread(npts-i)=z
+ enddo
+
+ call four2a(cspread,npts,1,1,1)
+
+ s=sum(abs(cspread)**2)
+ avep=s/npts
+ fac=sqrt(1.0/avep)
+ cspread=fac*cspread
+ c=cspread*c
+
+ return
+end subroutine lorentzian_fading