kopia lustrzana https://github.com/M17-Project/M17_Implementations
Add files via upload
rodzic
7960f48a57
commit
5eca167967
|
@ -0,0 +1,141 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "m17.h"
|
||||
|
||||
float sample;
|
||||
float last[8];
|
||||
float xcorr;
|
||||
float pld[SYM_PER_PLD];
|
||||
uint16_t soft_bit[2*SYM_PER_PLD];
|
||||
uint16_t d_soft_bit[2*SYM_PER_PLD]; //deinterleaved soft bits
|
||||
uint16_t lich_chunk[96];
|
||||
|
||||
uint8_t syncd=0;
|
||||
uint8_t pushed; //pushed symbols
|
||||
|
||||
int main(void)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
//wait for another symbol
|
||||
while(read(STDIN_FILENO, (uint8_t*)&sample, 4)<4);
|
||||
|
||||
if(!syncd)
|
||||
{
|
||||
//push new symbol
|
||||
for(uint8_t i=0; i<7; i++)
|
||||
{
|
||||
last[i]=last[i+1];
|
||||
}
|
||||
|
||||
last[7]=sample;
|
||||
|
||||
//calculate cross-correlation
|
||||
xcorr=0;
|
||||
for(uint8_t i=0; i<8; i++)
|
||||
{
|
||||
xcorr+=last[i]*str_sync[i];
|
||||
}
|
||||
|
||||
if(xcorr>8.0)
|
||||
{
|
||||
syncd=1;
|
||||
pushed=0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pld[pushed++]=sample;
|
||||
|
||||
if(pushed==SYM_PER_PLD)
|
||||
{
|
||||
//decode symbols to soft dibits
|
||||
for(uint8_t i=0; i<SYM_PER_PLD; i++)
|
||||
{
|
||||
//bit 0
|
||||
if(pld[i]>=symbs[3])
|
||||
{
|
||||
soft_bit[i*2+1]=0xFFFF;
|
||||
}
|
||||
else if(pld[i]>=symbs[2])
|
||||
{
|
||||
soft_bit[i*2+1]=-(float)0xFFFF/(symbs[3]-symbs[2])*symbs[2]+pld[i]*(float)0xFFFF/(symbs[3]-symbs[2]);
|
||||
}
|
||||
else if(pld[i]>=symbs[1])
|
||||
{
|
||||
soft_bit[i*2+1]=0x0000;
|
||||
}
|
||||
else if(pld[i]>=symbs[0])
|
||||
{
|
||||
soft_bit[i*2+1]=(float)0xFFFF/(symbs[1]-symbs[0])*symbs[1]-pld[i]*(float)0xFFFF/(symbs[1]-symbs[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
soft_bit[i*2+1]=0xFFFF;
|
||||
}
|
||||
|
||||
//bit 1
|
||||
if(pld[i]>=symbs[2])
|
||||
{
|
||||
soft_bit[i*2]=0x0000;
|
||||
}
|
||||
else if(pld[i]>=symbs[1])
|
||||
{
|
||||
soft_bit[i*2]=0x7FFF-pld[i]*(float)0xFFFF/(symbs[2]-symbs[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
soft_bit[i*2]=0xFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
//derandomize
|
||||
for(uint16_t i=0; i<SYM_PER_PLD*2; i++)
|
||||
{
|
||||
if((rand_seq[i/8]>>(7-(i%8)))&1) //soft XOR. flip soft bit if "1"
|
||||
soft_bit[i]=0xFFFF-soft_bit[i];
|
||||
}
|
||||
|
||||
//deinterleave
|
||||
for(uint16_t i=0; i<SYM_PER_PLD*2; i++)
|
||||
{
|
||||
d_soft_bit[i]=soft_bit[intrl_seq[i]];
|
||||
}
|
||||
|
||||
//extract LICH
|
||||
for(uint16_t i=0; i<96; i++)
|
||||
{
|
||||
lich_chunk[i]=d_soft_bit[i];
|
||||
}
|
||||
|
||||
//debug - dump LICH
|
||||
uint8_t tmp;
|
||||
for(uint16_t i=0; i<96; i++)
|
||||
{
|
||||
if(!(i%8))
|
||||
tmp=0;
|
||||
if(lich_chunk[i]>0x7FFF)
|
||||
tmp|=(1<<(7-(i%8)));
|
||||
if(!((i+1)%8))
|
||||
write(STDOUT_FILENO, &tmp, 1);
|
||||
}
|
||||
tmp=0;
|
||||
for(uint8_t i=0; i<4; i++)
|
||||
write(STDOUT_FILENO, &tmp, 1);
|
||||
|
||||
//job done
|
||||
syncd=0;
|
||||
pushed=0;
|
||||
|
||||
for(uint8_t i=0; i<8; i++)
|
||||
last[i]=0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
#ifndef M17_CONSTS
|
||||
#define M17_CONSTS
|
||||
|
||||
#define FLT_LEN 81 //baseband filter length (number of taps)
|
||||
#define SW_LEN 80 //syncword detector length
|
||||
#define XC_LEN 90 //cross-correlator lookback length in samples
|
||||
#define SYM_PER_PLD 184 //symbols per payload in a frame
|
||||
|
||||
//syncword patterns
|
||||
const int8_t str_sync[8]={-3, -3, -3, -3, +3, +3, -3, +3};
|
||||
const int8_t lsf_sync[8]={+3, +3, +3, +3, -3, -3, +3, -3};
|
||||
|
||||
//symbol levels
|
||||
const float symbs[4]={-3*0.12, -1*0.12, +1*0.12, +3*0.12};
|
||||
|
||||
//RRC filter - 10 samples per symbol, 8 symbols span
|
||||
const float taps[FLT_LEN]=
|
||||
{
|
||||
-0.003195702904062073, -0.002930279157647190, -0.001940667871554463,
|
||||
-0.000356087678023658, 0.001547011339077758, 0.003389554791179751,
|
||||
0.004761898604225673, 0.005310860846138910, 0.004824746306020221,
|
||||
0.003297923526848786, 0.000958710871218619, -0.001749908029791816,
|
||||
-0.004238694106631223, -0.005881783042101693, -0.006150256456781309,
|
||||
-0.004745376707651645, -0.001704189656473565, 0.002547854551539951,
|
||||
0.007215575568844704, 0.011231038205363532, 0.013421952197060707,
|
||||
0.012730475385624438, 0.008449554307303753, 0.000436744366018287,
|
||||
-0.010735380379191660, -0.023726883538258272, -0.036498030780605324,
|
||||
-0.046500883189991064, -0.050979050575999614, -0.047340680079891187,
|
||||
-0.033554880492651755, -0.008513823955725943, 0.027696543159614194,
|
||||
0.073664520037517042, 0.126689053778116234, 0.182990955139333916,
|
||||
0.238080025892859704, 0.287235637987091563, 0.326040247765297220,
|
||||
0.350895727088112619, 0.359452932027607974, 0.350895727088112619,
|
||||
0.326040247765297220, 0.287235637987091563, 0.238080025892859704,
|
||||
0.182990955139333916, 0.126689053778116234, 0.073664520037517042,
|
||||
0.027696543159614194, -0.008513823955725943, -0.033554880492651755,
|
||||
-0.047340680079891187, -0.050979050575999614, -0.046500883189991064,
|
||||
-0.036498030780605324, -0.023726883538258272, -0.010735380379191660,
|
||||
0.000436744366018287, 0.008449554307303753, 0.012730475385624438,
|
||||
0.013421952197060707, 0.011231038205363532, 0.007215575568844704,
|
||||
0.002547854551539951, -0.001704189656473565, -0.004745376707651645,
|
||||
-0.006150256456781309, -0.005881783042101693, -0.004238694106631223,
|
||||
-0.001749908029791816, 0.000958710871218619, 0.003297923526848786,
|
||||
0.004824746306020221, 0.005310860846138910, 0.004761898604225673,
|
||||
0.003389554791179751, 0.001547011339077758, -0.000356087678023658,
|
||||
-0.001940667871554463, -0.002930279157647190, -0.003195702904062073
|
||||
};
|
||||
|
||||
//randomizing pattern
|
||||
const uint8_t rand_seq[46]=
|
||||
{
|
||||
0xD6, 0xB5, 0xE2, 0x30, 0x82, 0xFF, 0x84, 0x62, 0xBA, 0x4E, 0x96, 0x90, 0xD8, 0x98, 0xDD, 0x5D, 0x0C, 0xC8, 0x52, 0x43, 0x91, 0x1D, 0xF8,
|
||||
0x6E, 0x68, 0x2F, 0x35, 0xDA, 0x14, 0xEA, 0xCD, 0x76, 0x19, 0x8D, 0xD5, 0x80, 0xD1, 0x33, 0x87, 0x13, 0x57, 0x18, 0x2D, 0x29, 0x78, 0xC3
|
||||
};
|
||||
|
||||
//interleaver pattern
|
||||
const uint16_t intrl_seq[368]=
|
||||
{
|
||||
0, 137, 90, 227, 180, 317, 270, 39, 360, 129, 82, 219, 172, 309, 262, 31,
|
||||
352, 121, 74, 211, 164, 301, 254, 23, 344, 113, 66, 203, 156, 293, 246, 15,
|
||||
336, 105, 58, 195, 148, 285, 238, 7, 328, 97, 50, 187, 140, 277, 230, 367,
|
||||
320, 89, 42, 179, 132, 269, 222, 359, 312, 81, 34, 171, 124, 261, 214, 351,
|
||||
304, 73, 26, 163, 116, 253, 206, 343, 296, 65, 18, 155, 108, 245, 198, 335,
|
||||
288, 57, 10, 147, 100, 237, 190, 327, 280, 49, 2, 139, 92, 229, 182, 319,
|
||||
272, 41, 362, 131, 84, 221, 174, 311, 264, 33, 354, 123, 76, 213, 166, 303,
|
||||
256, 25, 346, 115, 68, 205, 158, 295, 248, 17, 338, 107, 60, 197, 150, 287,
|
||||
240, 9, 330, 99, 52, 189, 142, 279, 232, 1, 322, 91, 44, 181, 134, 271,
|
||||
224, 361, 314, 83, 36, 173, 126, 263, 216, 353, 306, 75, 28, 165, 118, 255,
|
||||
208, 345, 298, 67, 20, 157, 110, 247, 200, 337, 290, 59, 12, 149, 102, 239,
|
||||
192, 329, 282, 51, 4, 141, 94, 231, 184, 321, 274, 43, 364, 133, 86, 223,
|
||||
176, 313, 266, 35, 356, 125, 78, 215, 168, 305, 258, 27, 348, 117, 70, 207,
|
||||
160, 297, 250, 19, 340, 109, 62, 199, 152, 289, 242, 11, 332, 101, 54, 191,
|
||||
144, 281, 234, 3, 324, 93, 46, 183, 136, 273, 226, 363, 316, 85, 38, 175,
|
||||
128, 265, 218, 355, 308, 77, 30, 167, 120, 257, 210, 347, 300, 69, 22, 159,
|
||||
112, 249, 202, 339, 292, 61, 14, 151, 104, 241, 194, 331, 284, 53, 6, 143,
|
||||
96, 233, 186, 323, 276, 45, 366, 135, 88, 225, 178, 315, 268, 37, 358, 127,
|
||||
80, 217, 170, 307, 260, 29, 350, 119, 72, 209, 162, 299, 252, 21, 342, 111,
|
||||
64, 201, 154, 291, 244, 13, 334, 103, 56, 193, 146, 283, 236, 5, 326, 95,
|
||||
48, 185, 138, 275, 228, 365, 318, 87, 40, 177, 130, 267, 220, 357, 310, 79,
|
||||
32, 169, 122, 259, 212, 349, 302, 71, 24, 161, 114, 251, 204, 341, 294, 63,
|
||||
16, 153, 106, 243, 196, 333, 286, 55, 8, 145, 98, 235, 188, 325, 278, 47
|
||||
};
|
||||
|
||||
#endif
|
Ładowanie…
Reference in New Issue