-
Notifications
You must be signed in to change notification settings - Fork 1
/
channel.h
83 lines (69 loc) · 1.89 KB
/
channel.h
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
/*
* File: channel.h
* Author: masoud
*
* Created on February 13, 2012, 7:42 PM
*/
#ifndef CHANNEL_H
#define CHANNEL_H
#include <vector>
typedef double LLRType;
//#define mylog logf
//#define myexp expf
#define mylog log
#define myexp exp
class Channel{
public:
double param;
void *ch;
Channel(double p);
inline unsigned int roundPseudoCodeword(const LLRType* solution, unsigned int length){
unsigned int c=0;
for(unsigned int i=0;i<length;i++)
c+=solution[i]>0.5;
return c;
}
inline void roundPseudoCodeword(const LLRType* solution, bool* rounded, unsigned int length){
for(unsigned int i=0;i<length;i++){
rounded[i]=solution[i]>0.5;
}
}
virtual double capacity(double)=0;
virtual double capacity()=0;
virtual double setCapacity(double)=0;
virtual unsigned int transmitzero(std::vector<LLRType>& llr)=0;
virtual unsigned int transmitzero(LLRType* llr, unsigned int length)=0;
//virtual void decode(const std::vector<LLRType>& llr,std::vector<bool>)=0;
virtual void print()=0;
};
class BSC: public Channel{
public:
BSC(double );
~BSC();
double capacity(double);
double capacity(){return capacity(param);}
unsigned int transmitzero(std::vector<LLRType>& llr);
unsigned int transmitzero(LLRType* llr, unsigned int length);
//void decode(const std::vector<LLRType>& llr,std::vector<bool>);
double setCapacity(double);
void print();
};
//parameter is SNR in dB
class AWGN: public Channel{
private:
double variance;
public:
AWGN(double );
~AWGN();
double capacity(){return capacity(param);}
double capacity(double);
unsigned int transmitzero(std::vector<LLRType>& llr);
unsigned int transmitzero(LLRType* llr, unsigned int N);
//void decode(const std::vector<LLRType>& llr,std::vector<bool>);
double setCapacity(double);
static inline double SNRtoVariance(double p){
return std::sqrt(std::pow(10,-p/10));
}
void print();
};
#endif /* CHANNEL_H */