Additiions and changes to test routines.

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7648 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Joe Taylor 2017-04-21 18:20:48 +00:00
parent 3d84a90ec6
commit 15c46c8ae8
7 changed files with 264 additions and 28 deletions

View File

@ -383,10 +383,12 @@ set (wsjt_FSRCS
lib/four2a.f90
lib/fqso_first.f90
lib/freqcal.f90
lib/fsk4hf/fsk4hf.f90
lib/gen4.f90
lib/gen65.f90
lib/gen9.f90
lib/geniscat.f90
lib/fsk4hf/genfsk4hf.f90
lib/genmsk144.f90
lib/genmsk40.f90
lib/fsk4hf/genmskhf.f90
@ -464,6 +466,7 @@ set (wsjt_FSRCS
lib/softsym9f.f90
lib/softsym9w.f90
lib/shell.f90
lib/fsk4hf/spec4.f90
lib/spec64.f90
lib/spec9f.f90
lib/stdmsg.f90
@ -1119,6 +1122,9 @@ target_link_libraries (ldpcsim144 wsjt_fort wsjt_cxx)
add_executable (ldpcsim168 lib/fsk4hf/ldpcsim168.f90 wsjtx.rc)
target_link_libraries (ldpcsim168 wsjt_fort wsjt_cxx)
add_executable (fsk4hf lib/fsk4hf/fsk4hf.f90 wsjtx.rc)
target_link_libraries (fsk4hf wsjt_fort wsjt_cxx)
add_executable (mskhfsim lib/fsk4hf/mskhfsim.f90 wsjtx.rc)
target_link_libraries (mskhfsim wsjt_fort wsjt_cxx)

145
lib/fsk4hf/fsk4hf.f90 Normal file
View File

@ -0,0 +1,145 @@
program fsk4hf
! Simulate characteristics of a potential mode using LDPC (168,84) code,
! 4-FSK modulation, and 30 s T/R sequences.
parameter (KK=84) !Information bits (72 + CRC12)
parameter (ND=84) !Data symbols: LDPC (168,84), r=1/2
parameter (NS=12) !Sync symbols (3 @ 4x4 Costas arrays)
parameter (NR=2) !Ramp up/down
parameter (NN=NR+NS+ND) !Total symbols (98)
parameter (NSPS=2688/84) !Samples per symbol (32)
parameter (NZ=NSPS*NN) !Samples in baseband waveform (3760)
character*8 arg
complex c0(0:NZ-1) !Complex waveform
complex c(0:NZ-1) !Complex waveform
real xnoise(0:NZ-1) !Generated random noise
real ynoise(0:NZ-1) !Generated random noise
real rxdata(2*ND),llr(2*ND) !Soft symbols
real s(0:NSPS,NN)
real savg(0:NSPS)
real ps(0:3)
integer id(ND) !Symbol values (0-3), data only
integer id1(ND) !Recovered data values
integer*1 msgbits(KK),decoded(KK),apmask(ND),cw(ND)
data msgbits/0,0,1,0,0,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,1, &
1,1,1,0,1,1,1,1,1,1,1,0,0,1,0,0,1,1,0,1,0,1,1,1,0,1,1,0,1,1, &
1,1,0,1,0,1,1,0,0,0,0,0,1,0,0,0,0,0,1,0,1,0,1,0/
nargs=iargc()
if(nargs.ne.5) then
print*,'Usage: fsk4hf f0(Hz) delay(ms) fspread(Hz) iters snr(dB)'
print*,'Example: fsk4hf 20 0 0 10 -20'
print*,'Set snr=0 to cycle through a range'
go to 999
endif
call getarg(1,arg)
read(arg,*) f0 !Generated carrier frequency
call getarg(2,arg)
read(arg,*) delay !Delta_t (ms) for Watterson model
call getarg(3,arg)
read(arg,*) fspread !Fspread (Hz) for Watterson model
call getarg(4,arg)
read(arg,*) iters !Iterations at each SNR
call getarg(5,arg)
read(arg,*) snrdb !Specified SNR_2500
twopi=8.0*atan(1.0)
fs=12000.0/84.0 !Sample rate = 142.857... Hz
dt=1.0/fs !Sample interval (s)
tt=NSPS*dt !Duration of "itone" symbols (s)
baud=1.0/tt !Keying rate for "itone" symbols (baud)
txt=NZ*dt !Transmission length (s)
bandwidth_ratio=2500.0/(fs/2.0)
write(*,1000) f0,delay,fspread,iters,baud,4*baud,txt
1000 format('f0:',f5.1,' Delay:',f4.1,' fSpread:',f5.2, &
' Iters:',i6/'Baud:',f7.3,' BW:',f5.1,' TxT:',f5.1,f5.2/)
write(*,1004)
1004 format(/' SNR sym bit ser ber fer fsigma'/50('-'))
call genfsk4hf(msgbits,f0,id,c0) !Generate baseband waveform
isna=-10
isnb=-30
if(snrdb.ne.0.0) then
isna=nint(snrdb)
isnb=isna
endif
do isnr=isna,isnb,-1 !Loop over SNR range
snrdb=isnr
sig=sqrt(bandwidth_ratio) * 10.0**(0.05*snrdb)
if(snrdb.gt.90.0) sig=1.0
nhard=0
nbit=0
nfe=0
sqf=0.
do iter=1,iters !Loop over requested iterations
c=c0
if(delay.ne.0.0 .or. fspread.ne.0.0) then
call watterson(c,NZ,fs,delay,fspread)
endif
c=sig*c !Scale to requested SNR
if(snrdb.lt.90) then
do i=0,NZ-1 !Generate gaussian noise
xnoise(i)=gran()
ynoise(i)=gran()
enddo
c=c + cmplx(xnoise,ynoise) !Add AWGN noise
endif
df=fs/(2*NSPS)
i0=nint(f0/df)
call spec4(c,s,savg)
do i=0,NSPS
write(12,3001) i*df,savg(i),db(savg(i))
3001 format(3f15.3)
enddo
do j=1,ND
nlo=0
nhi=0
k=j+5
if(j.ge.43) k=j+9
ps=s(i0:i0+6:2,k)
ps=sqrt(ps) !###
rlo=max(ps(1),ps(3))-max(ps(0),ps(2))
rhi=max(ps(2),ps(3))-max(ps(0),ps(1))
if(rlo.ge.0.0) nlo=1
if(rhi.ge.0.0) nhi=1
rxdata(2*j-1)=rhi
rxdata(2*j)=rlo
id1(j)=2*nhi+nlo
enddo
! write(*,1001) id(1:70)
! write(*,1001) id1(1:70)
!1001 format(70i1)
nhard=nhard+count(id.ne.id1)
nbit=nbit + count(iand(id,1).ne.iand(id1,1)) + &
count(iand(id,2).ne.iand(id1,2))
rxav=sum(rxdata)/ND
rx2av=sum(rxdata*rxdata)/ND
rxsig=sqrt(rx2av-rxav*rxav)
rxdata=rxdata/rxsig
ss=0.84
llr=2.0*rxdata/(ss*ss)
apmask=0
max_iterations=40
ifer=0
call bpdecode168(llr,apmask,max_iterations,decoded,niterations,cw)
nbadcrc=0
if(niterations.ge.0) call chkcrc12(decoded,nbadcrc)
if(niterations.lt.0 .or. count(msgbits.ne.decoded).gt.0 .or. &
nbadcrc.ne.0) ifer=1
nfe=nfe+ifer
enddo
fsigma=sqrt(sqf/iters)
ser=float(nhard)/(ND*iters)
ber=float(nbit)/(2*ND*iters)
fer=float(nfe)/iters
write(*,1050) snrdb,nhard,nbit,ser,ber,fer,fsigma
! write(60,1050) snrdb,nhard,ber,fer,fsigma
1050 format(f6.1,2i6,2f8.4,f7.3,f8.2)
enddo
999 end program fsk4hf

51
lib/fsk4hf/genfsk4hf.f90 Normal file
View File

@ -0,0 +1,51 @@
subroutine genfsk4hf(msgbits,f0,id,c)
parameter (KK=84) !Information bits (72 + CRC12)
parameter (ND=84) !Data symbols: LDPC (168,84), r=1/2
parameter (NS=12) !Sync symbols (3 @ 4x4 Costas arrays)
parameter (NR=2) !Ramp up/down
parameter (NN=NR+NS+ND) !Total symbols (98)
parameter (NSPS=2688/84) !Samples per symbol (32)
parameter (NZ=NSPS*NN) !Samples in baseband waveform (3136)
complex c(0:NZ-1) !Complex waveform
integer id0(NN) !2-bit data (values 0-3), all symbols
integer id(ND) !2-bit data (values 0-3), data only
integer*1 msgbits(KK),codeword(2*ND)
integer icos4(4) !4x4 Costas array
data icos4/0,1,3,2/
twopi=8.0*atan(1.0)
fs=12000.0/84.0
dt=1.0/fs
baud=1.0/(NSPS*dt)
call encode168(msgbits,codeword) !Encode the test message
id0(1)=0 !Ramp-up
id0(2:5)=icos4 !First Costas array
id0(48:51)=icos4 !Second
id0(94:97)=icos4 !Third
id0(98)=0 !Ramp down
j=5
do i=1,84 !Data symbols
id(i)=2*codeword(2*i-1) + codeword(2*i)
j=j+1
if(i.eq.43) j=j+4
id0(j)=id(i)
enddo
! Generate the 4-FSK waveform, low tone at f=0
c=0.
phi=0.d0
k=-1
do j=1,NN
dphi=twopi*(f0+id0(j)*baud)*dt
do i=1,NSPS
k=k+1
phi=phi+dphi
if(phi.gt.twopi) phi=phi-twopi
c(k)=cmplx(cos(phi),sin(phi))
enddo
enddo
return
end subroutine genfsk4hf

View File

@ -40,10 +40,7 @@ subroutine genmskhf(msgbits,id,icw,cbb,csync)
enddo
first=.false.
endif
call random_number(x)
codeword=0
where(x(1:ND).ge.0.5) codeword=1
call encode168(msgbits,codeword) !Encode the test message
icw=2*codeword - 1

View File

@ -17,10 +17,10 @@ program msksim
parameter (NS=65) !Sync symbols (2 x 26 + Barker 13)
parameter (NR=3) !Ramp up/down
parameter (NN=NR+NS+ND) !Total symbols (236)
parameter (NSPS=16) !Samples per MSK symbol (16)
parameter (NSPS=1152/72) !Samples per MSK symbol (16)
parameter (N2=2*NSPS) !Samples per OQPSK symbol (32)
parameter (N13=13*N2) !Samples in central sync vector (416)
parameter (NZ=NSPS*NN) !Samples in baseband waveform (3760)
parameter (NZ=NSPS*NN) !Samples in baseband waveform (3776)
parameter (NFFT1=4*NSPS,NH1=NFFT1/2)
character*8 arg
@ -28,7 +28,7 @@ program msksim
complex csync(0:NZ-1) !Sync symbols only, from cbb
complex cb13(0:N13-1) !Barker 13 waveform
complex c(0:NZ-1) !Complex waveform
complex c0(0:NZ-1) !Complex waveform
complex c0(0:NZ-1) !Complex waveform
complex zz(NS+ND) !Complex symbol values (intermediate)
complex z
real xnoise(0:NZ-1) !Generated random noise
@ -74,7 +74,7 @@ program msksim
baud=1.0/tt !Keying rate for "itone" symbols (baud)
txt=NZ*dt !Transmission length (s)
bandwidth_ratio=2500.0/(fs/2.0)
write(*,1000) f0,delay,fspread,maxn,iters,baud,1.5*baud,txt
write(*,1000) f0,delay,fspread,maxn,iters,baud,3*baud,txt
1000 format('f0:',f5.1,' Delay:',f4.1,' fSpread:',f5.2,' maxn:',i3, &
' Iters:',i6/'Baud:',f7.3,' BW:',f5.1,' TxT:',f5.1,f5.2/)
write(*,1004)
@ -106,7 +106,9 @@ program msksim
sqf=0.
do iter=1,iters !Loop over requested iterations
c=cbb
if(delay.ne.0.0 .or. fspread.ne.0.0) call watterson(c,fs,delay,fspread)
if(delay.ne.0.0 .or. fspread.ne.0.0) then
call watterson(c,NZ,fs,delay,fspread)
endif
c=sig*c !Scale to requested SNR
if(snrdb.lt.90) then
do i=0,NZ-1 !Generate gaussian noise

35
lib/fsk4hf/spec4.f90 Normal file
View File

@ -0,0 +1,35 @@
subroutine spec4(c,s,savg)
parameter (KK=84) !Information bits (72 + CRC12)
parameter (ND=84) !Data symbols: LDPC (168,84), r=1/2
parameter (NS=12) !Sync symbols (3 @ 4x4 Costas arrays)
parameter (NR=2) !Ramp up/down
parameter (NN=NR+NS+ND) !Total symbols (98)
parameter (NSPS=2688/84) !Samples per symbol (32)
parameter (NZ=NSPS*NN) !Samples in baseband waveform (3760)
parameter (NFFT=2*NSPS,NH=NSPS)
complex c(0:NZ-1)
complex c1(0:NFFT-1)
real s(0:NH,NN)
real savg(0:NH)
fs=12000.0/84.0
df=fs/NFFT
savg=0.
do j=1,NN
ia=(j-1)*NSPS
ib=ia + NSPS-1
c1(0:NSPS-1)=c(ia:ib)
c1(NSPS:)=0.
call four2a(c1,NFFT,1,-1,1)
do k=1,NSPS
s(k,j)=real(c1(k))**2 + aimag(c1(k))**2
enddo
savg=savg+s(0:NH,j)
enddo
s=s/NZ
savg=savg/(NN*NZ)
return
end subroutine spec4

View File

@ -1,15 +1,15 @@
subroutine watterson(c,fs,delay,fspread)
subroutine watterson(c,nz,fs,delay,fspread)
parameter (NZ=3840)
complex c(0:NZ-1)
complex c2(0:NZ-1)
complex cs1(0:NZ-1)
complex cs2(0:NZ-1)
parameter (NZMAX=3776)
complex c(0:nz-1)
complex c2(0:NZMAX-1)
complex cs1(0:NZMAX-1)
complex cs2(0:NZMAX-1)
nonzero=0
df=fs/NZ
df=fs/nz
if(fspread.gt.0.0) then
do i=0,NZ-1
do i=0,nz-1
xx=gran()
yy=gran()
cs1(i)=0.707*cmplx(xx,yy)
@ -17,11 +17,11 @@ subroutine watterson(c,fs,delay,fspread)
yy=gran()
cs2(i)=0.707*cmplx(xx,yy)
enddo
call four2a(cs1,NZ,1,-1,1) !To freq domain
call four2a(cs2,NZ,1,-1,1)
do i=0,NZ-1
call four2a(cs1,nz,1,-1,1) !To freq domain
call four2a(cs2,nz,1,-1,1)
do i=0,nz-1
f=i*df
if(i.gt.NZ/2) f=(i-NZ)*df
if(i.gt.nz/2) f=(i-nz)*df
x=(f/(0.5*fspread))**2
a=0.
if(x.le.50.0) then
@ -37,16 +37,16 @@ subroutine watterson(c,fs,delay,fspread)
!3101 format(f10.3,2f12.3,2f10.3)
endif
enddo
call four2a(cs1,NZ,1,1,1) !Back to time domain
call four2a(cs2,NZ,1,1,1)
cs1=cs1/NZ
cs2=cs2/NZ
call four2a(cs1,nz,1,1,1) !Back to time domain
call four2a(cs2,nz,1,1,1)
cs1(0:nz-1)=cs1(0:nz-1)/nz
cs2(0:nz-1)=cs2(0:nz-1)/nz
endif
nshift=nint(0.001*delay*fs)
c2=cshift(c,nshift)
c2(0:nz-1)=cshift(c(0:nz-1),nshift)
sq=0.
do i=0,NZ-1
do i=0,nz-1
if(nonzero.gt.1) then
c(i)=0.5*(cs1(i)*c(i) + cs2(i)*c2(i))
else
@ -56,7 +56,7 @@ subroutine watterson(c,fs,delay,fspread)
! write(61,3001) i/12000.0,c(i)
!3001 format(3f12.6)
enddo
rms=sqrt(sq/NZ)
rms=sqrt(sq/nz)
c=c/rms
return