2012-09-27 15:10:15 -04:00
|
|
|
program jt9sim
|
|
|
|
|
2012-09-28 14:07:07 -04:00
|
|
|
! Generate simulated data for testing of WSJT-X
|
2012-09-27 15:10:15 -04:00
|
|
|
|
2013-05-20 10:09:02 -04:00
|
|
|
parameter (NTMAX=120)
|
|
|
|
parameter (NMAX=NTMAX*12000)
|
2012-09-27 15:10:15 -04:00
|
|
|
integer ihdr(11)
|
2012-10-02 20:37:40 -04:00
|
|
|
integer*2 iwave !Generated waveform (no noise)
|
2012-11-25 15:34:41 -05:00
|
|
|
real*8 f0,f,dt,twopi,phi,dphi,baud,fspan,fsample,freq
|
2012-09-28 19:59:50 -04:00
|
|
|
character msg*22,msg0*22,message*22,msgsent*22,arg*8,fname*11
|
2012-10-02 20:37:40 -04:00
|
|
|
|
2012-10-17 15:58:35 -04:00
|
|
|
integer*4 i4tone(85) !Channel symbols (values 0-8)
|
2012-10-02 20:37:40 -04:00
|
|
|
integer*4 i4DataSymNoGray(69) !Data Symbols, values 0-7
|
2012-10-17 15:58:35 -04:00
|
|
|
integer*1 i1ScrambledBits(207) !Unpacked bits, scrambled order
|
|
|
|
integer*1 i1Bits(207) !Encoded information-carrying bits
|
2012-10-02 20:37:40 -04:00
|
|
|
integer*1 i1SoftSymbols(207)
|
2012-10-22 15:18:24 -04:00
|
|
|
include 'jt9sync.f90'
|
2012-09-28 14:07:07 -04:00
|
|
|
common/acom/dat(NMAX),iwave(NMAX)
|
2012-09-27 15:10:15 -04:00
|
|
|
|
|
|
|
nargs=iargc()
|
2012-09-28 14:07:07 -04:00
|
|
|
if(nargs.ne.6) then
|
2012-09-27 15:10:15 -04:00
|
|
|
print*,'Usage: jt9sim "message" fspan nsigs minutes SNR nfiles'
|
|
|
|
print*,'Example: "CQ K1ABC FN42" 200 20 2 -28 1'
|
|
|
|
print*,' '
|
|
|
|
print*,'Enter message = "" to use entries in msgs.txt.'
|
|
|
|
print*,'Enter SNR = 0 to generate a range of SNRs.'
|
|
|
|
go to 999
|
|
|
|
endif
|
|
|
|
|
|
|
|
call getarg(1,msg0)
|
|
|
|
message=msg0 !Transmitted message
|
|
|
|
call getarg(2,arg)
|
|
|
|
read(arg,*) fspan !Total freq range (Hz)
|
|
|
|
call getarg(3,arg)
|
|
|
|
read(arg,*) nsigs !Number of signals in each file
|
|
|
|
call getarg(4,arg)
|
|
|
|
read(arg,*) minutes !Length of file (1 2 5 10 30 minutes)
|
|
|
|
call getarg(5,arg)
|
|
|
|
read(arg,*) snrdb !S/N in dB (2500 hz reference BW)
|
|
|
|
call getarg(6,arg)
|
|
|
|
read(arg,*) nfiles !Number of files
|
|
|
|
|
|
|
|
rmsdb=25.
|
|
|
|
rms=10.0**(0.05*rmsdb)
|
|
|
|
fsample=12000.d0 !Sample rate (Hz)
|
|
|
|
dt=1.d0/fsample !Sample interval (s)
|
|
|
|
twopi=8.d0*atan(1.d0)
|
|
|
|
npts=12000*(60*minutes-6)
|
2012-09-28 14:07:07 -04:00
|
|
|
nsps=0
|
|
|
|
if(minutes.eq.1) nsps=6912
|
|
|
|
if(minutes.eq.2) nsps=15360
|
|
|
|
if(minutes.eq.5) nsps=40960
|
|
|
|
if(minutes.eq.10) nsps=82944
|
2012-10-02 11:56:18 -04:00
|
|
|
if(minutes.eq.30) nsps=252000
|
2012-09-28 14:07:07 -04:00
|
|
|
if(nsps.eq.0) stop 'Bad value for minutes.'
|
2012-11-27 10:38:03 -05:00
|
|
|
|
2013-05-22 21:05:37 -04:00
|
|
|
f0=1400.d0 !Center frequency (Hz)
|
2012-11-27 10:38:03 -05:00
|
|
|
! f0=1500.0
|
2012-11-26 16:06:41 -05:00
|
|
|
! if(minutes.eq.5) f0=1100.
|
|
|
|
! if(minutes.eq.10) f0=1050.
|
|
|
|
! if(minutes.eq.30) f0=1025.
|
2012-10-05 15:14:45 -04:00
|
|
|
|
2012-09-28 14:07:07 -04:00
|
|
|
ihdr=0 !Temporary ###
|
2013-05-22 21:05:37 -04:00
|
|
|
k=0 !Silence compiler warning
|
2012-10-04 15:03:39 -04:00
|
|
|
|
|
|
|
if(msg0(1:3).eq.'sin') read(msg0(4:),*) sinfreq
|
2012-09-27 15:10:15 -04:00
|
|
|
|
|
|
|
open(12,file='msgs.txt',status='old')
|
|
|
|
|
|
|
|
write(*,1000)
|
2012-09-28 14:07:07 -04:00
|
|
|
1000 format('File N freq S/N Message'/ &
|
2012-09-27 15:10:15 -04:00
|
|
|
'---------------------------------------------------')
|
|
|
|
|
2012-10-17 15:58:35 -04:00
|
|
|
do ifile=1,nfiles !Loop over all files
|
2012-10-24 15:48:49 -04:00
|
|
|
nmin=(ifile-1)*minutes
|
2012-09-27 15:10:15 -04:00
|
|
|
ihr=nmin/60
|
|
|
|
imin=mod(nmin,60)
|
2012-10-17 15:58:35 -04:00
|
|
|
write(fname,1002) ihr,imin !Create output filename
|
2012-09-27 15:10:15 -04:00
|
|
|
1002 format('000000_',2i2.2)
|
|
|
|
open(10,file=fname//'.wav',access='stream',status='unknown')
|
|
|
|
|
2012-09-28 14:07:07 -04:00
|
|
|
if(snrdb.lt.90) then
|
2012-10-01 15:40:23 -04:00
|
|
|
do i=1,npts
|
|
|
|
dat(i)=gran()
|
|
|
|
enddo
|
2012-09-28 14:07:07 -04:00
|
|
|
else
|
|
|
|
dat(1:npts)=0.
|
|
|
|
endif
|
2012-09-27 15:10:15 -04:00
|
|
|
|
|
|
|
if(msg0.ne.' ') then
|
2012-10-20 12:37:01 -04:00
|
|
|
call genjt9(message,msgsent,i4tone) !Encode message into tone #s
|
2012-09-27 15:10:15 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
rewind 12
|
2012-10-17 15:58:35 -04:00
|
|
|
do isig=1,nsigs !Loop over multiple signals
|
2012-09-27 15:10:15 -04:00
|
|
|
|
|
|
|
if(msg0.eq.' ') then
|
2012-10-17 15:58:35 -04:00
|
|
|
read(12,1004) message !Use pre-generated message texts
|
2012-09-27 15:10:15 -04:00
|
|
|
1004 format(a22)
|
2012-10-20 12:37:01 -04:00
|
|
|
call genjt9(message,msgsent,i4tone)
|
2012-09-27 15:10:15 -04:00
|
|
|
endif
|
2012-09-28 14:07:07 -04:00
|
|
|
|
|
|
|
f=f0
|
|
|
|
if(nsigs.gt.1) f=f0 - 0.5d0*fspan + fspan*(isig-1.d0)/(nsigs-1.d0)
|
2012-11-27 11:48:50 -05:00
|
|
|
snrdbx=snrdb
|
|
|
|
! snrdbx=snrdb + (ifile-1)*4.0
|
2012-10-06 11:38:06 -04:00
|
|
|
sig=10.0**(0.05*snrdbx)
|
2012-09-28 14:07:07 -04:00
|
|
|
write(*,1020) ifile,isig,f,snrdbx,msgsent
|
|
|
|
1020 format(i3,i4,f10.3,f7.1,2x,a22)
|
2012-09-27 15:10:15 -04:00
|
|
|
|
|
|
|
phi=0.
|
2012-11-25 15:34:41 -05:00
|
|
|
baud=12000.d0/nsps
|
2012-10-17 15:58:35 -04:00
|
|
|
k=12000 !Start audio at t = 1.0 s
|
2012-11-27 11:48:50 -05:00
|
|
|
! f1=0.0001 * (ifile-1)
|
|
|
|
f1=0.
|
|
|
|
! print*,ifile-1,f1
|
2012-11-27 10:38:03 -05:00
|
|
|
dphi2=0.
|
|
|
|
ddphi2=twopi*f1*dt/60.0
|
2012-09-28 14:07:07 -04:00
|
|
|
do isym=1,85
|
2012-10-17 15:58:35 -04:00
|
|
|
freq=f + i4tone(isym)*baud
|
2012-10-04 15:03:39 -04:00
|
|
|
if(msg0(1:3).eq.'sin') freq=sinfreq
|
2012-11-27 10:38:03 -05:00
|
|
|
dphi=twopi*freq*dt + dphi2
|
2012-09-28 14:07:07 -04:00
|
|
|
do i=1,nsps
|
2012-09-27 15:10:15 -04:00
|
|
|
phi=phi + dphi
|
2012-11-27 10:38:03 -05:00
|
|
|
dphi2=dphi2 + ddphi2
|
2012-09-27 15:10:15 -04:00
|
|
|
if(phi.lt.-twopi) phi=phi+twopi
|
|
|
|
if(phi.gt.twopi) phi=phi-twopi
|
|
|
|
xphi=phi
|
|
|
|
k=k+1
|
2012-10-02 11:56:18 -04:00
|
|
|
dat(k)=dat(k) + sig*sin(xphi) !Use lookup table for i*2 sin(x) ?
|
2012-09-27 15:10:15 -04:00
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
|
|
|
|
do i=1,npts
|
2012-09-28 14:07:07 -04:00
|
|
|
iwave(i)=nint(rms*dat(i))
|
2012-09-27 15:10:15 -04:00
|
|
|
enddo
|
|
|
|
|
2012-09-28 14:07:07 -04:00
|
|
|
write(10) ihdr,iwave(1:npts)
|
2012-09-27 15:10:15 -04:00
|
|
|
close(10)
|
2012-09-28 19:59:50 -04:00
|
|
|
|
2012-10-17 15:58:35 -04:00
|
|
|
! We're done! Now decode the data symbols from i4tone, as a test.
|
|
|
|
if(msg0.ne.' ') then
|
|
|
|
j=0
|
|
|
|
do i=1,85
|
|
|
|
if(isync(i).eq.1) cycle
|
|
|
|
j=j+1
|
|
|
|
i4DataSymNoGray(j)=igray(i4tone(i)-1,-1)
|
|
|
|
enddo
|
|
|
|
call unpackbits(i4DataSymNoGray,69,3,i1ScrambledBits)
|
|
|
|
call interleave9(i1ScrambledBits,-1,i1Bits)
|
2012-11-01 15:54:40 -04:00
|
|
|
|
2012-10-17 15:58:35 -04:00
|
|
|
do i=1,206
|
|
|
|
i4=-10
|
|
|
|
if(i1Bits(i).eq.1) i4=10
|
|
|
|
i4=i4+128
|
2013-05-22 21:05:37 -04:00
|
|
|
if(i4.le.127) i1SoftSymbols(k)=i4
|
|
|
|
if(i4.ge.128) i1SoftSymbols(k)=i4-256
|
2012-10-17 15:58:35 -04:00
|
|
|
enddo
|
2012-11-01 15:54:40 -04:00
|
|
|
limit=1000
|
|
|
|
call decode9(i1SoftSymbols,limit,nlim,msg)
|
2012-10-17 15:58:35 -04:00
|
|
|
if(msg.ne.msg0) print*,'Decode error: ',msg0,' ',msg
|
|
|
|
endif
|
2012-09-27 15:10:15 -04:00
|
|
|
enddo
|
|
|
|
|
|
|
|
999 end program jt9sim
|