First commits in the superfox branch: synctest, sfocsim, and rstest.

This commit is contained in:
Joe Taylor 2024-01-30 18:10:44 -05:00
parent d67a406bf0
commit 27824dc45d
4 changed files with 334 additions and 0 deletions

View File

@ -1154,6 +1154,12 @@ target_link_libraries (test_snr wsjt_fort)
add_executable (q65sim lib/qra/q65/q65sim.f90)
target_link_libraries (q65sim wsjt_fort wsjt_cxx)
#add_executable (rstest lib/superfox/rstest.f90)
#target_link_libraries (rstest wsjt_fort wsjt_cxx)
add_executable (synctest lib/superfox/synctest.f90)
target_link_libraries (synctest wsjt_fort wsjt_cxx)
add_executable (q65code lib/qra/q65/q65code.f90)
target_link_libraries (q65code wsjt_fort wsjt_cxx)

65
lib/superfox/rstest.f90 Normal file
View File

@ -0,0 +1,65 @@
program rstest
character arg*8
integer dgen(235) !Generated data, i*4
integer gsym0(255) !Encoded data, Karn
integer gsym(255) !Encoded data with errors
integer dat(235) !Decoded data, i*4
nargs=iargc()
if(nargs.ne.4) then
print*,'Usage: rstest M N K nerr'
print*,'Example: rstest 7 127 51 38'
go to 999
endif
nkv=0
call getarg(1,arg)
read(arg,*) mm
call getarg(2,arg)
read(arg,*) nn
call getarg(3,arg)
read(arg,*) kk
call getarg(4,arg)
read(arg,*) nerr
! Initialize the Karn codec
nq=2**mm
nfz=3
call rs_init(mm,nq,nn,kk,nfz) !Initialize the Karn RS codec
! Generate and random symbols wuth values 0 to nq-1
do i=1,kk
dgen(i)=(nq-0.0001)*ran1(idum)
enddo
write(*,1000)
1000 format('Generated data symbols, values 0-127:')
write(*,1002) dgen(1:kk)
1002 format(20i4)
call rs_encode(dgen,gsym0) !Encode dgen into gsym0
write(*,1004)
1004 format(/'Encoded channel symbols')
write(*,1002) gsym0(1:nn)
gsym=gsym0
do i=1,nerr !Introduce errors
gsym(i)=mod(gsym(i)+1,nq)
enddo
write(*,1006)
1006 format(/'Recovered channel symbols, with errors:')
write(*,1002) gsym(1:nn)
call rs_decode(gsym,era,0,dat,nfixed)
ibad=0
do i=1,kk
if(dat(i).ne.dgen(i)) ibad=ibad+1
enddo
write(*,1008)
1008 format(/'Decoded result:')
write(*,1002) dat(1:kk)
write(*,1100) nerr,nfixed,ibad
1100 format(/'nerr:',i3,' nfixed:',i3,' ibad:',i3)
999 end program rstest

116
lib/superfox/sfoxsim.f90 Normal file
View File

@ -0,0 +1,116 @@
program sfoxsim
! Generate a SuperFox waveform with specified SNR and channel parameters.
! Output is saved to a *.wav file.
! SuperFox uses a (127,51) code with 7-bit symbols, punctured to (125,49).
! The puncured symbols contain a 14-bit CRC.
! First tests use RS(127,51) code and Berlekamp-Massey decoder.
use wavhdr
! use packjt77
parameter (NMAX=15*12000)
parameter (NSPS=1024,NSYNC=2*12000)
parameter (NWAVE=125*NSPS+NSYNC)
type(hdr) h !Header for .wav file
character arg*12,fname*17
! character msg37*37,msgsent37*37
complex c0(0:NMAX-1)
complex c(0:NMAX-1)
complex cwave(0:NWAVE-1)
real wave(NMAX)
real xjunk(NWAVE)
real xdat(51)
integer*1 idat(51)
integer itone(125)
integer*1 msgbits(77)
integer*2 iwave(NMAX) !Generated full-length waveform
! Get command-line argument(s)
nargs=iargc()
if(nargs.ne.6) then
print*,'Usage: sfoxsim f0 DT fSpread del nfiles snr'
print*,'Example: sfoxsim 1500.0 0.0 0.1 1.0 10 -15'
go to 999
endif
call getarg(1,arg)
read(arg,*) f0 !Frequency (only used for single-signal
call getarg(2,arg)
read(arg,*) xdt !Time offset from nominal (s)
call getarg(3,arg)
read(arg,*) fspread !Watterson frequency spread (Hz)
call getarg(4,arg)
read(arg,*) delay !Watterson delay (ms)
call getarg(5,arg)
read(arg,*) nfiles !Number of files
call getarg(6,arg)
read(arg,*) snrdb !SNR_2500
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=128*baud !Occupied bandwidth (Hz)
tsync=NSYNC*dt !Duration of analog sync function
txt=tsync + 125*NSPS*dt !Overall 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
write(*,1000) f0,xdt,fspread,delay,tsync,txt,bw,snrdb
1000 format('f0:',f7.1,' DT:',f6.2,' fSpread:',f5.1,' delay:',f4.1/ &
'Tsync:',f4.1,' TxT:',f6.1,' BW:',f7.1,' SNR:',f6.1)
write(*,*)
! Source-encode, then get itone()
call random_number(xdat)
idat=int(128*xdat)
itone=0
itone(1:49)=idat(1:49)
write(*,'(20i4)') idat
write(*,*)
write(*,'(a17)') 'Channel symbols: '
write(*,'(20i4)') itone
write(*,*)
if(nsps.ne.-99) go to 999
do ifile=1,nfiles
c0=0.
c0(0:NWAVE-1)=cwave
c0=cshift(c0,-nint((xdt+0.5)/dt))
! if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c0,NMAX,NWAVE,fs,delay,fspread)
c=sig*c0
wave=imag(c)
peak=maxval(abs(wave))
nslots=1
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 sfoxsim

