fsk_lib;
+% Basic modem set up for Horus
+
function states = fsk_horus_init(Fs,Rs,M=2)
states = fsk_init(Fs,Rs,M);
- states.rtty = fsk_horus_init_rtty_uw(states);
- states.binary = fsk_horus_init_binary_uw;
% Freq. estimator limits - keep these narrow to stop errors with low SNR 4FSK
endfunction
-% init rtty protocol specifc states
+% init rtty protocol specific states
-function rtty = fsk_horus_init_rtty_uw(states)
+function rtty = fsk_horus_init_rtty
% Generate unque word that correlates against the ASCII "$$$$$" that
% is at the start of each frame.
% $ -> 36 decimal -> 0 1 0 0 1 0 0 binary
mapped_db = 2*dollar_bits - 1;
sync_bits = [1 1 0];
mapped_sb = 2*sync_bits - 1;
- %mapped_sb = [ 0 0 0 ];
mapped = [mapped_db mapped_sb];
- npad = rtty.npad = 3; % one start and two stop bits between 7 bit ascii chars
- nfield = rtty.nfield = 7; % length of ascii character field
+ npad = rtty.npad = 3; % one start and two stop bits between 7 bit ascii chars
+ nfield = rtty.nfield = 7; % length of ascii character field
rtty.uw = [mapped mapped mapped mapped mapped];
rtty.uw_thresh = length(rtty.uw) - 2; % allow a few bit errors when looking for UW
nfield = states.nfield;
npad = states.npad;
- str = []; str_dec = []; nstr = 0; ptx_crc = 1; rx_crc = "";
+ str = ""; str_dec = []; nstr = 0; ptx_crc = 1; rx_crc = "";
endpacket = 0;
st = uw_loc + length(states.uw); % first bit of first char
if test_frame_mode == 4
% horus rtty config ---------------------
- states = fsk_horus_init(8000, 100);
- states.tx_bits_file = "horus_tx_bits_rtty.txt"; % Octave file of bits we FSK modulate
+ states = fsk_horus_init(8000, 100, 2);
+ states.tx_bits_file = "horus_payload_rtty.txt"; % Octave file of bits we FSK modulate
+ uwstates = fsk_horus_init_rtty_uw(states);
+ states.ntestframebits = states.nbits;
end
if test_frame_mode == 5
% run test functions from here during development
if exist("fsk_horus_as_a_lib") == 0
- %run_sim(1, 2, 100, 9);
+ run_sim(4, 2, 10, 100);
%rx_bits = demod_file("~/Desktop/115.wav",6,0,90);
%rx_bits = demod_file("fsk_horus.raw",5);
%rx_bits = demod_file("~/Desktop/4FSK_Binary_NoLock.wav",4);
%rx_bits = demod_file("mp.raw",4);
%rx_bits = demod_file("~/Desktop/launchbox_v2_landing_8KHz_final.wav",4);
%rx_bits = demod_file("~/Desktop/bench_test_003.wav",7);
- rx_bits = demod_file("../build_linux/unittest/fskrx2.raw",8);
+ %rx_bits = demod_file("../build_linux/unittest/fskrx2.raw",8);
end
more off;
states = fsk_horus_init(8000, Rs, mFSK);
-uwstates = fsk_horus_init_rtty_uw(states);
+rtty = fsk_horus_init_rtty;
+binary = fsk_horus_init_binary_uw;
N = states.N;
Rs = states.Rs;
nsym = states.nsym;
nin = states.nin;
-nfield = states.rtty.nfield;
-npad = states.rtty.npad;
+nfield = rtty.nfield;
+npad = rtty.npad;
EbNo = 0;
SNR = 0;
% Look for complete Horus RTTY frame -------------------------------------------------------------------
nbits = length(rx_bits_buf);
- uw_loc = find_uw(states.rtty, 1, rx_bits_buf);
+ uw_loc = find_uw(rtty, 1, rx_bits_buf);
if uw_loc != -1
packet_found = 1;
- if (uw_loc + states.rtty.max_packet_len) < nbits
+ if (uw_loc + rtty.max_packet_len) < nbits
%printf("\n%d nbits: %d\n",uw_loc + states.rtty.max_packet_len, nbits);
- [str crc_ok] = extract_ascii(states.rtty, rx_bits_buf, uw_loc);
+ [str crc_ok] = extract_ascii(rtty, rx_bits_buf, uw_loc);
if crc_ok == 0
- [str_flipped crc_flipped_ok] = sd_bit_flipping(states.rtty, rx_bits_buf, rx_bits_sd_buf, uw_loc, uw_loc+states.rtty.max_packet_len);
+ [str_flipped crc_flipped_ok] = sd_bit_flipping(rtty, rx_bits_buf, rx_bits_sd_buf, uw_loc, uw_loc+rtty.max_packet_len);
if crc_flipped_ok
str = sprintf("%s fixed", str_flipped);
crc_ok = 1;
% so lets remove everything up to just after the UW we just used to force
% a search for the next UW.
- rx_bits_buf = rx_bits_buf(uw_loc+length(states.rtty.uw):length(rx_bits_buf));
- rx_bits_sd_buf = rx_bits_sd_buf(uw_loc+length(states.rtty.uw):length(rx_bits_sd_buf));
+ rx_bits_buf = rx_bits_buf(uw_loc+length(rtty.uw):length(rx_bits_buf));
+ rx_bits_sd_buf = rx_bits_sd_buf(uw_loc+length(rtty.uw):length(rx_bits_sd_buf));
if crc_ok
% extract GPS coords and save to log file for mapping software
% Look for complete Horus BINARY frame -------------------------------------------------------------------
nbits = length(rx_bits_buf);
- uw_loc = find_uw(states.binary, 1, rx_bits_buf);
+ uw_loc = find_uw(binary, 1, rx_bits_buf);
if uw_loc != -1
packet_found = 1;
- if (uw_loc + states.binary.max_packet_len) < nbits
+ if (uw_loc + binary.max_packet_len) < nbits
pin = uw_loc;
- nbytes = states.binary.max_packet_len/8;
+ nbytes = binary.max_packet_len/8;
for i=1:nbytes
if (pin+7) > nbits
pin
nbits
uw_loc
- states.binary.max_packet_len
+ binary.max_packet_len
end
rx_bytes(i) = rx_bits_buf(pin:pin+7) * (2.^(7:-1:0))';
pin += 8;
% so lets remove everything up to just after the UW we just used to force
% a search for the next UW.
- rx_bits_buf = rx_bits_buf(uw_loc+length(states.binary.uw):length(rx_bits_buf));
- rx_bits_sd_buf = rx_bits_sd_buf(uw_loc+length(states.binary.uw):length(rx_bits_sd_buf));
+ rx_bits_buf = rx_bits_buf(uw_loc+length(binary.uw):length(rx_bits_buf));
+ rx_bits_sd_buf = rx_bits_sd_buf(uw_loc+length(binary.uw):length(rx_bits_sd_buf));
end
end
% Keep very end of it as it may have part of a UW in it
if packet_found == 0
- max_len = states.rtty.max_packet_len*4;
+ max_len = rtty.max_packet_len*4;
if length(rx_bits_buf) > max_len
- rx_bits_buf = rx_bits_buf(length(rx_bits_buf)-states.rtty.max_packet_len:length(rx_bits_buf));
- rx_bits_sd_buf = rx_bits_sd_buf(length(rx_bits_sd_buf)-states.rtty.max_packet_len:length(rx_bits_sd_buf));
+ rx_bits_buf = rx_bits_buf(length(rx_bits_buf)-rtty.max_packet_len:length(rx_bits_buf));
+ rx_bits_sd_buf = rx_bits_sd_buf(length(rx_bits_sd_buf)-rtty.max_packet_len:length(rx_bits_sd_buf));
end
end