From cdcdedfe40fca3b30a0f4cce58c30f50128a8185 Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Fri, 16 Feb 2024 16:11:01 -0500 Subject: [PATCH] Temporary code (### commented out ###) for calibrating SNR. --- lib/superfox/ftrsd3.f90 | 5 +---- lib/superfox/plotspec.f90 | 39 +++++++++++++++++++++++++++++++++++++++ lib/superfox/sfoxtest.f90 | 15 +++++++++------ 3 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 lib/superfox/plotspec.f90 diff --git a/lib/superfox/ftrsd3.f90 b/lib/superfox/ftrsd3.f90 index 8eeab08a3..a4cbf4d4d 100644 --- a/lib/superfox/ftrsd3.f90 +++ b/lib/superfox/ftrsd3.f90 @@ -143,10 +143,7 @@ subroutine ftrsd3(s3,chansym0,rxdat,rxprob,rxdat2,rxprob2,ntrials0, & endif enddo call rs_decode_sf(workdat,era_pos,numera,nerr) !Call the decoder - do i=0,NN-1 - write(60,3101) i,chansym0(i),workdat(i),workdat(i)-chansym0(i) -3101 format(4i8) - enddo + if( nerr.ge.0) then ! We have a candidate codeword. Find its hard and soft distance from ! the received word. Also find pp1 and pp2 from the full array diff --git a/lib/superfox/plotspec.f90 b/lib/superfox/plotspec.f90 new file mode 100644 index 000000000..08fab4e64 --- /dev/null +++ b/lib/superfox/plotspec.f90 @@ -0,0 +1,39 @@ +subroutine plotspec(dat) + + use sfox_mod + real dat(NMAX) + real s(0:NSPS/2) + complex c(0:NSPS-1) + integer ipk(1) + + nblks=NZ/NSPS + s=0. + fac=1.0/NSPS + do j=1,nblks + ib=j*NSPS + ia=ib-NSPS+1 + c=fac*dat(ia:ib) + call four2a(c,NSPS,1,-1,1) + do i=0,NSPS/2 + s(i)=s(i) + real(c(i))**2 + aimag(c(i))**2 + enddo + enddo + + df=12000.0/NSPS + ipk=maxloc(s) + f0=df*(ipk(1)-1) + p_sig_plus_noise=maxval(s) + p_noise=0. + do i=0,NSPS/2 + f=i*df + if(f.le.2500+df .and. abs(f-f0).gt.0.5*df) p_noise=p_noise + s(i) + write(40,1000) f,s(i) +1000 format(2f10.3) + enddo + p_sig=p_sig_plus_noise - p_noise*df/2500.0 + snr=p_sig/p_noise + snrdb=db(snr) + write(*,1100) snrdb +1100 format('Measured SNR:',f7.2) + +end subroutine plotspec diff --git a/lib/superfox/sfoxtest.f90 b/lib/superfox/sfoxtest.f90 index a3c94187d..c461ff982 100644 --- a/lib/superfox/sfoxtest.f90 +++ b/lib/superfox/sfoxtest.f90 @@ -114,6 +114,7 @@ program sfoxtest call rs_encode_sf(msg0,parsym) !Compute parity symbols chansym0(0:kk-1)=msg0(1:kk) chansym0(kk:nn-1)=parsym(1:nn-kk) +! chansym0=NQ/2 !### TEMPORARY, for SNR calibration ### ! Generate clo, the LO for sync detection call timer('clo ',0) @@ -161,17 +162,17 @@ program sfoxtest crcvd=0. crcvd(1:NMAX)=cshift(sig*cdat(1:NMAX),-nint(xdt*fsample)) + cnoise - - dat=aimag(sig*cdat(1:NMAX)) + xnoise !Add generated AWGN noise - fac=32767.0 - if(snr.ge.90.0) iwave(1:NMAX)=nint(fac*dat(1:NMAX)) - if(snr.lt.90.0) iwave(1:NMAX)=nint(rms*dat(1:NMAX)) - call timer('watterso',0) if(fspread.ne.0 .or. delay.ne.0) call watterson(crcvd,NMAX,NZ,fsample,& delay,fspread) call timer('watterso',1) + dat=aimag(sig*cdat(1:NMAX)) + xnoise !Add generated AWGN noise +! call plotspec(dat) !### TEMPORARY, for SNR calibration ### + fac=32767.0 + if(snr.ge.90.0) iwave(1:NMAX)=nint(fac*dat(1:NMAX)) + if(snr.lt.90.0) iwave(1:NMAX)=nint(rms*dat(1:NMAX)) + ! Find signal freq and DT call timer('sync ',0) call sfox_sync(crcvd,clo,nv,f,t) @@ -248,3 +249,5 @@ program sfoxtest 999 call timer('sfoxtest',101) end program sfoxtest + +! include 'plotspec.f90' !### TEMPORARY, for SNR calibration ###