| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  | program wspr5sim
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-01 12:32:59 +00:00
										 |  |  | ! Generate simulated data for a 5-minute "WSPR-LF" mode.  Output is saved 
 | 
					
						
							|  |  |  | ! to a *.c5 or *.wav file.
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   use wavhdr
 | 
					
						
							|  |  |  |   include 'wsprlf_params.f90'            !Set various constants
 | 
					
						
							|  |  |  |   parameter (NMAX=300*12000)
 | 
					
						
							|  |  |  |   type(hdr) h                            !Header for .wav file
 | 
					
						
							|  |  |  |   character arg*12,fname*16
 | 
					
						
							|  |  |  |   character msg*22,msgsent*22
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   complex c0(0:NZ-1)
 | 
					
						
							|  |  |  |   complex c(0:NZ-1)
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |   real*8 fMHz
 | 
					
						
							|  |  |  |   integer itone(NN)
 | 
					
						
							| 
									
										
										
										
											2017-05-01 12:32:59 +00:00
										 |  |  |   integer*2 iwave(NMAX)                  !Generated full-length waveform  
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ! Get command-line argument(s)
 | 
					
						
							|  |  |  |   nargs=iargc()
 | 
					
						
							| 
									
										
										
										
											2017-05-25 16:24:57 +00:00
										 |  |  |   if(nargs.ne.8) then
 | 
					
						
							|  |  |  |      print*,'Usage:   wspr5sim "message"       f0  DT fsp del  nwav nfiles snr'
 | 
					
						
							|  |  |  |      print*,'Example: wspr5sim "K1ABC FN42 30" 50 0.0 0.1 1.0  1      10   -33'
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |      go to 999
 | 
					
						
							|  |  |  |   endif
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |   call getarg(1,msg)                     !Message to be transmitted
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   call getarg(2,arg)
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |   read(arg,*) f0                         !Freq relative to WSPR-band center (Hz)
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   call getarg(3,arg)
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |   read(arg,*) xdt                        !Time offset from nominal (s)
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   call getarg(4,arg)
 | 
					
						
							| 
									
										
										
										
											2017-05-25 16:24:57 +00:00
										 |  |  |   read(arg,*) fspread                    !Watterson frequency spread (Hz)
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   call getarg(5,arg)
 | 
					
						
							| 
									
										
										
										
											2017-05-25 16:24:57 +00:00
										 |  |  |   read(arg,*) delay                      !Watterson delay (ms)
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |   call getarg(6,arg)
 | 
					
						
							| 
									
										
										
										
											2017-05-25 16:24:57 +00:00
										 |  |  |   read(arg,*) nwav                       !1 for *.wav file, 0 for *.c5 file
 | 
					
						
							|  |  |  |   call getarg(7,arg)
 | 
					
						
							|  |  |  |   read(arg,*) nfiles                     !Number of files
 | 
					
						
							|  |  |  |   call getarg(8,arg)
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |   read(arg,*) snrdb                      !SNR_2500
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   twopi=8.0*atan(1.0)
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |   fs=12000.0/NDOWN                       !Sample rate
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   dt=1.0/fs                              !Sample interval (s)
 | 
					
						
							|  |  |  |   tt=NSPS*dt                             !Duration of "itone" symbols (s)
 | 
					
						
							|  |  |  |   ts=2*NSPS*dt                           !Duration of OQPSK symbols (s)
 | 
					
						
							|  |  |  |   baud=1.0/tt                            !Keying rate for "itone" symbols (baud)
 | 
					
						
							|  |  |  |   txt=NZ*dt                              !Transmission length (s)
 | 
					
						
							|  |  |  |   bandwidth_ratio=2500.0/(fs/2.0)
 | 
					
						
							|  |  |  |   sig=sqrt(bandwidth_ratio) * 10.0**(0.05*snrdb)
 | 
					
						
							|  |  |  |   if(snrdb.gt.90.0) sig=1.0
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |   txt=NN*NSPS0/12000.0
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-11 19:56:18 +00:00
										 |  |  |   call genwspr5(msg,msgsent,itone)       !Encode the message, get itone
 | 
					
						
							| 
									
										
										
										
											2017-06-02 13:58:32 +00:00
										 |  |  |   write(*,1000) f0,xdt,txt,snrdb,fspread,delay,nfiles,msgsent
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  | 1000 format('f0:',f9.3,'   DT:',f6.2,'   txt:',f6.1,'   SNR:',f6.1,    &
 | 
					
						
							| 
									
										
										
										
											2017-06-02 13:58:32 +00:00
										 |  |  |           '   fspread:',f6.1,'   delay:',f6.1,'  nfiles:',i3,2x,a22)
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   dphi0=twopi*(f0-0.25*baud)*dt
 | 
					
						
							|  |  |  |   dphi1=twopi*(f0+0.25*baud)*dt
 | 
					
						
							|  |  |  |   phi=0.0
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   c0=0.
 | 
					
						
							| 
									
										
										
										
											2017-04-28 12:04:05 +00:00
										 |  |  |   k=-1 + nint(xdt/dt)
 | 
					
						
							| 
									
										
										
										
											2017-05-01 12:32:59 +00:00
										 |  |  |   do j=1,NN                              !Generate OQPSK waveform from itone
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |      dphi=dphi0
 | 
					
						
							|  |  |  |      if(itone(j).eq.1) dphi=dphi1
 | 
					
						
							|  |  |  |      if(k.eq.0) phi=-dphi
 | 
					
						
							|  |  |  |      do i=1,NSPS
 | 
					
						
							|  |  |  |         k=k+1
 | 
					
						
							|  |  |  |         phi=phi+dphi
 | 
					
						
							|  |  |  |         if(phi.gt.twopi) phi=phi-twopi
 | 
					
						
							|  |  |  |         xphi=phi
 | 
					
						
							| 
									
										
										
										
											2017-04-28 12:04:05 +00:00
										 |  |  |         if(k.ge.0 .and. k.lt.NZ) c0(k)=cmplx(cos(xphi),sin(xphi))
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |      enddo
 | 
					
						
							|  |  |  |   enddo
 | 
					
						
							| 
									
										
										
										
											2017-05-25 16:24:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-02 13:58:32 +00:00
										 |  |  |   call sgran()
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   do ifile=1,nfiles
 | 
					
						
							| 
									
										
										
										
											2017-06-02 13:58:32 +00:00
										 |  |  |      c=c0
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |      if(nwav.eq.0) then
 | 
					
						
							| 
									
										
										
										
											2017-06-02 13:58:32 +00:00
										 |  |  |         if( fspread .ne. 0.0 .or. delay .ne. 0.0 ) then
 | 
					
						
							|  |  |  |            call watterson(c,NZ,fs,delay,fspread)
 | 
					
						
							|  |  |  |         endif
 | 
					
						
							|  |  |  |         c=c*sig
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |         if(snrdb.lt.90) then
 | 
					
						
							|  |  |  |            do i=0,NZ-1                   !Add gaussian noise at specified SNR
 | 
					
						
							|  |  |  |               xnoise=gran()
 | 
					
						
							|  |  |  |               ynoise=gran()
 | 
					
						
							| 
									
										
										
										
											2017-06-02 13:58:32 +00:00
										 |  |  |               c(i)=c(i) + cmplx(xnoise,ynoise)
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |            enddo
 | 
					
						
							|  |  |  |         endif
 | 
					
						
							|  |  |  |         write(fname,1100) ifile
 | 
					
						
							|  |  |  | 1100    format('000000_',i4.4,'.c5')
 | 
					
						
							|  |  |  |         open(10,file=fname,status='unknown',access='stream')
 | 
					
						
							|  |  |  |         fMHz=10.1387d0
 | 
					
						
							|  |  |  |         nmin=5
 | 
					
						
							| 
									
										
										
										
											2017-05-01 12:32:59 +00:00
										 |  |  |         write(10) fname,nmin,fMHz,c      !Save to *.c5 file
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |         close(10)
 | 
					
						
							|  |  |  |      else
 | 
					
						
							|  |  |  |         call wspr5_wav(baud,xdt,f0,itone,snrdb,iwave)
 | 
					
						
							|  |  |  |         h=default_header(12000,NMAX)
 | 
					
						
							|  |  |  |         write(fname,1102) ifile
 | 
					
						
							|  |  |  | 1102    format('000000_',i4.4,'.wav')
 | 
					
						
							|  |  |  |         open(10,file=fname,status='unknown',access='stream')
 | 
					
						
							| 
									
										
										
										
											2017-05-01 12:32:59 +00:00
										 |  |  |         write(10) h,iwave                !Save to *.wav file
 | 
					
						
							| 
									
										
										
										
											2017-04-28 16:49:09 +00:00
										 |  |  |         close(10)
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |      endif
 | 
					
						
							| 
									
										
										
										
											2017-04-28 17:46:24 +00:00
										 |  |  |      write(*,1110) ifile,xdt,f0,snrdb,fname
 | 
					
						
							|  |  |  | 1110 format(i4,f7.2,f8.2,f7.1,2x,a16)
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   enddo
 | 
					
						
							|  |  |  |        
 | 
					
						
							|  |  |  | 999 end program wspr5sim
 |