mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-05 22:57:47 -04:00
Bit tools.
This commit is contained in:
parent
4d83ca105c
commit
cb4352a996
36
plugins/channel/lora/lorabits.h
Normal file
36
plugins/channel/lora/lorabits.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
Interleaving is "easiest" if the same number of bits is used per symbol as for FEC
|
||||||
|
Chosen mode "spreading 8, low rate" has 6 bits per symbol, so use 4:6 FEC
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Needs adjusting for different sizes
|
||||||
|
void interleave(short* inout)
|
||||||
|
{
|
||||||
|
int i, index = 6;
|
||||||
|
short in[index * 2];
|
||||||
|
for (i = 0; i < index; i++)
|
||||||
|
in[i] = inout[i];
|
||||||
|
for (i = 0; i < index; i++) {
|
||||||
|
inout[i] = (1 & in[0 + i]) | (2 & in[1 + i]) | (4 & in[2 + i])
|
||||||
|
| (8 & in[3 + i]) | (16 & in[4 + i]) | (32 & in[5 + i]);
|
||||||
|
in[i + index] = in[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Same sequence for any size
|
||||||
|
void make_gray(void)
|
||||||
|
{
|
||||||
|
short gray[1<<8];
|
||||||
|
// short ungray[1<<8];
|
||||||
|
short k = 0;
|
||||||
|
for (short i = 0; i < 1<<8; i++) {
|
||||||
|
gray[i] = k;
|
||||||
|
// ungray[k] = i;
|
||||||
|
short r = (i+1) & ~i;
|
||||||
|
k ^= r;
|
||||||
|
}
|
||||||
|
// for (short i = 0; i < 1<<5; i++)
|
||||||
|
// printf("%x:%x:%x.\n", i, gray[i], ungray[gray[i]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -40,6 +40,7 @@ LoRaDemod::LoRaDemod(SampleSink* sampleSink) :
|
|||||||
m_bin = 0;
|
m_bin = 0;
|
||||||
m_result = 0;
|
m_result = 0;
|
||||||
m_count = 0;
|
m_count = 0;
|
||||||
|
m_header = 0;
|
||||||
|
|
||||||
loraFilter = new sfft(LORA_SFFT_LEN);
|
loraFilter = new sfft(LORA_SFFT_LEN);
|
||||||
negaFilter = new sfft(LORA_SFFT_LEN);
|
negaFilter = new sfft(LORA_SFFT_LEN);
|
||||||
@ -64,8 +65,8 @@ void LoRaDemod::configure(MessageQueue* messageQueue, Real Bandwidth)
|
|||||||
|
|
||||||
int LoRaDemod::detect(Complex c, Complex a)
|
int LoRaDemod::detect(Complex c, Complex a)
|
||||||
{
|
{
|
||||||
int i;
|
int i, result, negresult;
|
||||||
float peak;
|
float peak, negpeak;
|
||||||
float mag[LORA_SFFT_LEN];
|
float mag[LORA_SFFT_LEN];
|
||||||
float rev[LORA_SFFT_LEN];
|
float rev[LORA_SFFT_LEN];
|
||||||
|
|
||||||
@ -77,18 +78,21 @@ int LoRaDemod::detect(Complex c, Complex a)
|
|||||||
// process spectrum every 32 samples
|
// process spectrum every 32 samples
|
||||||
loraFilter->fetch(mag);
|
loraFilter->fetch(mag);
|
||||||
negaFilter->fetch(rev);
|
negaFilter->fetch(rev);
|
||||||
peak = 0.0f;
|
peak = negpeak = 0.0f;
|
||||||
m_result = 0;
|
result = negresult = 0;
|
||||||
for (i = 0; i < LORA_SFFT_LEN; i++) {
|
for (i = 0; i < LORA_SFFT_LEN; i++) {
|
||||||
if (rev[i]/3 > peak) {
|
if (rev[i] > negpeak) {
|
||||||
peak = rev[i]/3;
|
negpeak = rev[i];
|
||||||
m_result = i;
|
negresult = i;
|
||||||
}
|
}
|
||||||
if (mag[i] > peak) {
|
if (mag[i] > peak) {
|
||||||
peak = mag[i];
|
peak = mag[i];
|
||||||
m_result = i;
|
result = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (peak > negpeak) {
|
||||||
|
m_result = result;
|
||||||
|
}
|
||||||
return m_result;
|
return m_result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,10 @@
|
|||||||
#include "util/message.h"
|
#include "util/message.h"
|
||||||
#include "dsp/fftfilt.h"
|
#include "dsp/fftfilt.h"
|
||||||
|
|
||||||
#define SPREADFACTOR (1<<8)
|
#define DATA_BITS (6)
|
||||||
|
#define SAMPLEBITS (DATA_BITS + 2)
|
||||||
/* Chosen for number of bins, not symbol length */
|
#define SPREADFACTOR (1 << SAMPLEBITS)
|
||||||
#define LORA_SFFT_LEN (128)
|
#define LORA_SFFT_LEN (SPREADFACTOR / 2)
|
||||||
|
|
||||||
class LoRaDemod : public SampleSink {
|
class LoRaDemod : public SampleSink {
|
||||||
public:
|
public:
|
||||||
@ -73,6 +73,7 @@ private:
|
|||||||
int m_bin;
|
int m_bin;
|
||||||
int m_result;
|
int m_result;
|
||||||
int m_count;
|
int m_count;
|
||||||
|
int m_header;
|
||||||
|
|
||||||
sfft* loraFilter;
|
sfft* loraFilter;
|
||||||
sfft* negaFilter;
|
sfft* negaFilter;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user