Редизайн на основе текущей ветки мейнстрима + новые устройства.
[rtl-433.git] / include / baseband.h
1 /**
2  * Baseband
3  * 
4  * Various functions for baseband sample processing
5  *
6  * Copyright (C) 2012 by Benjamin Larsson <benjamin@southpole.se>
7  * Copyright (C) 2015 Tommy Vestermark
8  * 
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  */
14
15 #ifndef INCLUDE_BASEBAND_H_
16 #define INCLUDE_BASEBAND_H_
17
18 #include <stdint.h>
19
20 /// This will give a noisy envelope of OOK/ASK signals
21
22 /// Subtract the bias (-128) and get an envelope estimation (absolute squared)
23 /// @param *iq_buf: input samples (I/Q samples in interleaved uint8)
24 /// @param *y_buf: output 
25 /// @param len: number of samples to process
26 void envelope_detect(const uint8_t *iq_buf, uint16_t *y_buf, uint32_t len);
27
28 #define FILTER_ORDER 1
29
30 /// Filter state buffer
31 typedef struct {
32         int16_t y[FILTER_ORDER];
33         int16_t x[FILTER_ORDER];
34 } FilterState;
35
36 /// FM_Demod state buffer
37 typedef struct {
38         int16_t br, bi;         // Last I/Q sample
39         int16_t xlp, ylp;       // Low-pass filter state
40 } DemodFM_State;
41
42 /// Lowpass filter
43 ///
44 /// Function is stateful
45 /// @param *x_buf: input samples to be filtered
46 /// @param *y_buf: output from filter
47 /// @param len: number of samples to process
48 /// @param FilterState: State to store between chunk processing
49 void baseband_low_pass_filter(const uint16_t *x_buf, int16_t *y_buf, uint32_t len, FilterState *state);
50
51 /// FM demodulator
52 ///
53 /// Function is stateful
54 /// @param *x_buf: input samples (I/Q samples in interleaved uint8)
55 /// @param *y_buf: output from FM demodulator
56 /// @param len: number of samples to process
57 /// @param DemodFM_State: State to store between chunk processing
58 void baseband_demod_FM(const uint8_t *x_buf, int16_t *y_buf, unsigned num_samples, DemodFM_State *state);
59
60 /// Initialize tables and constants
61 /// Should be called once at startup
62 void baseband_init(void);
63
64 /// Dump binary data (for debug purposes)
65 void baseband_dumpfile(const uint8_t *buf, uint32_t len);
66
67 #endif /* INCLUDE_BASEBAND_H_ */