Open mutouyueliang opened 8 years ago
I'm still confusing about it. Anybody could explain how could it demodulate the bluetooth signal which modulated by GFSK?
The given C code represents a function called demod_byte
that takes an array of IQ samples (IQ_TYPE* rxp
), the number of bytes to demodulate (int num_byte
), and an output array to store the demodulated bytes (uint8_t *out_byte
).
Let's break down the function and understand its functionality:
Initialization:
i
, j
, I0
, Q0
, I1
, Q1
, bit_decision
, and sample_idx
.i
and j
are loop counters used in the subsequent loops.sample_idx
keeps track of the current position in the rxp
array.Byte Demodulation Loop:
num_byte
times).out_byte[i] = 0
).Bit Demodulation Loop:
j<8
).rxp
array.
I0
and Q0
store the real and imaginary parts of the current sample (rxp[sample_idx]
and rxp[sample_idx+1]
).I1
and Q1
store the real and imaginary parts of the next sample (rxp[sample_idx+2]
and rxp[sample_idx+3]
).(I0*Q1 - I1*Q0)
is greater than 0, bit_decision
is set to 1; otherwise, it is set to 0.j
positions and combined with the existing bits using a bitwise OR operation (out_byte[i] = out_byte[i] | (bit_decision<<j)
).sample_idx
to point to the next symbol in the rxp
array by incrementing it by SAMPLE_PER_SYMBOL*2
.
SAMPLE_PER_SYMBOL
indicates the number of IQ samples per symbol, and the multiplication by 2 accounts for the real and imaginary parts.Return:
out_byte
array, which is passed by reference.In summary, this code performs demodulation of IQ samples to recover binary data. It processes the IQ samples in chunks of four (I0, Q0, I1, Q1) and calculates a bit decision based on the difference between the products of consecutive samples. The bit decisions are combined to form bytes, which are then stored in the output array.
Hi Xianjun, Function demod_bits(a, num_bits, sample_per_symbol) implements the way how ADC samples is converted to bits.
1: Could you explain why the following code is able to determine the bit is 0 or 1:
2: If sample_per_symbol is 4, just the first two samples are used to determine the bit value of the symbol as showed in function demo_bits(). What's the purpose of the other two samples? Will they be just discarded?