summaryrefslogtreecommitdiff
path: root/controller/fw/src/dsss_demod.h
blob: 30ec3f7dff372615762cd2af6a09be5b30572712 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef __DSSS_DEMOD_H__
#define __DSSS_DEMOD_H__

#define DSSS_GOLD_CODE_LENGTH   ((1<<DSSS_GOLD_CODE_NBITS) - 1)
#define DSSS_GOLD_CODE_COUNT    ((1<<DSSS_GOLD_CODE_NBITS) + 1)
#define DSSS_CORRELATION_LENGTH (DSSS_GOLD_CODE_LENGTH * DSSS_DECIMATION)

#define PAYLOAD_DATA_BYTE ((PAYLOAD_DATA_BIT+7)/8)

struct iir_biquad {
    float a[2];
    float b[3];
};

struct iir_biquad_state {
    float reg[2];
};

struct cwt_iir_filter_state {
    struct iir_biquad_state st[3];
};

struct {
    int len; /* length of group in samples */
    float max; /* signed value of largest peak in group on any channel */
    uint64_t max_ts; /* absolute position of above peak */
    int max_ch; /* channel (gold sequence index) of above peak */
} group;

struct decoder_state {
    int last_phase;
    int candidate_phase;

    float last_score;
    float candidate_score;

    uint8_t data[PAYLOAD_DATA_BYTE]; 
    int data_pos;
};

struct dsss_demod_state {
    float signal[DSSS_CORRELATION_LENGTH];
    size_t signal_wpos;

    float correlation[DSSS_GOLD_CODE_COUNT][DSSS_WAVELET_LUT_SIZE];
    size_t correlation_wpos;

    struct cwt_iir_filter_state cwt_filter[DSSS_GOLD_CODE_COUNT];

    struct group group;

    struct group group_cache[DSSS_GROUP_CACHE_SIZE];
};

#ifdef SIMULATION
void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts, int record_channel);
#else /* SIMULATION */
void dsss_demod_step(struct dsss_demod_state *st, float new_value, uint64_t ts);
#endif /* SIMULATION */

#endif /* __DSSS_DEMOD_H__ */