diff options
Diffstat (limited to 'lib/ft4')
| -rw-r--r-- | lib/ft4/ft4_downsample.f90 | 2 | ||||
| -rw-r--r-- | lib/ft4/ft4_testmsg.f90 | 50 | ||||
| -rw-r--r-- | lib/ft4/ft4code.f90 | 101 | ||||
| -rw-r--r-- | lib/ft4/ft4sim.f90 | 52 | ||||
| -rw-r--r-- | lib/ft4/gen_ft4wave.f90 | 2 | ||||
| -rw-r--r-- | lib/ft4/get_ft4_bitmetrics.f90 | 2 | ||||
| -rw-r--r-- | lib/ft4/getcandidates4.f90 | 166 | ||||
| -rw-r--r-- | lib/ft4/subtractft4.f90 | 2 | ||||
| -rw-r--r-- | lib/ft4/sync4d.f90 | 192 |
9 files changed, 347 insertions, 222 deletions
diff --git a/lib/ft4/ft4_downsample.f90 b/lib/ft4/ft4_downsample.f90 index bbe53a2a..a6305c83 100644 --- a/lib/ft4/ft4_downsample.f90 +++ b/lib/ft4/ft4_downsample.f90 @@ -31,7 +31,7 @@ subroutine ft4_downsample(dd,newdata,f0,c) if(newdata) then x=dd - call four2a(x,NMAX,1,-1,0) !r2c FFT to freq domain + call four2a(cx,NMAX,1,-1,0) !r2c FFT to freq domain endif i0=nint(f0/df) c1=0. diff --git a/lib/ft4/ft4_testmsg.f90 b/lib/ft4/ft4_testmsg.f90 new file mode 100644 index 00000000..0d700ead --- /dev/null +++ b/lib/ft4/ft4_testmsg.f90 @@ -0,0 +1,50 @@ + parameter (MAXTEST=75,NTEST=47) + character*37 testmsg(MAXTEST) + data testmsg(1:NTEST)/ & + "TNX BOB 73 GL", & ! 0.0 + "PA9XYZ 590003 IO91NP", & ! 0.2 + "G4ABC/P R 570007 JO22DB", & ! 0.2 + "K1ABC W9XYZ 6A WI", & ! 0.3 + "W9XYZ K1ABC R 17B EMA", & ! 0.3 + "123456789ABCDEF012", & ! 0.5 + "CQ K1ABC FN42", & ! 1. + "K1ABC W9XYZ EN37", & ! 1. + "W9XYZ K1ABC -11", & ! 1. + "K1ABC W9XYZ R-09", & ! 1. + "W9XYZ K1ABC RRR", & ! 1. + "K1ABC W9XYZ 73", & ! 1. + "K1ABC W9XYZ RR73", & ! 1. + "CQ FD K1ABC FN42", & ! 1. + "CQ TEST K1ABC/R FN42", & ! 1. + "K1ABC/R W9XYZ EN37", & ! 1. + "W9XYZ K1ABC/R R FN42", & ! 1. + "K1ABC/R W9XYZ RR73", & ! 1. + "CQ TEST K1ABC FN42", & ! 1. + "W9XYZ <PJ4/K1ABC> -11", & ! 1. + "<PJ4/K1ABC> W9XYZ R-09", & ! 1. + "CQ W9XYZ EN37", & ! 1. + "<YW18FIFA> W9XYZ -11", & ! 1. + "W9XYZ <YW18FIFA> R-09", & ! 1. + "<YW18FIFA> KA1ABC", & ! 1. + "KA1ABC <YW18FIFA> -11", & ! 1. + "<YW18FIFA> KA1ABC R-17", & ! 1. + "<YW18FIFA> KA1ABC 73", & ! 1. + "CQ G4ABC/P IO91", & ! 2. + "G4ABC/P PA9XYZ JO22", & ! 2. + "PA9XYZ G4ABC/P RR73", & ! 2. + "K1ABC W9XYZ 579 WI", & ! 3. + "W9XYZ K1ABC R 589 MA", & ! 3. + "K1ABC KA0DEF 559 MO", & ! 3. + "TU; KA0DEF K1ABC R 569 MA", & ! 3. + "KA1ABC G3AAA 529 0013", & ! 3. + "TU; G3AAA K1ABC R 559 MA", & ! 3. + "CQ KH1/KH7Z", & ! 4. + "CQ PJ4/K1ABC", & ! 4. + "PJ4/K1ABC <W9XYZ>", & ! 4. + "<W9XYZ> PJ4/K1ABC RRR", & ! 4. + "PJ4/K1ABC <W9XYZ> 73", & ! 4. + "<W9XYZ> YW18FIFA", & ! 4. + "YW18FIFA <W9XYZ> RRR", & ! 4. + "<W9XYZ> YW18FIFA 73", & ! 4. + "CQ YW18FIFA", & ! 4. + "<KA1ABC> YW18FIFA RR73"/ diff --git a/lib/ft4/ft4code.f90 b/lib/ft4/ft4code.f90 new file mode 100644 index 00000000..a7b2ccdd --- /dev/null +++ b/lib/ft4/ft4code.f90 @@ -0,0 +1,101 @@ +program ft4code + +! Provides examples of message packing, LDPC(174,91) encoding, bit and +! symbol ordering, and other details of the FT8 protocol. + + use packjt77 + include 'ft4_params.f90' !Set various constants + include 'ft4_testmsg.f90' + parameter (NWAVE=NN*NSPS) + + character*37 msg,msgsent + character*77 c77 + character*9 comment + character bad*1,msgtype*18 + integer itone(NN) + integer*1 msgbits(77),rvec(77),codeword(174) + data rvec/0,1,0,0,1,0,1,0,0,1,0,1,1,1,1,0,1,0,0,0,1,0,0,1,1,0,1,1,0, & + 1,0,0,1,0,1,1,0,0,0,0,1,0,0,0,1,0,1,0,0,1,1,1,1,0,0,1,0,1, & + 0,1,0,1,0,1,1,0,1,1,1,1,1,0,0,0,1,0,1/ + +! Get command-line argument(s) + nargs=iargc() + if(nargs.ne.1 .and. nargs.ne.3) then + print* + print*,'Program ft4code: Provides examples of message packing, ', & + 'LDPC(174,91) encoding,' + print*,'bit and symbol ordering, and other details of the FT4 protocol.' + print* + print*,'Usage: ft4code [-c grid] "message" # Results for specified message' + print*,' ft4code -t # Examples of all message types' + go to 999 + endif + + call getarg(1,msg) !Message to be transmitted + if(len(trim(msg)).eq.2 .and. msg(1:2).eq.'-t') then + nmsg=NTEST + else + call fmtmsg(msg,iz) !To upper case; collapse multiple blanks + nmsg=1 + endif + + write(*,1010) +1010 format(4x,'Message',31x,'Decoded',29x,'Err i3.n3'/100('-')) + + do imsg=1,nmsg + if(nmsg.gt.1) msg=testmsg(imsg) + +! Generate msgsent, msgbits, and itone + i3=-1 + n3=-1 + call pack77(msg,i3,n3,c77) + call genft4(msg,0,msgsent,msgbits,itone) + call encode174_91(msgbits,codeword) + msgtype="" + if(i3.eq.0) then + if(n3.eq.0) msgtype="Free text" + if(n3.eq.1) msgtype="DXpedition mode" + if(n3.eq.2) msgtype="EU VHF Contest" + if(n3.eq.3) msgtype="ARRL Field Day" + if(n3.eq.4) msgtype="ARRL Field Day" + if(n3.eq.5) msgtype="Telemetry" + if(n3.ge.6) msgtype="Undefined type" + endif + if(i3.eq.1) msgtype="Standard msg" + if(i3.eq.2) msgtype="EU VHF Contest" + if(i3.eq.3) msgtype="ARRL RTTY Roundup" + if(i3.eq.4) msgtype="Nonstandard calls" + if(i3.ge.5) msgtype="Undefined msg type" + if(i3.ge.1) n3=-1 + bad=" " + comment=' ' + if(msg.ne.msgsent) bad="*" + if(n3.ge.0) then + write(*,1020) imsg,msg,msgsent,bad,i3,n3,msgtype,comment +1020 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',i1,1x,a18,1x,a9) + else + write(*,1022) imsg,msg,msgsent,bad,i3,msgtype,comment +1022 format(i2,'.',1x,a37,1x,a37,1x,a1,2x,i1,'.',1x,1x,a18,1x,a9) + endif + enddo + + if(nmsg.eq.1) then + write(*,1030) ieor(msgbits,rvec) +1030 format(/'Source-encoded message before scrambling, 77 bits: ',/77i1) + write(*,1032) rvec +1032 format(/'Scrambling vector, 77 bits: ',/77i1) + write(*,1034) msgbits +1034 format(/'Source-encoded message after scrambling, 77 bits:'/77i1) + write(*,1036) codeword(78:91) +1036 format(/'14-bit CRC: ',/14i1) + write(*,1038) codeword(92:174) +1038 format(/'83 Parity bits: ',/83i1) + write(*,1040) 0,itone,0 +1040 format(/'Channel symbols (105 tones):'/ & + 'R Sync',13x,'Data',13x, & + ' Sync',13x,'Data',13x, & + ' Sync',13x,'Data',13x,' Sync R'/ & + i1,1x,4i1,1x,29i1,1x,4i1,1x,29i1,1x,4i1,1x,29i1,1x,4i1,i2) + endif + +999 end program ft4code diff --git a/lib/ft4/ft4sim.f90 b/lib/ft4/ft4sim.f90 index 959cf423..cef22303 100644 --- a/lib/ft4/ft4sim.f90 +++ b/lib/ft4/ft4sim.f90 @@ -5,27 +5,23 @@ program ft4sim use wavhdr use packjt77 include 'ft4_params.f90' !Set various constants - parameter (NWAVE=NN*NSPS) - parameter (NZZ=21*3456) !72576 type(hdr) h !Header for .wav file character arg*12,fname*17 character msg37*37,msgsent37*37 character c77*77 - complex c0(0:NZZ-1) - complex c(0:NZZ-1) - real wave(NZZ) - real dphi(0:NZZ-1) - real pulse(3*NSPS) + complex c0(0:NMAX-1) + complex c(0:NMAX-1) + real wave(NMAX) integer itone(NN) integer*1 msgbits(77) - integer*2 iwave(NZZ) !Generated full-length waveform + integer*2 iwave(NMAX) !Generated full-length waveform integer icos4(4) data icos4/0,1,3,2/ ! Get command-line argument(s) nargs=iargc() if(nargs.ne.7) then - print*,'Usage: ft4sim "message" f0 DT fdop del nfiles snr' + print*,'Usage: ft4sim "message" f0 DT fdop del nfiles snr' print*,'Examples: ft4sim "CQ W9XYZ EN37" 1500 0.0 0.1 1.0 10 -15' print*,' ft4sim "K1ABC W9XYZ R 539 WI" 1500 0.0 0.1 1.0 10 -15' go to 999 @@ -82,49 +78,25 @@ program ft4sim call sgran() -! The filtered frequency pulse - do i=1,3*NSPS - tt=(i-1.5*NSPS)/real(NSPS) - pulse(i)=gfsk_pulse(1.0,tt) - enddo - -! Define the instantaneous frequency waveform - dphi_peak=twopi*hmod/real(NSPS) - dphi=0.0 - do j=1,NN - ib=(j-1)*NSPS - ie=ib+3*NSPS-1 - dphi(ib:ie)=dphi(ib:ie)+dphi_peak*pulse*itone(j) - enddo - - phi=0.0 - c0=0.0 - dphi=dphi+twopi*f0*dt -! do j=0,NMAX-1 !### ??? ### - do j=0,(NN+2)*NSPS-1 - c0(j)=cmplx(cos(phi),sin(phi)) - phi=mod(phi+dphi(j),twopi) - enddo - - c0(0:NSPS-1)=c0(0:NSPS-1)*(1.0-cos(twopi*(/(i,i=0,NSPS-1)/)/(2.0*NSPS)) )/2.0 - c0((NN+1)*NSPS:(NN+2)*NSPS-1)=c0((NN+1)*NSPS:(NN+2)*NSPS-1)*(1.0+cos(twopi*(/(i,i=0,NSPS-1)/)/(2.0*NSPS) ))/2.0 - c0((NN+2)*NSPS:)=0. + fsample=12000.0 + icmplx=1 + call gen_ft4wave(itone,NN,NSPS,fsample,f0,c0,wave,icmplx,NMAX) k=nint((xdt+0.5)/dt)-NSPS c0=cshift(c0,-k) if(k.gt.0) c0(0:k-1)=0.0 - if(k.lt.0) c0(NZZ+k:NZZ-1)=0.0 + if(k.lt.0) c0(NMAX+k:NMAX-1)=0.0 do ifile=1,nfiles c=c0 - if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c,NZZ,NWAVE,fs,delay,fspread) + if(fspread.ne.0.0 .or. delay.ne.0.0) call watterson(c,NMAX,NZ,fs,delay,fspread) c=sig*c wave=real(c) peak=maxval(abs(wave)) nslots=1 if(snrdb.lt.90) then - do i=1,NZZ !Add gaussian noise at specified SNR + do i=1,NMAX !Add gaussian noise at specified SNR xnoise=gran() wave(i)=wave(i) + xnoise enddo @@ -140,7 +112,7 @@ program ft4sim endif if(any(abs(wave).gt.32767.0)) print*,"Warning - data will be clipped." iwave=nint(wave) - h=default_header(12000,NZZ) + h=default_header(12000,NMAX) write(fname,1102) ifile 1102 format('000000_',i6.6,'.wav') open(10,file=fname,status='unknown',access='stream') diff --git a/lib/ft4/gen_ft4wave.f90 b/lib/ft4/gen_ft4wave.f90 index 82399361..13018242 100644 --- a/lib/ft4/gen_ft4wave.f90 +++ b/lib/ft4/gen_ft4wave.f90 @@ -37,7 +37,7 @@ subroutine gen_ft4wave(itone,nsym,nsps,fsample,f0,cwave,wave,icmplx,nwave) wave=0. if(icmplx.eq.1) cwave=0. k=0 - do j=0,nwave-1 + do j=0,(nsym+2)*nsps-1 k=k+1 if(icmplx.eq.0) then wave(k)=sin(phi) diff --git a/lib/ft4/get_ft4_bitmetrics.f90 b/lib/ft4/get_ft4_bitmetrics.f90 index eba86a41..9c8a4ab4 100644 --- a/lib/ft4/get_ft4_bitmetrics.f90 +++ b/lib/ft4/get_ft4_bitmetrics.f90 @@ -47,6 +47,8 @@ subroutine get_ft4_bitmetrics(cd,bitmetrics,badsync) is3=0 is4=0 badsync=.false. + ibmax=0 + do k=1,4 ip=maxloc(s4(:,k)) if(icos4a(k-1).eq.(ip(1)-1)) is1=is1+1 diff --git a/lib/ft4/getcandidates4.f90 b/lib/ft4/getcandidates4.f90 index 3f62e814..8ff80642 100644 --- a/lib/ft4/getcandidates4.f90 +++ b/lib/ft4/getcandidates4.f90 @@ -1,83 +1,83 @@ -subroutine getcandidates4(dd,fa,fb,syncmin,nfqso,maxcand,savg,candidate, &
- ncand,sbase)
-
- include 'ft4_params.f90'
- real s(NH1,NHSYM)
- real savg(NH1),savsm(NH1)
- real sbase(NH1)
- real x(NFFT1)
- real window(NFFT1)
- complex cx(0:NH1)
- real candidate(2,maxcand),candidatet(2,maxcand)
- real dd(NMAX)
- equivalence (x,cx)
- logical first
- data first/.true./
- save first,window
-
- if(first) then
- first=.false.
- pi=4.0*atan(1.)
- window=0.
- call nuttal_window(window,NFFT1)
- endif
-
-! Compute symbol spectra, stepping by NSTEP steps.
- savg=0.
- df=12000.0/NFFT1
- fac=1.0/300.0
- do j=1,NHSYM
- ia=(j-1)*NSTEP + 1
- ib=ia+NFFT1-1
- if(ib.gt.NMAX) exit
- x=fac*dd(ia:ib)*window
- call four2a(x,NFFT1,1,-1,0) !r2c FFT
- s(1:NH1,j)=abs(cx(1:NH1))**2
- savg=savg + s(1:NH1,j) !Average spectrum
- enddo
- savg=savg/NHSYM
- savsm=0.
- do i=8,NH1-7
- savsm(i)=sum(savg(i-7:i+7))/15.
- enddo
-
- nfa=fa/df
- if(nfa.lt.nint(200.0/df)) nfa=nint(200.0/df)
- nfb=fb/df
- if(nfb.gt.nint(4910.0/df)) nfb=nint(4910.0/df)
- call ft4_baseline(savg,nfa,nfb,sbase)
- if(any(sbase(nfa:nfb).le.0)) return
- savsm(nfa:nfb)=savsm(nfa:nfb)/sbase(nfa:nfb)
- f_offset = -1.5*12000.0/NSPS
- ncand=0
- candidatet=0
- do i=nfa+1,nfb-1
- if(savsm(i).ge.savsm(i-1) .and. savsm(i).ge.savsm(i+1) .and. &
- savsm(i).ge.syncmin) then
- den=savsm(i-1)-2*savsm(i)+savsm(i+1)
- del=0.
- if(den.ne.0.0) del=0.5*(savsm(i-1)-savsm(i+1))/den
- fpeak=(i+del)*df+f_offset
- if(fpeak.lt.200.0 .or. fpeak.gt.4910.0) cycle
- speak=savsm(i) - 0.25*(savsm(i-1)-savsm(i+1))*del
- ncand=ncand+1
- candidatet(1,ncand)=fpeak
- candidatet(2,ncand)=speak
- if(ncand.eq.maxcand) exit
- endif
- enddo
- candidate=0
- nq=count(abs(candidatet(1,1:ncand)-nfqso).le.20.0)
- n1=1
- n2=nq+1
- do i=1,ncand
- if(abs(candidatet(1,i)-nfqso).le.20.0) then
- candidate(1:2,n1)=candidatet(1:2,i)
- n1=n1+1
- else
- candidate(1:2,n2)=candidatet(1:2,i)
- n2=n2+1
- endif
- enddo
-return
-end subroutine getcandidates4
+subroutine getcandidates4(dd,fa,fb,syncmin,nfqso,maxcand,savg,candidate, & + ncand,sbase) + + include 'ft4_params.f90' + real s(NH1,NHSYM) + real savg(NH1),savsm(NH1) + real sbase(NH1) + real x(NFFT1) + real window(NFFT1) + complex cx(0:NH1) + real candidate(2,maxcand),candidatet(2,maxcand) + real dd(NMAX) + equivalence (x,cx) + logical first + data first/.true./ + save first,window + + if(first) then + first=.false. + pi=4.0*atan(1.) + window=0. + call nuttal_window(window,NFFT1) + endif + +! Compute symbol spectra, stepping by NSTEP steps. + savg=0. + df=12000.0/NFFT1 + fac=1.0/300.0 + do j=1,NHSYM + ia=(j-1)*NSTEP + 1 + ib=ia+NFFT1-1 + if(ib.gt.NMAX) exit + x=fac*dd(ia:ib)*window + call four2a(x,NFFT1,1,-1,0) !r2c FFT + s(1:NH1,j)=abs(cx(1:NH1))**2 + savg=savg + s(1:NH1,j) !Average spectrum + enddo + savg=savg/NHSYM + savsm=0. + do i=8,NH1-7 + savsm(i)=sum(savg(i-7:i+7))/15. + enddo + + nfa=fa/df + if(nfa.lt.nint(200.0/df)) nfa=nint(200.0/df) + nfb=fb/df + if(nfb.gt.nint(4910.0/df)) nfb=nint(4910.0/df) + call ft4_baseline(savg,nfa,nfb,sbase) + if(any(sbase(nfa:nfb).le.0)) return + savsm(nfa:nfb)=savsm(nfa:nfb)/sbase(nfa:nfb) + f_offset = -1.5*12000.0/NSPS + ncand=0 + candidatet=0 + do i=nfa+1,nfb-1 + if(savsm(i).ge.savsm(i-1) .and. savsm(i).ge.savsm(i+1) .and. & + savsm(i).ge.syncmin) then + den=savsm(i-1)-2*savsm(i)+savsm(i+1) + del=0. + if(den.ne.0.0) del=0.5*(savsm(i-1)-savsm(i+1))/den + fpeak=(i+del)*df+f_offset + if(fpeak.lt.200.0 .or. fpeak.gt.4910.0) cycle + speak=savsm(i) - 0.25*(savsm(i-1)-savsm(i+1))*del + ncand=ncand+1 + candidatet(1,ncand)=fpeak + candidatet(2,ncand)=speak + if(ncand.eq.maxcand) exit + endif + enddo + candidate=0 + nq=count(abs(candidatet(1,1:ncand)-nfqso).le.20.0) + n1=1 + n2=nq+1 + do i=1,ncand + if(abs(candidatet(1,i)-nfqso).le.20.0) then + candidate(1:2,n1)=candidatet(1:2,i) + n1=n1+1 + else + candidate(1:2,n2)=candidatet(1:2,i) + n2=n2+1 + endif + enddo +return +end subroutine getcandidates4 diff --git a/lib/ft4/subtractft4.f90 b/lib/ft4/subtractft4.f90 index ae104ddb..8fb16532 100644 --- a/lib/ft4/subtractft4.f90 +++ b/lib/ft4/subtractft4.f90 @@ -16,7 +16,7 @@ subroutine subtractft4(dd,itone,f0,dt) integer itone(103) logical first data first/.true./ - common/heap8/cref(NFRAME),camp(NMAX),cfilt(NMAX),cw(NMAX),xjunk(NFRAME) + common/heap4/cref(NFRAME),camp(NMAX),cfilt(NMAX),cw(NMAX),xjunk(NFRAME) save first nstart=dt*12000+1-NSPS diff --git a/lib/ft4/sync4d.f90 b/lib/ft4/sync4d.f90 index 8d78f66a..50ae5d9f 100644 --- a/lib/ft4/sync4d.f90 +++ b/lib/ft4/sync4d.f90 @@ -1,96 +1,96 @@ -subroutine sync4d(cd0,i0,ctwk,itwk,sync)
-
-! Compute sync power for a complex, downsampled FT4 signal.
-
- include 'ft4_params.f90'
- parameter(NP=NMAX/NDOWN,NSS=NSPS/NDOWN)
- complex cd0(0:NP-1)
- complex csynca(2*NSS),csyncb(2*NSS),csyncc(2*NSS),csyncd(2*NSS)
- complex csync2(2*NSS)
- complex ctwk(2*NSS)
- complex z1,z2,z3,z4
- logical first
- integer icos4a(0:3),icos4b(0:3),icos4c(0:3),icos4d(0:3)
- data icos4a/0,1,3,2/
- data icos4b/1,0,2,3/
- data icos4c/2,3,1,0/
- data icos4d/3,2,0,1/
- data first/.true./
- save first,twopi,csynca,csyncb,csyncc,csyncd,fac
-
- p(z1)=(real(z1*fac)**2 + aimag(z1*fac)**2)**0.5 !Statement function for power
-
- if( first ) then
- twopi=8.0*atan(1.0)
- k=1
- phia=0.0
- phib=0.0
- phic=0.0
- phid=0.0
- do i=0,3
- dphia=2*twopi*icos4a(i)/real(NSS)
- dphib=2*twopi*icos4b(i)/real(NSS)
- dphic=2*twopi*icos4c(i)/real(NSS)
- dphid=2*twopi*icos4d(i)/real(NSS)
- do j=1,NSS/2
- csynca(k)=cmplx(cos(phia),sin(phia))
- csyncb(k)=cmplx(cos(phib),sin(phib))
- csyncc(k)=cmplx(cos(phic),sin(phic))
- csyncd(k)=cmplx(cos(phid),sin(phid))
- phia=mod(phia+dphia,twopi)
- phib=mod(phib+dphib,twopi)
- phic=mod(phic+dphic,twopi)
- phid=mod(phid+dphid,twopi)
- k=k+1
- enddo
- enddo
- first=.false.
- fac=1.0/(2.0*NSS)
- endif
-
- i1=i0 !four Costas arrays
- i2=i0+33*NSS
- i3=i0+66*NSS
- i4=i0+99*NSS
-
- z1=0.
- z2=0.
- z3=0.
- z4=0.
-
- if(itwk.eq.1) csync2=ctwk*csynca !Tweak the frequency
- z1=0.
- if(i1.ge.0 .and. i1+4*NSS-1.le.NP-1) then
- z1=sum(cd0(i1:i1+4*NSS-1:2)*conjg(csync2))
- elseif( i1.lt.0 ) then
- npts=(i1+4*NSS-1)/2
- if(npts.le.16) then
- z1=0.
- else
- z1=sum(cd0(0:i1+4*NSS-1:2)*conjg(csync2(2*NSS-npts:)))
- endif
- endif
-
- if(itwk.eq.1) csync2=ctwk*csyncb !Tweak the frequency
- if(i2.ge.0 .and. i2+4*NSS-1.le.NP-1) z2=sum(cd0(i2:i2+4*NSS-1:2)*conjg(csync2))
-
- if(itwk.eq.1) csync2=ctwk*csyncc !Tweak the frequency
- if(i3.ge.0 .and. i3+4*NSS-1.le.NP-1) z3=sum(cd0(i3:i3+4*NSS-1:2)*conjg(csync2))
-
- if(itwk.eq.1) csync2=ctwk*csyncd !Tweak the frequency
- z4=0.
- if(i4.ge.0 .and. i4+4*NSS-1.le.NP-1) then
- z4=sum(cd0(i4:i4+4*NSS-1:2)*conjg(csync2))
- elseif( i4+4*NSS-1.gt.NP-1 ) then
- npts=(NP-1-i4+1)/2
- if(npts.le.16) then
- z4=0.
- else
- z4=sum(cd0(i4:i4+2*npts-1:2)*conjg(csync2(1:npts)))
- endif
- endif
-
- sync = p(z1) + p(z2) + p(z3) + p(z4)
-
- return
-end subroutine sync4d
+subroutine sync4d(cd0,i0,ctwk,itwk,sync) + +! Compute sync power for a complex, downsampled FT4 signal. + + include 'ft4_params.f90' + parameter(NP=NMAX/NDOWN,NSS=NSPS/NDOWN) + complex cd0(0:NP-1) + complex csynca(2*NSS),csyncb(2*NSS),csyncc(2*NSS),csyncd(2*NSS) + complex csync2(2*NSS) + complex ctwk(2*NSS) + complex z1,z2,z3,z4 + logical first + integer icos4a(0:3),icos4b(0:3),icos4c(0:3),icos4d(0:3) + data icos4a/0,1,3,2/ + data icos4b/1,0,2,3/ + data icos4c/2,3,1,0/ + data icos4d/3,2,0,1/ + data first/.true./ + save first,twopi,csynca,csyncb,csyncc,csyncd,fac + + p(z1)=(real(z1*fac)**2 + aimag(z1*fac)**2)**0.5 !Statement function for power + + if( first ) then + twopi=8.0*atan(1.0) + k=1 + phia=0.0 + phib=0.0 + phic=0.0 + phid=0.0 + do i=0,3 + dphia=2*twopi*icos4a(i)/real(NSS) + dphib=2*twopi*icos4b(i)/real(NSS) + dphic=2*twopi*icos4c(i)/real(NSS) + dphid=2*twopi*icos4d(i)/real(NSS) + do j=1,NSS/2 + csynca(k)=cmplx(cos(phia),sin(phia)) + csyncb(k)=cmplx(cos(phib),sin(phib)) + csyncc(k)=cmplx(cos(phic),sin(phic)) + csyncd(k)=cmplx(cos(phid),sin(phid)) + phia=mod(phia+dphia,twopi) + phib=mod(phib+dphib,twopi) + phic=mod(phic+dphic,twopi) + phid=mod(phid+dphid,twopi) + k=k+1 + enddo + enddo + first=.false. + fac=1.0/(2.0*NSS) + endif + + i1=i0 !four Costas arrays + i2=i0+33*NSS + i3=i0+66*NSS + i4=i0+99*NSS + + z1=0. + z2=0. + z3=0. + z4=0. + + if(itwk.eq.1) csync2=ctwk*csynca !Tweak the frequency + z1=0. + if(i1.ge.0 .and. i1+4*NSS-1.le.NP-1) then + z1=sum(cd0(i1:i1+4*NSS-1:2)*conjg(csync2)) + elseif( i1.lt.0 ) then + npts=(i1+4*NSS-1)/2 + if(npts.le.16) then + z1=0. + else + z1=sum(cd0(0:i1+4*NSS-1:2)*conjg(csync2(2*NSS-npts:))) + endif + endif + + if(itwk.eq.1) csync2=ctwk*csyncb !Tweak the frequency + if(i2.ge.0 .and. i2+4*NSS-1.le.NP-1) z2=sum(cd0(i2:i2+4*NSS-1:2)*conjg(csync2)) + + if(itwk.eq.1) csync2=ctwk*csyncc !Tweak the frequency + if(i3.ge.0 .and. i3+4*NSS-1.le.NP-1) z3=sum(cd0(i3:i3+4*NSS-1:2)*conjg(csync2)) + + if(itwk.eq.1) csync2=ctwk*csyncd !Tweak the frequency + z4=0. + if(i4.ge.0 .and. i4+4*NSS-1.le.NP-1) then + z4=sum(cd0(i4:i4+4*NSS-1:2)*conjg(csync2)) + elseif( i4+4*NSS-1.gt.NP-1 ) then + npts=(NP-1-i4+1)/2 + if(npts.le.16) then + z4=0. + else + z4=sum(cd0(i4:i4+2*npts-1:2)*conjg(csync2(1:npts))) + endif + endif + + sync = p(z1) + p(z2) + p(z3) + p(z4) + + return +end subroutine sync4d |
