| 
									
										
										
										
											2018-10-25 16:39:17 -05:00
										 |  |  | subroutine watterson(c,npts,nsig,fs,delay,fspread)
 | 
					
						
							|  |  |  | !
 | 
					
						
							|  |  |  | ! npts is the total length of the simulated data vector
 | 
					
						
							|  |  |  | ! nsig is the number of points that are occupied by signal
 | 
					
						
							|  |  |  | !
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   complex c(0:npts-1)
 | 
					
						
							| 
									
										
										
										
											2017-06-22 13:47:28 +00:00
										 |  |  |   complex c2(0:npts-1)
 | 
					
						
							|  |  |  |   complex cs1(0:npts-1)
 | 
					
						
							|  |  |  |   complex cs2(0:npts-1)
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-19 16:06:42 +00:00
										 |  |  |   nonzero=0
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   df=fs/npts
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  |   if(fspread.gt.0.0) then
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |      do i=0,npts-1
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  |         xx=gran()
 | 
					
						
							|  |  |  |         yy=gran()
 | 
					
						
							| 
									
										
										
										
											2017-04-19 16:06:42 +00:00
										 |  |  |         cs1(i)=0.707*cmplx(xx,yy)
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  |         xx=gran()
 | 
					
						
							|  |  |  |         yy=gran()
 | 
					
						
							| 
									
										
										
										
											2017-04-19 16:06:42 +00:00
										 |  |  |         cs2(i)=0.707*cmplx(xx,yy)
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  |      enddo
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |      call four2a(cs1,npts,1,-1,1)     !To freq domain
 | 
					
						
							|  |  |  |      call four2a(cs2,npts,1,-1,1)
 | 
					
						
							|  |  |  |      do i=0,npts-1
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  |         f=i*df
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |         if(i.gt.npts/2) f=(i-npts)*df
 | 
					
						
							| 
									
										
										
										
											2017-04-19 16:06:42 +00:00
										 |  |  |         x=(f/(0.5*fspread))**2
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  |         a=0.
 | 
					
						
							|  |  |  |         if(x.le.50.0) then
 | 
					
						
							|  |  |  |            a=exp(-x)
 | 
					
						
							|  |  |  |         endif
 | 
					
						
							|  |  |  |         cs1(i)=a*cs1(i)
 | 
					
						
							|  |  |  |         cs2(i)=a*cs2(i)
 | 
					
						
							| 
									
										
										
										
											2017-04-19 16:06:42 +00:00
										 |  |  |         if(abs(f).lt.10.0) then
 | 
					
						
							|  |  |  |            p1=real(cs1(i))**2 + aimag(cs1(i))**2
 | 
					
						
							|  |  |  |            p2=real(cs2(i))**2 + aimag(cs2(i))**2
 | 
					
						
							|  |  |  |            if(p1.gt.0.0) nonzero=nonzero+1
 | 
					
						
							|  |  |  | !           write(62,3101) f,p1,p2,db(p1+1.e-12)-60,db(p2+1.e-12)-60
 | 
					
						
							|  |  |  | !3101       format(f10.3,2f12.3,2f10.3)
 | 
					
						
							|  |  |  |         endif
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  |      enddo
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |      call four2a(cs1,npts,1,1,1)     !Back to time domain
 | 
					
						
							|  |  |  |      call four2a(cs2,npts,1,1,1)
 | 
					
						
							|  |  |  |      cs1(0:npts-1)=cs1(0:npts-1)/npts
 | 
					
						
							|  |  |  |      cs2(0:npts-1)=cs2(0:npts-1)/npts
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  |   endif
 | 
					
						
							| 
									
										
										
										
											2017-04-20 12:55:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   nshift=nint(0.001*delay*fs)
 | 
					
						
							| 
									
										
										
										
											2019-01-13 09:25:30 -06:00
										 |  |  |   if(delay.gt.0.0) then
 | 
					
						
							| 
									
										
										
										
											2019-01-25 16:26:13 -06:00
										 |  |  |      c2(0:npts-1)=cshift(c(0:npts-1),-nshift) !negative shifts are right shifts
 | 
					
						
							| 
									
										
										
										
											2019-01-13 09:25:30 -06:00
										 |  |  |   else
 | 
					
						
							|  |  |  |      c2(0:npts-1)=0.0
 | 
					
						
							|  |  |  |   endif
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  |   sq=0.
 | 
					
						
							| 
									
										
										
										
											2017-04-27 17:43:21 +00:00
										 |  |  |   do i=0,npts-1
 | 
					
						
							| 
									
										
										
										
											2017-04-19 16:06:42 +00:00
										 |  |  |      if(nonzero.gt.1) then
 | 
					
						
							|  |  |  |         c(i)=0.5*(cs1(i)*c(i) + cs2(i)*c2(i))
 | 
					
						
							|  |  |  |      else
 | 
					
						
							|  |  |  |         c(i)=0.5*(c(i) + c2(i))
 | 
					
						
							|  |  |  |      endif
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  |      sq=sq + real(c(i))**2 + aimag(c(i))**2
 | 
					
						
							|  |  |  | !     write(61,3001) i/12000.0,c(i)
 | 
					
						
							|  |  |  | !3001 format(3f12.6)
 | 
					
						
							|  |  |  |   enddo
 | 
					
						
							| 
									
										
										
										
											2018-10-25 16:39:17 -05:00
										 |  |  |   rms=sqrt(sq/nsig) 
 | 
					
						
							| 
									
										
										
										
											2017-04-07 19:44:29 +00:00
										 |  |  |   c=c/rms
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return
 | 
					
						
							|  |  |  | end subroutine watterson
 |