diff options
| author | hibby <d@vehibberd.com> | 2018-02-16 15:17:14 +0000 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2018-02-16 15:17:14 +0000 |
| commit | 37f727ac0746fd85504aa46c1f023c09b3eff33a (patch) | |
| tree | c8a7ce04545040a8f161ba279528730bd9a3e6ab /lib/flat4.f90 | |
| parent | d63dd8d081a6fcd0715cd13f26df59fb831769d2 (diff) | |
New upstream version 1.8.0+repackupstream/1.8.0+repack
Diffstat (limited to 'lib/flat4.f90')
| -rw-r--r-- | lib/flat4.f90 | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/lib/flat4.f90 b/lib/flat4.f90 index fd96a3ab..faf15459 100644 --- a/lib/flat4.f90 +++ b/lib/flat4.f90 @@ -1,4 +1,4 @@ -subroutine flat4(s,npts,nflatten) +subroutine flat4(s,npts0,nflatten) ! Flatten a spectrum for optimum display ! Input: s(npts) Linear scale in power @@ -12,39 +12,42 @@ subroutine flat4(s,npts,nflatten) real*8 x(1000),y(1000),a(5) data nseg/10/,npct/10/ + npts=min(6827,npts0) if(s(1).gt.1.e29) go to 900 !Boundary between Rx intervals: do nothing do i=1,npts s(i)=10.0*log10(s(i)) !Convert to dB scale enddo - if(nflatten.eq.0) go to 900 - nlen=npts/nseg !Length of test segment - i0=npts/2 !Midpoint - k=0 - do n=2,nseg !Skip first segment, likely rolloff here - ib=n*nlen - ia=ib-nlen+1 - if(n.eq.nseg) ib=npts - call pctile(s(ia),ib-ia+1,npct,base) !Find lowest npct of points in segment - do i=ia,ib - if(s(i).le.base) then - if (k.lt.1000) k=k+1 !Save these "lower envelope" points - x(k)=i-i0 - y(k)=s(i) - endif + if(nflatten.gt.0) then + nterms=5 + if(nflatten.eq.2) nterms=1 + nlen=npts/nseg !Length of test segment + i0=npts/2 !Midpoint + k=0 + do n=1,nseg !Skip first segment, likely rolloff here + ib=n*nlen + ia=ib-nlen+1 + if(n.eq.nseg) ib=npts + call pctile(s(ia),ib-ia+1,npct,base) !Find lowest npct of points + do i=ia,ib + if(s(i).le.base) then + if (k.lt.1000) k=k+1 !Save these "lower envelope" points + x(k)=i-i0 + y(k)=s(i) + endif + enddo enddo - enddo - kz=k - a=0. - nterms=3 + kz=k + a=0. - call polfit(x,y,y,kz,nterms,0,a,chisqr) !Fit a low-order polynomial + call polyfit(x,y,y,kz,nterms,0,a,chisqr) !Fit a low-order polynomial - do i=1,npts - t=i-i0 - yfit=a(1)+t*(a(2)+t*(a(3)+t*(a(4)+t*(a(5))))) - s(i)=s(i)-yfit !Subtract the fitted baseline - enddo + do i=1,npts + t=i-i0 + yfit=a(1)+t*(a(2)+t*(a(3)+t*(a(4)+t*(a(5))))) + s(i)=s(i)-yfit !Subtract the fitted baseline + enddo + endif 900 return end subroutine flat4 |
