]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/qamdemod.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / qamdemod.m
1 ## Copyright (C) 2007 Sylvain Pelissier <sylvain.pelissier@gmail.com>
2 ## Copyright (C) 2009 Christian Neumair <cneumair@gnome.org>
3 ##
4 ## This program is free software; you can redistribute it and/or modify it under
5 ## the terms of the GNU General Public License as published by the Free Software
6 ## Foundation; either version 3 of the License, or (at your option) any later
7 ## version.
8 ##
9 ## This program is distributed in the hope that it will be useful, but WITHOUT
10 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 ## details.
13 ##
14 ## You should have received a copy of the GNU General Public License along with
15 ## this program; if not, see <http://www.gnu.org/licenses/>.
16
17 ## -*- texinfo -*-
18 ## @deftypefn {Function File} qamdemod (@var{x},@var{m})
19 ## Create the QAM demodulation of x with a size of alphabet m.
20 ## @seealso{qammod,pskmod,pskdemod}
21 ## @end deftypefn
22
23 function z = qamdemod(y,m)
24     if(nargin < 2)
25         usage('y = qamdemod(x,m)');
26         exit;
27    end
28     
29     c = sqrt(m);
30     if(c ~= fix(c)  || log2(c) ~= fix(log2(c)))
31         error('m must be a square of a power of 2');
32     end
33     
34     x = qammod(0:(m-1),m);
35     x = reshape(x,1,m);
36     z = zeros(size(y));
37     for k = 1:numel(y)
38         [n z(k)] = min(abs(y(k) - x));
39     end
40     z = z - 1;