From e5887a00d3791f4aeb564e9540d7700e24c2aa9a Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sat, 23 Jan 2016 04:23:15 +0000 Subject: [PATCH] working with scrambler and interleaver, stored files and streaming git-svn-id: https://svn.code.sf.net/p/freetel/code@2645 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/fsk_horus.m | 4 ++-- codec2-dev/octave/fsk_horus_stream.m | 7 ++++--- codec2-dev/src/horus_l2.c | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/codec2-dev/octave/fsk_horus.m b/codec2-dev/octave/fsk_horus.m index 074a539b..38e2eb82 100644 --- a/codec2-dev/octave/fsk_horus.m +++ b/codec2-dev/octave/fsk_horus.m @@ -664,7 +664,7 @@ endfunction function run_sim(test_frame_mode) test_frame_mode = 5; - frames = 10; + frames = 100; EbNodB = 60; timing_offset = 0.0; % see resample() for clock offset below fading = 0; % modulates tx power at 2Hz with 20dB fade depth, @@ -1068,7 +1068,7 @@ endfunction if exist("fsk_horus_as_a_lib") == 0 %run_sim(5); - rx_bits = demod_file("~/Desktop/4FSK_Scram_Interleaved.wav",5); + rx_bits = demod_file("~/Desktop/test2.wav",4); %rx_bits = demod_file("fsk_horus.raw",5); %rx_bits = demod_file("~/Desktop/4FSK_Binary_NoLock.wav",4); %rx_bits = demod_file("~/Desktop/phorus_binary_ascii.wav",4); diff --git a/codec2-dev/octave/fsk_horus_stream.m b/codec2-dev/octave/fsk_horus_stream.m index f87a9907..7784ad6b 100755 --- a/codec2-dev/octave/fsk_horus_stream.m +++ b/codec2-dev/octave/fsk_horus_stream.m @@ -32,8 +32,8 @@ telem_upload_enabled = false; telem_upload_command = "python telem_upload.py -c vk5dgr_Octave"; more off; -states = fsk_horus_init(8000, 100); -%states = fsk_horus_init_rtty_uw(states); +states = fsk_horus_init(8000, 50, 4); +uwstates = fsk_horus_init_rtty_uw(states); N = states.N; Rs = states.Rs; nsym = states.nsym; @@ -56,6 +56,7 @@ while c % demodulate samples to bit stream while length(rx) > nin + states = est_freq(states, rx(1:nin)', states.M); [rx_bits states] = fsk_horus_demod(states, rx(1:nin)'); rx_bits_buf = [rx_bits_buf rx_bits]; rx_bits_sd_buf = [rx_bits_sd_buf states.rx_bits_sd]; @@ -65,7 +66,7 @@ while c SNR = EbNo + 10*log10(states.Rs/3000); %printf("nin: %d length(rx): %d length(rx_bits_buf): %d \n", nin, length(rx), length(rx_bits_buf)); endwhile - f = (states.f1+states.f2)/2; shift = states.f2 - states.f1; + f = (states.f(1)+states.f(2))/2; shift = states.f(2) - states.f(1); printf("max: %d f: %d fshift %d ppm: %d Eb/No: %3.1f SNR: %3.1f bits: %d\r", max(s), f, shift, states.ppm, EbNo, SNR, length(rx_bits_buf)); packet_found = 0; diff --git a/codec2-dev/src/horus_l2.c b/codec2-dev/src/horus_l2.c index b87d46ec..f3cdc73e 100644 --- a/codec2-dev/src/horus_l2.c +++ b/codec2-dev/src/horus_l2.c @@ -44,7 +44,7 @@ $ gcc horus_l2.c -o horus_l2 -Wall -DINTERLEAVER -DTEST_INTERLEAVER -DSCRAMBLER - 5/ Compile for use as decoder called by fsk_horus.m and fsk_horus_stream.m: + 5/ Compile for use as decoder called by fsk_horus.m and fsk_horus_stream.m: $ gcc horus_l2.c -o horus_l2 -Wall -DDEC_RX_BITS -DHORUS_L2_RX @@ -466,7 +466,7 @@ void horus_l2_decode_rx_packet(unsigned char *output_payload_data, #ifdef INTERLEAVER -int primes[] = { +uint16_t primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, @@ -478,9 +478,10 @@ int primes[] = { void interleave(unsigned char *inout, int nbytes, int dir) { - int nbits = nbytes*8; - int i, j, n, ibit, ibyte, ishift, jbyte, jshift; - int b; + /* note: to work on small uCs (e.g. AVR) needed to declare specific words sizes */ + uint16_t nbits = (uint16_t)nbytes*8; + uint32_t i, j, n, ibit, ibyte, ishift, jbyte, jshift; + uint32_t b; unsigned char out[nbytes]; memset(out, 0, nbytes); @@ -489,7 +490,7 @@ void interleave(unsigned char *inout, int nbytes, int dir) nearest prime to nbits. It also uses storage, is run on every call, and has an upper limit. Oh Well, still seems to interleave OK. */ i = 1; - int imax = sizeof(primes)/sizeof(int); + uint16_t imax = sizeof(primes)/sizeof(uint16_t); while ((primes[i] < nbits) && (i < imax)) i++; b = primes[i-1]; @@ -501,10 +502,10 @@ void interleave(unsigned char *inout, int nbytes, int dir) */ i = n; - j = (b*i) % nbits; + j = (b*i) % nbits; /* note these all need to be 32-bit ints to make multiply work without overflow */ if (dir) { - int tmp = j; + uint16_t tmp = j; j = i; i = tmp; } @@ -525,8 +526,9 @@ void interleave(unsigned char *inout, int nbytes, int dir) /* write jbit to ibit position */ out[jbyte] |= ibit << jshift; // replace with i-th bit + //out[ibyte] |= ibit << ishift; // replace with i-th bit } - + memcpy(inout, out, nbytes); #ifdef DEBUG0 -- 2.25.1