root/experimental/components/Demodulator/src/DemodulatorDSP.cpp @ 3996

Revision 3996, 3.6 KB (checked in by jgaeddert, 6 years ago)

Adding functionality to Demodulator methods

  • Property svn:eol-style set to native
Line 
1/****************************************************************************
2
3Copyright 2007 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE Demodulator.
6
7OSSIE Demodulator is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12OSSIE Demodulator is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OSSIE Demodulator; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21****************************************************************************/
22
23
24#include <iostream>
25#include "DemodulatorDSP.h"
26#include <math.h>
27
28// Default constructor
29DemodulatorDSP::DemodulatorDSP()
30{
31    bitsPerSymbol = 1;
32    Demodulate = &DemodulateBPSK;
33    state_i = 0;
34    state_q = 0;
35}
36
37// Destructor
38DemodulatorDSP::~DemodulatorDSP()
39{
40}
41
42// Set modulation scheme
43void DemodulatorDSP::SetModulationScheme( ModulationScheme _ms )
44{
45    switch ( _ms ) {
46    case MOD_BPSK:
47        Demodulate = &DemodulateBPSK;
48        bitsPerSymbol = 1;
49        break;
50    case MOD_QPSK:
51        Demodulate = &DemodulateQPSK;
52        bitsPerSymbol = 2;
53        break;
54    case MOD_8PSK:
55        Demodulate = &Demodulate8PSK;
56        bitsPerSymbol = 3;
57        break;
58    case MOD_16QAM:
59        Demodulate = &Demodulate16QAM;
60        bitsPerSymbol = 4;
61        break;
62    case MOD_4PAM:
63        Demodulate = &Demodulate4PAM;
64        bitsPerSymbol = 2;
65        break;
66    case MOD_DBPSK:
67        state_i = 0;
68        state_q = 0;
69        Demodulate = &DemodulateBPSK;
70        bitsPerSymbol = 1;
71        break;
72    case MOD_DQPSK:
73        state_i = 0;
74        state_q = 0;
75        Demodulate = &DemodulateQPSK;
76        bitsPerSymbol = 2;
77        break;
78    case MOD_D8PSK:
79        state_i = 0;
80        state_q = 0;
81        Demodulate = &Demodulate8PSK;
82        bitsPerSymbol = 3;
83        break;
84    default:
85        std::cerr << "ERROR: DemodulatorDSP::SetModulationScheme(): "
86                  << "unknown mod. scheme " << _ms << std::endl;
87        std::cerr << "  => Using BPSK instead" << std::endl;
88        SetModulationScheme( MOD_BPSK );
89        //throw 0;
90    }
91   
92    mod_scheme = _ms;
93}
94
95///
96void DemodulatorDSP::DemodulateSequence(
97        short * I_in,
98        short * Q_in,
99        unsigned int N_in,
100        char * bits_out)
101{
102    unsigned int j(0);
103    for (unsigned int i=0; i<N_in; i++) {
104        Demodulate(I_in[i], Q_in[i], bits_out+j);
105        j += bitsPerSymbol;
106    }
107}
108
109
110//
111void DemodulateBPSK(
112    short & I_in,
113    short & Q_in,
114    char * bits_out)
115{
116    bits_out[0] = ( I_in > 0 ) ? BIT1 : BIT0;
117}
118
119//
120void DemodulateQPSK(
121    short & I_in,
122    short & Q_in,
123    char * bits_out)
124{
125    bits_out[0] = ( I_in > 0 ) ? BIT1 : BIT0;
126    bits_out[1] = ( Q_in > 0 ) ? BIT1 : BIT0;
127}
128
129//
130void Demodulate8PSK(
131    short & I_in,
132    short & Q_in,
133    char * bits_out)
134{
135    std::cerr << "ERROR: Demodulate8PSK not yet supported!" << std::endl;
136    throw 0;
137}
138
139//
140void Demodulate16QAM(
141    short & I_in,
142    short & Q_in,
143    char * bits_out)
144{
145    std::cerr << "ERROR: Demodulate16QAM not yet supported!" << std::endl;
146    throw 0;
147}
148
149//
150void Demodulate4PAM(
151    short & I_in,
152    short & Q_in,
153    char * bits_out)
154{
155    std::cerr << "ERROR: Demodulate4PAM not yet supported!" << std::endl;
156    throw 0;
157}
158
159
Note: See TracBrowser for help on using the browser.