Merged master 8748
This commit is contained in:
@@ -1,196 +0,0 @@
|
||||
program msk144sd
|
||||
!
|
||||
! A simple decoder for slow msk144.
|
||||
! Can be used as a (slow) brute-force multi-decoder by looping
|
||||
! over a set of carrier frequencies.
|
||||
!
|
||||
use options
|
||||
use timer_module, only: timer
|
||||
use timer_impl, only: init_timer
|
||||
use readwav
|
||||
|
||||
parameter (NRECENT=10)
|
||||
parameter (NSPM=864)
|
||||
parameter (NPATTERNS=4)
|
||||
|
||||
character ch
|
||||
character*80 line
|
||||
character*500 infile
|
||||
character*12 mycall,hiscall
|
||||
character*6 mygrid
|
||||
character(len=500) optarg
|
||||
character*22 msgreceived
|
||||
character*12 recent_calls(NRECENT)
|
||||
|
||||
complex cdat(30*375)
|
||||
complex c(NSPM)
|
||||
complex ct(NSPM)
|
||||
|
||||
real softbits(144)
|
||||
real xmc(NPATTERNS)
|
||||
|
||||
logical :: display_help=.false.
|
||||
|
||||
type(wav_header) :: wav
|
||||
|
||||
integer iavmask(8)
|
||||
integer iavpatterns(8,NPATTERNS)
|
||||
integer npkloc(10)
|
||||
|
||||
integer*2 id2(30*12000)
|
||||
integer*2 ichunk(7*1024)
|
||||
|
||||
data iavpatterns/ &
|
||||
1,1,1,1,0,0,0,0, &
|
||||
0,0,1,1,1,1,0,0, &
|
||||
1,1,1,1,1,0,0,0, &
|
||||
1,1,1,1,1,1,0,0/
|
||||
data xmc/2.0,4.5,2.5,3.0/
|
||||
|
||||
type (option) :: long_options(2) = [ &
|
||||
option ('frequency',.true.,'f','rxfreq',''), &
|
||||
option ('help',.false.,'h','Display this help message','') &
|
||||
]
|
||||
t0=0.0
|
||||
ntol=100
|
||||
nrxfreq=1500
|
||||
|
||||
do
|
||||
call getopt('f:h',long_options,ch,optarg,narglen,nstat,noffset,nremain,.true.)
|
||||
if( nstat .ne. 0 ) then
|
||||
exit
|
||||
end if
|
||||
select case (ch)
|
||||
case ('f')
|
||||
read (optarg(:narglen), *) nrxfreq
|
||||
case ('h')
|
||||
display_help = .true.
|
||||
end select
|
||||
end do
|
||||
|
||||
if(display_help .or. nstat.lt.0 .or. nremain.lt.1) then
|
||||
print *, ''
|
||||
print *, 'Usage: msk144sd [OPTIONS] file1 [file2 ...]'
|
||||
print *, ''
|
||||
print *, ' decode pre-recorded .WAV file(s)'
|
||||
print *, ''
|
||||
print *, 'OPTIONS:'
|
||||
do i = 1, size (long_options)
|
||||
call long_options(i) % print (6)
|
||||
end do
|
||||
go to 999
|
||||
endif
|
||||
|
||||
call init_timer ('timer.out')
|
||||
call timer('msk144 ',0)
|
||||
ndecoded=0
|
||||
do ifile=noffset+1,noffset+nremain
|
||||
call get_command_argument(ifile,optarg,narglen)
|
||||
infile=optarg(:narglen)
|
||||
call timer('read ',0)
|
||||
call wav%read (infile)
|
||||
i1=index(infile,'.wav')
|
||||
if( i1 .eq. 0 ) i1=index(infile,'.WAV')
|
||||
read(infile(i1-6:i1-1),*,err=998) nutc
|
||||
inquire(FILE=infile,SIZE=isize)
|
||||
npts=min((isize-216)/2,360000)
|
||||
read(unit=wav%lun) id2(1:npts)
|
||||
close(unit=wav%lun)
|
||||
call timer('read ',1)
|
||||
|
||||
! do if=1,89 ! brute force multi-decoder
|
||||
fo=nrxfreq
|
||||
! fo=(if-1)*25.0+300.0
|
||||
call msksddc(id2,npts,fo,cdat)
|
||||
np=npts/32
|
||||
ntol=200 ! actual ntol is ntol/32=6.25 Hz. Detection window is 12.5 Hz wide
|
||||
fc=1500.0
|
||||
call msk144spd(cdat,np,ntol,ndecodesuccess,msgreceived,fc,fest,tdec,navg,ct, &
|
||||
softbits,recent_calls,nrecent)
|
||||
nsnr=0 ! need an snr estimate
|
||||
if( ndecodesuccess .eq. 1 ) then
|
||||
fest=fo+fest-fc ! fudging because spd thinks input signal is at 1500 Hz
|
||||
goto 900
|
||||
endif
|
||||
! If short ping decoder doesn't find a decode
|
||||
npat=NPATTERNS
|
||||
do iavg=1,npat
|
||||
iavmask=iavpatterns(1:8,iavg)
|
||||
navg=sum(iavmask)
|
||||
deltaf=4.0/real(navg) ! search increment for frequency sync
|
||||
npeaks=3
|
||||
ntol=200
|
||||
fc=1500.0
|
||||
call msk144sync(cdat(1:6*NSPM),6,ntol,deltaf,iavmask,npeaks,fc, &
|
||||
fest,npkloc,nsyncsuccess,xmax,c)
|
||||
if( nsyncsuccess .eq. 0 ) cycle
|
||||
|
||||
do ipk=1,npeaks
|
||||
do is=1,3
|
||||
ic0=npkloc(ipk)
|
||||
if(is.eq.2) ic0=max(1,ic0-1)
|
||||
if(is.eq.3) ic0=min(NSPM,ic0+1)
|
||||
ct=cshift(c,ic0-1)
|
||||
call msk144decodeframe(ct,softbits,msgreceived,ndecodesuccess, &
|
||||
recent_calls,nrecent)
|
||||
if(ndecodesuccess .gt. 0) then
|
||||
tdec=tsec+xmc(iavg)*tframe
|
||||
fest=fo+(fest-fc)/32.0
|
||||
goto 900
|
||||
endif
|
||||
enddo !Slicer dither
|
||||
enddo !Peak loop
|
||||
enddo
|
||||
|
||||
! enddo
|
||||
900 continue
|
||||
if( ndecodesuccess .gt. 0 ) then
|
||||
write(*,1020) nutc,nsnr,tdec,nint(fest),' % ',msgreceived,navg
|
||||
1020 format(i6.6,i4,f5.1,i5,a3,a22,i4)
|
||||
endif
|
||||
enddo
|
||||
|
||||
call timer('msk144 ',1)
|
||||
call timer('msk144 ',101)
|
||||
go to 999
|
||||
|
||||
998 print*,'Cannot read from file:'
|
||||
print*,infile
|
||||
|
||||
999 continue
|
||||
end program msk144sd
|
||||
|
||||
subroutine msksddc(id2,npts,fc,cdat)
|
||||
|
||||
! The msk144 detector/demodulator/decoder will decode signals
|
||||
! with carrier frequency, fc, in the range fN/4 +/- 0.03333*fN.
|
||||
!
|
||||
! For slow MSK144 with nslow=32:
|
||||
! fs=12000/32=375 Hz, fN=187.5 Hz
|
||||
!
|
||||
! This routine accepts input samples with fs=12000 Hz. It
|
||||
! downconverts and decimates by 32 to center a signal with input carrier
|
||||
! frequency fc at new carrier frequency 1500/32=46.875 Hz.
|
||||
! The analytic signal is returned.
|
||||
|
||||
parameter (NFFT1=30*12000,NFFT2=30*375)
|
||||
integer*2 id2(npts)
|
||||
complex cx(0:NFFT1)
|
||||
complex cdat(30*375)
|
||||
|
||||
dt=1.0/12000.0
|
||||
df=1.0/(NFFT1*dt)
|
||||
icenter=int(fc/df+0.5)
|
||||
i46p875=int(46.875/df+0.5)
|
||||
ishift=icenter-i46p875
|
||||
cx=cmplx(0.0,0.0)
|
||||
cx(1:npts)=id2
|
||||
call four2a(cx,NFFT1,1,-1,1)
|
||||
cx=cshift(cx,ishift)
|
||||
cx(2*i46p875+1:)=cmplx(0.0,0.0)
|
||||
call four2a(cx,NFFT2,1,1,1)
|
||||
cdat(1:npts/32)=cx(0:npts/32-1)/NFFT1
|
||||
return
|
||||
|
||||
end subroutine msksddc
|
||||
|
||||
@@ -1,150 +0,0 @@
|
||||
subroutine sync8(dd,nfa,nfb,syncmin,nfqso,s,candidate,ncand,sbase)
|
||||
|
||||
include 'ft8_params.f90'
|
||||
! Search over +/- 1.5s relative to 0.5s TX start time.
|
||||
parameter (JZ=38)
|
||||
complex cx(0:NH1)
|
||||
real s(NH1,NHSYM)
|
||||
real savg(NH1)
|
||||
real sbase(NH1)
|
||||
real x(NFFT1)
|
||||
real sync2d(NH1,-JZ:JZ)
|
||||
real red(NH1)
|
||||
real candidate0(3,200)
|
||||
real candidate(3,200)
|
||||
real dd(NMAX)
|
||||
integer jpeak(NH1)
|
||||
integer indx(NH1)
|
||||
integer ii(1)
|
||||
integer icos7(0:6)
|
||||
data icos7/2,5,6,0,4,1,3/ !Costas 7x7 tone pattern
|
||||
equivalence (x,cx)
|
||||
|
||||
! Compute symbol spectra, stepping by NSTEP steps.
|
||||
savg=0.
|
||||
tstep=NSTEP/12000.0
|
||||
df=12000.0/NFFT1 !3.125 Hz
|
||||
fac=1.0/300.0
|
||||
do j=1,NHSYM
|
||||
ia=(j-1)*NSTEP + 1
|
||||
ib=ia+NSPS-1
|
||||
x(1:NSPS)=fac*dd(ia:ib)
|
||||
x(NSPS+1:)=0.
|
||||
call four2a(x,NFFT1,1,-1,0) !r2c FFT
|
||||
do i=1,NH1
|
||||
s(i,j)=real(cx(i))**2 + aimag(cx(i))**2
|
||||
enddo
|
||||
savg=savg + s(1:NH1,j) !Average spectrum
|
||||
enddo
|
||||
call baseline(savg,nfa,nfb,sbase)
|
||||
! savg=savg/NHSYM
|
||||
! do i=1,NH1
|
||||
! write(51,3051) i*df,savg(i),db(savg(i))
|
||||
!3051 format(f10.3,e12.3,f12.3)
|
||||
! enddo
|
||||
|
||||
ia=max(1,nint(nfa/df))
|
||||
ib=nint(nfb/df)
|
||||
nssy=NSPS/NSTEP ! # steps per symbol
|
||||
nfos=NFFT1/NSPS ! # frequency bin oversampling factor
|
||||
jstrt=0.5/tstep
|
||||
|
||||
do i=ia,ib
|
||||
do j=-JZ,+JZ
|
||||
ta=0.
|
||||
tb=0.
|
||||
tc=0.
|
||||
t0a=0.
|
||||
t0b=0.
|
||||
t0c=0.
|
||||
do n=0,6
|
||||
k=j+jstrt+nssy*n
|
||||
if(k.ge.1.and.k.le.NHSYM) then
|
||||
ta=ta + s(i+nfos*icos7(n),k)
|
||||
t0a=t0a + sum(s(i:i+nfos*6:nfos,k))
|
||||
endif
|
||||
tb=tb + s(i+nfos*icos7(n),k+nssy*36)
|
||||
t0b=t0b + sum(s(i:i+nfos*6:nfos,k+nssy*36))
|
||||
if(k+nssy*72.le.NHSYM) then
|
||||
tc=tc + s(i+nfos*icos7(n),k+nssy*72)
|
||||
t0c=t0c + sum(s(i:i+nfos*6:nfos,k+nssy*72))
|
||||
endif
|
||||
enddo
|
||||
t=ta+tb+tc
|
||||
t0=t0a+t0b+t0c
|
||||
t0=(t0-t)/6.0
|
||||
sync_abc=t/t0
|
||||
|
||||
t=tb+tc
|
||||
t0=t0b+t0c
|
||||
t0=(t0-t)/6.0
|
||||
sync_bc=t/t0
|
||||
sync2d(i,j)=max(sync_abc,sync_bc)
|
||||
enddo
|
||||
enddo
|
||||
|
||||
red=0.
|
||||
do i=ia,ib
|
||||
ii=maxloc(sync2d(i,-JZ:JZ)) - 1 - JZ
|
||||
j0=ii(1)
|
||||
jpeak(i)=j0
|
||||
red(i)=sync2d(i,j0)
|
||||
! write(52,3052) i*df,red(i),db(red(i))
|
||||
!3052 format(3f12.3)
|
||||
enddo
|
||||
iz=ib-ia+1
|
||||
call indexx(red(ia:ib),iz,indx)
|
||||
ibase=indx(nint(0.40*iz)) - 1 + ia
|
||||
base=red(ibase)
|
||||
red=red/base
|
||||
|
||||
candidate0=0.
|
||||
k=0
|
||||
do i=1,200
|
||||
n=ia + indx(iz+1-i) - 1
|
||||
if(red(n).lt.syncmin) exit
|
||||
if(k.lt.200) k=k+1
|
||||
candidate0(1,k)=n*df
|
||||
candidate0(2,k)=(jpeak(n)-1)*tstep
|
||||
candidate0(3,k)=red(n)
|
||||
enddo
|
||||
ncand=k
|
||||
|
||||
! Put nfqso at top of list, and save only the best of near-dupe freqs.
|
||||
do i=1,ncand
|
||||
if(abs(candidate0(1,i)-nfqso).lt.10.0) candidate0(1,i)=-candidate0(1,i)
|
||||
if(i.ge.2) then
|
||||
do j=1,i-1
|
||||
fdiff=abs(candidate0(1,i))-abs(candidate0(1,j))
|
||||
if(abs(fdiff).lt.4.0) then
|
||||
if(candidate0(3,i).ge.candidate0(3,j)) candidate0(3,j)=0.
|
||||
if(candidate0(3,i).lt.candidate0(3,j)) candidate0(3,i)=0.
|
||||
endif
|
||||
enddo
|
||||
! write(*,3001) i,candidate0(1,i-1),candidate0(1,i),candidate0(3,i-1), &
|
||||
! candidate0(3,i)
|
||||
!3001 format(i2,4f8.1)
|
||||
endif
|
||||
enddo
|
||||
|
||||
fac=20.0/maxval(s)
|
||||
s=fac*s
|
||||
|
||||
! Sort by sync
|
||||
! call indexx(candidate0(3,1:ncand),ncand,indx)
|
||||
! Sort by frequency
|
||||
call indexx(candidate0(1,1:ncand),ncand,indx)
|
||||
k=1
|
||||
! do i=ncand,1,-1
|
||||
do i=1,ncand
|
||||
j=indx(i)
|
||||
if( candidate0(3,j) .ge. syncmin .and. candidate0(2,j).ge.-1.5 ) then
|
||||
candidate(1,k)=abs(candidate0(1,j))
|
||||
candidate(2,k)=candidate0(2,j)
|
||||
candidate(3,k)=candidate0(3,j)
|
||||
k=k+1
|
||||
endif
|
||||
enddo
|
||||
ncand=k-1
|
||||
return
|
||||
end subroutine sync8
|
||||
@@ -1,186 +0,0 @@
|
||||
White Paper: FT8 for DXpeditions
|
||||
-----------------------------------
|
||||
Joe Taylor, K1JT - October 27, 2017
|
||||
|
||||
Assumptions:
|
||||
|
||||
1. WSJT-X will have two distinct options that enable the maximum-rate
|
||||
QSO exchanges described below. Fox must select "Fox"; all Hounds must
|
||||
select "Hound".
|
||||
|
||||
2. There will be an announced basic dial frequency for each band, say
|
||||
f0=14082 kHz for 20m. This is the basic Channel.
|
||||
|
||||
3. Fox always transmits in the 1st sequence, 200-800 Hz above f0.
|
||||
|
||||
4. Hounds call in 2nd sequence, 1000-5000 Hz above f0. Hounds
|
||||
transmitting below f0+1000 Hz will not be answered.
|
||||
|
||||
5. If found necessary, additional Channels may be defined in which
|
||||
Hounds can transmit. (However, I suggest that CQ-by-call-area may
|
||||
be easier to implement and use; and the software could be made to
|
||||
prevent Hounds in the wrong area from transmitting.)
|
||||
|
||||
6. Ideally, Fox and Hounds should all use CAT control configured with
|
||||
*Split Operation* set to *Rig* or *Fake It*, and transceiver dial
|
||||
frequencies should best be calibrated to within a few Hz. (WSJT-X
|
||||
provides tools that make this fairly easy to do.)
|
||||
|
||||
|
||||
When Fox is running a pileup, QSOs will look something like the
|
||||
following exchanges. Here I've assumed the Fox callsign is KH1DX,
|
||||
his locator AJ10:
|
||||
|
||||
------------------------------------------------------------------------
|
||||
Fox Hounds
|
||||
------------------------------------------------------------------------
|
||||
1. CQ KH1DX AJ10
|
||||
2. KH1DX K1ABC FN42, KH1DX W9XYZ EN37, ...
|
||||
3. K1ABC KH1DX -13
|
||||
4. KH1DX K1ABC R-11
|
||||
5. K1ABC R 73; W9XYZ <KH1DX> -17
|
||||
6. ... no copy from W9XYZ ...
|
||||
7. W9XYZ KH1DX -17
|
||||
8. ... no copy from W9XYZ ...
|
||||
9. G4AAA KH1DX -11
|
||||
10. KH1DX G4AAA R-03
|
||||
11. G4AAA R 73; DL3BBB <KH1DX> -12
|
||||
12. KH1DX DL3BBB R-09
|
||||
13. DL3BBB R 73; DE <KH1DX>
|
||||
14. ...
|
||||
------------------------------------------------------------------------
|
||||
|
||||
All messages except those containing "<...>" are standard FT8 messages
|
||||
(i3bit=0, iFreeText=0). Hounds transmit only standard messages.
|
||||
|
||||
Fox transmits standard messages and also special messages with
|
||||
i3bit=1. The special messages contain a callsign whose completed QSO
|
||||
is being acknowledged; a callsign for the next station to be worked; a
|
||||
hash code corresponding to the Fox callsign; and a signal report.
|
||||
Users will see the Fox callsign enclosed in angle brackets, <KH1DX>.
|
||||
The 72-bit message payload contains two 28-bit callsigns, a 10-bit
|
||||
hash code, and a 6-bit signal report. If no call has been queued up
|
||||
by Fox for the next QSO, the acknowledgment message takes the
|
||||
abbreviated form shown in line 13 above.
|
||||
|
||||
When a Hound receives a message with i3bit=1, the decoder interprets
|
||||
the remaining 72 bits as described above. If the 10-bit hash code
|
||||
matches that for Fox's callsign, the message is displayed as in the
|
||||
QSO exchanges shown above. Otherwise the message is considered a
|
||||
false decode and is not displayed.
|
||||
|
||||
|
||||
Station Setup and Operation for FOX
|
||||
-----------------------------------
|
||||
|
||||
A wide Rx bandwidth (up to 5 kHz) is selected. The basic dial
|
||||
frequency is set 1 kHz above f0 (thus 14083 kHz in my example) and the
|
||||
audio TxFreq somewhere between -200 and -800 Hz. (Yes, negative
|
||||
numbers are OK. *Split Operation* will reset the Tx dial frequency as
|
||||
needed and will keep the generated Tx audio frequency between 1500 and
|
||||
2000 Hz.) Hounds with audio TxFreq set to N Hz will be received by Fox
|
||||
at N-1000 Hz.
|
||||
|
||||
WSJT-X at Fox will maintain and display a list of all decoded Hounds
|
||||
calling Fox in the past 2 to 4 Rx cycles. The list might look
|
||||
something like this (but typically will be much longer):
|
||||
|
||||
----------------------------
|
||||
Call Grid Rpt Freq
|
||||
----------------------------
|
||||
AA2UK FM29 -11 240
|
||||
AD9H EN61 +02 1260
|
||||
K0TPP EM48 -15 1980
|
||||
N2BJ EN61 +11 540
|
||||
N4NDR EL98 -17 4620
|
||||
NX4E EM70 +00 3780
|
||||
ON3LA JN29 -10 3300
|
||||
PD9BG JO21 -21 2100
|
||||
PJ4/KA1XYZ FK60 -07 1020
|
||||
VE1SKY FN74 +03 1620
|
||||
WB2REM EL97 -13 3060
|
||||
...
|
||||
----------------------------
|
||||
|
||||
Fox can choose to have the list sorted on any column.
|
||||
|
||||
Fox selects a Hound to call next by clicking on a line. Or he can hit
|
||||
"F1" to have the program select a caller according to one of these
|
||||
criteria (maybe others as well?):
|
||||
|
||||
- Weakest caller
|
||||
- Strongest caller
|
||||
- Strongest one below -N dB (with N selectable)
|
||||
- Choose a call at random
|
||||
- Random choice with S/N between snrMin and snrMax dB.
|
||||
|
||||
After a particular Hound has been called, Fox's Auto-Sequencer looks
|
||||
for a response containing "R+rpt" originating from that same callsign.
|
||||
If such a message is received, Fox's next transmission will be the
|
||||
special "acknowledge-and-call-next" type, with i3bit=1. If the
|
||||
expected message is not received, as in example line 6 above, the
|
||||
report is sent to the same station again. If the second attempt fails
|
||||
and another Hound callsign has been queued up, the QSO is aborted and
|
||||
the next Hound is called.
|
||||
|
||||
|
||||
Station Setup and Operation for Hounds
|
||||
--------------------------------------
|
||||
|
||||
Dial frequency is set to f0, 14082 kHz in my example. Rx bandwidth and
|
||||
displayed range on the Wide Graph can be anything convenient, say 200
|
||||
to 2600 Hz. (Signal from Fox will be expected between 200 and 800
|
||||
Hz.) Enter callsign and locator of Fox on WSJT-X main window as *DX
|
||||
Call* and *DX Grid*. Choose a TxFreq offset of 1000 + 60*N for some N
|
||||
in the range 1 to 80 (maybe even higher?). Move TxFreq as desired,
|
||||
hoping to find a clear slot, by using Shift+F11 and Shift+F12.
|
||||
|
||||
- Hit F1 to call Fox in your next Tx sequence. Yes, you must hit F1
|
||||
repeatedly, in order to keep calling.
|
||||
|
||||
- The Auto-sequencer will watch for a decoded message that contains
|
||||
"MyCall DXcall rpt" or "MyCall <DXcall> rpt". When one of these is
|
||||
received, your next transmission will be "DXcall MyCall R+rpt",
|
||||
sent automatically.
|
||||
|
||||
- After you send the "R+rpt" message, AutoSeq will watch for a
|
||||
message that starts with "MyCall R 73; ...". When that is
|
||||
received, you're in his log, and you'll be prompted to log the QSO.
|
||||
|
||||
Random thoughts
|
||||
---------------
|
||||
|
||||
Fox's decoder has access to signals in a 4 kHz (maybe even 5 kHz?)
|
||||
window. At 60 Hz intervals, that's enough for around 65 (or 80?)
|
||||
non-overlapping Hound signals. If the pileup becomes too deep, more
|
||||
spectrum might be used; but note that WSJT-X can't access more than 5
|
||||
kHz at one time. A better solution might be for Fox to call "CQ n
|
||||
KH1DX AJ10", where n is a single digit indicating call area. The
|
||||
decoder could then limit the list of eligible calls to those in the
|
||||
specified call area. After decoding such a CQ, the software at Hound
|
||||
could refuse to transmit unless MyCall falls in the specified call
|
||||
area. (Other special CQ formats can be imagined that would limit the
|
||||
eligible Hound callsigns even further.)
|
||||
|
||||
We haven't thought much, yet, about logging issues for Fox. I imagine
|
||||
we could do what's necessary to join a N1MM+ logging network, if that's
|
||||
deemed desirable.
|
||||
|
||||
A few questions:
|
||||
|
||||
Q1: Should the Auto-Sequencer allow for other cases in which a QSO has
|
||||
been initiated by Fox, but one of next two messages is not copied by
|
||||
either Fox or Hound? For example, what if K1ABC does not copy message
|
||||
#5? Should he keep sending his message "KH1DX K1ABC R-11" ? If Fox
|
||||
receives this message again, should he acknowledge again? And poor
|
||||
W9XYZ, who never received an acknowledgment, will probably keep
|
||||
sending "KH1DX W9XYZ R-19", or whatever. If Fox eventually copies the
|
||||
message, should the program remember that W9XYZ had been called, and
|
||||
thus send him an acknowledgment?
|
||||
|
||||
Q2: Should we provide a stack for several to-be-called callsigns,
|
||||
rather than just one? Should re-ordering of calls in the stack be
|
||||
permitted?
|
||||
|
||||
Q3: Can we handle WSJT-X "Type 1" and "Type 2" compound callsigns, for
|
||||
Hounds?
|
||||
@@ -1,304 +0,0 @@
|
||||
subroutine syncmsk(cdat,npts,jpk,ipk,idf,rmax,snr,metric,decoded)
|
||||
|
||||
! Attempt synchronization, and if successful decode using Viterbi algorithm.
|
||||
|
||||
use iso_c_binding, only: c_loc,c_size_t
|
||||
use packjt
|
||||
use hashing
|
||||
use timer_module, only: timer
|
||||
|
||||
parameter (NSPM=1404,NSAVE=2000)
|
||||
complex cdat(npts) !Analytic signal
|
||||
complex cb(66) !Complex waveform for Barker-11 code
|
||||
complex cd(0:11,0:3)
|
||||
complex c(0:NSPM-1) !Complex data for one message length
|
||||
complex c2(0:NSPM-1)
|
||||
complex cb3(1:NSPM,3)
|
||||
real r(12000)
|
||||
real rdat(12000)
|
||||
real ss1(12000)
|
||||
real symbol(234)
|
||||
real rdata(198)
|
||||
real rd2(198)
|
||||
real rsave(NSAVE)
|
||||
real xp(29)
|
||||
complex z,z0,z1,z2,z3,cfac
|
||||
integer*1 e1(198)
|
||||
integer*1, target :: d8(13)
|
||||
integer*1 i1hash(4)
|
||||
integer*1 i1
|
||||
integer*4 i4Msg6BitWords(12) !72-bit message as 6-bit words
|
||||
integer mettab(0:255,0:1) !Metric table for BPSK modulation
|
||||
integer ipksave(NSAVE)
|
||||
integer jpksave(NSAVE)
|
||||
integer indx(NSAVE)
|
||||
integer b11(11) !Barker-11 code
|
||||
character*22 decoded
|
||||
character*72 c72
|
||||
logical first
|
||||
equivalence (i1,i4)
|
||||
equivalence (ihash,i1hash)
|
||||
data xp/0.500000, 0.401241, 0.309897, 0.231832, 0.168095, &
|
||||
0.119704, 0.083523, 0.057387, 0.039215, 0.026890, &
|
||||
0.018084, 0.012184, 0.008196, 0.005475, 0.003808, &
|
||||
0.002481, 0.001710, 0.001052, 0.000789, 0.000469, &
|
||||
0.000329, 0.000225, 0.000187, 0.000086, 0.000063, &
|
||||
0.000017, 0.000091, 0.000032, 0.000045/
|
||||
data first/.true./
|
||||
data b11/1,1,1,0,0,0,1,0,0,1,0/
|
||||
save first,cb,cd,twopi,dt,f0,f1,mettab
|
||||
|
||||
phi=0.
|
||||
if(first) then
|
||||
! Get the metric table
|
||||
bias=0.0
|
||||
scale=20.0
|
||||
xln2=log(2.0)
|
||||
mettab=0
|
||||
do i=128,156
|
||||
x0=log(max(0.001,2.0*xp(i-127)))/xln2
|
||||
x1=log(max(0.001,2.0*(1.0-xp(i-127))))/xln2
|
||||
mettab(i,0)=nint(scale*(x0-bias))
|
||||
mettab(i,1)=nint(scale*(x1-bias))
|
||||
mettab(256-i,0)=mettab(i,1)
|
||||
mettab(256-i,1)=mettab(i,0)
|
||||
enddo
|
||||
do i=157,255
|
||||
mettab(i,0)=mettab(156,0)
|
||||
mettab(i,1)=mettab(156,1)
|
||||
mettab(256-i,0)=mettab(i,1)
|
||||
mettab(256-i,1)=mettab(i,0)
|
||||
enddo
|
||||
j=0
|
||||
twopi=8.0*atan(1.0)
|
||||
dt=1.0/12000.0
|
||||
f0=1000.0
|
||||
f1=2000.0
|
||||
dphi=0
|
||||
do i=1,11
|
||||
if(b11(i).eq.0) dphi=twopi*f0*dt
|
||||
if(b11(i).eq.1) dphi=twopi*f1*dt
|
||||
do n=1,6
|
||||
j=j+1
|
||||
phi=phi+dphi
|
||||
cb(j)=cmplx(cos(phi),sin(phi))
|
||||
enddo
|
||||
enddo
|
||||
cb3=0.
|
||||
cb3(1:66,1)=cb
|
||||
cb3(283:348,1)=cb
|
||||
cb3(769:834,1)=cb
|
||||
|
||||
cb3(1:66,2)=cb
|
||||
cb3(487:552,2)=cb
|
||||
cb3(1123:1188,2)=cb
|
||||
|
||||
cb3(1:66,3)=cb
|
||||
cb3(637:702,3)=cb
|
||||
cb3(919:984,3)=cb
|
||||
|
||||
phi=0.
|
||||
do n=0,3
|
||||
k=-1
|
||||
dphi=twopi*f0*dt
|
||||
if(n.ge.2) dphi=twopi*f1*dt
|
||||
do i=0,5
|
||||
k=k+1
|
||||
phi=phi+dphi
|
||||
if(phi.gt.twopi) phi=phi-twopi
|
||||
cd(k,n)=cmplx(cos(phi),sin(phi))
|
||||
enddo
|
||||
|
||||
dphi=twopi*f0*dt
|
||||
if(mod(n,2).eq.1) dphi=twopi*f1*dt
|
||||
do i=6,11
|
||||
k=k+1
|
||||
phi=phi+dphi
|
||||
if(phi.gt.twopi) phi=phi-twopi
|
||||
cd(k,n)=cmplx(cos(phi),sin(phi))
|
||||
enddo
|
||||
enddo
|
||||
|
||||
first=.false.
|
||||
endif
|
||||
|
||||
nfft=NSPM
|
||||
jz=npts-nfft
|
||||
decoded=" "
|
||||
ipk=0
|
||||
jpk=0
|
||||
metric=-9999
|
||||
r=0.
|
||||
|
||||
call timer('sync1 ',0)
|
||||
do j=1,jz !Find the Barker-11 sync vectors
|
||||
z=0.
|
||||
ss=0.
|
||||
do i=1,66
|
||||
ss=ss + real(cdat(j+i-1))**2 + aimag(cdat(j+i-1))**2
|
||||
z=z + cdat(j+i-1)*conjg(cb(i)) !Signal matching Barker 11
|
||||
enddo
|
||||
ss=sqrt(ss/66.0)*66.0
|
||||
r(j)=abs(z)/(0.908*ss) !Goodness-of-fit to Barker 11
|
||||
ss1(j)=ss
|
||||
enddo
|
||||
call timer('sync1 ',1)
|
||||
|
||||
call timer('sync2 ',0)
|
||||
jz=npts-nfft
|
||||
rmax=0.
|
||||
! n1=35, n2=69, n3=94
|
||||
k=0
|
||||
do j=1,jz !Find best full-message sync
|
||||
if(ss1(j).lt.85.0) cycle
|
||||
r1=r(j) + r(j+282) + r(j+768) ! 6*(12+n1) 6*(24+n1+n2)
|
||||
r2=r(j) + r(j+486) + r(j+1122) ! 6*(12+n2) 6*(24+n2+n3)
|
||||
r3=r(j) + r(j+636) + r(j+918) ! 6*(12+n3) 6*(24+n3+n1)
|
||||
if(r1.gt.rmax) then
|
||||
rmax=r1
|
||||
jpk=j
|
||||
ipk=1
|
||||
endif
|
||||
if(r2.gt.rmax) then
|
||||
rmax=r2
|
||||
jpk=j
|
||||
ipk=2
|
||||
endif
|
||||
if(r3.gt.rmax) then
|
||||
rmax=r3
|
||||
jpk=j
|
||||
ipk=3
|
||||
endif
|
||||
rrmax=max(r1,r2,r3)
|
||||
if(rrmax.gt.1.9) then
|
||||
k=min(k+1,NSAVE)
|
||||
if(r1.eq.rrmax) ipksave(k)=1
|
||||
if(r2.eq.rrmax) ipksave(k)=2
|
||||
if(r3.eq.rrmax) ipksave(k)=3
|
||||
jpksave(k)=j
|
||||
rsave(k)=rrmax
|
||||
endif
|
||||
enddo
|
||||
call timer('sync2 ',1)
|
||||
kmax=k
|
||||
|
||||
call indexx(rsave,kmax,indx)
|
||||
|
||||
call timer('sync3 ',0)
|
||||
do kk=1,kmax
|
||||
k=indx(kmax+1-kk)
|
||||
ipk=ipksave(k)
|
||||
jpk=jpksave(k)
|
||||
rmax=rsave(k)
|
||||
|
||||
c=conjg(cb3(1:NSPM,ipk))*cdat(jpk:jpk+nfft-1)
|
||||
smax=0.
|
||||
dfx=0.
|
||||
idfbest=0
|
||||
do itry=1,25
|
||||
idf=itry/2
|
||||
if(mod(itry,2).eq.0) idf=-idf
|
||||
idf=4*idf
|
||||
twk=idf
|
||||
call tweak1(c,NSPM,-twk,c2)
|
||||
z=sum(c2)
|
||||
if(abs(z).gt.smax) then
|
||||
dfx=twk
|
||||
smax=abs(z)
|
||||
phi=atan2(aimag(z),real(z)) !Carrier phase offset
|
||||
idfbest=idf
|
||||
endif
|
||||
enddo
|
||||
idf=idfbest
|
||||
call tweak1(cdat,npts,-dfx,cdat)
|
||||
cfac=cmplx(cos(phi),-sin(phi))
|
||||
cdat=cfac*cdat
|
||||
|
||||
sig=0.
|
||||
ref=0.
|
||||
rdat(1:npts)=cdat
|
||||
iz=11
|
||||
do k=1,234 !Compute soft symbols
|
||||
j=jpk+6*(k-1)
|
||||
|
||||
z0=2.0*dot_product(cdat(j:j+iz),cd(0:iz,0))
|
||||
z1=2.0*dot_product(cdat(j:j+iz),cd(0:iz,1))
|
||||
z2=2.0*dot_product(cdat(j:j+iz),cd(0:iz,2))
|
||||
z3=2.0*dot_product(cdat(j:j+iz),cd(0:iz,3))
|
||||
|
||||
!### Maybe these should be weighted by yellow() ?
|
||||
if(j+1404+iz.lt.npts) then
|
||||
z0=z0 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,0))
|
||||
z1=z1 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,1))
|
||||
z2=z2 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,2))
|
||||
z3=z3 + dot_product(cdat(j+1404:j+1404+iz),cd(0:iz,3))
|
||||
endif
|
||||
|
||||
if(j-1404.ge.1) then
|
||||
z0=z0 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,0))
|
||||
z1=z1 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,1))
|
||||
z2=z2 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,2))
|
||||
z3=z3 + dot_product(cdat(j-1404:j-1404+iz),cd(0:iz,3))
|
||||
endif
|
||||
|
||||
sym=max(abs(real(z2)),abs(real(z3))) - max(abs(real(z0)),abs(real(z1)))
|
||||
|
||||
if(sym.lt.0.0) then
|
||||
phi=atan2(aimag(z0),real(z0))
|
||||
sig=sig + real(z0)**2
|
||||
ref=ref + aimag(z0)**2
|
||||
else
|
||||
phi=atan2(aimag(z1),real(z1))
|
||||
sig=sig + real(z1)**2
|
||||
ref=ref + aimag(z1)**2
|
||||
endif
|
||||
n=k
|
||||
if(ipk.eq.2) n=k+47
|
||||
if(ipk.eq.3) n=k+128
|
||||
if(n.gt.234) n=n-234
|
||||
ibit=0
|
||||
if(sym.ge.0) ibit=1
|
||||
symbol(n)=sym
|
||||
enddo
|
||||
snr=db(sig/ref-1.0)
|
||||
|
||||
rdata(1:35)=symbol(12:46)
|
||||
rdata(36:104)=symbol(59:127)
|
||||
rdata(105:198)=symbol(140:233)
|
||||
|
||||
! Re-order the symbols and make them i*1
|
||||
j=0
|
||||
do i=1,99
|
||||
i4=128+rdata(i) !### Should be nint() ??? ###
|
||||
if(i4.gt.255) i4=255
|
||||
if(i4.lt.0) i4=0
|
||||
j=j+1
|
||||
e1(j)=i1
|
||||
rd2(j)=rdata(i)
|
||||
i4=128+rdata(i+99)
|
||||
if(i4.gt.255) i4=255
|
||||
if(i4.lt.0) i4=0
|
||||
j=j+1
|
||||
e1(j)=i1
|
||||
rd2(j)=rdata(i+99)
|
||||
enddo
|
||||
|
||||
! Decode the message
|
||||
nb1=87
|
||||
call vit213(e1,nb1,mettab,d8,metric)
|
||||
ihash=nhash(c_loc(d8),int(9,c_size_t),146)
|
||||
ihash=2*iand(ihash,32767)
|
||||
decoded=' '
|
||||
if(d8(10).eq.i1hash(2) .and. d8(11).eq.i1hash(1)) then
|
||||
write(c72,1012) d8(1:9)
|
||||
1012 format(9b8.8)
|
||||
read(c72,1014) i4Msg6BitWords
|
||||
1014 format(12b6.6)
|
||||
call unpackmsg(i4Msg6BitWords,decoded) !Unpack to get msgsent
|
||||
endif
|
||||
if(decoded.ne.' ') exit
|
||||
enddo
|
||||
call timer('sync3 ',1)
|
||||
|
||||
return
|
||||
end subroutine syncmsk
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef BOOST_THREAD_SHARED_MUTEX_HPP
|
||||
#define BOOST_THREAD_SHARED_MUTEX_HPP
|
||||
|
||||
// shared_mutex.hpp
|
||||
//
|
||||
// (C) Copyright 2007 Anthony Williams
|
||||
// (C) Copyright 2011-2012 Vicente J. Botet Escriba
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/thread/detail/config.hpp>
|
||||
#if defined(BOOST_THREAD_PLATFORM_WIN32)
|
||||
#if defined(BOOST_THREAD_PROVIDES_GENERIC_SHARED_MUTEX_ON_WIN)
|
||||
#include <boost/thread/pthread/shared_mutex.hpp>
|
||||
#else
|
||||
#include <boost/thread/win32/shared_mutex.hpp>
|
||||
#endif
|
||||
#elif defined(BOOST_THREAD_PLATFORM_PTHREAD)
|
||||
//#include <boost/thread/v2/shared_mutex.hpp>
|
||||
#include <boost/thread/pthread/shared_mutex.hpp>
|
||||
#else
|
||||
#error "Boost threads unavailable on this platform"
|
||||
#endif
|
||||
|
||||
#include <boost/thread/lockable_traits.hpp>
|
||||
|
||||
namespace boost
|
||||
{
|
||||
typedef shared_mutex shared_timed_mutex;
|
||||
namespace sync
|
||||
{
|
||||
#ifdef BOOST_THREAD_NO_AUTO_DETECT_MUTEX_TYPES
|
||||
template<>
|
||||
struct is_basic_lockable<shared_mutex>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
template<>
|
||||
struct is_lockable<shared_mutex>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
File name: wsprsim.c (first committed to wsjtx June 13, 2015)
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "wsprsim_utils.h"
|
||||
#include "wsprd_utils.h"
|
||||
#include "fano.h"
|
||||
|
||||
int printdata=0;
|
||||
|
||||
void usage() {
|
||||
printf("Usage: wsprsim [options] message\n");
|
||||
printf(" message format: \"K1ABC FN42 33\"\n");
|
||||
printf(" \"PJ4/K1ABC 33\"\n");
|
||||
printf(" \"<PJ4/K1ABC> FK52UD 33\"\n");
|
||||
printf("Options:\n");
|
||||
printf(" -c (print channel symbols)\n");
|
||||
printf(" -d (print packed data with zero tail - 11 bytes)\n");
|
||||
printf(" -f x (-100 Hz < f < 100 Hz)\n");
|
||||
printf(" -o filename (write a c2 file with this name)\n");
|
||||
printf(" -s x (x is snr of signal that is written to .c2 file)\n");
|
||||
printf("\n");
|
||||
printf(" e.g. ./wsprsim -cds -28 -o 150613_1920.c2 \"K1ABC FN42 33\"\n");
|
||||
printf(" then ./wsprd 150613_1920.c2\n");
|
||||
}
|
||||
|
||||
int add_signal_vector(float f0, float t0, float amp, unsigned char* symbols
|
||||
, double* isig, double* qsig)
|
||||
{
|
||||
int i, j, ii, idelay;
|
||||
double phi=0.0, twopidt, df, dt, dphi;
|
||||
twopidt=8.0*atan(1.0)/375.0;
|
||||
df=375.0/256.0;
|
||||
dt=1/375.0;
|
||||
idelay=t0/dt;
|
||||
|
||||
for (i=0; i<162; i++) {
|
||||
dphi=twopidt*(f0 + ( (double)symbols[i]-1.5)*df );
|
||||
for ( j=0; j<256; j++ ) {
|
||||
ii=idelay+256*i+j;
|
||||
isig[ii]=isig[ii]+amp*cos(phi);
|
||||
qsig[ii]=qsig[ii]+amp*sin(phi);
|
||||
phi=phi+dphi;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
char* tobinary(int x)
|
||||
{
|
||||
static char b[33];
|
||||
b[0] = '\0';
|
||||
|
||||
long unsigned int z;
|
||||
for (z = 0x80000000; z > 0; z >>= 1)
|
||||
{
|
||||
strcat(b, ((x & z) == z) ? "1" : "0");
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
double gaussrand()
|
||||
{
|
||||
static double V1, V2, S;
|
||||
static int phase = 0;
|
||||
double X;
|
||||
|
||||
if(phase == 0) {
|
||||
do {
|
||||
double U1 = (double)rand() / RAND_MAX;
|
||||
double U2 = (double)rand() / RAND_MAX;
|
||||
|
||||
V1 = 2 * U1 - 1;
|
||||
V2 = 2 * U2 - 1;
|
||||
S = V1 * V1 + V2 * V2;
|
||||
} while(S >= 1 || S == 0);
|
||||
|
||||
X = V1 * sqrt(-2 * log(S) / S);
|
||||
} else
|
||||
X = V2 * sqrt(-2 * log(S) / S);
|
||||
|
||||
phase = 1 - phase;
|
||||
|
||||
return X;
|
||||
}
|
||||
|
||||
unsigned long writec2file(char *c2filename, int trmin, double freq
|
||||
, double *idat, double *qdat)
|
||||
{
|
||||
int i;
|
||||
float buffer[2*45000];
|
||||
memset(buffer,0,sizeof(float)*2*45000);
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen(c2filename,"wb");
|
||||
if( fp == NULL ) {
|
||||
fprintf(stderr, "Could not open c2 file '%s'\n", c2filename);
|
||||
return 0;
|
||||
}
|
||||
unsigned long nwrite = fwrite(c2filename,sizeof(char),14,fp);
|
||||
nwrite = fwrite(&trmin, sizeof(int), 1, fp);
|
||||
nwrite = fwrite(&freq, sizeof(double), 1, fp);
|
||||
|
||||
for(i=0; i<45000; i++) {
|
||||
buffer[2*i]=idat[i];
|
||||
buffer[2*i+1]=-qdat[i];
|
||||
}
|
||||
|
||||
nwrite = fwrite(buffer, sizeof(float), 2*45000, fp);
|
||||
if( nwrite == 2*45000 ) {
|
||||
return nwrite;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//********************************************************************
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
extern char *optarg;
|
||||
extern int optind;
|
||||
int i, c, printchannel=0, writec2=0;
|
||||
float snr=50.0;
|
||||
float f0=0.0, t0=1.0;
|
||||
char *message, *c2filename, *hashtab;
|
||||
c2filename=malloc(sizeof(char)*15);
|
||||
hashtab=malloc(sizeof(char)*32768*13);
|
||||
memset(hashtab,0,sizeof(char)*32768*13);
|
||||
|
||||
// message length is 22 characters
|
||||
message=malloc(sizeof(char)*23);
|
||||
|
||||
strcpy(c2filename,"000000_0001.c2");
|
||||
|
||||
srand(getpid());
|
||||
|
||||
while ( (c = getopt(argc, argv, "cdf:o:s:")) !=-1 ) {
|
||||
switch (c) {
|
||||
case 'c':
|
||||
printchannel=1;
|
||||
break;
|
||||
case 'd':
|
||||
printdata=1;
|
||||
break;
|
||||
case 'f':
|
||||
f0 = atof(optarg);
|
||||
case 'o':
|
||||
c2filename = optarg;
|
||||
writec2=1;
|
||||
break;
|
||||
case 's':
|
||||
// snr = (float)atoi(optarg);
|
||||
snr = atof(optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( optind+1 > argc ) {
|
||||
usage();
|
||||
return 0;
|
||||
} else {
|
||||
message=argv[optind];
|
||||
}
|
||||
|
||||
unsigned char channel_symbols[162];
|
||||
get_wspr_channel_symbols(message, hashtab, channel_symbols);
|
||||
|
||||
if( printchannel ) {
|
||||
printf("Channel symbols:\n");
|
||||
for (i=0; i<162; i++) {
|
||||
printf("%d ",channel_symbols[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// add noise, then signal
|
||||
double isig[45000], qsig[45000];
|
||||
memset(isig,0,sizeof(double)*45000);
|
||||
memset(qsig,0,sizeof(double)*45000);
|
||||
|
||||
if( snr < 40 ) {
|
||||
// snr in 375Hz is 8.2 dB higher than in 2500 Hz.
|
||||
snr=snr+8.2;
|
||||
snr=pow(10,snr/20.0)*pow(2,0.5);
|
||||
|
||||
for (i = 0; i<45000; i++) {
|
||||
isig[i]=isig[i]+gaussrand();
|
||||
qsig[i]=qsig[i]+gaussrand();
|
||||
}
|
||||
} else {
|
||||
snr=1.0;
|
||||
}
|
||||
|
||||
add_signal_vector(f0, t0, snr, channel_symbols, isig, qsig);
|
||||
if( writec2) {
|
||||
// write a .c2 file
|
||||
double carrierfreq=10.1387;
|
||||
int wsprtype=2;
|
||||
printf("Writing %s\n",c2filename);
|
||||
writec2file(c2filename, wsprtype, carrierfreq, isig, qsig);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
Reference in New Issue
Block a user