2017-06-13 15:42:45 -04:00
|
|
|
program ft8sim
|
|
|
|
|
|
|
|
! Generate simulated data for a 15-second HF/6m mode using 8-FSK.
|
|
|
|
! Output is saved to a *.wav file.
|
|
|
|
|
|
|
|
use wavhdr
|
|
|
|
include 'ft8_params.f90' !Set various constants
|
2017-12-13 15:22:15 -05:00
|
|
|
parameter (NWAVE=NN*NSPS)
|
2017-06-13 15:42:45 -04:00
|
|
|
type(hdr) h !Header for .wav file
|
2017-12-13 15:22:15 -05:00
|
|
|
character arg*12,fname*17
|
2018-07-29 17:29:11 -04:00
|
|
|
character msg*37,msgsent*37,msg0*37
|
2017-06-14 16:21:01 -04:00
|
|
|
complex c0(0:NMAX-1)
|
|
|
|
complex c(0:NMAX-1)
|
2017-12-13 15:22:15 -05:00
|
|
|
real wave(NMAX)
|
2017-06-13 15:42:45 -04:00
|
|
|
integer itone(NN)
|
2018-07-29 17:29:11 -04:00
|
|
|
integer*1 msgbits(77)
|
2017-07-28 11:50:13 -04:00
|
|
|
integer*2 iwave(NMAX) !Generated full-length waveform
|
2017-06-13 15:42:45 -04:00
|
|
|
|
|
|
|
! Get command-line argument(s)
|
|
|
|
nargs=iargc()
|
2018-07-29 17:29:11 -04:00
|
|
|
if(nargs.ne.8) then
|
2018-07-04 10:52:39 -04:00
|
|
|
print*,'Usage: ft8sim "message" nsig|f0 DT fdop del width nfiles snr'
|
|
|
|
print*,'Examples: ft8sim "K1ABC W9XYZ EN37" 1500.0 0.0 0.1 1.0 0 10 -18'
|
|
|
|
print*,' ft8sim "K1ABC W9XYZ EN37" 10 0.0 0.1 1.0 25 10 -18'
|
|
|
|
print*,' ft8sim "K1ABC W9XYZ EN37" 25 0.0 0.1 1.0 25 10 -18'
|
|
|
|
print*,' ft8sim "K1ABC RR73; W9XYZ <KH1/KH7Z> -11" 300 0 0 0 25 1 -10'
|
2017-06-13 15:42:45 -04:00
|
|
|
go to 999
|
|
|
|
endif
|
2018-07-29 17:29:11 -04:00
|
|
|
call getarg(1,msg) !Message to be transmitted
|
2017-12-13 15:22:15 -05:00
|
|
|
call getarg(2,arg)
|
2017-07-13 18:23:59 -04:00
|
|
|
read(arg,*) f0 !Frequency (only used for single-signal)
|
2017-12-13 15:22:15 -05:00
|
|
|
call getarg(3,arg)
|
2017-07-13 18:23:59 -04:00
|
|
|
read(arg,*) xdt !Time offset from nominal (s)
|
2017-12-13 15:22:15 -05:00
|
|
|
call getarg(4,arg)
|
2017-07-13 18:23:59 -04:00
|
|
|
read(arg,*) fspread !Watterson frequency spread (Hz)
|
2017-12-13 15:22:15 -05:00
|
|
|
call getarg(5,arg)
|
2017-07-13 18:23:59 -04:00
|
|
|
read(arg,*) delay !Watterson delay (ms)
|
2017-12-13 15:22:15 -05:00
|
|
|
call getarg(6,arg)
|
|
|
|
read(arg,*) width !Filter transition width (Hz)
|
2017-07-13 18:23:59 -04:00
|
|
|
call getarg(7,arg)
|
|
|
|
read(arg,*) nfiles !Number of files
|
|
|
|
call getarg(8,arg)
|
2017-06-13 15:42:45 -04:00
|
|
|
read(arg,*) snrdb !SNR_2500
|
2018-06-05 09:40:00 -04:00
|
|
|
|
2017-12-13 15:22:15 -05:00
|
|
|
nsig=1
|
2017-12-19 15:59:59 -05:00
|
|
|
if(f0.lt.100.0) then
|
|
|
|
nsig=f0
|
|
|
|
f0=1500
|
|
|
|
endif
|
2017-06-13 15:42:45 -04:00
|
|
|
|
2017-07-28 11:50:13 -04:00
|
|
|
nfiles=abs(nfiles)
|
2017-06-13 15:42:45 -04:00
|
|
|
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=8*baud !Occupied bandwidth (Hz)
|
|
|
|
txt=NZ*dt !Transmission length (s)
|
|
|
|
bandwidth_ratio=2500.0/(fs/2.0)
|
2017-06-14 16:21:01 -04:00
|
|
|
sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb)
|
2017-06-13 15:42:45 -04:00
|
|
|
if(snrdb.gt.90.0) sig=1.0
|
|
|
|
txt=NN*NSPS/12000.0
|
|
|
|
|
2017-07-28 11:50:13 -04:00
|
|
|
! Source-encode, then get itone()
|
2018-07-29 17:29:11 -04:00
|
|
|
if(index(msg,';').le.0) then
|
2017-12-08 12:03:11 -05:00
|
|
|
i3bit=0
|
2018-07-29 17:29:11 -04:00
|
|
|
call genft8(msg,i3bit,0,1,msgsent,msgbits,itone)
|
2017-12-08 12:03:11 -05:00
|
|
|
write(*,1000) f0,xdt,txt,snrdb,bw,msgsent
|
2017-06-13 15:42:45 -04:00
|
|
|
1000 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1, &
|
|
|
|
' BW:',f4.1,2x,a22)
|
2017-12-08 12:03:11 -05:00
|
|
|
else
|
2018-07-29 17:29:11 -04:00
|
|
|
call foxgen_wrap(msg,msgbits,itone)
|
|
|
|
write(*,1001) f0,xdt,txt,snrdb,bw,msg
|
2017-12-08 12:03:11 -05:00
|
|
|
1001 format('f0:',f9.3,' DT:',f6.2,' TxT:',f6.1,' SNR:',f6.1, &
|
2018-07-29 17:29:11 -04:00
|
|
|
' BW:',f4.1,2x,a37)
|
2017-12-08 12:03:11 -05:00
|
|
|
endif
|
2017-07-08 10:06:48 -04:00
|
|
|
|
2018-01-30 11:57:14 -05:00
|
|
|
write(*,1030) msgbits(1:56)
|
|
|
|
1030 format(/'Call1: ',28i1,' Call2: ',28i1)
|
2018-07-29 17:29:11 -04:00
|
|
|
write(*,1032) msgbits(57:72),msgbits(73:75)
|
|
|
|
1032 format('Grid: ',16i1,' 3Bit: ',3i1)
|
2018-01-30 11:57:14 -05:00
|
|
|
write(*,1034) itone
|
|
|
|
1034 format(/'Channel symbols:'/79i1/)
|
2017-12-01 11:23:27 -05:00
|
|
|
|
2018-06-07 12:40:25 -04:00
|
|
|
call sgran()
|
|
|
|
|
2017-12-01 11:23:27 -05:00
|
|
|
msg0=msg
|
2017-06-13 15:42:45 -04:00
|
|
|
do ifile=1,nfiles
|
2017-07-13 18:23:59 -04:00
|
|
|
c=0.
|
|
|
|
do isig=1,nsig
|
|
|
|
c0=0.
|
2017-12-19 15:59:59 -05:00
|
|
|
if(nsig.eq.2) then
|
|
|
|
if(index(msg,'R-').gt.0) f0=500
|
2017-12-22 12:25:16 -05:00
|
|
|
i1=index(msg,' ')
|
|
|
|
msg(i1+4:i1+4)=char(ichar('A')+isig-1)
|
2017-12-19 15:59:59 -05:00
|
|
|
if(isig.eq.2) then
|
|
|
|
f0=f0+100
|
|
|
|
endif
|
2018-07-29 17:29:11 -04:00
|
|
|
call genft8(msg,i3bit,msgsent,msgbits,itone)
|
2017-12-19 15:59:59 -05:00
|
|
|
endif
|
2017-07-13 18:23:59 -04:00
|
|
|
if(nsig.eq.25) then
|
2017-11-14 13:14:50 -05:00
|
|
|
f0=(isig+2)*100.0
|
2017-12-04 12:54:30 -05:00
|
|
|
else if(nsig.eq.50) then
|
2017-12-01 11:23:27 -05:00
|
|
|
msg=msg0
|
2017-12-04 12:54:30 -05:00
|
|
|
f0=1000.0 + (isig-1)*60.0
|
2017-12-01 11:23:27 -05:00
|
|
|
i1=index(msg,' ')
|
|
|
|
i2=index(msg(i1+1:),' ') + i1
|
2017-12-04 12:54:30 -05:00
|
|
|
msg(i1+2:i1+2)=char(ichar('0')+mod(isig-1,10))
|
|
|
|
msg(i1+3:i1+3)=char(ichar('A')+mod(isig-1,26))
|
|
|
|
msg(i1+4:i1+4)=char(ichar('A')+mod(isig-1,26))
|
|
|
|
msg(i1+5:i1+5)=char(ichar('A')+mod(isig-1,26))
|
|
|
|
write(msg(i2+3:i2+4),'(i2.2)') isig-1
|
2017-12-01 11:23:27 -05:00
|
|
|
if(ifile.ge.2 .and. isig.eq.ifile-1) then
|
|
|
|
write(msg(i2+1:i2+4),1002) -isig
|
|
|
|
1002 format('R',i3.2)
|
|
|
|
f0=600.0 + mod(isig-1,5)*60.0
|
|
|
|
endif
|
2018-07-29 17:29:11 -04:00
|
|
|
call genft8(msg,i3bit,msgsent,msgbits,itone)
|
2017-07-13 18:23:59 -04:00
|
|
|
endif
|
2018-07-02 17:13:27 -04:00
|
|
|
! k=nint((xdt+0.5+0.01*gran())/dt)
|
|
|
|
k=nint((xdt+0.5)/dt)
|
|
|
|
ia=k
|
2017-06-19 16:15:43 -04:00
|
|
|
phi=0.0
|
2017-07-01 09:08:30 -04:00
|
|
|
do j=1,NN !Generate complex waveform
|
2018-06-30 15:56:19 -04:00
|
|
|
dphi=twopi*(f0*dt+itone(j)/real(NSPS))
|
2017-06-19 16:15:43 -04:00
|
|
|
do i=1,NSPS
|
2017-07-13 18:23:59 -04:00
|
|
|
if(k.ge.0 .and. k.lt.NMAX) c0(k)=cmplx(cos(phi),sin(phi))
|
2018-07-02 17:13:27 -04:00
|
|
|
k=k+1
|
2018-06-30 15:56:19 -04:00
|
|
|
phi=mod(phi+dphi,twopi)
|
2017-06-19 16:15:43 -04:00
|
|
|
enddo
|
|
|
|
enddo
|
2017-07-13 18:23:59 -04:00
|
|
|
if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c0,NMAX,fs,delay,fspread)
|
|
|
|
c=c+sig*c0
|
2017-06-19 16:15:43 -04:00
|
|
|
enddo
|
2017-12-13 15:22:15 -05:00
|
|
|
ib=k
|
|
|
|
wave=real(c)
|
|
|
|
peak=maxval(abs(wave(ia:ib)))
|
|
|
|
rms=sqrt(dot_product(wave(ia:ib),wave(ia:ib))/NWAVE)
|
|
|
|
nslots=1
|
|
|
|
if(width.gt.0.0) call filt8(f0,nslots,width,wave)
|
2017-11-14 13:14:50 -05:00
|
|
|
|
2017-06-13 15:42:45 -04:00
|
|
|
if(snrdb.lt.90) then
|
2017-12-13 15:22:15 -05:00
|
|
|
do i=1,NMAX !Add gaussian noise at specified SNR
|
2017-06-13 15:42:45 -04:00
|
|
|
xnoise=gran()
|
2017-12-13 15:22:15 -05:00
|
|
|
wave(i)=wave(i) + xnoise
|
2017-06-13 15:42:45 -04:00
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
|
|
|
|
fac=32767.0
|
|
|
|
rms=100.0
|
2017-12-13 15:22:15 -05:00
|
|
|
if(snrdb.ge.90.0) iwave(1:NMAX)=nint(fac*wave)
|
|
|
|
if(snrdb.lt.90.0) iwave(1:NMAX)=nint(rms*wave)
|
2017-06-13 15:42:45 -04:00
|
|
|
|
|
|
|
h=default_header(12000,NMAX)
|
|
|
|
write(fname,1102) ifile
|
2017-06-15 11:38:50 -04:00
|
|
|
1102 format('000000_',i6.6,'.wav')
|
2017-06-13 15:42:45 -04:00
|
|
|
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
|
2017-06-15 11:43:33 -04:00
|
|
|
1110 format(i4,f7.2,f8.2,f7.1,2x,a17)
|
2017-06-16 16:14:36 -04:00
|
|
|
enddo
|
2017-06-13 15:42:45 -04:00
|
|
|
|
|
|
|
999 end program ft8sim
|
2017-12-08 12:03:11 -05:00
|
|
|
|
|
|
|
|