AFSKModem

The AFSKModem object implements a AFSK modulator / demodulator.

Warning

This modem does not output IQData but real data. To work, it needs to be followed by a FM modulator/demodulator.
It produces AUDIO, not BASEBAND data.

class AFSKModem {
    constructor( name : string );
    configure( {'bit_rate': bitrate, 'low_tone': low, 'high_tone': high  } );

    FloatData modulateBits( Uint8Array of bits ); 
    Uint8Array demodulate( FloatData in );
} ;

.configure

var modem = new AFSKModem('test');
modem.configure( { 'bit_rate': 50, 'low_tone': 1270, 'high_tone': 1440  } ); 

If only the bit rate is specified, the following standard low_tone and high_tones are applied:

  • bitrate = 300 : low_tone = 1600 Hz, high_tone = 1800 Hz
  • bitrate = 1200 : low_tone = 1200 Hz, high_tone = 2200 Hz
  • bitrate = 2400 : low_tone = 2400 Hz, high_tone = 4400 Hz
  • bitrate = 9600 : low_tone = 3000 Hz, high_tone = 9000 Hz

.modulateBits

This will generate the float samples ready to be used for modulation. This is the audio signal.
The sampling rate is estimated automatically from the bitrate, minimal value is 48k.

var bit_array = new Uint8Array( len );  
FloatData output = modem.modulateBits( bit_array ); 

.demodulate

Converts audio samples to bits based on the tones and bitrate specified. Internally, the demodulator uses two correlators.

Uint8Array demodulate( FloatData in );

Example

  • Send and receive 16 bytes using AFSK 1200 bds
rename('AFSK');

function printBits( x ) {
    var l=0 ;
    var m = '' ;
    while( l < x.length  ) {

         for( var b=0 ; (b<8) && (l<x.length) ; b++,l++) {
              if( x[l]>0 ) {
                  m = m + '1' ;
              } else {
                  m = m + '0' ;
              }
         }
         m = m + ' ' ;

    }
    print(m);
}

// Generate 16 bytes message
var L = 16*8 ;
var msg = new Uint8Array(L) ;
for( var i=0 ; i < L ; i+=2 ) {
    msg[i] = 1 ;
    msg[i+1] = 0 ;
}


printBits( msg );
//================================== 
// TX Path
//==================================
var modem = new AFSKModem('test');
modem.configure( { 'bit_rate': 2400  } );  
// Get the audio from the modem
var audio = modem.modulateBits( msg );
print(' Samplerate : ' + audio.getSampleRate()) ;
print(' Size : ' + audio.getLength() ) ;
print('');

// Generate the FM IQ
var modulator = new NBFM('modulator'); 
modulator.configure( {'modulation_index': 0.1} );
var IQ = modulator.modulate( audio );

//==================================
// RX Path
//==================================
// Convert IQ to audio
var demodulator = new NBFM('demod');
demodulator.configure( {'modulation_index': 0.1} );
var received_audio = demodulator.demodulate( IQ);
// extract bits from audio
var dem = new AFSKModem('rx');
dem.configure( {'bit_rate' : 2400 }) ;
var rx = dem.demodulate( received_audio ) ;

printBits( rx );

Ouput:

AFSK:0)> 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 
(AFSK:0)>  Samplerate : 48000
(AFSK:0)>  Size : 2561
(AFSK:0)> 
(AFSK:0)> 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010 10101010

Last update: July 16, 2022