]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/genqammod.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / genqammod.m
1 ## Copyright (C) 2006 Charalampos C. Tsimenidis
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{y} =} genqammod (@var{x}, @var{c})
18 ##
19 ## Modulates an information sequence of intergers @var{x} in the range
20 ## @code{[0 @dots{} M-1]} onto a quadrature amplitude modulated signal 
21 ## @var{y}, where  @code{M = length(c) - 1} and @var{c} is a 1D vector 
22 ## specifing the signal constellation mapping to be used. An example of
23 ## combined 4PAM-4PSK is
24 ##
25 ## @example
26 ## @group
27 ##  d = randint(1,1e4,8);
28 ##  c = [1+j -1+j -1-j 1-j 1+sqrt(3) j*(1+sqrt(3)) -1-sqrt(3) -j*(1+sqrt(3))];
29 ##  y = genqammod(d,c);
30 ##  z = awgn(y,20);
31 ##  plot(z,'rx')
32 ## @end group
33 ## @end example
34 ## @end deftypefn
35 ## @seealso{genqamdemod}
36
37 function y=genqammod(x,c)
38
39 if nargin<2
40         usage("y = genqammod (x, c)");   
41 endif    
42
43 m=0:length(c)-1;
44 if ~isempty(find(ismember(x,m)==0))
45         error("x elements should be integers in the set [0, length(c)-1].");
46 endif   
47
48 y=c(x+1);
49
50 %!assert(genqammod([0:7],[-7:2:7]),[-7:2:7])
51 %!assert(genqammod([0:7],[-7 -5 -1 -3 7 5 1 3]),[-7 -5 -1 -3 7 5 1 3])