| 
									
										
										
										
											2019-11-27 09:08:17 -06:00
										 |  |  | program ft8sim_gfsk
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  | ! Generate simulated "type 2" ft8 files
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  | ! Output is saved to a *.wav file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   use wavhdr
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  |   use packjt77
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |   include 'ft8_params.f90'               !Set various constants
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |   parameter (NWAVE=NN*NSPS)
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |   type(hdr) h                            !Header for .wav file
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |   character arg*12,fname*17
 | 
					
						
							| 
									
										
										
										
											2018-12-05 16:06:33 -06:00
										 |  |  |   character msg37*37,msgsent37*37
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  |   character c77*77
 | 
					
						
							| 
									
										
										
										
											2017-06-14 20:21:01 +00:00
										 |  |  |   complex c0(0:NMAX-1)
 | 
					
						
							|  |  |  |   complex c(0:NMAX-1)
 | 
					
						
							| 
									
										
										
										
											2019-11-27 09:08:17 -06:00
										 |  |  |   complex cwave(0:NWAVE-1)
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |   real wave(NMAX)
 | 
					
						
							| 
									
										
										
										
											2019-11-27 09:08:17 -06:00
										 |  |  |   real xjunk(NWAVE)
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |   integer itone(NN)
 | 
					
						
							| 
									
										
										
										
											2018-07-29 16:29:11 -05:00
										 |  |  |   integer*1 msgbits(77)
 | 
					
						
							| 
									
										
										
										
											2017-07-28 15:50:13 +00:00
										 |  |  |   integer*2 iwave(NMAX)                  !Generated full-length waveform
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Get command-line argument(s)
 | 
					
						
							|  |  |  |   nargs=iargc()
 | 
					
						
							| 
									
										
										
										
											2019-11-27 09:08:17 -06:00
										 |  |  |   if(nargs.ne.7) then
 | 
					
						
							|  |  |  |      print*,'Usage:    ft8sim "message"                 f0     DT fdop del nfiles snr'
 | 
					
						
							|  |  |  |      print*,'Examples: ft8sim "K1ABC W9XYZ EN37"       1500.0 0.0  0.1 1.0   10   -18'
 | 
					
						
							|  |  |  |      print*,'          ft8sim "WA9XYZ/R KA1ABC/R FN42" 1500.0 0.0  0.1 1.0   10   -18'
 | 
					
						
							| 
									
										
										
										
											2018-10-19 19:45:38 -05:00
										 |  |  |      print*,'          ft8sim "K1ABC RR73; W9XYZ <KH1/KH7Z> -11" 300 0 0 0 25 1 -10'
 | 
					
						
							| 
									
										
										
										
											2020-04-21 13:48:47 -04:00
										 |  |  |      print*,'          ft8sim "<G4ABC/P> <PA9XYZ> R 570007 JO22DB" 1500 0 0 0 1 -10'
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |      go to 999
 | 
					
						
							|  |  |  |   endif
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  |   call getarg(1,msg37)                   !Message to be transmitted
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |   call getarg(2,arg)
 | 
					
						
							| 
									
										
										
										
											2017-07-13 22:23:59 +00:00
										 |  |  |   read(arg,*) f0                         !Frequency (only used for single-signal)
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |   call getarg(3,arg)
 | 
					
						
							| 
									
										
										
										
											2017-07-13 22:23:59 +00:00
										 |  |  |   read(arg,*) xdt                        !Time offset from nominal (s)
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |   call getarg(4,arg)
 | 
					
						
							| 
									
										
										
										
											2017-07-13 22:23:59 +00:00
										 |  |  |   read(arg,*) fspread                    !Watterson frequency spread (Hz)
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |   call getarg(5,arg)
 | 
					
						
							| 
									
										
										
										
											2017-07-13 22:23:59 +00:00
										 |  |  |   read(arg,*) delay                      !Watterson delay (ms)
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |   call getarg(6,arg)
 | 
					
						
							| 
									
										
										
										
											2017-07-13 22:23:59 +00:00
										 |  |  |   read(arg,*) nfiles                     !Number of files
 | 
					
						
							| 
									
										
										
										
											2019-11-27 09:08:17 -06:00
										 |  |  |   call getarg(7,arg)
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |   read(arg,*) snrdb                      !SNR_2500
 | 
					
						
							| 
									
										
										
										
											2018-06-05 08:40:00 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |   nsig=1
 | 
					
						
							| 
									
										
										
										
											2017-12-19 20:59:59 +00:00
										 |  |  |   if(f0.lt.100.0) then
 | 
					
						
							|  |  |  |      nsig=f0
 | 
					
						
							|  |  |  |      f0=1500
 | 
					
						
							|  |  |  |   endif
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 15:50:13 +00:00
										 |  |  |   nfiles=abs(nfiles)
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00: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)
 | 
					
						
							| 
									
										
										
										
											2019-11-27 09:08:17 -06:00
										 |  |  |   bt=2.0                         
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |   bandwidth_ratio=2500.0/(fs/2.0)
 | 
					
						
							| 
									
										
										
										
											2017-06-14 20:21:01 +00:00
										 |  |  |   sig=sqrt(2*bandwidth_ratio) * 10.0**(0.05*snrdb)
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |   if(snrdb.gt.90.0) sig=1.0
 | 
					
						
							|  |  |  |   txt=NN*NSPS/12000.0
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  |   ! Source-encode, then get itone()
 | 
					
						
							|  |  |  |   i3=-1
 | 
					
						
							|  |  |  |   n3=-1
 | 
					
						
							|  |  |  |   call pack77(msg37,i3,n3,c77)
 | 
					
						
							| 
									
										
										
										
											2018-11-05 11:59:48 -05:00
										 |  |  |   call genft8(msg37,i3,n3,msgsent37,msgbits,itone)
 | 
					
						
							| 
									
										
										
										
											2019-11-27 09:08:17 -06:00
										 |  |  |   call gen_ft8wave(itone,NN,NSPS,bt,fs,f0,cwave,xjunk,1,NWAVE)  !Generate complex cwave
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   write(*,*)  
 | 
					
						
							| 
									
										
										
										
											2020-04-21 13:48:47 -04:00
										 |  |  |   write(*,'(a23,a37,3x,a7,i1,a1,i1)') 'Decoded message: ',msgsent37,'i3.n3: ',i3,'.',n3
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  |   write(*,1000) f0,xdt,txt,snrdb,bw
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  | 1000 format('f0:',f9.3,'   DT:',f6.2,'   TxT:',f6.1,'   SNR:',f6.1,    &
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  |        '  BW:',f4.1)
 | 
					
						
							|  |  |  |   write(*,*)  
 | 
					
						
							|  |  |  |   if(i3.eq.1) then
 | 
					
						
							|  |  |  |     write(*,*) '         mycall                         hiscall                    hisgrid'
 | 
					
						
							|  |  |  |     write(*,'(28i1,1x,i1,1x,28i1,1x,i1,1x,i1,1x,15i1,1x,3i1)') msgbits(1:77) 
 | 
					
						
							| 
									
										
										
										
											2017-12-08 17:03:11 +00:00
										 |  |  |   else
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  |     write(*,'(a14)') 'Message bits: '
 | 
					
						
							|  |  |  |     write(*,'(77i1)') msgbits
 | 
					
						
							| 
									
										
										
										
											2017-12-08 17:03:11 +00:00
										 |  |  |   endif
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  |   write(*,*) 
 | 
					
						
							|  |  |  |   write(*,'(a17)') 'Channel symbols: '
 | 
					
						
							|  |  |  |   write(*,'(79i1)') itone
 | 
					
						
							|  |  |  |   write(*,*)  
 | 
					
						
							| 
									
										
										
										
											2017-12-01 16:23:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 11:40:25 -05:00
										 |  |  |   call sgran()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |   do ifile=1,nfiles
 | 
					
						
							| 
									
										
										
										
											2019-11-27 09:08:17 -06:00
										 |  |  |      c0=0.
 | 
					
						
							|  |  |  |      c0(0:NWAVE-1)=cwave
 | 
					
						
							|  |  |  |      c0=cshift(c0,-nint((xdt+0.5)/dt))
 | 
					
						
							| 
									
										
										
										
											2018-10-25 16:39:17 -05:00
										 |  |  |      if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c0,NMAX,NWAVE,fs,delay,fspread)
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  |      c=sig*c0
 | 
					
						
							|  |  |  |   
 | 
					
						
							| 
									
										
										
										
											2019-11-27 09:08:17 -06:00
										 |  |  |      wave=imag(c)
 | 
					
						
							|  |  |  |      peak=maxval(abs(wave))
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |      nslots=1
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  |    
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |      if(snrdb.lt.90) then
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |         do i=1,NMAX                   !Add gaussian noise at specified SNR
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |            xnoise=gran()
 | 
					
						
							| 
									
										
										
										
											2017-12-13 20:22:15 +00:00
										 |  |  |            wave(i)=wave(i) + xnoise
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |         enddo
 | 
					
						
							|  |  |  |      endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-07 11:10:25 -06:00
										 |  |  |      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)
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00:00
										 |  |  |      h=default_header(12000,NMAX)
 | 
					
						
							|  |  |  |      write(fname,1102) ifile
 | 
					
						
							| 
									
										
										
										
											2017-06-15 15:38:50 +00:00
										 |  |  | 1102 format('000000_',i6.6,'.wav')
 | 
					
						
							| 
									
										
										
										
											2017-06-13 19:42:45 +00: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 15:43:33 +00:00
										 |  |  | 1110 format(i4,f7.2,f8.2,f7.1,2x,a17)
 | 
					
						
							| 
									
										
										
										
											2018-10-19 16:52:00 -05:00
										 |  |  |   enddo    
 | 
					
						
							| 
									
										
										
										
											2019-11-27 09:08:17 -06:00
										 |  |  | 999 end program ft8sim_gfsk
 |