147
lib/superfox/synctest.f90 Normal file
View File

@ -0,0 +1,147 @@
program synctest
! Generate and test sync waveforms for possible use in SuperFox signal.
use wavhdr
parameter (NMAX=15*12000) !Total samples in .wav file
parameter (NFFT=32768)
parameter (MMAX=150,JMAX=300)
type(hdr) h !Header for .wav file
integer*2 iwave(NMAX) !Generated i*2 waveform
real*4 xnoise(NMAX) !Random noise
real*4 dat(NMAX) !Generated real data
real ccf(-MMAX:MMAX,-JMAX:JMAX) !2D CCF: DT, dFreq offsets
complex cdat(-15000:NMAX) !Generated complex waveform
complex clo(NMAX) !Complex Local Oscillator
complex cnoise(NMAX) !Complex noise
complex crcvd(-15000:NMAX) !Signal as received
complex c(0:NFFT-1)
complex w,wstep,w0,wstep0
integer ipk(2)
character fname*17,arg*12
character*1 line(-30:30),mark(0:5)
data mark/' ','.','-','+','X','$'/
nargs=iargc()
if(nargs.ne.4) then
print*,'Usage: synctest f0 DT width snr'
print*,'Example: synctest 1500.0 2.5 1500 -20'
go to 999
endif
call getarg(1,arg)
read(arg,*) f0
call getarg(2,arg)
read(arg,*) xdt
call getarg(3,arg)
read(arg,*) syncwidth
call getarg(4,arg)
read(arg,*) snrdb
ntrperiod=15
rms=100.
fsample=12000.d0 !Sample rate (Hz)
npts=fsample*ntrperiod !Total samples in .wav file
twopi=8.d0*atan(1.d0)
tsync=2.0
nsync=fsample*tsync
nsym=125 !Number of channel symbols
nsps=1024
nsync=tsync*fsample
baud=12000.d0/nsps !Keying rate (6.67 baud fot 15-s sequences)
h=default_header(12000,npts)
fname='000000_000001.wav'
open(10,file=trim(fname),access='stream',status='unknown')
xnoise=0.
cnoise=0.
if(snrdb.lt.90) then
do i=1,npts !Generate Gaussian noise
x=gran()
y=gran()
xnoise(i)=x
cnoise(i)=cmplx(x,y)
enddo
endif
bandwidth_ratio=2500.0/6000.0
sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb)
if(snrdb.gt.90.0) sig=1.0
w0=1.0
w=1.0
a0=1500.0+ syncwidth/2.0 !Frequency at midpoint of LO waveform
a1=f0 + syncwidth/2.0 !Frequency at midpoint of sync waveform
a2=2.0*syncwidth/tsync !Frequency drift rate
! Generate complex sync signal
x0=0.5*(nsync+1)
s=2.0/nsync
cdat=0.
i0=xdt*12000.0
do i=1,nsync
if(i.eq.nsync/2+1) a2=-a2 !Reverse sign of drift at midpoint
x=s*(i-x0)
dphi0=(a0 + x*a2) * (twopi/fsample)
wstep0=cmplx(cos(dphi0),sin(dphi0))
w0=w0*wstep0
dphi=(a1 + x*a2) * (twopi/fsample)
wstep=cmplx(cos(dphi),sin(dphi))
w=w*wstep
clo(i)=conjg(sig*w0)
cdat(i+i0)=sig*w
enddo
dat=aimag(cdat(1:NMAX)) + xnoise !Add generated AWGN noise
fac=32767.0
if(snrdb.ge.90.0) iwave(1:npts)=nint(fac*dat(1:npts))
if(snrdb.lt.90.0) iwave(1:npts)=nint(rms*dat(1:npts))
write(10) h,iwave(1:npts) !Save the .wav file
close(10)
crcvd(-1000:0)=0.
crcvd(1:NMAX)=cdat(1:NMAX) + cnoise
ccf=0.
df=12000.0/NFFT !0.366211
do m=-MMAX,MMAX
lag=100*m
! c(0:nsync-1)=crcvd(1+lag:nsync+lag)*conjg(cdat(1:nsync))
c(0:nsync-1)=crcvd(1+lag:nsync+lag)*clo(1:nsync)
c(nsync:)=0.
fac=1.e-3
c=fac*c
call four2a(c,NFFT,1,-1,1)
do j=-JMAX,JMAX
k=j
if(k.lt.0) k=k+NFFT
ccf(m,j)=real(c(k))**2 + aimag(c(k))**2
enddo
enddo
ccf=ccf/maxval(ccf)
ipk=maxloc(ccf)
ipk(1)=ipk(1)-MMAX-1
ipk(2)=ipk(2)-JMAX-1
ma=ipk(1)-10
mb=ipk(1)+10
ja=ipk(2)-30
jb=ipk(2)+30
do m=ma,mb
do j=ja,jb
k=5.999*ccf(m,j)
line(j-ipk(2))=mark(k)
enddo
write(*,1300) m/120.0,line
1300 format(f6.3,2x,61a1)
enddo
dt=ipk(1)/120.0
dfreq=ipk(2)*df
f=1500.0+dfreq
t=dt
write(*,1100) f0,xdt
1100 format(/'f0:',f7.1,' xdt:',f6.2)
write(*,1112) f,t
1112 format('f: ',f7.1,' DT:',f6.2)
write(*,1110) f-f0,t-xdt
1110 format('err:',f6.1,f12.2)
999 end program synctest