1 /*
2 * Copyright (c) 2007 - 2015 Joseph Gaeddert
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23 //
24 // modem_ook.c
25 //
26
27 #include <stdio.h>
28 #include <assert.h>
29 #include <math.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "liquid.internal.h"
34
35 // create an ook (on/off keying) modem object
MODEM(_create_ook)36 MODEM() MODEM(_create_ook)()
37 {
38 MODEM() q = (MODEM()) malloc( sizeof(struct MODEM(_s)) );
39 q->scheme = LIQUID_MODEM_OOK;
40
41 MODEM(_init)(q, 1);
42
43 q->modulate_func = &MODEM(_modulate_ook);
44 q->demodulate_func = &MODEM(_demodulate_ook);
45
46 // reset and return
47 MODEM(_reset)(q);
48 return q;
49 }
50
51 // modulate symbol using on/off keying
MODEM(_modulate_ook)52 void MODEM(_modulate_ook)(MODEM() _q,
53 unsigned int _sym_in,
54 float complex * _y)
55 {
56 // compute output sample directly from input
57 *_y = _sym_in ? 0.0f : M_SQRT2;
58 }
59
60 // demodulate OOK
MODEM(_demodulate_ook)61 void MODEM(_demodulate_ook)(MODEM() _q,
62 float complex _x,
63 unsigned int * _sym_out)
64 {
65 // slice directly to output symbol
66 *_sym_out = (crealf(_x) > M_SQRT1_2 ) ? 0 : 1;
67
68 // re-modulate symbol and store state
69 MODEM(_modulate_ook)(_q, *_sym_out, &_q->x_hat);
70 _q->r = _x;
71 }
72
73