summaryrefslogtreecommitdiff
path: root/lib/refspectrum.f90
diff options
context:
space:
mode:
authorhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
committerhibby <d@vehibberd.com>2026-10-06 21:24:40 +0100
commitc25cbdf6fb6d946175f4335fab77bfea601b56db (patch)
tree6f7a94b7b81f999e434f61b73d47e337dfd26bf2 /lib/refspectrum.f90
parent71f5689252c9f13e70e1c24856904475b2307809 (diff)
parent0685fcada9f95fe90f70b387cd7d757da8209624 (diff)
Merge tag 'debian/3.2.0_rc1+dfsg-2' into debian/trixie-backportsdebian/trixie-backports
tagging wsjtx 3.2.0~rc1+dfsg-2
Diffstat (limited to 'lib/refspectrum.f90')
-rw-r--r--lib/refspectrum.f9048
1 files changed, 40 insertions, 8 deletions
diff --git a/lib/refspectrum.f90 b/lib/refspectrum.f90
index 68b514f9..01a79ab0 100644
--- a/lib/refspectrum.f90
+++ b/lib/refspectrum.f90
@@ -1,11 +1,14 @@
-subroutine refspectrum(id2,bclear,brefspec,buseref,fname)
+subroutine refspectrum(id2,ninput,bclear,brefspec,buseref,fname)
! Input:
! id2 i*2 Raw 16-bit integer data, 12000 Hz sample rate
+! ninput Valid input count, 1..3456; zero resets stream history
! brefspec logical True when accumulating a reference spectrum
parameter (NFFT=6912,NH=NFFT/2,NPOLYLOW=400,NPOLYHIGH=2600)
integer*2 id2(NFFT)
+ integer*2 measurement(NH)
+ integer ninput,nmeasurement,offset,ncopy
logical*1 bclear,brefspec,buseref,blastuse
real xs(0:NH-1) !Saved upper half of input chunk convolved with h(t)
@@ -30,15 +33,41 @@ subroutine refspectrum(id2,bclear,brefspec,buseref,fname)
w(i)=ww*ww/NFFT
enddo
nsave=0
+ nmeasurement=0
s=0.0
filter=1.0
xs=0.
first=.false.
endif
- if(bclear) s=0.
+ if(bclear) then
+ s=0.
+ fil=1.0
+ ref=0.0
+ filter=0.0
+ cfil=0.0
+ xs=0.0
+ nsave=0
+ nmeasurement=0
+ blastuse=.false.
+ endif
+ if(ninput.lt.0.or.ninput.gt.NH) return
+ if(ninput.eq.0) then
+ xs=0.0
+ nmeasurement=0
+ if(.not.buseref) blastuse=.false.
+ return
+ endif
if(brefspec) then
- x(0:NH-1)=0.001*id2(1:NH)
+ offset=0
+ do while(offset.lt.ninput)
+ ncopy=min(NH-nmeasurement,ninput-offset)
+ measurement(nmeasurement+1:nmeasurement+ncopy)=id2(offset+1:offset+ncopy)
+ offset=offset+ncopy
+ nmeasurement=nmeasurement+ncopy
+ if(nmeasurement.lt.NH) cycle
+ nmeasurement=0
+ x(0:NH-1)=0.001*measurement
x(NH:NFFT-1)=0.0
call four2a(cx,NFFT,1,-1,0) !r2c FFT
@@ -118,6 +147,7 @@ subroutine refspectrum(id2,bclear,brefspec,buseref,fname)
enddo
close(16)
endif
+ enddo
return
endif
@@ -136,21 +166,23 @@ subroutine refspectrum(id2,bclear,brefspec,buseref,fname)
cx(1:NH)=fil(1:NH)/NFFT
call four2a(cx,NFFT,1,1,-1)
x=cshift(x,-400)
- x(800:NH)=0.0
+! Retain only the causal 800-tap response. Leaving the negative-time tail
+! near NFFT produces circular wraparound that depends on input chunk size.
+ x(800:NFFT-1)=0.0
call four2a(cx,NFFT,1,-1,0)
cfil=cx
close(16)
endif
! Use overlap and add method to apply causal reference filter.
- x(0:NH-1)=id2(1:NH)
- x(NH:NFFT-1)=0.0
+ x(0:ninput-1)=id2(1:ninput)
+ x(ninput:NFFT-1)=0.0
x=x/NFFT
call four2a(cx,NFFT,1,-1,0)
cx=cfil*cx
call four2a(cx,NFFT,1,1,-1)
x(0:NH-1)=x(0:NH-1)+xs
- xs=x(NH:NFFT-1)
- id2(1:NH)=nint(x(0:NH-1))
+ xs=x(ninput:ninput+NH-1)
+ id2(1:ninput)=nint(x(0:ninput-1))
endif
blastuse=buseref