-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdsp.hpp
More file actions
94 lines (80 loc) · 4.45 KB
/
dsp.hpp
File metadata and controls
94 lines (80 loc) · 4.45 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
#include <cstddef>
#include <cstdint>
#define PI 3.1415926535897932384626433
// misc
#define SAMPLE_RATE 48000
#define CARRIER_FRQ 18000
// chirp as preamble
#define PREAM_BODY 65536
#define BUBBLE_BODY 256
#define CARRIER_BODY 65536
// symbol
#define SYMBOL_BODY 512
// fir lpf: kaiser win, fs=48k, fpass=797, fstop=1385, ripple=0.5db, attenuation=30db
#define LPF_COEF {0.000124664045870304, 0.000394491129554808, 0.000684033264406025, 0.000987636274658144, 0.00129875773563981, 0.00161006837151945, 0.00191358197480440, 0.00220081000588834, 0.00246294075623155, 0.00269103818573058, 0.00287625868804753, 0.00301007856614888, 0.00308453035540879, 0.00309244147501886, 0.00302766798995435, 0.00288532115519047, 0.00266197882592678, 0.00235587405040860, 0.00196706037968397, 0.00149754434823990, 0.000951382506173104, 0.000334737851517275, -0.000344105879776180, -0.00107477628625929, -0.00184489111416042, -0.00264018424786627, -0.00344467908143997, -0.00424090726301074, -0.00501016853377223, -0.00573283154517412, -0.00638866610825062, -0.00695720640942454, -0.00741813192144036, -0.00775166787207127, -0.00793899036943913, -0.00796262640506029, -0.00780685152858496, -0.00745806470513344, -0.00690513756126165, -0.00613972963765264, -0.00515656173229218, -0.00395364407449961, -0.00253244349732995, -0.000897998164873570, 0.000941035163123161, 0.00297239725477994, 0.00518031092360616, 0.00754563184455037, 0.0100460648536682, 0.0126564437523484, 0.0153490668162704, 0.0180940944701433, 0.0208599809557199, 0.0236139558255672, 0.0263225305825472, 0.0289520286023617, 0.0314691327512264, 0.0338414162397385, 0.0360378995537758, 0.0380295440554619, 0.0397897511720657, 0.0412948206067085, 0.0425243377685547, 0.0434615388512611, 0.0440935865044594, 0.0444117970764637, 0.0444117970764637, 0.0440935865044594, 0.0434615388512611, 0.0425243377685547, 0.0412948206067085, 0.0397897511720657, 0.0380295440554619, 0.0360378995537758, 0.0338414162397385, 0.0314691327512264, 0.0289520286023617, 0.0263225305825472, 0.0236139558255672, 0.0208599809557199, 0.0180940944701433, 0.0153490668162704, 0.0126564437523484, 0.0100460648536682, 0.00754563184455037, 0.00518031092360616, 0.00297239725477994, 0.000941035163123161, -0.000897998164873570, -0.00253244349732995, -0.00395364407449961, -0.00515656173229218, -0.00613972963765264, -0.00690513756126165, -0.00745806470513344, -0.00780685152858496, -0.00796262640506029, -0.00793899036943913, -0.00775166787207127, -0.00741813192144036, -0.00695720640942454, -0.00638866610825062, -0.00573283154517412, -0.00501016853377223, -0.00424090726301074, -0.00344467908143997, -0.00264018424786627, -0.00184489111416042, -0.00107477628625929, -0.000344105879776180, 0.000334737851517275, 0.000951382506173104, 0.00149754434823990, 0.00196706037968397, 0.00235587405040860, 0.00266197882592678, 0.00288532115519047, 0.00302766798995435, 0.00309244147501886, 0.00308453035540879, 0.00301007856614888, 0.00287625868804753, 0.00269103818573058, 0.00246294075623155, 0.00220081000588834, 0.00191358197480440, 0.00161006837151945, 0.00129875773563981, 0.000987636274658144, 0.000684033264406025, 0.000394491129554808, 0.000124664045870304}
#define LPF_LEN 132
// typedefs
typedef struct {
union {
float L;
float I;
};
union {
float R;
float Q;
};
} sample_t;
typedef enum {
MOD_BPSK = 0, // 1 bit/sym
MOD_QPSK = 1, // 2 bit/sym
MOD_QAM16 = 2, // 4 bit/sym
MOD_OFDM_BPSK = 4, // 16 bit/sym
MOD_OFDM_QPSK = 5, // 32 bit/sym
MOD_OFDM_QAM16 = 6, // 64 bit/sym
} mod_t;
typedef int8_t int1_t;
typedef int8_t int2_t;
typedef int8_t int4_t;
typedef union {
int1_t bpsk;
int2_t qpsk;
int4_t qam16;
int16_t ofdm_bpsk;
int32_t ofdm_qpsk;
int64_t ofdm_qam16;
} sym_t;
// declarations
class fir_filter {
public:
fir_filter();
~fir_filter();
void init(const float* const, int); // initialize coefficients
void clear(); // clear z
sample_t filter(const sample_t&);
private:
void* data;
};
class biquad_filter {
public:
biquad_filter();
~biquad_filter();
void init(const float*);
void clear();
sample_t filter(const sample_t&);
private:
void* data;
};
class ofdm_modem {
public:
ofdm_modem();
~ofdm_modem();
sample_t* const fdd; // x16, freq-domain data
sample_t* const tdd; // x512, time-domain data
void modulate(void);
void demodulate(void);
private:
void* data;
};
float chirp(size_t);
float fast_exp(float);