2013-07-08 09:17:22 -04:00
|
|
|
subroutine downsam9(id2,npts8,nsps8,newdat,nspsd,fpk,c2,nz2)
|
2012-11-27 10:38:03 -05:00
|
|
|
|
2015-02-02 13:29:00 -05:00
|
|
|
!Downsample from id2() into c2() so as to yield nspsd samples per symbol,
|
|
|
|
!mixing from fpk down to zero frequency. The downsample factor is 432.
|
2012-11-27 10:38:03 -05:00
|
|
|
|
2015-02-01 11:23:36 -05:00
|
|
|
use, intrinsic :: iso_c_binding
|
|
|
|
use FFTW3
|
|
|
|
|
2013-07-08 09:17:22 -04:00
|
|
|
include 'constants.f90'
|
2015-02-01 11:23:36 -05:00
|
|
|
! parameter (NMAX1=1024*1920)
|
|
|
|
parameter (NMAX1=884736)
|
2015-02-02 13:29:00 -05:00
|
|
|
type(C_PTR) :: plan !Pointers plan for big FFT
|
2013-07-08 09:17:22 -04:00
|
|
|
integer*2 id2(0:8*npts8-1)
|
|
|
|
real*4 x1(0:NMAX1-1)
|
|
|
|
complex c1(0:NMAX1/2)
|
2015-02-02 13:29:00 -05:00
|
|
|
complex c2(0:1440-1)
|
2013-07-08 09:17:22 -04:00
|
|
|
real s(5000)
|
2015-02-01 11:23:36 -05:00
|
|
|
logical first
|
|
|
|
common/patience/npatience,nthreads
|
|
|
|
data first/.true./
|
|
|
|
save plan,first
|
2012-11-27 10:38:03 -05:00
|
|
|
|
2015-02-02 13:29:00 -05:00
|
|
|
nfft1=604800 !Forward FFT length
|
2013-07-08 09:17:22 -04:00
|
|
|
df1=12000.0/nfft1
|
|
|
|
npts=8*npts8
|
2013-05-14 10:29:01 -04:00
|
|
|
|
|
|
|
if(newdat.eq.1) then
|
2015-02-02 13:29:00 -05:00
|
|
|
fac=6.963e-6 !Why this weird constant?
|
2013-07-08 09:17:22 -04:00
|
|
|
do i=0,npts-1
|
|
|
|
x1(i)=fac*id2(i)
|
2012-11-27 11:48:50 -05:00
|
|
|
enddo
|
2013-07-08 09:17:22 -04:00
|
|
|
x1(npts:nfft1-1)=0. !Zero the rest of x1
|
2015-02-01 11:23:36 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
if(first) then
|
|
|
|
nflags=FFTW_ESTIMATE
|
|
|
|
if(npatience.eq.1) nflags=FFTW_ESTIMATE_PATIENT
|
|
|
|
if(npatience.eq.2) nflags=FFTW_MEASURE
|
|
|
|
if(npatience.eq.3) nflags=FFTW_PATIENT
|
|
|
|
if(npatience.eq.4) nflags=FFTW_EXHAUSTIVE
|
|
|
|
! Plan the FFTs just once
|
|
|
|
plan=fftwf_plan_dft_r2c_1d(nfft1,x1,c1,nflags)
|
|
|
|
first=.false.
|
|
|
|
endif
|
|
|
|
|
|
|
|
if(newdat.eq.1) then
|
|
|
|
fac=6.963e-6 !Why this weird constant?
|
|
|
|
do i=0,npts-1
|
|
|
|
x1(i)=fac*id2(i)
|
|
|
|
enddo
|
|
|
|
x1(npts:nfft1-1)=0. !Zero the rest of x1
|
|
|
|
call timer('FFTbig9 ',0)
|
|
|
|
call fftwf_execute_dft_r2c(plan,x1,c1)
|
|
|
|
call timer('FFTbig9 ',1)
|
2013-07-08 09:17:22 -04:00
|
|
|
|
2015-02-01 11:23:36 -05:00
|
|
|
nadd=int(1.0/df1)
|
2013-05-14 10:29:01 -04:00
|
|
|
s=0.
|
2013-07-08 09:17:22 -04:00
|
|
|
do i=1,5000
|
2015-02-01 11:23:36 -05:00
|
|
|
j=int((i-1)/df1)
|
2013-05-14 10:29:01 -04:00
|
|
|
do n=1,nadd
|
|
|
|
j=j+1
|
|
|
|
s(i)=s(i)+real(c1(j))**2 + aimag(c1(j))**2
|
|
|
|
enddo
|
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
|
2013-07-08 09:17:22 -04:00
|
|
|
ndown=8*nsps8/nspsd !Downsample factor
|
2012-11-27 10:38:03 -05:00
|
|
|
nfft2=nfft1/ndown !Backward FFT length
|
|
|
|
nh2=nfft2/2
|
2013-07-08 09:17:22 -04:00
|
|
|
nf=nint(fpk)
|
2015-02-01 11:23:36 -05:00
|
|
|
i0=int(fpk/df1)
|
2013-07-08 09:17:22 -04:00
|
|
|
|
|
|
|
nw=100
|
|
|
|
ia=max(1,nf-nw)
|
|
|
|
ib=min(5000,nf+nw)
|
|
|
|
call pctile(s(ia),ib-ia+1,40,avenoise)
|
|
|
|
|
2012-11-27 12:10:28 -05:00
|
|
|
fac=sqrt(1.0/avenoise)
|
2012-11-27 10:38:03 -05:00
|
|
|
do i=0,nfft2-1
|
|
|
|
j=i0+i
|
|
|
|
if(i.gt.nh2) j=j-nfft2
|
2012-11-27 11:48:50 -05:00
|
|
|
c2(i)=fac*c1(j)
|
2012-11-27 10:38:03 -05:00
|
|
|
enddo
|
2013-07-08 09:17:22 -04:00
|
|
|
call four2a(c2,nfft2,1,1,1) !FFT back to time domain
|
|
|
|
nz2=8*npts8/ndown
|
2012-11-27 10:38:03 -05:00
|
|
|
|
|
|
|
return
|
|
|
|
end subroutine downsam9
|