Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[b92126]: src / genqamdemod.cc Maximize Restore History

Download this file

genqamdemod.cc    114 lines (105 with data), 3.3 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
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//Copyright (C) 2006 Charalampos C. Tsimenidis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see
// <http://www.gnu.org/licenses/>.
#include <octave/oct.h>
#include <octave/ov-fcn.h>
DEFUN_DLD (genqamdemod, args, ,
"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {@var{y} =} genqamdemod (@var{x}, @var{C})\n\
General quadrature amplitude demodulation. The complex envelope\n\
quadrature amplitude modulated signal @var{x} is demodulated using a\n\
constellation mapping specified by the 1D vector @var{C}.\n\
@end deftypefn")
{
octave_value retval;
int i, j, m;
double tmp1, tmp2;
if (args.length () != 2)
{
print_usage ();
return retval;
}
int nr1 (args(0).rows ());
int nc1 (args(0).columns ());
int arg_is_empty1 = empty_arg ("genqamdemod", nr1, nc1);
Matrix y (nr1,nc1);
int nr2 (args(1).rows ());
int nc2 (args(1).columns ());
int M = (nr2>nc2)?nr2:nc2;
if (arg_is_empty1 < 0)
return retval;
if (arg_is_empty1 > 0)
return octave_value (Matrix ());
if (args(0).is_real_type () && args(1).is_real_type ())
{ // Real-valued signal & constellation
Matrix x (args(0).matrix_value ());
ColumnVector constellation (args(1).vector_value ());
for (i = 0;i < nr1;i++)
{
for (j = 0;j < nc1;j++)
{
tmp1 = fabs (x(i,j)-constellation(0));
y(i,j) = 0;
for (m = 1; m < M;m++)
{
tmp2 = fabs (x(i,j)-constellation(m));
if (tmp2 < tmp1)
{
y(i,j) = m;
tmp1 = tmp2;
}
}
}
}
}
else if (args(0).is_complex_type () || args(1).is_complex_type ())
{ // Complex-valued input & constellation
ComplexMatrix x (args(0).complex_matrix_value ());
ComplexColumnVector constellation (args(1).complex_vector_value ());
if (!error_state)
{
for (i = 0;i < nr1;i++)
{
for (j = 0;j < nc1;j++)
{
tmp1 = abs (x(i,j)-constellation(0));
y(i,j) = 0;
for (m = 1;m < M;m++)
{
tmp2 = abs (x(i,j)-constellation(m));
if (tmp2 < tmp1)
{
y(i,j) = m;
tmp1 = tmp2;
}
}
}
}
}
else
print_usage ();
}
else
{
print_usage ();
}
return retval = y;
}
/*
%% Test input validation
%!error genqamdemod ()
%!error genqamdemod (1)
%!error genqamdemod (1, 2, 3)
*/