2024-01-30 18:10:44 -05:00
|
|
|
program synctest
|
|
|
|
|
|
|
|
! Generate and test sync waveforms for possible use in SuperFox signal.
|
|
|
|
|
|
|
|
use wavhdr
|
2024-01-31 11:18:42 -05:00
|
|
|
include "sfox_params.f90"
|
2024-01-30 18:10:44 -05:00
|
|
|
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
|
2024-01-30 18:34:43 -05:00
|
|
|
complex cdat(NMAX) !Generated complex waveform
|
2024-01-30 18:10:44 -05:00
|
|
|
complex clo(NMAX) !Complex Local Oscillator
|
|
|
|
complex cnoise(NMAX) !Complex noise
|
2024-01-30 18:34:43 -05:00
|
|
|
complex crcvd(NMAX) !Signal as received
|
2024-01-31 14:16:40 -05:00
|
|
|
! real xdat(ND) !Temporary: for generating idat
|
2024-01-31 12:46:24 -05:00
|
|
|
integer*1 idat(ND) !Encoded data, 7-bit integers
|
2024-01-31 13:45:53 -05:00
|
|
|
integer*1 jdat(ND) !Recovered hard-decision symbols
|
2024-01-30 18:10:44 -05:00
|
|
|
character fname*17,arg*12
|
|
|
|
|
|
|
|
nargs=iargc()
|
2024-01-31 11:37:19 -05:00
|
|
|
if(nargs.ne.6) then
|
|
|
|
print*,'Usage: synctest f0 DT fspread delay width snr'
|
|
|
|
print*,'Example: synctest 1500.0 2.5 0.0 0.0 100 -20'
|
2024-01-30 18:10:44 -05:00
|
|
|
go to 999
|
|
|
|
endif
|
|
|
|
call getarg(1,arg)
|
|
|
|
read(arg,*) f0
|
|
|
|
call getarg(2,arg)
|
|
|
|
read(arg,*) xdt
|
|
|
|
call getarg(3,arg)
|
2024-01-31 11:37:19 -05:00
|
|
|
read(arg,*) fspread
|
2024-01-30 18:10:44 -05:00
|
|
|
call getarg(4,arg)
|
2024-01-31 11:37:19 -05:00
|
|
|
read(arg,*) delay
|
|
|
|
call getarg(5,arg)
|
|
|
|
read(arg,*) syncwidth
|
|
|
|
call getarg(6,arg)
|
2024-01-30 18:10:44 -05:00
|
|
|
read(arg,*) snrdb
|
|
|
|
|
|
|
|
rms=100.
|
2024-01-30 18:34:43 -05:00
|
|
|
fsample=12000.0 !Sample rate (Hz)
|
2024-01-31 10:47:16 -05:00
|
|
|
baud=12000.0/nsps !Keying rate, 11.719 baud for nsps=1024
|
2024-01-31 14:16:40 -05:00
|
|
|
idummy=0
|
2024-01-31 12:46:24 -05:00
|
|
|
|
2024-01-31 14:16:40 -05:00
|
|
|
do i=1,ND
|
|
|
|
idat(i)=128*ran1(idummy)
|
|
|
|
enddo
|
2024-01-31 12:46:24 -05:00
|
|
|
|
2024-01-31 11:18:42 -05:00
|
|
|
h=default_header(12000,NMAX)
|
2024-01-30 18:10:44 -05:00
|
|
|
fname='000000_000001.wav'
|
|
|
|
open(10,file=trim(fname),access='stream',status='unknown')
|
2024-01-31 11:18:42 -05:00
|
|
|
|
2024-01-30 18:10:44 -05:00
|
|
|
xnoise=0.
|
|
|
|
cnoise=0.
|
|
|
|
if(snrdb.lt.90) then
|
2024-01-31 11:18:42 -05:00
|
|
|
do i=1,NMAX !Generate Gaussian noise
|
2024-01-30 18:10:44 -05:00
|
|
|
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
|
|
|
|
|
2024-01-31 12:18:31 -05:00
|
|
|
!Generate cdat (SuperFox waveform) and clo (LO needed for sync detection)
|
2024-01-31 12:46:24 -05:00
|
|
|
call gen_sfox(idat,f0,fsample,syncwidth,cdat,clo)
|
2024-01-31 12:18:31 -05:00
|
|
|
|
2024-01-31 12:08:50 -05:00
|
|
|
crcvd=0.
|
2024-01-31 12:18:31 -05:00
|
|
|
crcvd(1:NMAX)=cshift(sig*cdat(1:NMAX),-nint(xdt*fsample)) + cnoise
|
2024-01-30 18:10:44 -05:00
|
|
|
|
2024-01-31 12:18:31 -05:00
|
|
|
dat=aimag(sig*cdat(1:NMAX)) + xnoise !Add generated AWGN noise
|
2024-01-30 18:10:44 -05:00
|
|
|
fac=32767.0
|
2024-01-31 11:18:42 -05:00
|
|
|
if(snrdb.ge.90.0) iwave(1:NMAX)=nint(fac*dat(1:NMAX))
|
|
|
|
if(snrdb.lt.90.0) iwave(1:NMAX)=nint(rms*dat(1:NMAX))
|
|
|
|
write(10) h,iwave(1:NMAX) !Save the .wav file
|
2024-01-30 18:10:44 -05:00
|
|
|
close(10)
|
|
|
|
|
2024-01-31 11:37:19 -05:00
|
|
|
if(fspread.ne.0 .or. delay.ne.0) call watterson(crcvd,NMAX,NZ,fsample, &
|
|
|
|
delay,fspread)
|
|
|
|
|
2024-01-31 12:46:24 -05:00
|
|
|
! Find signal freq and DT
|
|
|
|
|
|
|
|
call sync_sf(crcvd,clo,f,t)
|
|
|
|
|
2024-01-31 13:45:53 -05:00
|
|
|
call hard_symbols(crcvd,f,t,jdat)
|
|
|
|
nharderr=count(jdat.ne.idat)
|
|
|
|
|
2024-01-30 18:10:44 -05:00
|
|
|
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)
|
2024-01-31 13:45:53 -05:00
|
|
|
write(*,1120) nharderr
|
|
|
|
1120 format('Hard errors:',i4)
|
2024-01-30 18:10:44 -05:00
|
|
|
|
|
|
|
999 end program synctest
|
2024-01-31 12:08:50 -05:00
|
|
|
|
|
|
|
include 'gen_sfox.f90'
|
2024-01-31 12:46:24 -05:00
|
|
|
include 'sync_sf.f90'
|
2024-01-31 13:45:53 -05:00
|
|
|
include 'hard_symbols.f90'
|
2024-01-31 14:16:40 -05:00
|
|
|
include 'ran1.f90'
|