diff options
Diffstat (limited to 'lib/cwsim.f90')
| -rw-r--r-- | lib/cwsim.f90 | 100 |
1 files changed, 9 insertions, 91 deletions
diff --git a/lib/cwsim.f90 b/lib/cwsim.f90 index 92300b72..3c36a820 100644 --- a/lib/cwsim.f90 +++ b/lib/cwsim.f90 @@ -3,6 +3,7 @@ program cwsim ! Generate simulated audio for a CW message sent repeatedly for 60 seconds use wavhdr + use morse_encoder, only: encode_morse parameter (NMAX=60*12000) type(hdr) h !Header for the .wav file integer*2 iwave(NMAX) !Generated waveform (no noise) @@ -33,19 +34,23 @@ program cwsim call getarg(6,arg) read(arg,*) snrdb !S/N in dB (2500 hz reference BW) + call encode_morse(trim(message),icw,ncw) + if(ncw.eq.0) then + print*,'Error: message contains unsupported Morse characters' + stop 1 + endif + rms=500.0 bandwidth_ratio=2500.0/6000.0 sig=sqrt(2*bandwidth_ratio)*10.0**(0.05*snrdb) twopi=8.0*atan(1.0) h=default_header(12000,NMAX) - open(10,file='000000_0000.wav',access='stream',status='unknown') + open(10,file='000000_0000.wav',access='stream',status='replace') do i=1,NMAX !Generate gaussian noise xnoise(i)=gran() enddo - itone=0 - call morse(message,icw,ncw) call cwsig(icw,ncw,ifreq,wpm,sig,cdat) nfft=NMAX @@ -112,6 +117,7 @@ subroutine cwsig(icw,ncw,ifreq,wpm,sig,cdat) complex z(NMAX) real x(NMAX) real y(NMAX) + save z,x,y !Keep these big arrays off the stack real*8 dt,twopi,phi,dphi,fsample,tdit,t nspd=nint(1.2*12000.0/wpm) @@ -145,91 +151,3 @@ subroutine cwsig(icw,ncw,ifreq,wpm,sig,cdat) return end subroutine cwsig - -subroutine morse(msg,idat,n) - -! Convert ascii message to a Morse code bit string. -! Dash = 3 dots -! Space between dots, dashes = 1 dot -! Space between letters = 3 dots -! Space between words = 7 dots - - character*(*) msg - integer idat(500) - integer*1 ic(21,38) - data ic/ & - 1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,20, & - 1,0,1,1,1,0,1,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, & - 1,1,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & - 1,0,1,1,1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,1,1,0,1,0,1,1,1,0,0,0,0,0,0,0,14, & - 1,0,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 6, & - 1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 4, & - 1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 8, & - 1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,10, & - 1,1,1,0,1,0,1,0,1,1,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,14, & - 1,1,1,0,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,12, & - 1,1,1,0,1,0,1,0,1,1,1,0,1,0,0,0,0,0,0,0,14, & - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2/ !Incremental word space - save - - msglen=len(trim(msg)) - idat=0 - n=6 - do k=1,msglen - jj=ichar(msg(k:k)) - if(jj.ge.97 .and. jj.le.122) jj=jj-32 !Convert lower to upper case - if(jj.ge.48 .and. jj.le.57) j=jj-48 !Numbers - if(jj.ge.65 .and. jj.le.90) j=jj-55 !Letters - if(jj.eq.47) j=36 !Slash (/) - if(jj.eq.32) j=37 !Word space - j=j+1 - -! Insert this character - nmax=ic(21,j) - if (n + nmax + 4 .gt. size (idat)) exit - do i=1,nmax - n=n+1 - idat(n)=ic(i,j) - enddo - -! Insert character space of 2 dit lengths: - n=n+1 - idat(n)=0 - n=n+1 - idat(n)=0 - enddo - -! Insert word space at end of message - do j=1,4 - n=n+1 - idat(n)=0 - enddo - - return -end subroutine morse |
