2020-03-06 12:06:44 -05:00
|
|
|
subroutine subtractft8(dd0,itone,f0,dt,lrefinedt)
|
2017-07-06 10:44:17 -04:00
|
|
|
|
2020-02-25 09:04:18 -05:00
|
|
|
! Subtract an ft8 signal
|
|
|
|
!
|
|
|
|
! Measured signal : dd(t) = a(t)cos(2*pi*f0*t+theta(t))
|
2020-02-24 16:18:42 -05:00
|
|
|
! Reference signal : cref(t) = exp( j*(2*pi*f0*t+phi(t)) )
|
|
|
|
! Complex amp : cfilt(t) = LPF[ dd(t)*CONJG(cref(t)) ]
|
2020-02-25 09:04:18 -05:00
|
|
|
! Subtract : dd(t) = dd(t) - 2*REAL{cref*cfilt}
|
|
|
|
|
2017-07-06 10:44:17 -04:00
|
|
|
parameter (NMAX=15*12000,NFRAME=1920*79)
|
2020-03-08 13:03:52 -04:00
|
|
|
parameter (NFFT=NMAX,NFILT=4000)
|
2020-02-24 16:18:42 -05:00
|
|
|
real dd(NMAX),dd0(NMAX)
|
|
|
|
real window(-NFILT/2:NFILT/2)
|
|
|
|
real x(NFFT+2)
|
2020-03-08 13:03:52 -04:00
|
|
|
real endcorrection(NFILT/2+1)
|
2020-02-25 09:04:18 -05:00
|
|
|
complex cx(0:NFFT/2)
|
|
|
|
complex cref,camp,cfilt,cw,z
|
|
|
|
integer itone(79)
|
2020-03-06 12:06:44 -05:00
|
|
|
logical first,lrefinedt,ldt
|
2017-07-06 10:44:17 -04:00
|
|
|
data first/.true./
|
2020-02-25 09:04:18 -05:00
|
|
|
common/heap8/cref(NFRAME),camp(NMAX),cfilt(NMAX),cw(NMAX)
|
2020-02-24 16:18:42 -05:00
|
|
|
equivalence (x,cx)
|
2020-03-08 13:03:52 -04:00
|
|
|
save first,/heap8/,endcorrection
|
2017-07-06 10:44:17 -04:00
|
|
|
|
2020-02-25 09:04:18 -05:00
|
|
|
if(first) then ! Create and normalize the filter
|
2017-07-06 10:44:17 -04:00
|
|
|
pi=4.0*atan(1.0)
|
|
|
|
fac=1.0/float(nfft)
|
2020-02-24 16:18:42 -05:00
|
|
|
sumw=0.0
|
2017-07-06 10:44:17 -04:00
|
|
|
do j=-NFILT/2,NFILT/2
|
|
|
|
window(j)=cos(pi*j/NFILT)**2
|
2020-02-24 16:18:42 -05:00
|
|
|
sumw=sumw+window(j)
|
2017-07-06 10:44:17 -04:00
|
|
|
enddo
|
|
|
|
cw=0.
|
2020-02-24 16:18:42 -05:00
|
|
|
cw(1:NFILT+1)=window/sumw
|
2017-07-06 10:44:17 -04:00
|
|
|
cw=cshift(cw,NFILT/2+1)
|
|
|
|
call four2a(cw,nfft,1,-1,1)
|
|
|
|
cw=cw*fac
|
|
|
|
first=.false.
|
2020-03-08 13:03:52 -04:00
|
|
|
do j=1,NFILT/2+1
|
|
|
|
endcorrection(j)=1.0/(1.0-sum(window(j-1:NFILT/2))/sumw)
|
|
|
|
enddo
|
2017-07-06 10:44:17 -04:00
|
|
|
endif
|
|
|
|
|
2020-02-26 13:14:49 -05:00
|
|
|
! Generate complex reference waveform cref
|
2020-02-25 09:04:18 -05:00
|
|
|
call gen_ft8wave(itone,79,1920,2.0,12000.0,f0,cref,xjunk,1,NFRAME)
|
|
|
|
|
2020-03-06 12:06:44 -05:00
|
|
|
ldt=lrefinedt
|
2020-02-26 13:14:49 -05:00
|
|
|
if(ldt) then !Are we refining DT ?
|
2020-03-06 12:06:44 -05:00
|
|
|
sqa=sqf(-90)
|
|
|
|
sqb=sqf(+90)
|
|
|
|
sq0=sqf(0)
|
2020-02-25 09:04:18 -05:00
|
|
|
call peakup(sqa,sq0,sqb,dx)
|
|
|
|
if(abs(dx).gt.1.0) return !No acceptable minimum: do not subtract
|
2020-03-06 14:21:04 -05:00
|
|
|
i2=nint(90.0*dx) !Best estimate of idt
|
2020-03-06 12:06:44 -05:00
|
|
|
ldt=.false.
|
2020-02-25 09:04:18 -05:00
|
|
|
sq0=sqf(i2) !Do the subtraction with idt=i2
|
2020-02-26 13:14:49 -05:00
|
|
|
else
|
|
|
|
sq0=sqf(0) !Do the subtraction with idt=0
|
2020-02-24 16:18:42 -05:00
|
|
|
endif
|
2020-02-25 09:04:18 -05:00
|
|
|
dd0=dd !Return dd0 with this signal subtracted
|
2017-07-06 10:44:17 -04:00
|
|
|
return
|
2020-02-25 09:04:18 -05:00
|
|
|
|
|
|
|
contains
|
|
|
|
|
|
|
|
real function sqf(idt) !Internal function: all variables accessible
|
|
|
|
nstart=dt*12000+1 + idt
|
|
|
|
camp=0.
|
|
|
|
dd=dd0
|
|
|
|
do i=1,nframe
|
|
|
|
j=nstart-1+i
|
|
|
|
if(j.ge.1.and.j.le.NMAX) camp(i)=dd(j)*conjg(cref(i))
|
|
|
|
enddo
|
|
|
|
|
|
|
|
cfilt(1:nframe)=camp(1:nframe)
|
|
|
|
cfilt(nframe+1:)=0.0
|
|
|
|
call four2a(cfilt,nfft,1,-1,1)
|
|
|
|
cfilt(1:nfft)=cfilt(1:nfft)*cw(1:nfft)
|
|
|
|
call four2a(cfilt,nfft,1,1,1)
|
2020-03-08 13:03:52 -04:00
|
|
|
cfilt(1:NFILT/2+1)=cfilt(1:NFILT/2+1)*endcorrection
|
|
|
|
cfilt(nframe:nframe-NFILT/2:-1)=cfilt(nframe:nframe-NFILT/2:-1)*endcorrection
|
2020-02-25 09:04:18 -05:00
|
|
|
x=0.
|
|
|
|
do i=1,nframe
|
|
|
|
j=nstart+i-1
|
|
|
|
if(j.ge.1 .and. j.le.NMAX) then
|
|
|
|
z=cfilt(i)*cref(i)
|
|
|
|
dd(j)=dd(j)-2.0*real(z) !Subtract the reconstructed signal
|
|
|
|
x(i)=dd(j)
|
|
|
|
endif
|
|
|
|
enddo
|
|
|
|
sqq=0.
|
|
|
|
if(ldt) then
|
|
|
|
call four2a(cx,NFFT,1,-1,0) !Forward FFT, r2c
|
|
|
|
df=12000.0/NFFT
|
|
|
|
ia=(f0-1.5*6.25)/df
|
|
|
|
ib=(f0+8.5*6.25)/df
|
|
|
|
do i=ia,ib
|
|
|
|
sqq=sqq + real(cx(i))*real(cx(i)) + aimag(cx(i))*aimag(cx(i))
|
|
|
|
enddo
|
|
|
|
endif
|
|
|
|
sqf=sqq
|
|
|
|
return
|
|
|
|
end function sqf
|
|
|
|
|
|
|
|
end subroutine subtractft8
|