summaryrefslogtreecommitdiff
path: root/lib/ft8var/ft8_downsamplevar.f90
blob: 6e7293f40e95a6e890715989563bf5049f38c4b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
subroutine ft8_downsamplevar(residual,cxx,newdat1,f0,nqso,c0,c2,c3,lhighsens)

! Downconvert to complex data sampled at 200 Hz ==> 32 samples/symbol
  use ft8_mod1, only : windowc1,facc1
  parameter (NFFT1=192000,NFFT2=3200)      !192000/60 = 3200
  
  logical newdat1
  complex, intent(out) :: c0(-800:4000),c2(-800:4000),c3(-800:4000)
  real, intent(in) :: residual(180000)
  complex, intent(inout) :: cxx(0:96000)
  complex cx(0:96000),c1(0:3199) ! 0:NFFT1/2
  real x(NFFT1)
  real, intent(in) :: f0
  integer, intent(in) :: nqso
  logical(1), intent(in) :: lhighsens
  equivalence (x,cx)

  if(newdat1) then
! Residual has changed, recompute the long FFT
     x(1:180000)=residual
     x(180001:NFFT1)=0.                       !Zero-pad the x array
     call four2avar(cx,NFFT1,1,-1,0)             !r2c FFT to freq domain
     newdat1=.false.
     cxx=cx
  endif

  df=0.0625 ! 12000.0/NFFT1
!  tonewidth=6.25 Hz ! 12000.0/1920.
  i0=nint(f0/df)
  ft=f0+55.75; it=min(nint(ft/df),96000)
  fb=f0-5.75; ib=max(1,nint(fb/df))
  c1=cmplx(0.0,0.0)
  k=it-ib
  c1(0:k)=cxx(ib:it)
  c1(0:54)=c1(0:54)*windowc1(54:0:-1)
  c1(k-54:k)=c1(k-54:k)*windowc1
  c1=cshift(c1,i0-ib)
  if(lhighsens) then; c1(0)=c1(0)*1.93; c1(799)=c1(799)*1.7; c1(800)=c1(800)*1.7; c1(3199)=c1(3199)*1.93
  else; c1(45)=c1(45)*1.49; c1(54)=c1(54)*1.49; c1(3145)=c1(3145)*1.49; c1(3154)=c1(3154)*1.49
  endif ! 10346..10347
  call four2avar(c1,NFFT2,1,1,1)            !c2c FFT back to time domain
  c0(-800:-1)=0.; c0(0:3199)=facc1*c1(0:3199); c0(3200:4000)=0.
  if(nqso.gt.1) then
    c2(-800:-1)=0.; c2(3200:4000)=0.
    do i=0,3198; c2(i)=c0(i)+c0(i+1); enddo
    c2(3199)=c0(3199); c2=c2/2
  endif
  if(nqso.eq.3) then
    c3(-800:-1)=0.; c3(3200:4000)=0.
    do i=1,3199; c3(i)=c0(i-1)+c0(i); enddo
    c3(0)=c0(0); c3=c3/2
  endif

  return
end subroutine ft8_downsamplevar