윤보민

last change of receiver part

1 #include <iostream> 1 #include <iostream>
2 #include "myMatrix.h" 2 #include "myMatrix.h"
3 using namespace std; 3 using namespace std;
4 -void scalarmult(int n, int m, float a, float *b, float *c){ 4 +
5 - int N = n*m; 5 +float dot(int N, float*C, float*D) {
6 - for(int i=0;i<N;i++) c[i] = a*b[i]; 6 + float sum = 0.0;
7 + for (int i = 0; i < N; i++) sum += C[i] * D[i];
8 + return sum;
9 +}
10 +void scalarmult(int n, int m, float a, float *b, float *c) {
11 + int N = n * m;
12 + for (int i = 0; i<N; i++) c[i] = a * b[i];
13 +}
14 +void matrixadd(int n, int m, float *a, float *b, float *c) {
15 + int N = n * m;
16 + for (int i = 0; i<N; i++) c[i] = a[i] + b[i];
7 } 17 }
8 -void matrixadd(int n, int m, float *a, float *b, float *c){
9 - int N = n*m;
10 - for (int i = 0; i<N; i++) c[i] = a[i]+b[i];
11 -}
12 // (N by K) C X (K by M) D = (N by M) E 18 // (N by K) C X (K by M) D = (N by M) E
13 void matrixmult(int N, int K, int M, float*C, float*D, float*E) { 19 void matrixmult(int N, int K, int M, float*C, float*D, float*E) {
14 int n, k, m; 20 int n, k, m;
...@@ -43,7 +49,7 @@ int GaussElimination(int N, float *a, float *b) ...@@ -43,7 +49,7 @@ int GaussElimination(int N, float *a, float *b)
43 b[j] -= b[i] * aji; 49 b[j] -= b[i] * aji;
44 }// if(i!=j) 50 }// if(i!=j)
45 } // other rows 51 } // other rows
46 - //showequation(N, a, b); 52 + //showequation(N, a, b);
47 } 53 }
48 return 0; 54 return 0;
49 } 55 }
......
1 -void scalarmult(int n, int m, float a, float *b, float *c); 1 +void scalarmult(int n, int m, float a, float *b, float *c);
2 -void matrixadd(int n, int m, float *a, float *b, float *c); 2 +void matrixadd(int n, int m, float *a, float *b, float *c);
3 void matrixmult(int N, int K, int M, float*C, float*D, float*E); 3 void matrixmult(int N, int K, int M, float*C, float*D, float*E);
4 +float dot(int N, float*C, float*D);
4 int GaussElimination(int, float*, float*); 5 int GaussElimination(int, float*, float*);
5 -void showMatrix(int n, int m, float* F); 6 +void showMatrix(int n, int m, float* F);
6 void showMatrix(char*name, int n, int m, float* F); 7 void showMatrix(char*name, int n, int m, float* F);
7 void showequation(int N, float *a, float *b); 8 void showequation(int N, float *a, float *b);
...\ No newline at end of file ...\ No newline at end of file
......
1 #include "receiver.h" 1 #include "receiver.h"
2 - 2 +#include "myMatrix.h"
3 -Creceiver::Creceiver() {} 3 +Creceiver::Creceiver() {
4 - 4 + float t = 0.0, T = 0.01;
5 -void Creceiver::demodulate() { 5 + float dt = T / Nsamplespersymbol;
6 - 6 + c0t = new float[Nsamplespersymbol];
7 - T = Nsamplespersymbol; 7 + c1t = new float[Nsamplespersymbol];
8 - float c0[Nsamplespersymbol], c1[Nsamplespersymbol]; 8 + for (int i = 0; i < Nsamplespersymbol; i++, t += dt) {
9 - for (int i = 1; i <= Nsamplespersymbol; i++) { 9 + c0t[i] = cos(2.*3.141592*t / T);
10 - c0[i - 1] = sqrt(2 / T) * cos(2 * PI / T * i); 10 + c1t[i] = sin(2.*3.141592*t / T);
11 - c1[i - 1] = sqrt(2 / T) * sin(2 * PI / T * i);
12 - }
13 - float temp0[1], temp1[1];
14 - for (int i = 0; i < Nbits / 2; i++) {
15 - matrixmult(1, Nsamplespersymbol, 1, r + (Nbitspersymbol * i), c0, temp0);
16 - matrixmult(1, Nsamplespersymbol, 1, r + (Nbitspersymbol * i), c1, temp1);
17 - constellation[2 * i] = temp0[0];
18 - constellation[2 * i + 1] = temp1[0];
19 } 11 }
20 - for (int j = 0; j < Nbits; j++) { 12 +}
21 - if (constellation[j] >= 0) DecodedData[j] = '0'; 13 +void Creceiver::demodulate() {
22 - else DecodedData[j] = '1'; 14 + int nn = Nsamplespersymbol / Nbitspersymbol;
15 + for (int i = 0; i < Nbits; i += 2) {
16 + int symbol = detectSymbol(constellation + i, r + i * nn);
17 + if (symbol == 0) { DecodedData[i] = 0; DecodedData[i + 1] = 0; }
18 + else if (symbol == 1) { DecodedData[i] = 1; DecodedData[i + 1] = 0; }
19 + else if (symbol == 2) { DecodedData[i] = 1; DecodedData[i + 1] = 1; }
20 + else { DecodedData[i] = 0; DecodedData[i + 1] = 1; }
23 } 21 }
24 - 22 +}
23 +int Creceiver::detectSymbol(float *co, float* rr) {
24 + float dummy[Nbitspersymbol];
25 + co[0] = dot(Nsamplespersymbol, rr, c0t);
26 + co[1] = dot(Nsamplespersymbol, rr, c1t);
27 + if (co[0] >= 0 && co[1] >= 0) return 0;
28 + else if (co[0] < 0 && co[1] >= 0) return 1;
29 + else if (co[0] < 0 && co[1] < 0) return 2;
30 + return 3;
25 } 31 }
...\ No newline at end of file ...\ No newline at end of file
......
1 #ifndef __RECEIVER 1 #ifndef __RECEIVER
2 -
3 #define __RECEIVER 2 #define __RECEIVER
4 -#define PI 3.141592
5 #include <cmath> 3 #include <cmath>
6 -#include <fstream>
7 #include "variables.h" 4 #include "variables.h"
8 -#include "myMatrix.h"
9 class Creceiver { 5 class Creceiver {
10 public: 6 public:
11 - float T;
12 Creceiver(); 7 Creceiver();
13 float *r; // corrupted signal = received signal 8 float *r; // corrupted signal = received signal
14 float constellation[Nbits]; 9 float constellation[Nbits];
15 char DecodedData[Nbits]; 10 char DecodedData[Nbits];
16 void demodulate(); 11 void demodulate();
12 + int detectSymbol(float *, float *);
13 + float *c0t, *c1t;
17 }; 14 };
18 -
19 -#endif
...\ No newline at end of file ...\ No newline at end of file
15 +#endif
......