From 968705cb9cf6a95f9e32d1f52dae5c77daa3b9f8 Mon Sep 17 00:00:00 2001 From: Steven Franke Date: Wed, 1 Jun 2016 01:58:46 +0000 Subject: [PATCH] Some cleanup to genmsk144.f90 and commented out debug statements for loopback test on OS X. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6713 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- lib/genmsk144.f90 | 33 ++++++++--------------------- lib/jtmsk_decode.f90 | 42 ++++++++++++++++++------------------ lib/jtmsk_decode144.f90 | 5 ++--- lib/syncmsk144.f90 | 47 +++++++++++++++++------------------------ 4 files changed, 51 insertions(+), 76 deletions(-) diff --git a/lib/genmsk144.f90 b/lib/genmsk144.f90 index 7dbf7a75d..282bdc041 100644 --- a/lib/genmsk144.f90 +++ b/lib/genmsk144.f90 @@ -53,8 +53,9 @@ subroutine genmsk144(msg0,ichk,msgsent,i4tone,itype) if( first ) then first=.false. nsym=128 - pchk_file="peg-128-80-reg3.pchk" - gen_file="peg-128-80-reg3.gen" +!! Fix this + pchk_file="/Users/sfranke/Builds/wsjtx_install/peg-128-80-reg3.pchk" + gen_file="/Users/sfranke/Builds/wsjtx_install/peg-128-80-reg3.gen" call init_ldpc(trim(pchk_file)//char(0),trim(gen_file)//char(0)) pi=4.*atan(1.0) twopi=8.*atan(1.0) @@ -124,13 +125,10 @@ subroutine genmsk144(msg0,ichk,msgsent,i4tone,itype) enddo call ldpc_encode(msgbits,codeword) -write(*,*) 'codeword',codeword - j=0 - do i=1,nsym/2 !Reorder the encoded bits - j=j+1 - reorderedcodeword(j)=codeword(2*i-1) - reorderedcodeword(j+nsym/2)=codeword(2*i) - enddo + +! Reorder the bits. + reorderedcodeword(1:64)=codeword(1:127:2) + reorderedcodeword(65:128)=codeword(2:128:2) !Create 144-bit channel vector: !8-bit sync word + 48 bits + 8-bit sync word + 80 bits @@ -146,19 +144,12 @@ write(*,*) 'codeword',codeword is=(i-1)*12+7 xq(is:is+11)=bitseq(2*i+1)*pp enddo - xq(864-5:864)=bitseq(1)*pp(1:6) !first half of last zero bit on q channel + xq(864-5:864)=bitseq(1)*pp(1:6) !last half symbol do i=1,72 is=(i-1)*12+1 xi(is:is+11)=bitseq(2*i)*pp enddo -! dphi=2*pi*1500/12000.0; -! phi=0.0 -! do i=1,864 -! waveform(i)=imag(complex(xi(i),xq(i))*complex(cos(phi),sin(phi))) -! phi=mod(phi+dphi,twopi) -! enddo - ! Map I and Q to tones. i4tone=0 do i=1,72 @@ -167,14 +158,8 @@ write(*,*) 'codeword',codeword enddo endif -! Had to flip the polarity - not sure if this will be needed when we are -! sending the tone to Modulator.cpp. +! Flip polarity i4tone=-i4tone+1 -! print*,"transmitted tones" -! do i=1,144 -! print*,i,bitseq(i),i4tone(i) -! enddo - 999 return end subroutine genmsk144 diff --git a/lib/jtmsk_decode.f90 b/lib/jtmsk_decode.f90 index 2214791e3..335e3aca1 100644 --- a/lib/jtmsk_decode.f90 +++ b/lib/jtmsk_decode.f90 @@ -1,10 +1,10 @@ subroutine jtmsk_decode(id2,narg,line) -! Decoder for JTMSK mode +! Calls the experimental decoder for JTMSK 72ms ldpc messages parameter (NMAX=30*12000) parameter (NFFTMAX=512*1024) - parameter (NSPM=1404) !Samples per JTMSK long message + parameter (NSPM=864) !Samples per JTMSK long message integer*2 id2(0:NMAX) !Raw i*2 data, up to T/R = 30 s integer hist(0:32868) real d(0:NMAX) !Raw r*4 data @@ -54,58 +54,58 @@ subroutine jtmsk_decode(id2,narg,line) !### Would it be better to set median rms to 1.0 ? ! d(0:npts-1)=d(0:npts-1)/rms !Normalize so that rms=1.0 call mskdt(d,npts,ty,yellow,nyel) +! do i=1,nyel +! print*,i,ty(i),yellow(i) +! enddo + nyel=min(nyel,5) n=log(float(npts))/log(2.0) + 1.0 nfft=min(2**n,1024*1024) call analytic(d,npts,nfft,c) !Convert to analytic signal and filter - nbefore=NSPM - nafter=4*NSPM + nafter=NSPM ! Process ping list (sorted by S/N) from top down. +! do n=1,nyel do n=1,nyel - ia=ty(n)*12000.0 - nbefore + ia=ty(n)*12000.0 - NSPM/2 if(ia.lt.1) ia=1 - ib=ia + nafter + ib=ia + 2*nafter-1 if(ib.gt.NFFTMAX) ib=NFFTMAX iz=ib-ia+1 cdat2(1:iz)=c(ia:ib) !Select nlen complex samples +! write(*,*) ty(1),ia,ib,iz ja=ia/NSPM + 1 jb=ib/NSPM t0=ia/12000.0 - - do itry=1,21 +! do itry=1,21 + do itry=1,1 idf1=(itry/2) * 50 if(mod(itry,2).eq.1) idf1=-idf1 if(abs(idf1).gt.ntol) exit fpk=idf1 + nrxfreq call tweak1(cdat2,iz,1500.0-fpk,cdat) - call syncmsk(cdat,iz,jpk,ipk,idf,rmax,snr,metric,msg) + call syncmsk144(cdat,iz,jpk,ipk,idf,rmax,snr,metric,msg,freq) if(metric.eq.-9999) cycle !No output if no significant sync if(msg(1:1).eq.' ') call jtmsk_short(cdat,iz,narg,tbest,idfpk,msg) if(msg(1:1).eq.'<' .and. naggressive.eq.0 .and. & narg(13)/8.ne.narg(12)) msg=' ' if(msg(1:1).ne.' ') then - if(msg.ne.msg0) then +! if(msg.ne.msg0) then nline=nline+1 nsnr0=-99 - endif - freq=fpk+idf +! endif t0=(ia+jpk)/12000.0 y=10.0**(0.1*(yellow(n)-1.5)) nsnr=max(-5,nint(db(y))) - if(nsnr.gt.nsnr0 .and. nline.gt.0) then - call rectify_msk(cdat2(jpk:jpk+NSPM-1),msg,narg(13),freq2) - freq=freq2 - if(msg(1:1).eq.'<') freq=freq2+idfpk -!### Check freq values !!! +! if(nsnr.gt.nsnr0 .and. nline.gt.0) then write(line(nline),1020) nutc,nsnr,t0,nint(freq),msg -1020 format(i6.6,i4,f5.1,i5,' & ',a22) +1020 format(i6.6,i4,f5.1,i5,' & ',a22) nsnr0=nsnr - go to 900 - endif +! go to 900 +! endif msg0=msg - if(nline.ge.maxlines) go to 900 +! if(nline.ge.maxlines) go to 900 endif enddo ! print*,'c',nutc,n,nint(yellow(n)-4.0),freq,freq2 diff --git a/lib/jtmsk_decode144.f90 b/lib/jtmsk_decode144.f90 index 6e7be40fd..1c0142194 100644 --- a/lib/jtmsk_decode144.f90 +++ b/lib/jtmsk_decode144.f90 @@ -86,7 +86,6 @@ subroutine jtmsk_decode(id2,narg,line) fpk=idf1 + nrxfreq call tweak1(cdat2,iz,1500.0-fpk,cdat) call syncmsk144(cdat,iz,jpk,ipk,idf,rmax,snr,metric,msg,freq) -print*,'returned message :',msg if(metric.eq.-9999) cycle !No output if no significant sync if(msg(1:1).eq.' ') call jtmsk_short(cdat,iz,narg,tbest,idfpk,msg) if(msg(1:1).eq.'<' .and. naggressive.eq.0 .and. & @@ -109,11 +108,11 @@ print*,'returned message :',msg ! if(nline.ge.maxlines) go to 900 endif enddo - print*,'c',nutc,n,nint(yellow(n)-4.0),freq,freq2 +! print*,'c',nutc,n,nint(yellow(n)-4.0),freq,freq2 enddo 900 continue - print*,'d',nutc,n,nint(yellow(n)-4.0),freq,freq2 +! print*,'d',nutc,n,nint(yellow(n)-4.0),freq,freq2 if(line(1)(1:6).eq.' ') line(1)(1:1)=char(0) return diff --git a/lib/syncmsk144.f90 b/lib/syncmsk144.f90 index 649108636..42f1759f1 100644 --- a/lib/syncmsk144.f90 +++ b/lib/syncmsk144.f90 @@ -43,12 +43,13 @@ subroutine syncmsk144(cdat,npts,jpk,ipk,idf,rmax,snr,metric,msgreceived,fest) data s8/0,1,1,1,0,0,1,0/ save first,cb,cd,pi,twopi,dt,f0,f1 + open(unit=78,file="/Users/sfranke/Builds/wsjtx_install/sfdebug.txt") if(first) then - print*,"Initializing ldpc." - pchk_file="peg-128-80-reg3.pchk" - gen_file="peg-128-80-reg3.gen" + write(78,*) "Initializing ldpc." + pchk_file="/Users/sfranke/Builds/wsjtx_install/peg-128-80-reg3.pchk" + gen_file="/Users/sfranke/Builds/wsjtx_install/peg-128-80-reg3.gen" call init_ldpc(trim(pchk_file)//char(0),trim(gen_file)//char(0)) - + write(78,*) "after init_ldpc" ! define half-sine pulse and raised-cosine edge window pi=4d0*datan(1d0) twopi=8d0*datan(1d0) @@ -70,11 +71,7 @@ subroutine syncmsk144(cdat,npts,jpk,ipk,idf,rmax,snr,metric,msgreceived,fest) cbi(25:36)=pp*s8(6) cbi(37:42)=pp(1:6)*s8(8) cb=cmplx(cbi,cbq) -! print*,"cb" -! do i=1,42 -! print*,i,cbi(i),cbq(i) -! enddo - + first=.false. endif @@ -112,9 +109,10 @@ subroutine syncmsk144(cdat,npts,jpk,ipk,idf,rmax,snr,metric,msgreceived,fest) q1=200*al/(tot-tonespec(ilpk)) endif fdiff=(ihpk-ilpk)*df - write(*,*) "Coarse frequency error: ",ferr - write(*,*) "Tone / avg : ",q1 - write(*,*) "Tone separation : ",fdiff + +! write(78,*) "Coarse frequency error: ",ferr +! write(78,*) "Tone / avg : ",q1 +! write(78,*) "Tone separation : ",fdiff ! remove coarse freq error - should now be within a few Hz call tweak1(cdat,npts,-(1500+ferr),cdat) @@ -135,25 +133,23 @@ subroutine syncmsk144(cdat,npts,jpk,ipk,idf,rmax,snr,metric,msgreceived,fest) iloc=maxloc(dd) ic2=iloc(1) - write(*,*) "Syncs: ic1,ic2 ",ic1,ic2 +! write(78,*) "Syncs: ic1,ic2 ",ic1,ic2 ic=ic2 -! open(unit=78,file="blah.txt") ! do i=1,npts-448-41 ! write(78,*) i,abs(cc1(i)),abs(cc2(i)),abs(cc(i)),dd(i),abs(cc3(i)) ! enddo -! close(78) cca=sum(cdat(ic:ic+41)*conjg(cb)) ccb=sum(cdat(ic+56*6:ic+56*6+41)*conjg(cb)) phase0=atan2(imag(cca+ccb),real(cca+ccb)) cfac=ccb*conjg(cca) ferr2=atan2(imag(cfac),real(cfac))/(twopi*56*6*dt) - write(*,*) "Fine frequency error: ",ferr2 - write(*,*) "Coarse Carrier phase : ",phase0 + write(78,*) "Fine frequency error: ",ferr2 + write(78,*) "Coarse Carrier phase : ",phase0 fest=1500+ferr+ferr2 - write(*,*) "Estimated f0 : ",fest + write(78,*) "Estimated f0 : ",fest ! Remove fine frequency error call tweak1(cdat,npts,-ferr2,cdat) @@ -164,22 +160,18 @@ subroutine syncmsk144(cdat,npts,jpk,ipk,idf,rmax,snr,metric,msgreceived,fest) cfac=ccb*conjg(cca) ffin=atan2(imag(cfac),real(cfac))/(twopi*56*6*dt) phase0=atan2(imag(cca+ccb),real(cca+ccb)) - write(*,*) "Final freq error: ",ffin + write(78,*) "Final freq error: ",ffin cfac=cmplx(cos(phase0),sin(phase0)) cdat=cdat*conjg(cfac) - open(unit=79,file="cdat.txt") - write(*,*) "npts = ",npts do i=1,864 ii=ic+i-1 if( ii .gt. npts ) then ii=ii-864 endif c(i)=cdat(ii) - write(79,*) i,real(c(i)),imag(c(i)) enddo - close(79) do i=1,72 softbits(2*i-1)=imag(c(1+(i-1)*12)) softbits(2*i)=real(c(7+(i-1)*12)) @@ -190,8 +182,8 @@ subroutine syncmsk144(cdat,npts,jpk,ipk,idf,rmax,snr,metric,msgreceived,fest) hardbits(i)=1 endif enddo -! write(*,*) hardbits(1:8) -! write(*,*) hardbits(57:57+7) +! write(78,*) hardbits(1:8) +! write(78,*) hardbits(57:57+7) hardword(1:48)=hardbits(9:9+47) hardword(49:128)=hardbits(65:65+80-1) @@ -213,7 +205,7 @@ subroutine syncmsk144(cdat,npts,jpk,ipk,idf,rmax,snr,metric,msgreceived,fest) max_iterations=20 max_dither=100 call ldpc_decode(unscrambledsoftbits, decoded, max_iterations, niterations, max_dither, ndither) - write(*,*) 'Decoder used ',niterations,' and ',ndither,' dither trials.' + write(78,*) 'Decoder used ',niterations,'iterations and ',ndither,' dither trials.' if( niterations .lt. 0 ) then msgreceived=' ' @@ -236,7 +228,6 @@ subroutine syncmsk144(cdat,npts,jpk,ipk,idf,rmax,snr,metric,msgreceived,fest) ! Compare calculated hash with received byte 10 - if they agree, keep the message. i1hashdec=ihashdec - write(*,*) "Hashes",i1hashdec,i1Dec8BitBytes(10) if( i1hashdec .eq. i1Dec8BitBytes(10) ) then ! Good hash --- unpack 72-bit message @@ -249,7 +240,7 @@ subroutine syncmsk144(cdat,npts,jpk,ipk,idf,rmax,snr,metric,msgreceived,fest) enddo call unpackmsg(i4Dec6BitWords,msgreceived) endif - +close(78) return end subroutine syncmsk144