From 920fd25537e0432b053fff5f50779bf5fd57f938 Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Tue, 19 Jul 2016 13:16:10 +0000 Subject: [PATCH] Starting work toward flexible use of AP decoding in QRA64. Beware, this is still in progress! git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6928 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- lib/jt65_decode.f90 | 3 +- lib/qra/qra64/qra64_subs.c | 28 ++++---- lib/qra/qra64/qra64sim.f90 | 127 ++++++++----------------------------- lib/qra64a.f90 | 60 +++++++++--------- lib/qra64code.f90 | 2 +- plotter.cpp | 4 +- 6 files changed, 73 insertions(+), 151 deletions(-) diff --git a/lib/jt65_decode.f90 b/lib/jt65_decode.f90 index e9b6a7031..08b69d861 100644 --- a/lib/jt65_decode.f90 +++ b/lib/jt65_decode.f90 @@ -99,7 +99,8 @@ contains if(nsubmode.ge.100) then ! This is QRA64 mode - call qra64a(dd,nf1,nf2,nfqso,ntol,mycall,sync,nsnr,dtx,nfreq,decoded,nft) + call qra64a(dd,nf1,nf2,nfqso,ntol,mycall,hiscall,hisgrid,sync,nsnr, & + dtx,nfreq,decoded,nft) ! if(sync.lt.12.8) go to 900 !### Temporary ### if (associated(this%callback)) then ndrift=0 diff --git a/lib/qra/qra64/qra64_subs.c b/lib/qra/qra64/qra64_subs.c index d857dc8af..e09d02c77 100644 --- a/lib/qra/qra64/qra64_subs.c +++ b/lib/qra/qra64/qra64_subs.c @@ -1,4 +1,4 @@ -// qra64_subs.c +// qra64_subs.c // Fortran interface routines for QRA64 #include "qra64.h" @@ -10,13 +10,12 @@ static qra64codec *pqra64codec = NULL; void qra64_enc_(int x[], int y[]) { - if (pqra64codec==NULL) - pqra64codec = qra64_init(QRA_AUTOAP); - + if (pqra64codec==NULL) pqra64codec = qra64_init(QRA_AUTOAP); qra64_encode(pqra64codec, y, x); } -void qra64_dec_(float r[], int* nmycall, int xdec[], int* rc) +void qra64_dec_(float r[], int* nmycall, int* nhiscall, int* nhisgrid, + int xdec[], float* snr, int* rc) { // Return codes: // rc=-16 failed sanity check @@ -41,21 +40,20 @@ void qra64_dec_(float r[], int* nmycall, int xdec[], int* rc) #endif if(ncall!=ncall0) { - if (pqra64codec!=NULL) - qra64_close(pqra64codec); - pqra64codec = qra64_init(QRA_AUTOAP); - // the following apset call is not strictly necessary - // It enables AP decoding of messages directed to our call - // also in the case we have never made a CQ - qra64_apset(pqra64codec,ncall,0,0,APTYPE_MYCALL); + if (pqra64codec!=NULL) qra64_close(pqra64codec); + pqra64codec = qra64_init(QRA_AUTOAP); + // the following apset call is not strictly necessary + // It enables AP decoding of messages directed to our call + // also in the case we have never made a CQ + qra64_apset(pqra64codec,ncall,0,0,APTYPE_MYCALL); ncall0=ncall; } *rc = qra64_decode(pqra64codec,&EbNodBEstimated,xdec,r); + *snr = EbNodBEstimated - 31.0; #ifdef NICO_WANTS_SNR_DUMP fout = fopen("C:\\JTSDK\\snrdump.txt","a+"); - if ((*rc)>=0) - fprintf(fout,"rc=%d snr=%.2f dB\n",*rc,EbNodBEstimated-31.0f); + if ((*rc)>=0) fprintf(fout,"rc=%d snr=%.2f dB\n",*rc,EbNodBEstimated-31.0f); fclose(fout); -#endif +#endif } diff --git a/lib/qra/qra64/qra64sim.f90 b/lib/qra/qra64/qra64sim.f90 index 66fa30b0c..15f946301 100644 --- a/lib/qra/qra64/qra64sim.f90 +++ b/lib/qra/qra64/qra64sim.f90 @@ -4,7 +4,6 @@ program qra64sim use wavhdr use packjt - use options parameter (NMAX=54*12000) ! = 648,000 parameter (NFFT=10*65536,NH=NFFT/2) type(hdr) h !Header for .wav file @@ -16,93 +15,29 @@ program qra64sim complex cspread(0:NFFT-1) !Complex amplitude for Rayleigh fading complex z real*8 f0,dt,twopi,phi,dphi,baud,fsample,freq - character msg*22,fname*11,csubmode*1,c,optarg*500,numbuf*32 + character msg*22,fname*11,csubmode*1,arg*12 character msgsent*22 - logical :: display_help=.false.,seed_prngs=.true. - type (option) :: long_options(9) = [ & - option ('help',.false.,'h','Display this help message',''), & - option ('sub-mode',.true.,'M','message','MSG'), & - option ('sub-mode',.true.,'m','sub mode, default MODE=A','MODE'), & - option ('num-sigs',.true.,'n','number of signals per file, default SIGNALS=10','SIGNALS'), & - option ('doppler-spread',.true.,'d','Doppler spread, default SPREAD=0.0','SPREAD'), & - option ('time-offset',.true.,'t','Time delta, default SECONDS=0.0','SECONDS'), & - option ('num-files',.true.,'f','Number of files to generate, default FILES=1','FILES'), & - option ('no-prng-seed',.false.,'p','Do not seed PRNGs (use for reproducible tests)',''), & - option ('strength',.true.,'s','S/N in dB (2500Hz reference b/w), default SNR=0','SNR') ] -! Default parameters: - csubmode='A' - mode65=1 - nsigs=10 - fspread=0. - xdt=0. - snrdb=0. - nfiles=1 - - do - call getopt('hM:m:n:d:t:f:ps:',long_options,c,optarg,narglen,nstat,noffset,nremain,.true.) - if( nstat .ne. 0 ) then - exit - end if - select case (c) - case ('h') - display_help = .true. - case ('M') - read (optarg(:narglen), *) msg - print*,msg - case ('m') - read (optarg(:narglen), *) csubmode - if(csubmode.eq.'A') mode65=1 - if(csubmode.eq.'B') mode65=2 - if(csubmode.eq.'C') mode65=4 - case ('n') - read (optarg(:narglen), *,err=10) nsigs - case ('d') - read (optarg(:narglen), *,err=10) fspread - case ('t') - read (optarg(:narglen), *) numbuf - if (numbuf(1:1) == '\') then - read (numbuf(2:), *,err=10) xdt - else - read (numbuf, *,err=10) xdt - end if - case ('f') - read (optarg(:narglen), *,err=10) nfiles - case ('p') - seed_prngs=.false. - case ('s') - read (optarg(:narglen), *) numbuf - if (numbuf(1:1) == '\') then - read (numbuf(2:), *,err=10) snrdb - else - read (numbuf, *,err=10) snrdb - end if - end select - cycle -10 display_help=.true. - print *, 'Optional argument format error for option -', c - end do - - if(display_help .or. nstat.lt.0 .or. nremain.ge.1) then - print *, '' - print *, 'Usage: jt65sim [OPTIONS]' - print *, '' - print *, ' Generate one or more simulated JT65 signals in .WAV file(s)' - print *, '' - print *, 'Example: jt65sim -m B -n 10 -d 0.2 -s \\-24.5 -t 0.0 -f 4' - print *, '' - print *, 'OPTIONS: NB Use \ (\\ on *nix shells) to escape -ve arguments' - print *, '' - do i = 1, size (long_options) - call long_options(i) % print (6) - end do + nargs=iargc() + if(nargs.ne. 7) then + print *, 'Usage: qra64sim "msg" A-E Nsigs fDop DT Nfiles SNR' + print *, 'Example qra64sim "K1ABC W9XYZ EN37" A 10 0.2 0.0 1 0' go to 999 endif - - if (seed_prngs) then - call init_random_seed() !Seed Fortran RANDOM_NUMBER generator - call sgran() !Seed C rand generator (used in gran) - end if + call getarg(1,msg) + call getarg(2,csubmode) + mode64=2**(ichar(csubmode)-ichar('A')) + print*,csubmode,' ',mode64 + call getarg(3,arg) + read(arg,*) nsigs + call getarg(4,arg) + read(arg,*) fspread + call getarg(5,arg) + read(arg,*) xdt + call getarg(6,arg) + read(arg,*) nfiles + call getarg(7,arg) + read(arg,*) snrdb rms=100. fsample=12000.d0 !Sample rate (Hz) @@ -116,11 +51,13 @@ program qra64sim dfsig=2000.0/nsigs !Freq spacing between sigs in file (Hz) ichk=0 + write(*,1000) +1000 format('File Sig Freq A-E S/N DT Dop Message'/60('-')) + do ifile=1,nfiles !Loop over requested number of files write(fname,1002) ifile !Output filename 1002 format('000000_',i4.4) open(10,file=fname//'.wav',access='stream',status='unknown') - xnoise=0. cdat=0. if(snrdb.lt.90) then @@ -129,32 +66,30 @@ program qra64sim enddo endif -! msg="K1ABC W9XYZ EN37" do isig=1,nsigs !Generate requested number of sigs if(mod(nsigs,2).eq.0) f0=1500.0 + dfsig*(isig-0.5-nsigs/2) if(mod(nsigs,2).eq.1) f0=1500.0 + dfsig*(isig-(nsigs+1)/2) xsnr=snrdb if(snrdb.eq.0.0) xsnr=-19 - isig - if(csubmode.eq.'B' .and. snrdb.eq.0.0) xsnr=-21 - isig - if(csubmode.eq.'C' .and. snrdb.eq.0.0) xsnr=-21 - isig call genqra64(msg,ichk,msgsent,itone,itype) - bandwidth_ratio=2500.0/6000.0 - sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*xsnr) +! bandwidth_ratio=2500.0/6000.0 +! sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*xsnr) + sig=sqrt(2.0)*10.0**(0.05*xsnr) if(xsnr.gt.90.0) sig=1.0 write(*,1020) ifile,isig,f0,csubmode,xsnr,xdt,fspread,msg 1020 format(i4,i4,f10.3,2x,a1,2x,f5.1,f6.2,f5.1,1x,a22) phi=0.d0 dphi=0.d0 - k=12000 + xdt*12000 !Start audio at t = xdt + 1.0 s + k=(xdt+1.0)*12000 !Start audio at t = xdt + 1.0 s isym0=-99 do i=1,npts !Add this signal into cdat() isym=i/nsps + 1 if(isym.gt.nsym) exit if(isym.ne.isym0) then - freq=f0 + itone(isym)*baud*mode65 + freq=f0 + itone(isym)*baud*mode64 dphi=twopi*freq*dt isym0=isym endif @@ -172,21 +107,13 @@ program qra64sim twopi=8*atan(1.0) cspread(0)=1.0 cspread(NH)=0. - -! The following options were added 3/15/2016 to make the half-power tone -! widths equal to the requested Doppler spread. (Previously we effectively -! used b=1.0 and Gaussian shape, which made the tones 1.665 times wider.) -! b=2.0*sqrt(log(2.0)) !Gaussian (before 3/15/2016) -! b=2.0 !Lorenzian 3/15 - 3/27 b=6.0 !Lorenzian 3/28 onward - do i=1,NH f=i*df x=b*f/fspread z=0. a=0. if(x.lt.3.0) then !Cutoff beyond x=3 -! a=sqrt(exp(-x*x)) !Gaussian a=sqrt(1.111/(1.0+x*x)-0.1) !Lorentzian call random_number(r1) phi1=twopi*r1 diff --git a/lib/qra64a.f90 b/lib/qra64a.f90 index 4ec18d217..a7c643159 100644 --- a/lib/qra64a.f90 +++ b/lib/qra64a.f90 @@ -1,9 +1,12 @@ -subroutine qra64a(dd,nf1,nf2,nfqso,ntol,mycall_12,sync,nsnr,dtx,nfreq, & - decoded,nft) +subroutine qra64a(dd,nf1,nf2,nfqso,ntol,mycall_12,hiscall_12,hisgrid_6, & + sync,nsnr,dtx,nfreq,decoded,nft) use packjt parameter (NFFT=2*6912,NH=NFFT/2,NZ=5760) - character decoded*22,mycall_12*12,mycall*6 + character decoded*22 + character*12 mycall_12,hiscall_12 + character*6 mycall,hiscall,hisgrid_6 + character*4 hisgrid logical ltext integer icos7(0:6) integer ipk(1) @@ -13,7 +16,6 @@ subroutine qra64a(dd,nf1,nf2,nfqso,ntol,mycall_12,sync,nsnr,dtx,nfreq, & real s(NZ) real savg(NZ) real blue(0:25) - real red0(NZ) real red(NZ) real x(NFFT) complex cx(0:NH) @@ -53,11 +55,10 @@ subroutine qra64a(dd,nf1,nf2,nfqso,ntol,mycall_12,sync,nsnr,dtx,nfreq, & savg=savg/base - 1.0 ss=ss/base - red0=0. + red=-99. fac=1.0/sqrt(21.0) sync=0. do if0=ia,ib - red0(if0)=0. do j=0,25 t=-3.0 do n=0,6 @@ -65,10 +66,10 @@ subroutine qra64a(dd,nf1,nf2,nfqso,ntol,mycall_12,sync,nsnr,dtx,nfreq, & t=t + ss(i,1+2*n+j) + ss(i,1+2*n+j+78) + ss(i,1+2*n+j+154) enddo ccf(if0,j)=fac*t - if(ccf(if0,j).gt.red0(if0)) then - red0(if0)=ccf(if0,j) - if(red0(if0).gt.sync) then - sync=red0(if0) + if(ccf(if0,j).gt.red(if0)) then + red(if0)=ccf(if0,j) + if(red(if0).gt.sync) then + sync=red(if0) f0=if0*df dtx=j*istep/12000.0 - 1.0 i0=if0 @@ -78,21 +79,7 @@ subroutine qra64a(dd,nf1,nf2,nfqso,ntol,mycall_12,sync,nsnr,dtx,nfreq, & enddo enddo -! red(ia:ib)=0. -! rewind 73 -! do i=ia+3,ib-3 -! r1=red0(i) -! red0(i)=0. -! r0=max(red0(i-3),red0(i-2),red0(i+2),red0(i+3)) -! red0(i)=r1 -! red(i)=max(0.0,r1-r0) -! write(73,3001) i*df,red(i),red0(i),r0 -!3001 format(4f12.3) -! enddo -! flush(73) - - red0=red0-4.0 - write(17) ia,ib,red0(ia:ib) + write(17) ia,ib,red(ia:ib) close(17) if0=nint(f0/df) @@ -117,8 +104,7 @@ subroutine qra64a(dd,nf1,nf2,nfqso,ntol,mycall_12,sync,nsnr,dtx,nfreq, & i=abs(ipk(1)-2*icos7(n)) if(i.le.1) nhard=nhard+1 enddo -! print*,'a',nhard,nhard,nhard - if(nhard.lt.6) go to 900 + if(nhard.lt.5) go to 900 do i=0,63 k=i0 + 2*i @@ -130,17 +116,29 @@ subroutine qra64a(dd,nf1,nf2,nfqso,ntol,mycall_12,sync,nsnr,dtx,nfreq, & enddo enddo - if(sync.gt.1.0) nsnr=nint(10.0*log10(sync) - 38.0) -! if(sync.lt.12.8) go to 900 !### Temporary ### + if(sync.gt.1.0) snr1=10.0*log10(sync) - 38.0 + nsnr=nint(snr1) mycall=mycall_12(1:6) !### May need fixing ### + hiscall=hiscall_12(1:6) + hisgrid=hisgrid_6(1:4) call packcall(mycall,nmycall,ltext) - call qra64_dec(s3,nmycall,dat4,irc) !Attempt decoding + call packcall(hiscall,nhiscall,ltext) + call packgrid(hisgrid,nhisgrid,ltext) + snr2=-99. + call qra64_dec(s3,nmycall,nhiscall,nhisgrid,dat4,snr2,irc) !Attempt decoding if(irc.ge.0) then call unpackmsg(dat4,decoded) !Unpack the user message call fmtmsg(decoded,iz) nft=100 + irc + nsnr=nint(snr2) + else + snr2=0. endif -900 return +900 continue + write(78,3900) sync,snr1,snr2,snr2-snr1,dtx,nfreq,nhard,irc,decoded +3900 format(4f7.1,f7.2,i6,2i4,2x,a22) + + return end subroutine qra64a diff --git a/lib/qra64code.f90 b/lib/qra64code.f90 index e697cf034..dab1509b4 100644 --- a/lib/qra64code.f90 +++ b/lib/qra64code.f90 @@ -86,7 +86,7 @@ program QRA64code mycall=' ' if(i1.ge.4) mycall=msg(1:i1-1) call packcall(mycall,nmycall,ltext) - call qra64_dec(s3,nmycall,dec,irc) !Decode + call qra64_dec(s3,nmycall,dec,snr,irc) !Decode decoded=" " if(irc.ge.0) then diff --git a/plotter.cpp b/plotter.cpp index 6024fdd53..0c0add863 100644 --- a/plotter.cpp +++ b/plotter.cpp @@ -141,7 +141,6 @@ void CPlotter::draw(float swide[], bool bScroll, bool bRed) j0=FreqfromX(i-1)/df_qra64; j1=FreqfromX(i)/df_qra64; smax=0.0; - y3[i]=0.0; for(int jj=j0; jj<=j1; jj++) { if(dec_data.sred[jj]>smax) smax=dec_data.sred[jj]; } @@ -150,7 +149,7 @@ void CPlotter::draw(float swide[], bool bScroll, bool bRed) } float fac=0.8/qMax(y3max,10.0f); for(int i=1; i0.0) { + if(y3[i]>0) { y2=fac*y3[i]; LineBuf2[k].setX(i); LineBuf2[k].setY(int(m_h2*(0.9-y2))); @@ -271,7 +270,6 @@ void CPlotter::drawRed(int ia, int ib, float swide[]) { m_ia=ia; m_ib=ib; - draw(swide,false,true); }